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(); }