diff --git a/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java b/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java index b22c07dfbf..ed6b60f46b 100644 --- a/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java +++ b/Mage.Client/src/main/java/mage/client/remote/CallbackClientImpl.java @@ -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("joinedTable")) { + } 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")) { TableClientMessage message = (TableClientMessage) callback.getData(); joinedTable(message.getRoomId(), message.getTableId(), message.getFlag()); } diff --git a/Mage.Common/src/log4j.properties b/Mage.Common/config/log4j.properties similarity index 100% rename from Mage.Common/src/log4j.properties rename to Mage.Common/config/log4j.properties diff --git a/Mage.Common/src/mage/interfaces/MageServer.java b/Mage.Common/src/mage/interfaces/MageServer.java index dc9d9d038f..3dd9c192e6 100644 --- a/Mage.Common/src/mage/interfaces/MageServer.java +++ b/Mage.Common/src/mage/interfaces/MageServer.java @@ -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 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; diff --git a/Mage.Common/src/mage/remote/Session.java b/Mage.Common/src/mage/remote/Session.java index 66c2f1d6bb..2ef6bd1bbe 100644 --- a/Mage.Common/src/mage/remote/Session.java +++ b/Mage.Common/src/mage/remote/Session.java @@ -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()) { diff --git a/Mage.Server.Console/src/main/java/mage/server/console/ConnectDialog.java b/Mage.Server.Console/src/main/java/mage/server/console/ConnectDialog.java index 6b78bd83b6..a18518efd8 100644 --- a/Mage.Server.Console/src/main/java/mage/server/console/ConnectDialog.java +++ b/Mage.Server.Console/src/main/java/mage/server/console/ConnectDialog.java @@ -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()); - connection.setProxyHost(this.txtProxyServer.getText()); - connection.setProxyPort(Integer.valueOf(this.txtProxyPort.getText())); - connection.setProxyUsername(this.txtProxyUserName.getText()); - connection.setProxyPassword(new String(this.txtPasswordField.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(); diff --git a/Mage.Server.Console/src/main/java/mage/server/console/ConsoleFrame.form b/Mage.Server.Console/src/main/java/mage/server/console/ConsoleFrame.form index 950fd48075..caae29505a 100644 --- a/Mage.Server.Console/src/main/java/mage/server/console/ConsoleFrame.form +++ b/Mage.Server.Console/src/main/java/mage/server/console/ConsoleFrame.form @@ -56,6 +56,19 @@ + + + + + + + + + + + + + diff --git a/Mage.Server.Console/src/main/java/mage/server/console/ConsoleFrame.java b/Mage.Server.Console/src/main/java/mage/server/console/ConsoleFrame.java index 7b6afe5a27..dfa32ab257 100644 --- a/Mage.Server.Console/src/main/java/mage/server/console/ConsoleFrame.java +++ b/Mage.Server.Console/src/main/java/mage/server/console/ConsoleFrame.java @@ -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; diff --git a/Mage.Server/src/main/java/mage/server/ChatManager.java b/Mage.Server/src/main/java/mage/server/ChatManager.java index 4d2bcabc4f..62586ecfcf 100644 --- a/Mage.Server/src/main/java/mage/server/ChatManager.java +++ b/Mage.Server/src/main/java/mage/server/ChatManager.java @@ -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; /** * diff --git a/Mage.Server/src/main/java/mage/server/MageServerImpl.java b/Mage.Server/src/main/java/mage/server/MageServerImpl.java index c330fb5877..58ca705872 100644 --- a/Mage.Server/src/main/java/mage/server/MageServerImpl.java +++ b/Mage.Server/src/main/java/mage/server/MageServerImpl.java @@ -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 { diff --git a/Mage.Server/src/main/java/mage/server/Session.java b/Mage.Server/src/main/java/mage/server/Session.java index 8c30ae2f06..d5a72b048f 100644 --- a/Mage.Server/src/main/java/mage/server/Session.java +++ b/Mage.Server/src/main/java/mage/server/Session.java @@ -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(); }