From 1791b809db55670498ca4c6f3127f509a9dd98a1 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Tue, 1 Nov 2016 23:02:11 +0100 Subject: [PATCH] Added some more info to some logger and game messages. Removed unused method. --- .../src/mage/interfaces/MageServer.java | 7 --- Mage.Common/src/mage/remote/SessionImpl.java | 55 ++++++++++--------- .../main/java/mage/server/MageServerImpl.java | 7 --- .../src/main/java/mage/server/Main.java | 46 +++++++++++----- .../main/java/mage/server/SessionManager.java | 6 +- .../main/java/mage/server/UserManager.java | 2 +- 6 files changed, 63 insertions(+), 60 deletions(-) diff --git a/Mage.Common/src/mage/interfaces/MageServer.java b/Mage.Common/src/mage/interfaces/MageServer.java index 947cc83531..d9702a1254 100644 --- a/Mage.Common/src/mage/interfaces/MageServer.java +++ b/Mage.Common/src/mage/interfaces/MageServer.java @@ -62,16 +62,9 @@ public interface MageServer { boolean resetPassword(String sessionId, String email, String authToken, String password) throws MageException; - // connection methods - // DEPRECATED - Use connectUser instead. This is only kept for older clients. - // This can be deleted once users transitioned to newer clients (1.4.6v1 and later). - boolean registerClient(String userName, String sessionId, MageVersion version) throws MageException; - boolean connectUser(String userName, String password, String sessionId, MageVersion version) throws MageException; boolean connectAdmin(String password, String sessionId, MageVersion version) throws MageException; -// Not used -// void deregisterClient(String sessionId) throws MageException; // update methods List getMissingExpansionData(List codes); diff --git a/Mage.Common/src/mage/remote/SessionImpl.java b/Mage.Common/src/mage/remote/SessionImpl.java index b3a43bdf38..9acb85673d 100644 --- a/Mage.Common/src/mage/remote/SessionImpl.java +++ b/Mage.Common/src/mage/remote/SessionImpl.java @@ -214,33 +214,34 @@ public class SessionImpl implements Session { @Override public synchronized boolean connect(final Connection connection) { - return establishJBossRemotingConnection(connection) && handleRemotingTaskExceptions(new RemotingTask() { - @Override - public boolean run() throws Throwable { - logger.info("Trying to log-in as " + getUserName() + " to XMAGE server at " + connection.getHost() + ":" + connection.getPort()); - boolean registerResult; - if (connection.getAdminPassword() == null) { - // for backward compatibility. don't remove twice call - first one does nothing but for version checking - registerResult = server.connectUser(connection.getUsername(), connection.getPassword(), sessionId, client.getVersion()); - if (registerResult) { - server.setUserData(connection.getUsername(), sessionId, connection.getUserData(), client.getVersion().toString()); + return establishJBossRemotingConnection(connection) + && handleRemotingTaskExceptions(new RemotingTask() { + @Override + public boolean run() throws Throwable { + logger.info("Trying to log-in as " + getUserName() + " to XMAGE server at " + connection.getHost() + ":" + connection.getPort()); + boolean registerResult; + if (connection.getAdminPassword() == null) { + // for backward compatibility. don't remove twice call - first one does nothing but for version checking + registerResult = server.connectUser(connection.getUsername(), connection.getPassword(), sessionId, client.getVersion()); + if (registerResult) { + server.setUserData(connection.getUsername(), sessionId, connection.getUserData(), client.getVersion().toString()); + } + } else { + registerResult = server.connectAdmin(connection.getAdminPassword(), sessionId, client.getVersion()); + } + if (registerResult) { + serverState = server.getServerState(); + if (!connection.getUsername().equals("Admin")) { + updateDatabase(connection.isForceDBComparison(), serverState); + } + logger.info("Logged-in as " + getUserName() + " to MAGE server at " + connection.getHost() + ":" + connection.getPort()); + client.connected(getUserName() + "@" + connection.getHost() + ":" + connection.getPort() + " "); + return true; + } + disconnect(false); + return false; } - } else { - registerResult = server.connectAdmin(connection.getAdminPassword(), sessionId, client.getVersion()); - } - if (registerResult) { - serverState = server.getServerState(); - if (!connection.getUsername().equals("Admin")) { - updateDatabase(connection.isForceDBComparison(), serverState); - } - logger.info("Logged-in as " + getUserName() + " to MAGE server at " + connection.getHost() + ":" + connection.getPort()); - client.connected(getUserName() + "@" + connection.getHost() + ":" + connection.getPort() + " "); - return true; - } - disconnect(false); - return false; - } - }); + }); } @Override @@ -489,7 +490,7 @@ public class SessionImpl implements Session { sessionState = SessionState.DISCONNECTED; logger.info("Disconnected ... "); if (askForReconnect) { - client.showError("Network error. You have been disconnected"); + client.showError("Network error. You have been disconnected from " + connection.getHost()); } client.disconnected(askForReconnect); // MageFrame with check to reconnect pingTime.clear(); diff --git a/Mage.Server/src/main/java/mage/server/MageServerImpl.java b/Mage.Server/src/main/java/mage/server/MageServerImpl.java index b2f2c51843..7b77141f30 100644 --- a/Mage.Server/src/main/java/mage/server/MageServerImpl.java +++ b/Mage.Server/src/main/java/mage/server/MageServerImpl.java @@ -182,13 +182,6 @@ public class MageServerImpl implements MageServer { return true; } - @Override - public boolean registerClient(String userName, String sessionId, MageVersion version) throws MageException { - // This method is deprecated, so just inform the server version. - logger.info("MageVersionException: userName=" + userName + ", version=" + version); - throw new MageVersionException(version, Main.getVersion()); - } - @Override public boolean connectUser(String userName, String password, String sessionId, MageVersion version) throws MageException { try { diff --git a/Mage.Server/src/main/java/mage/server/Main.java b/Mage.Server/src/main/java/mage/server/Main.java index e849916cef..f6c461cfd7 100644 --- a/Mage.Server/src/main/java/mage/server/Main.java +++ b/Mage.Server/src/main/java/mage/server/Main.java @@ -278,7 +278,7 @@ public class Main { StringBuilder sessionInfo = new StringBuilder(); User user = UserManager.getInstance().getUser(session.getUserId()); if (user != null) { - sessionInfo.append(user.getName()); + sessionInfo.append(user.getName()).append(" [").append(user.getGameInfo()).append("]"); } else { sessionInfo.append("[user missing] "); } @@ -309,9 +309,9 @@ public class Main { protected Connector connector; - public MageTransporterServer(InvokerLocator locator, Object target, String subsystem, MageServerInvocationHandler callback) throws Exception { + public MageTransporterServer(InvokerLocator locator, Object target, String subsystem, MageServerInvocationHandler serverInvocationHandler) throws Exception { super(locator, target, subsystem); - connector.addInvocationHandler("callback", callback); + connector.addInvocationHandler("callback", serverInvocationHandler); connector.setLeasePeriod(ConfigSettings.getInstance().getLeasePeriod()); connector.addConnectionListener(new ClientConnectionListener()); } @@ -332,18 +332,45 @@ public class Main { @Override public void setMBeanServer(MBeanServer server) { - + /** + * An MBean is a managed Java object, similar to a JavaBeans + * component, that follows the design patterns set forth in the JMX + * specification. An MBean can represent a device, an application, + * or any resource that needs to be managed. MBeans expose a + * management interface that consists of the following: + * + * A set of readable or writable attributes, or both. A set of + * invokable operations. A self-description. + * + */ + if (server != null) { + logger.info("Default domain: " + server.getDefaultDomain()); + } } @Override public void setInvoker(ServerInvoker invoker) { + logger.info("Invoker version: " + ((BisocketServerInvoker) invoker).getVersion()); ((BisocketServerInvoker) invoker).setSecondaryBindPort(ConfigSettings.getInstance().getSecondaryBindPort()); ((BisocketServerInvoker) invoker).setBacklog(ConfigSettings.getInstance().getBacklogSize()); ((BisocketServerInvoker) invoker).setNumAcceptThreads(ConfigSettings.getInstance().getNumAcceptThreads()); } + @Override + public void addListener(InvokerCallbackHandler callbackHandler) { + // Called for every client connecting to the server + ServerInvokerCallbackHandler handler = (ServerInvokerCallbackHandler) callbackHandler; + try { + String sessionId = handler.getClientSessionId(); + SessionManager.getInstance().createSession(sessionId, callbackHandler); + } catch (Throwable ex) { + logger.fatal("", ex); + } + } + @Override public Object invoke(final InvocationRequest invocation) throws Throwable { + // Called for every client connecting to the server (after add Listener) String sessionId = invocation.getSessionId(); Map map = invocation.getRequestPayload(); String host; @@ -357,17 +384,6 @@ public class Main { return null; } - @Override - public void addListener(InvokerCallbackHandler callbackHandler) { - ServerInvokerCallbackHandler handler = (ServerInvokerCallbackHandler) callbackHandler; - try { - String sessionId = handler.getClientSessionId(); - SessionManager.getInstance().createSession(sessionId, callbackHandler); - } catch (Throwable ex) { - logger.fatal("", ex); - } - } - @Override public void removeListener(InvokerCallbackHandler callbackHandler) { ServerInvokerCallbackHandler handler = (ServerInvokerCallbackHandler) callbackHandler; diff --git a/Mage.Server/src/main/java/mage/server/SessionManager.java b/Mage.Server/src/main/java/mage/server/SessionManager.java index 843aefe05b..ad824fdcc7 100644 --- a/Mage.Server/src/main/java/mage/server/SessionManager.java +++ b/Mage.Server/src/main/java/mage/server/SessionManager.java @@ -135,13 +135,13 @@ public class SessionManager { logger.debug("DISCONNECT " + reason.toString() + " - sessionId: " + sessionId); sessions.remove(sessionId); switch (reason) { - case Disconnected: + case Disconnected: // regular session end session.kill(reason); break; - case SessionExpired: + case SessionExpired: // session ends after no reconnect happens in the defined time span session.kill(reason); break; - case LostConnection: + case LostConnection: // user lost connection - session expires countdaoun starts session.userLostConnection(); break; default: diff --git a/Mage.Server/src/main/java/mage/server/UserManager.java b/Mage.Server/src/main/java/mage/server/UserManager.java index 160134edb0..867a17c25b 100644 --- a/Mage.Server/src/main/java/mage/server/UserManager.java +++ b/Mage.Server/src/main/java/mage/server/UserManager.java @@ -141,7 +141,7 @@ public class UserManager { @Override public void run() { try { - LOGGER.info("USER REMOVE - " + user.getName() + " (" + reason.toString() + ") userId: " + userId); + LOGGER.info("USER REMOVE - " + user.getName() + " (" + reason.toString() + ") userId: " + userId + " [" + user.getGameInfo() + "]"); user.remove(reason); LOGGER.debug("USER REMOVE END - " + user.getName()); } catch (Exception ex) {