// *************************************************************** // Function: VerifyConnectedGS.cpp // *************************************************************** #include "Main.h" #include "GameServerData.h" bool HashPassword(unsigned char* pSourceData, unsigned char* pDestBuf); bool RegisterGameServer(long* pIp, short port, long id, short maxPlayers); //************************************ // Name: VerifyConnectedGS // // Verifies that the game server sent the correct password and if so register the game server. // // Parameters: // pData - Network data // // Return: // //************************************ void VerifyConnectedGS(NetMessage* pData) { unsigned char MyPassHash[33]; memset(MyPassHash, 0, 33); //Hash this servers current gameserv authentication password HashPassword(gServerConfig.authorizationPassword, MyPassHash); //------------------------------------------------- //Compare the hashes. If they match send a message //and register the game server. //------------------------------------------------- if (memcmp(MyPassHash, pData->pData+2, 32)==0) { SOCKETINFO socket_info=gpInternalComm->GetClientById(pData->networkId); //Extract the player limit for the server short playerLimit=Read_uShort(pData->pData+38); //If the login server and game server are being run on the same IP char login_serv_ip[4]; gpLoginServer->GetIp(login_serv_ip); if (memcmp(login_serv_ip, socket_info.ip, 4)==0) { char game_serv_ip[4]={127, 0, 0, 1}; RegisterGameServer((long*)game_serv_ip, 1, pData->networkId, playerLimit); } //If true the login server will send players to the detected IP //If false the login server will send players to the IP the game server specifies when registering else if (gServerConfig.detectGameServIp) { RegisterGameServer((long*)socket_info.ip, 2, pData->networkId, playerLimit); } else { RegisterGameServer((long*)(pData->pData+2+32), 3, pData->networkId, playerLimit); } unsigned char packet[2]={LS_AUTHORIZATION_SUCCESS, 0x00}; NetMessage s; s.networkId=pData->networkId; s.Set(2, packet); gpInternalComm->SendData(&s); } //--------------------------------------------------------------- //If the password hash received does not match our password hash //--------------------------------------------------------------- else { //Send incorrect password packet unsigned char packet[2]={LS_INCORRECT_AUTH_PASS, 0x00}; NetMessage s; s.networkId=pData->networkId; s.Set(2, packet); gpInternalComm->SendData(&s); //Instruct the server to close the connection in 5 seconds NetMessage m(6000, 1, pData->networkId, 0); gpInternalComm->SendControl(&m); } } //************************************ // Name: RegisterGameServer // // Registers a game server with the login server. When registered a game server can be sent players and accessed from the admin console. // // Parameters: // pIp - Game server ip // port - Game server port // networkId - Connection network id // maxPlayers - Max players allowed on game server. // // Return: // true //************************************ bool RegisterGameServer(long* pIp, short port, long networkId, short maxPlayers) { GAMESERVER_DATA g_data; memcpy(g_data.ip, pIp, 4); g_data.port=port; g_data.networkId=networkId; g_data.isLocked=false; g_data.currentPlayers=0; g_data.maxPlayers=maxPlayers; if (port==1) { sprintf(g_data.mode, "Proxy"); } else if (port==2) { sprintf(g_data.mode, "Auto"); } else { sprintf(g_data.mode, "Manual"); } typedef pair gpair; gGameServers.insert(gpair(g_data.networkId, g_data)); gCoreLog.notice("Game Server: %d.%d.%d.%d : %s has been registered!", g_data.ip[0], g_data.ip[1], g_data.ip[2], g_data.ip[3], g_data.mode); return true; }