mirror of
https://github.com/correl/mage.git
synced 2025-01-12 11:08:01 +00:00
Added sending broadcast message to all users on server from Admin Console.
This commit is contained in:
parent
8536d9d78d
commit
bdb2754847
10 changed files with 114 additions and 33 deletions
|
@ -28,8 +28,6 @@
|
||||||
|
|
||||||
package mage.client.remote;
|
package mage.client.remote;
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
import javax.swing.SwingUtilities;
|
|
||||||
import mage.cards.decks.Deck;
|
import mage.cards.decks.Deck;
|
||||||
import mage.client.MageFrame;
|
import mage.client.MageFrame;
|
||||||
import mage.client.chat.ChatPanel;
|
import mage.client.chat.ChatPanel;
|
||||||
|
@ -46,6 +44,9 @@ import mage.utils.CompressUtil;
|
||||||
import mage.view.*;
|
import mage.view.*;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
@ -104,8 +105,16 @@ public class CallbackClientImpl implements CallbackClient {
|
||||||
panel.receiveMessage(message.getUsername(), message.getMessage(), message.getTime(), message.getColor());
|
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();
|
TableClientMessage message = (TableClientMessage) callback.getData();
|
||||||
joinedTable(message.getRoomId(), message.getTableId(), message.getFlag());
|
joinedTable(message.getRoomId(), message.getTableId(), message.getFlag());
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,16 +28,17 @@
|
||||||
|
|
||||||
package mage.interfaces;
|
package mage.interfaces;
|
||||||
|
|
||||||
import mage.game.match.MatchOptions;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.UUID;
|
|
||||||
import mage.MageException;
|
import mage.MageException;
|
||||||
import mage.cards.decks.DeckCardLists;
|
import mage.cards.decks.DeckCardLists;
|
||||||
import mage.game.GameException;
|
import mage.game.GameException;
|
||||||
|
import mage.game.match.MatchOptions;
|
||||||
import mage.game.tournament.TournamentOptions;
|
import mage.game.tournament.TournamentOptions;
|
||||||
import mage.utils.MageVersion;
|
import mage.utils.MageVersion;
|
||||||
import mage.view.*;
|
import mage.view.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
@ -120,6 +121,7 @@ public interface MageServer {
|
||||||
public List<UserView> getUsers(String sessionId) throws MageException;
|
public List<UserView> getUsers(String sessionId) throws MageException;
|
||||||
public void disconnectUser(String sessionId, String userSessionId) throws MageException;
|
public void disconnectUser(String sessionId, String userSessionId) throws MageException;
|
||||||
public void removeTable(String sessionId, UUID tableId) throws MageException;
|
public void removeTable(String sessionId, UUID tableId) throws MageException;
|
||||||
|
public void sendBroadcastMessage(String sessionId, String message) throws MageException;
|
||||||
|
|
||||||
// messages of the day
|
// messages of the day
|
||||||
public Object getServerMessagesCompressed(String sessionId) throws MageException;
|
public Object getServerMessagesCompressed(String sessionId) throws MageException;
|
||||||
|
|
|
@ -573,6 +573,20 @@ public class Session {
|
||||||
return false;
|
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) {
|
public boolean joinGame(UUID gameId) {
|
||||||
try {
|
try {
|
||||||
if (isConnected()) {
|
if (isConnected()) {
|
||||||
|
|
|
@ -34,7 +34,12 @@
|
||||||
|
|
||||||
package mage.server.console;
|
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.BufferedReader;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
@ -43,16 +48,6 @@ import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.CancellationException;
|
import java.util.concurrent.CancellationException;
|
||||||
import java.util.concurrent.ExecutionException;
|
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.setHost(this.txtServer.getText());
|
||||||
connection.setPort(Integer.valueOf(this.txtPort.getText()));
|
connection.setPort(Integer.valueOf(this.txtPort.getText()));
|
||||||
connection.setPassword(new String(txtPassword.getPassword()));
|
connection.setPassword(new String(txtPassword.getPassword()));
|
||||||
|
|
||||||
connection.setProxyType((ProxyType) this.cbProxyType.getSelectedItem());
|
connection.setProxyType((ProxyType) this.cbProxyType.getSelectedItem());
|
||||||
|
if (!this.cbProxyType.getSelectedItem().equals(ProxyType.NONE)) {
|
||||||
connection.setProxyHost(this.txtProxyServer.getText());
|
connection.setProxyHost(this.txtProxyServer.getText());
|
||||||
connection.setProxyPort(Integer.valueOf(this.txtProxyPort.getText()));
|
connection.setProxyPort(Integer.valueOf(this.txtProxyPort.getText()));
|
||||||
connection.setProxyUsername(this.txtProxyUserName.getText());
|
connection.setProxyUsername(this.txtProxyUserName.getText());
|
||||||
connection.setProxyPassword(new String(this.txtPasswordField.getPassword()));
|
connection.setProxyPassword(new String(this.txtPasswordField.getPassword()));
|
||||||
|
}
|
||||||
|
|
||||||
logger.debug("connecting: " + connection.getProxyType() + " " + connection.getProxyHost() + " " + connection.getProxyPort());
|
logger.debug("connecting: " + connection.getProxyType() + " " + connection.getProxyHost() + " " + connection.getProxyPort());
|
||||||
task = new ConnectTask();
|
task = new ConnectTask();
|
||||||
task.execute();
|
task.execute();
|
||||||
|
|
|
@ -56,6 +56,19 @@
|
||||||
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnConnectActionPerformed"/>
|
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="btnConnectActionPerformed"/>
|
||||||
</Events>
|
</Events>
|
||||||
</Component>
|
</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">
|
<Component class="javax.swing.JLabel" name="lblStatus">
|
||||||
<Properties>
|
<Properties>
|
||||||
<Property name="text" type="java.lang.String" value="Not Connected"/>
|
<Property name="text" type="java.lang.String" value="Not Connected"/>
|
||||||
|
|
|
@ -34,12 +34,6 @@
|
||||||
|
|
||||||
package mage.server.console;
|
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.MageClient;
|
||||||
import mage.interfaces.callback.ClientCallback;
|
import mage.interfaces.callback.ClientCallback;
|
||||||
import mage.remote.Connection;
|
import mage.remote.Connection;
|
||||||
|
@ -47,6 +41,10 @@ import mage.remote.Session;
|
||||||
import mage.utils.MageVersion;
|
import mage.utils.MageVersion;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
|
import javax.swing.*;
|
||||||
|
import java.util.UUID;
|
||||||
|
import java.util.prefs.Preferences;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
@ -103,11 +101,13 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
|
||||||
public void enableButtons() {
|
public void enableButtons() {
|
||||||
btnConnect.setEnabled(true);
|
btnConnect.setEnabled(true);
|
||||||
btnConnect.setText("Disconnect");
|
btnConnect.setText("Disconnect");
|
||||||
|
btnSendMessage.setEnabled(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void disableButtons() {
|
public void disableButtons() {
|
||||||
btnConnect.setEnabled(true);
|
btnConnect.setEnabled(true);
|
||||||
btnConnect.setText("Connect");
|
btnConnect.setText("Connect");
|
||||||
|
btnSendMessage.setEnabled(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** This method is called from within the constructor to
|
/** 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();
|
jToolBar1 = new javax.swing.JToolBar();
|
||||||
btnConnect = new javax.swing.JButton();
|
btnConnect = new javax.swing.JButton();
|
||||||
|
btnSendMessage = new javax.swing.JButton();
|
||||||
lblStatus = new javax.swing.JLabel();
|
lblStatus = new javax.swing.JLabel();
|
||||||
consolePanel1 = new mage.server.console.ConsolePanel();
|
consolePanel1 = new mage.server.console.ConsolePanel();
|
||||||
|
|
||||||
|
@ -140,6 +141,19 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
|
||||||
});
|
});
|
||||||
jToolBar1.add(btnConnect);
|
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");
|
lblStatus.setText("Not Connected");
|
||||||
jToolBar1.add(Box.createHorizontalGlue());
|
jToolBar1.add(Box.createHorizontalGlue());
|
||||||
jToolBar1.add(lblStatus);
|
jToolBar1.add(lblStatus);
|
||||||
|
@ -173,6 +187,13 @@ public class ConsoleFrame extends javax.swing.JFrame implements MageClient {
|
||||||
}
|
}
|
||||||
}//GEN-LAST:event_btnConnectActionPerformed
|
}//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
|
* @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
|
// Variables declaration - do not modify//GEN-BEGIN:variables
|
||||||
private javax.swing.JButton btnConnect;
|
private javax.swing.JButton btnConnect;
|
||||||
|
private javax.swing.JButton btnSendMessage;
|
||||||
private mage.server.console.ConsolePanel consolePanel1;
|
private mage.server.console.ConsolePanel consolePanel1;
|
||||||
private javax.swing.JToolBar jToolBar1;
|
private javax.swing.JToolBar jToolBar1;
|
||||||
private javax.swing.JLabel lblStatus;
|
private javax.swing.JLabel lblStatus;
|
||||||
|
|
|
@ -28,9 +28,10 @@
|
||||||
|
|
||||||
package mage.server;
|
package mage.server;
|
||||||
|
|
||||||
|
import mage.view.ChatMessage.MessageColor;
|
||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.ConcurrentHashMap;
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
import mage.view.ChatMessage.MessageColor;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
|
@ -36,6 +36,7 @@ import mage.game.tournament.TournamentOptions;
|
||||||
import mage.interfaces.Action;
|
import mage.interfaces.Action;
|
||||||
import mage.interfaces.MageServer;
|
import mage.interfaces.MageServer;
|
||||||
import mage.interfaces.ServerState;
|
import mage.interfaces.ServerState;
|
||||||
|
import mage.interfaces.callback.ClientCallback;
|
||||||
import mage.remote.MageVersionException;
|
import mage.remote.MageVersionException;
|
||||||
import mage.server.draft.DraftManager;
|
import mage.server.draft.DraftManager;
|
||||||
import mage.server.game.*;
|
import mage.server.game.*;
|
||||||
|
@ -45,8 +46,8 @@ import mage.server.util.ServerMessagesUtil;
|
||||||
import mage.server.util.ThreadExecutor;
|
import mage.server.util.ThreadExecutor;
|
||||||
import mage.utils.CompressUtil;
|
import mage.utils.CompressUtil;
|
||||||
import mage.utils.MageVersion;
|
import mage.utils.MageVersion;
|
||||||
import mage.view.ChatMessage.MessageColor;
|
|
||||||
import mage.view.*;
|
import mage.view.*;
|
||||||
|
import mage.view.ChatMessage.MessageColor;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -741,6 +742,22 @@ public class MageServerImpl implements MageServer {
|
||||||
return null;
|
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 {
|
protected void execute(final String sessionId, final Action action) throws MageException {
|
||||||
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
if (SessionManager.getInstance().isValidSession(sessionId)) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -28,8 +28,6 @@
|
||||||
|
|
||||||
package mage.server;
|
package mage.server;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.UUID;
|
|
||||||
import mage.MageException;
|
import mage.MageException;
|
||||||
import mage.interfaces.callback.ClientCallback;
|
import mage.interfaces.callback.ClientCallback;
|
||||||
import mage.players.net.UserData;
|
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.HandleCallbackException;
|
||||||
import org.jboss.remoting.callback.InvokerCallbackHandler;
|
import org.jboss.remoting.callback.InvokerCallbackHandler;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @author BetaSteward_at_googlemail.com
|
* @author BetaSteward_at_googlemail.com
|
||||||
|
@ -89,6 +90,9 @@ public class Session {
|
||||||
public void registerAdmin() {
|
public void registerAdmin() {
|
||||||
this.isAdmin = true;
|
this.isAdmin = true;
|
||||||
User user = UserManager.getInstance().createUser("Admin", host);
|
User user = UserManager.getInstance().createUser("Admin", host);
|
||||||
|
if (user == null) {
|
||||||
|
user = UserManager.getInstance().findUser("Admin");
|
||||||
|
}
|
||||||
user.setUserData(new UserData(UserGroup.ADMIN, 0));
|
user.setUserData(new UserData(UserGroup.ADMIN, 0));
|
||||||
this.userId = user.getId();
|
this.userId = user.getId();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue