From 526f0c09bc361492f6712a4dd8ae45c504e4cf0a Mon Sep 17 00:00:00 2001 From: BetaSteward Date: Sun, 26 Jun 2011 00:45:25 -0400 Subject: [PATCH] fixed client ip address --- Mage.Common/src/mage/remote/Session.java | 1 + Mage.Server/src/main/java/mage/server/Main.java | 7 +++++-- Mage.Server/src/main/java/mage/server/Session.java | 7 +++++-- Mage.Server/src/main/java/mage/server/SessionManager.java | 4 ++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/Mage.Common/src/mage/remote/Session.java b/Mage.Common/src/mage/remote/Session.java index dbafa22ede..55079d9de7 100644 --- a/Mage.Common/src/mage/remote/Session.java +++ b/Mage.Common/src/mage/remote/Session.java @@ -145,6 +145,7 @@ public class Session { callbackMetadata.put(Bisocket.IS_CALLBACK_SERVER, "true"); CallbackHandler callbackHandler = new CallbackHandler(); callbackClient.addListener(callbackHandler, callbackMetadata); + callbackClient.invoke(""); this.sessionId = callbackClient.getSessionId(); boolean registerResult = false; diff --git a/Mage.Server/src/main/java/mage/server/Main.java b/Mage.Server/src/main/java/mage/server/Main.java index 6d94fd4488..fe9321b9a3 100644 --- a/Mage.Server/src/main/java/mage/server/Main.java +++ b/Mage.Server/src/main/java/mage/server/Main.java @@ -53,6 +53,7 @@ import org.jboss.remoting.ClientDisconnectedException; import org.jboss.remoting.ConnectionListener; import org.jboss.remoting.InvocationRequest; import org.jboss.remoting.InvokerLocator; +import org.jboss.remoting.Remoting; import org.jboss.remoting.ServerInvocationHandler; import org.jboss.remoting.ServerInvoker; import org.jboss.remoting.callback.InvokerCallbackHandler; @@ -175,6 +176,9 @@ public class Main { @Override public Object invoke(final InvocationRequest invocation) throws Throwable { + String sessionId = invocation.getSessionId(); + InetAddress clientAddress = (InetAddress) invocation.getRequestPayload().get(Remoting.CLIENT_ADDRESS); + SessionManager.getInstance().getSession(sessionId).setHost(clientAddress.getHostAddress()); return null; } @@ -183,8 +187,7 @@ public class Main { ServerInvokerCallbackHandler handler = (ServerInvokerCallbackHandler) callbackHandler; try { String sessionId = handler.getClientSessionId(); - InetAddress clientAddress = handler.getCallbackClient().getAddressSeenByServer(); - SessionManager.getInstance().createSession(sessionId, callbackHandler, clientAddress.getHostAddress()); + SessionManager.getInstance().createSession(sessionId, callbackHandler); } catch (Throwable ex) { logger.fatal("", ex); } diff --git a/Mage.Server/src/main/java/mage/server/Session.java b/Mage.Server/src/main/java/mage/server/Session.java index b8376dcdc6..4134d6e625 100644 --- a/Mage.Server/src/main/java/mage/server/Session.java +++ b/Mage.Server/src/main/java/mage/server/Session.java @@ -55,10 +55,9 @@ public class Session { private boolean isAdmin = false; private AsynchInvokerCallbackHandler callbackHandler; - public Session(String sessionId, InvokerCallbackHandler callbackHandler, String host) { + public Session(String sessionId, InvokerCallbackHandler callbackHandler) { this.sessionId = sessionId; this.callbackHandler = (AsynchInvokerCallbackHandler) callbackHandler; - this.host = host; this.isAdmin = false; this.timeConnected = new Date(); } @@ -134,4 +133,8 @@ public class Session { public Date getConnectionTime() { return timeConnected; } + + void setHost(String hostAddress) { + this.host = hostAddress; + } } diff --git a/Mage.Server/src/main/java/mage/server/SessionManager.java b/Mage.Server/src/main/java/mage/server/SessionManager.java index 3219308fb8..79c9f23e69 100644 --- a/Mage.Server/src/main/java/mage/server/SessionManager.java +++ b/Mage.Server/src/main/java/mage/server/SessionManager.java @@ -57,8 +57,8 @@ public class SessionManager { return sessions.get(sessionId); } - public void createSession(String sessionId, InvokerCallbackHandler callbackHandler, String host) { - Session session = new Session(sessionId, callbackHandler, host); + public void createSession(String sessionId, InvokerCallbackHandler callbackHandler) { + Session session = new Session(sessionId, callbackHandler); sessions.put(sessionId, session); }