OSDN Git Service

Send the version information with the client registration
authorPSpeed42@gmail.com <PSpeed42@gmail.com@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Sat, 19 Mar 2011 07:31:58 +0000 (07:31 +0000)
committerPSpeed42@gmail.com <PSpeed42@gmail.com@75d07b2b-3a1a-0410-a2c5-0572b91ccdca>
Sat, 19 Mar 2011 07:31:58 +0000 (07:31 +0000)
and kick the client if they don't match.  Need to fix some
other things before the reason actually makes it to the
client before the socket is closed... but at least they'll
know something is wrong.

git-svn-id: http://jmonkeyengine.googlecode.com/svn/trunk@7041 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

engine/src/networking/com/jme3/network/base/DefaultClient.java
engine/src/networking/com/jme3/network/base/DefaultServer.java
engine/src/networking/com/jme3/network/message/ClientRegistrationMessage.java

index 85beb0a..0afb8f5 100644 (file)
@@ -41,6 +41,7 @@ import java.util.logging.Logger;
 
 import com.jme3.network.*;
 import com.jme3.network.message.ClientRegistrationMessage; //hopefully temporary
+import com.jme3.network.message.DisconnectMessage; //hopefully temporary
 import com.jme3.network.kernel.Connector;
 import com.jme3.network.serializing.Serializer;
 
@@ -137,6 +138,8 @@ public class DefaultClient implements Client
         if( reliable != null ) {
             reg = new ClientRegistrationMessage();
             reg.setId(tempId);
+            reg.setGameName(getGameName());
+            reg.setVersion(getVersion());
             reg.setReliable(true);
             send(reg);            
         }
@@ -264,6 +267,11 @@ public class DefaultClient implements Client
             log.log( Level.INFO, "Connection established, id:{0}.", this.id );
             fireConnected();
             return;
+        } if( m instanceof DisconnectMessage ) {
+            // Can't do too much else yet
+            String reason = ((DisconnectMessage)m).getReason();
+            log.log( Level.SEVERE, "Connection terminated, reason:{0}.", reason );
+            close();               
         }
     
         messageListeners.messageReceived( this, m );
index 2af45b0..3bdd321 100644 (file)
@@ -235,6 +235,7 @@ public class DefaultServer implements Server
     protected void registerClient( KernelAdapter ka, Endpoint p, ClientRegistrationMessage m )
     {
         Connection addedConnection = null;
+        Connection bootedConnection = null;
 
         // generally this will only be called by one thread but it's        
         // important enough I won't take chances
@@ -251,7 +252,7 @@ public class DefaultServer implements Server
             } else {
                 log.log( Level.FINE, "Refining client registration for endpoint:{0}.", p );
             } 
+          
             // Fill in what we now know       
             if( ka == fastAdapter ) {
                 c.fast = p;
@@ -264,6 +265,20 @@ public class DefaultServer implements Server
             } else {
                 // It must be the reliable one            
                 c.reliable = p;
+                // Validate the name and version which is only sent
+                // over the reliable connection at this point.
+                if( !getGameName().equals(m.getGameName()) 
+                    || getVersion() != m.getVersion() ) {
+                    log.log( Level.INFO, "Kicking client due to name/version mismatch:{0}.", c );
+            
+                    // Need to kick them off... I may regret doing this from within
+                    // the sync block but the alternative is more code
+                    c.close( "Server client mismatch, server:" + getGameName() + " v" + getVersion()
+                             + "  client:" + m.getGameName() + " v" + m.getVersion() );
+                    return;                        
+                }                                   
                 
                 if( c.fast == null && fastAdapter != null ) {
                     // Still waiting for the fast connection to
index b8a3df0..3af502b 100644 (file)
@@ -46,6 +46,8 @@ import com.jme3.network.serializing.Serializable;
 @Serializable()
 public class ClientRegistrationMessage extends Message {
     private long id;
+    private String gameName;
+    private int version;
 
     public long getId() {
         return id;
@@ -54,4 +56,20 @@ public class ClientRegistrationMessage extends Message {
     public void setId(long id) {
         this.id = id;
     }
+    
+    public void setGameName( String name ) {
+        this.gameName = name;
+    }
+    public String getGameName() {
+        return gameName;
+    }
+    
+    public void setVersion( int version ) {
+        this.version = version;
+    }
+    
+    public int getVersion() {
+        return version;
+    }
 }