use of de.gg.engine.network.message.SuccessfulHandshakeResponse in project ProjektGG by eskalon.
the class GameServer method onClientHandshake.
@Override
protected synchronized void onClientHandshake(Connection con, ClientHandshakeRequest msg) {
Short id = connections.get(con);
LobbyPlayer p;
if (!serverSetup.getVersion().equals(msg.getVersion())) {
Log.info("Server", "Kick: Version mismatch (%s)", msg.getVersion());
con.sendTCP(new FailedHandshakeResponse(Lang.get("dialog.connecting_failed.version_mismatch")));
con.close();
return;
}
if (savedGame != null) {
short foundId = -1;
for (Entry<Short, String> e : savedGame.clientIdentifiers.entrySet()) {
if (e.getValue().equals(msg.getHostname())) {
foundId = e.getKey();
break;
}
}
if (foundId == -1) {
Log.info("Server", "Kick: Client isn't part of this loaded save game");
con.sendTCP(new FailedHandshakeResponse(Lang.get("dialog.connecting_failed.not_in_save")));
con.close();
return;
} else {
if ((id == HOST_PLAYER_NETWORK_ID && foundId != HOST_PLAYER_NETWORK_ID) || (foundId == HOST_PLAYER_NETWORK_ID && id != HOST_PLAYER_NETWORK_ID)) {
// Host has hanged changed
Log.info("Server", "Kick: The host of a loaded save game cannot be changed");
con.sendTCP(new FailedHandshakeResponse(Lang.get("dialog.connecting_failed.cannot_change_host")));
con.close();
// Server gets closed if need be
return;
}
Log.info("Server", "Client was recognized as part of this loaded save game");
Player oldPlayer = savedGame.world.getPlayer(foundId);
Character oldCharacter = savedGame.world.getCharacter(oldPlayer.getCurrentlyPlayedCharacterId());
p = new LobbyPlayer(oldCharacter.getName(), oldCharacter.getSurname(), oldPlayer.getIcon(), -1, oldCharacter.isMale());
}
} else {
Log.info("Server", "Client %d was registered as new player", id);
p = PlayerUtils.getRandomPlayerWithUnusedProperties(playerStubs, players.values());
}
players.put(id, p);
// Inform the other clients
resultListener.onPlayerJoined(id, p);
// Establish RMI connection (part 1)
objectSpace.addConnection(con);
Log.info("Server", "RMI connection to client established");
// Perform the handshake
con.sendTCP(new SuccessfulHandshakeResponse(id));
}
Aggregations