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;
if( reliable != null ) {
reg = new ClientRegistrationMessage();
reg.setId(tempId);
+ reg.setGameName(getGameName());
+ reg.setVersion(getVersion());
reg.setReliable(true);
send(reg);
}
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 );
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
} else {
log.log( Level.FINE, "Refining client registration for endpoint:{0}.", p );
}
-
+
// Fill in what we now know
if( ka == fastAdapter ) {
c.fast = p;
} 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
@Serializable()
public class ClientRegistrationMessage extends Message {
private long id;
+ private String gameName;
+ private int version;
public long getId() {
return id;
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;
+ }
}