From a14df8a68f68b65115af611985c9598ff51c527b Mon Sep 17 00:00:00 2001 From: "PSp..om" Date: Sat, 19 Mar 2011 17:13:58 +0000 Subject: [PATCH] added disconnect information to the client state listener so that clients that care can know why they were booted, etc. git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@7043 75d07b2b-3a1a-0410-a2c5-0572b91ccdca --- .../com/jme3/network/ClientStateListener.java | 15 +++++++++++++-- .../com/jme3/network/base/DefaultClient.java | 10 +++++++--- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/engine/src/networking/com/jme3/network/ClientStateListener.java b/engine/src/networking/com/jme3/network/ClientStateListener.java index 271fdfba7..09f1577f3 100644 --- a/engine/src/networking/com/jme3/network/ClientStateListener.java +++ b/engine/src/networking/com/jme3/network/ClientStateListener.java @@ -50,7 +50,18 @@ public interface ClientStateListener /** * Called when the client has disconnected from the remote - * server. + * server. If info is null then the client shut down the + * connection normally, otherwise the info object contains + * additional information about the disconnect. */ - public void clientDisconnected( Client c ); + public void clientDisconnected( Client c, DisconnectInfo info ); + + /** + * Provided with the clientDisconnected() notification to + * include additional information about the disconnect. + */ + public class DisconnectInfo + { + public String reason; + } } diff --git a/engine/src/networking/com/jme3/network/base/DefaultClient.java b/engine/src/networking/com/jme3/network/base/DefaultClient.java index 0afb8f5c1..26a8d46f6 100644 --- a/engine/src/networking/com/jme3/network/base/DefaultClient.java +++ b/engine/src/networking/com/jme3/network/base/DefaultClient.java @@ -40,6 +40,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import com.jme3.network.*; +import com.jme3.network.ClientStateListener.DisconnectInfo; import com.jme3.network.message.ClientRegistrationMessage; //hopefully temporary import com.jme3.network.message.DisconnectMessage; //hopefully temporary import com.jme3.network.kernel.Connector; @@ -208,7 +209,7 @@ public class DefaultClient implements Client // Wait for the threads? - fireDisconnected(); + fireDisconnected(null); isRunning = false; } @@ -250,10 +251,10 @@ public class DefaultClient implements Client } } - protected void fireDisconnected() + protected void fireDisconnected( DisconnectInfo info ) { for( ClientStateListener l : stateListeners ) { - l.clientDisconnected( this ); + l.clientDisconnected( this, info ); } } @@ -271,6 +272,9 @@ public class DefaultClient implements Client // Can't do too much else yet String reason = ((DisconnectMessage)m).getReason(); log.log( Level.SEVERE, "Connection terminated, reason:{0}.", reason ); + DisconnectInfo info = new DisconnectInfo(); + info.reason = reason; + fireDisconnected(info); close(); }