GameServerTable gameServerTable = GameServerTable.getInstance();
int id = gameServerAuth.getDesiredID();
byte[] hexId = gameServerAuth.getHexID();
GameServerInfo gsi = gameServerTable.getRegisteredGameServerById(id);
// 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())
{
forceClose(LoginServerFail.REASON_ALREADY_LOGGED8IN);
}
else
{
attachGameServerInfo(gsi, gameServerAuth);
}
}
}
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 && gameServerAuth.acceptAlternateID())
{
gsi = new GameServerInfo(id, hexId, this);
if(gameServerTable.registerWithFirstAvaliableId(gsi))
{
attachGameServerInfo(gsi, gameServerAuth);
gameServerTable.registerServerOnDB(gsi);
}
else
{
forceClose(LoginServerFail.REASON_NO_FREE_ID);
}
}
else
{
// server id is already taken, and we cant get a new one for you
forceClose(LoginServerFail.REASON_WRONG_HEXID);
}
}
}
else
{
// can we register on this id?
if(Config.ACCEPT_NEW_GAMESERVER)
{
gsi = new GameServerInfo(id, hexId, this);
if(gameServerTable.register(id, gsi))
{
attachGameServerInfo(gsi, gameServerAuth);
gameServerTable.registerServerOnDB(gsi);