/**
* Recieves a player name, sent from a pending connection, and connects that
* connection.
*/
private void receivePlayerName(Packet packet, int connId) {
final IConnection conn = getPendingConnection(connId);
String name = (String) packet.getObject(0);
boolean returning = false;
// this had better be from a pending connection
if (conn == null) {
System.out.println("server: got a client name from a non-pending" + " connection");
return;
}
// check if they're connecting with the same name as a ghost player
for (Enumeration<Player> i = game.getPlayers(); i.hasMoreElements();) {
Player player = i.nextElement();
if (player.getName().equals(name)) {
if (player.isGhost()) {
returning = true;
player.setGhost(false);
// switch id
connId = player.getId();
conn.setId(connId);
}
}
}
if (!returning) {
// Check to avoid duplicate names...
name = correctDupeName(name);
send(connId, new Packet(Packet.COMMAND_SERVER_CORRECT_NAME, name));
}
// right, switch the connection into the "active" bin
connectionsPending.removeElement(conn);
connections.addElement(conn);
connectionIds.put(new Integer(conn.getId()), conn);
// add and validate the player info
if (!returning) {
int team = Player.TEAM_NONE;
for (Player p : game.getPlayersVector()) {