Added sending broadcast message to all users on server from Admin Console.

This commit is contained in:
magenoxx 2012-01-25 19:13:27 +04:00
parent 8536d9d78d
commit bdb2754847
10 changed files with 114 additions and 33 deletions

View file

@ -28,8 +28,6 @@
package mage.client.remote;
import java.util.UUID;
import javax.swing.SwingUtilities;
import mage.cards.decks.Deck;
import mage.client.MageFrame;
import mage.client.chat.ChatPanel;
@ -46,6 +44,9 @@ import mage.utils.CompressUtil;
import mage.view.*;
import org.apache.log4j.Logger;
import javax.swing.*;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
@ -104,8 +105,16 @@ public class CallbackClientImpl implements CallbackClient {
panel.receiveMessage(message.getUsername(), message.getMessage(), message.getTime(), message.getColor());
}
}
} else if (callback.getMethod().equals("serverMessage")) {
if (callback.getData() != null) {
ChatMessage message = (ChatMessage) callback.getData();
if (message.getColor().equals(ChatMessage.MessageColor.RED)) {
JOptionPane.showMessageDialog(null, message.getMessage(), "Server message", JOptionPane.WARNING_MESSAGE);
} else {
JOptionPane.showMessageDialog(null, message.getMessage(), "Server message", JOptionPane.INFORMATION_MESSAGE);
}
else if (callback.getMethod().equals("joinedTable")) {
}
} else if (callback.getMethod().equals("joinedTable")) {
TableClientMessage message = (TableClientMessage) callback.getData();
joinedTable(message.getRoomId(), message.getTableId(), message.getFlag());
}

View file

@ -28,16 +28,17 @@
package mage.interfaces;
import mage.game.match.MatchOptions;
import java.util.List;
import java.util.UUID;
import mage.MageException;
import mage.cards.decks.DeckCardLists;
import mage.game.GameException;
import mage.game.match.MatchOptions;
import mage.game.tournament.TournamentOptions;
import mage.utils.MageVersion;
import mage.view.*;
import java.util.List;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
@ -120,6 +121,7 @@ public interface MageServer {
public List<UserView> getUsers(String sessionId) throws MageException;
public void disconnectUser(String sessionId, String userSessionId) throws MageException;
public void removeTable(String sessionId, UUID tableId) throws MageException;
public void sendBroadcastMessage(String sessionId, String message) throws MageException;
// messages of the day
public Object getServerMessagesCompressed(String sessionId) throws MageException;

View file

@ -573,6 +573,20 @@ public class Session {
return false;
}
public boolean sendBroadcastMessage(String message) {
try {
if (isConnected()) {
server.sendBroadcastMessage(sessionId, message);
return true;
}
} catch (MageException ex) {
handleMageException(ex);
} catch (Throwable t) {
handleThrowable(t);
}
return false;
}
public boolean joinGame(UUID gameId) {
try {
if (isConnected()) {

View file

@ -34,7 +34,12 @@
package mage.server.console;
import java.awt.Cursor;
import mage.remote.Connection;
import mage.remote.Connection.ProxyType;
import org.apache.log4j.Logger;
import javax.swing.*;
import java.awt.*;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
@ -43,16 +48,6 @@ import java.util.Arrays;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.concurrent.ExecutionException;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.SwingWorker;
import mage.remote.Connection;
import mage.remote.Connection.ProxyType;
import org.apache.log4j.Logger;
/**
*
@ -416,11 +411,15 @@ public class ConnectDialog extends JDialog {
connection.setHost(this.txtServer.getText());
connection.setPort(Integer.valueOf(this.txtPort.getText()));
connection.setPassword(new String(txtPassword.getPassword()));
connection.setProxyType((ProxyType) this.cbProxyType.getSelectedItem());
if (!this.cbProxyType.getSelectedItem().equals(ProxyType.NONE)) {
connection.setProxyHost(this.txtProxyServer.getText());
connection.setProxyPort(Integer.valueOf(this.txtProxyPort.getText()));
connection.setProxyUsername(this.txtProxyUserName.getText());
connection.setProxyPassword(new String(this.txtPasswordField.getPassword()));
}
logger.debug("connecting: " + connection.getProxyType() + " " + connection.getProxyHost() + " " + connection.getProxyPort());
task = new ConnectTask();
task.execute();

View file

@ -56,6 +56,19 @@
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnConnectActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JButton" name="btnSendMessage">
<Properties>
<Property name="actionCommand" type="java.lang.String" value="SendMessage"/>
<Property name="enabled" type="boolean" value="false"/>
<Property name="focusable" type="boolean" value="false"/>
<Property name="horizontalTextPosition" type="int" value="0"/>
<Property name="label" type="java.lang.String" value="Send Message"/>
<Property name="verticalTextPosition" type="int" value="3"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnSendMessageActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="lblStatus">
<Properties>
<Property name="text" type="java.lang.String" value="Not Connected"/>

View file

@ -34,12 +34,6 @@
package mage.server.console;
import java.util.UUID;
import java.util.prefs.Preferences;
import javax.swing.Box;
import javax.swing.JOptionPane;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import mage.interfaces.MageClient;
import mage.interfaces.callback.ClientCallback;
import mage.remote.Connection;
@ -47,6 +41,10 @@ import mage.remote.Session;
import mage.utils.MageVersion;
import org.apache.log4j.Logger;
import javax.swing.*;
import java.util.UUID;
import java.util.prefs.Preferences;
/**
*
* @author BetaSteward_at_googlemail.com
@ -103,11 +101,13 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
public void enableButtons() {
btnConnect.setEnabled(true);
btnConnect.setText("Disconnect");
btnSendMessage.setEnabled(true);
}
public void disableButtons() {
btnConnect.setEnabled(true);
btnConnect.setText("Connect");
btnSendMessage.setEnabled(false);
}
/** This method is called from within the constructor to
@ -121,6 +121,7 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
jToolBar1 = new javax.swing.JToolBar();
btnConnect = new javax.swing.JButton();
btnSendMessage = new javax.swing.JButton();
lblStatus = new javax.swing.JLabel();
consolePanel1 = new mage.server.console.ConsolePanel();
@ -140,6 +141,19 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
});
jToolBar1.add(btnConnect);
btnSendMessage.setActionCommand("SendMessage");
btnSendMessage.setEnabled(false);
btnSendMessage.setFocusable(false);
btnSendMessage.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
btnSendMessage.setLabel("Send Message");
btnSendMessage.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
btnSendMessage.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
btnSendMessageActionPerformed(evt);
}
});
jToolBar1.add(btnSendMessage);
lblStatus.setText("Not Connected");
jToolBar1.add(Box.createHorizontalGlue());
jToolBar1.add(lblStatus);
@ -173,6 +187,13 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
}
}//GEN-LAST:event_btnConnectActionPerformed
private void btnSendMessageActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSendMessageActionPerformed
String message = JOptionPane.showInputDialog(null, "Type message to send", "Broadcast message", JOptionPane.INFORMATION_MESSAGE);
if (message != null) {
session.sendBroadcastMessage(message);
}
}//GEN-LAST:event_btnSendMessageActionPerformed
/**
* @param args the command line arguments
*/
@ -190,6 +211,7 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton btnConnect;
private javax.swing.JButton btnSendMessage;
private mage.server.console.ConsolePanel consolePanel1;
private javax.swing.JToolBar jToolBar1;
private javax.swing.JLabel lblStatus;

View file

@ -28,9 +28,10 @@
package mage.server;
import mage.view.ChatMessage.MessageColor;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import mage.view.ChatMessage.MessageColor;
/**
*

View file

@ -36,6 +36,7 @@ import mage.game.tournament.TournamentOptions;
import mage.interfaces.Action;
import mage.interfaces.MageServer;
import mage.interfaces.ServerState;
import mage.interfaces.callback.ClientCallback;
import mage.remote.MageVersionException;
import mage.server.draft.DraftManager;
import mage.server.game.*;
@ -45,8 +46,8 @@ import mage.server.util.ServerMessagesUtil;
import mage.server.util.ThreadExecutor;
import mage.utils.CompressUtil;
import mage.utils.MageVersion;
import mage.view.ChatMessage.MessageColor;
import mage.view.*;
import mage.view.ChatMessage.MessageColor;
import org.apache.log4j.Logger;
import java.util.ArrayList;
@ -741,6 +742,22 @@ public class MageServerImpl implements MageServer {
return null;
}
public void sendBroadcastMessage(final String sessionId, final String message) throws MageException {
execute(sessionId, new Action() {
public void execute() {
if (SessionManager.getInstance().isAdmin(sessionId) && message != null) {
for (User user: UserManager.getInstance().getUsers()) {
if (message.toLowerCase().startsWith("warn")) {
user.fireCallback(new ClientCallback("serverMessage", null, new ChatMessage("SERVER", message, null, MessageColor.RED)));
} else {
user.fireCallback(new ClientCallback("serverMessage", null, new ChatMessage("SERVER", message, null, MessageColor.BLUE)));
}
}
}
}
});
}
protected void execute(final String sessionId, final Action action) throws MageException {
if (SessionManager.getInstance().isValidSession(sessionId)) {
try {

View file

@ -28,8 +28,6 @@
package mage.server;
import java.util.Date;
import java.util.UUID;
import mage.MageException;
import mage.interfaces.callback.ClientCallback;
import mage.players.net.UserData;
@ -41,6 +39,9 @@ import org.jboss.remoting.callback.Callback;
import org.jboss.remoting.callback.HandleCallbackException;
import org.jboss.remoting.callback.InvokerCallbackHandler;
import java.util.Date;
import java.util.UUID;
/**
*
* @author BetaSteward_at_googlemail.com
@ -89,6 +90,9 @@ public class Session {
public void registerAdmin() {
this.isAdmin = true;
User user = UserManager.getInstance().createUser("Admin", host);
if (user == null) {
user = UserManager.getInstance().findUser("Admin");
}
user.setUserData(new UserData(UserGroup.ADMIN, 0));
this.userId = user.getId();
}