Send the version information with the client registration

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: https://jmonkeyengine.googlecode.com/svn/trunk@7041 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
3.0
PSp..om 14 years ago
parent 3087235def
commit b6b6175866
  1. 8
      engine/src/networking/com/jme3/network/base/DefaultClient.java
  2. 17
      engine/src/networking/com/jme3/network/base/DefaultServer.java
  3. 18
      engine/src/networking/com/jme3/network/message/ClientRegistrationMessage.java

@ -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 );

@ -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

@ -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;
}
}

Loading…
Cancel
Save