{
protocolVersion = 0;
}
log.info("Trying to register server: " + requestId + ", " + getGameServer().getConnectionIpAddress());
AttGS client = getGameServer();
GameServerTable gameServerTable = GameServerTable.getInstance();
GameServerInfo gsi = gameServerTable.getRegisteredGameServerById(requestId);
// is there a gameserver registered with this id?
if(gsi != null)
{
// does the hex id match?
if(Arrays.equals(gsi.getHexId(), hexId))
// check to see if this GS is already connected
{
synchronized(gsi)
{
if(gsi.isAuthed())
{
sendPacket(new LoginServerFail(LoginServerFail.REASON_ALREADY_LOGGED8IN));
}
else
{
client.setGameServerInfo(gsi);
gsi.setGameServer(client);
gsi.setPorts(ports);
gsi.setGameHosts(externalIp, internalIp, advIpList);
gsi.setMaxPlayers(maxOnline);
gsi.setAuthed(true);
}
}
}
else // there is already a server registered with the desired id and different hex id
// try to register this one with an alternative id
if(Config.ACCEPT_NEW_GAMESERVER && acceptAlternateID)
{
gsi = new GameServerInfo(requestId, hexId, client);
if(gameServerTable.registerWithFirstAvailableId(gsi))
{
client.setGameServerInfo(gsi);
gsi.setGameServer(client);
gsi.setPorts(ports);
gsi.setGameHosts(externalIp, internalIp, advIpList);
gsi.setMaxPlayers(maxOnline);
gsi.setAuthed(true);
if(reserveHostOnLogin)
{
gameServerTable.registerServerOnDB(gsi);
}
}
else
{
sendPacket(new LoginServerFail(LoginServerFail.REASON_NO_FREE_ID));
}
}
else
// server id is already taken, and we cant get a new one for you
{
sendPacket(new LoginServerFail(LoginServerFail.REASON_WRONG_HEXID));
}
}
else if(Config.ACCEPT_NEW_GAMESERVER)
{
gsi = new GameServerInfo(requestId, hexId, client);
if(gameServerTable.register(requestId, gsi))
{
client.setGameServerInfo(gsi);
gsi.setGameServer(client);
gsi.setPorts(ports);
gsi.setGameHosts(externalIp, internalIp, advIpList);
gsi.setMaxPlayers(maxOnline);
gsi.setAuthed(true);
if(reserveHostOnLogin)
{
gameServerTable.registerServerOnDB(gsi);
}
}
else
// some one took this ID meanwhile
{