void LogonCommServerSocket::OnConnect() { if( !IsServerAllowed(GetRemoteAddress().s_addr) ) { printf("Server connection from %u(%s:%u) DENIED, not an allowed IP.\n", GetRemoteAddress().s_addr, GetIP(), GetPort()); Disconnect(); return; } sInfoCore.AddServerSocket(this); removed = false; }
void InformationCore::CheckServers() { serverSocketLock.Acquire(); set<LogonCommServerSocket*>::iterator itr, it2; LogonCommServerSocket * s; for(itr = m_serverSockets.begin(); itr != m_serverSockets.end();) { s = *itr; it2 = itr; ++itr; if(!IsServerAllowed(s->GetRemoteAddress().s_addr)) { DEBUG_LOG("LogonServer","Disconnecting socket: %s due to it no longer being on an allowed IP.\n", s->GetIP()); s->Disconnect(); } } serverSocketLock.Release(); }
HRESULT LobbyServerSite::OnAppMessage(FedMessaging * pthis, CFMConnection & cnxnFrom, FEDMESSAGE * pfm) { CFLServer * pServer = CFLServer::FromConnection(cnxnFrom); assert(pServer); cnxnFrom.ResetAbsentCount(); switch (pfm->fmid) { case FM_S_LOGON_LOBBY: { CASTPFM(pfmLogon, S, LOGON_LOBBY, pfm); pfmLogon->cbvStaticCoreInfo; char szRemote[16]; if (pfmLogon->verLobby == LOBBYVER_LS) { if(pfmLogon->dwPort != 0) // A port of 0 means the server couldn't find out its listening port pServer->SetServerPort(pfmLogon->dwPort); else pServer->SetServerPort(6073); // Tell the client to enum the old fashioned way //KGJV #114 // fill in StaticCoreInfo StaticCoreInfo* pcoreinfo = (StaticCoreInfo*)FM_VAR_REF(pfmLogon, vStaticCoreInfo); pServer->SetStaticCoreInfo(pfmLogon->cStaticCoreInfo, pcoreinfo); //Imago: reorganized some stuff to get a better debug message // location char * szLoc = FM_VAR_REF(pfmLogon, szLocation); pServer->SetLocation(szLoc); //Imago #2 6/10 char * szPrivilegedUsers = FM_VAR_REF(pfmLogon, szPrivilegedUsers); pServer->SetPrivilegedUsers(szPrivilegedUsers); //Imago #62 6/10 char * szVersion = FM_VAR_REF(pfmLogon, szServerVersion); pServer->SetVersion(szVersion); // max games pServer->SetMaxGamesAllowed(pfmLogon->MaxGames); // current games (allow servers to update) - Imago 6/25/08 pServer->SetCurrentGamesCount(pfmLogon->CurGames); // rebuild the master core list g_pLobbyApp->BuildStaticCoreInfo(); // break; mmf took out break so we can check ip below // KGJV moved mmf's stuff inside lobby version check // mmf add check to see if they are an allowed or blocked server pthis->GetIPAddress(cnxnFrom, szRemote); debugf("FM_S_LOGON_LOBBY: %s:%d loc:%s #games:%i\n",&szRemote,pfmLogon->dwPort,pServer->GetLocation(),pfmLogon->CurGames); if (!strncmp("127.0.0.1",szRemote,9)) break; // check for loopback and always allow if (IsServerAllowed(szRemote)) break; } char * szReason; // if we got this far we are not on the approved list fall through to reject below szReason = "Your server IP address is not approved for connection to this Lobby. Please contact the Lobby Admin."; //Imago fix typo 6/10 // end mmf if (pfmLogon->verLobby > LOBBYVER_LS) szReason = "The Public Lobby server that you connected to is older than your version. The Zone needs to update their lobby server. Please try again later."; if (pfmLogon->verLobby < LOBBYVER_LS) // mmf took out the else and made this an explicit if for above szReason szReason = "Your server's version did not get auto-updated properly. Please try again later."; BEGIN_PFM_CREATE(*pthis, pfmNewMissionAck, L, LOGON_SERVER_NACK) FM_VAR_PARM((char *)szReason, CB_ZTS) END_PFM_CREATE pthis->SendMessages(&cnxnFrom, FM_GUARANTEED, FM_FLUSH); pthis->DeleteConnection(cnxnFrom); break; } case FM_S_NEW_MISSION: { // a server has created a mission of their own volition. We need to map it into our "cookie space" CASTPFM(pfmNewMission, S, NEW_MISSION, pfm); CFLMission * pMission = pServer->CreateMission(NULL); // NULL = no client created this BEGIN_PFM_CREATE(*pthis, pfmNewMissionAck, L, NEW_MISSION_ACK) END_PFM_CREATE pfmNewMissionAck->dwIGCMissionID = pfmNewMission->dwIGCMissionID; pfmNewMissionAck->dwCookie = (DWORD) pMission; pthis->SendMessages(&cnxnFrom, FM_GUARANTEED, FM_FLUSH); // we won't broadcast it until the server sends us a lobby mission info, when it's good and ready debugf("FM_S_NEW_MISSION id:%d cookie:%d\n",pfmNewMissionAck->dwIGCMissionID,pfmNewMissionAck->dwCookie); } break; case FM_LS_LOBBYMISSIONINFO: { CASTPFM(pfmLobbyMissionInfo, LS, LOBBYMISSIONINFO, pfm); CFLMission * pMission = CFLMission::FromCookie(pfmLobbyMissionInfo->dwCookie); if (pMission) // if it's already gone away--just ignore it. { //Imago 6/26/08 //Moved this code inside the mission check //now the lobby does not crash trying to find a disconnected server's IP //KGJV #114 - server didnt fill szServerAddr but only reserved the bits. We fill it here. debugf("FM_LS_LOBBYMISSIONINFO:%d (pmission:%x cookie:%x) sent cookie:%x connected?%i\n",pfmLobbyMissionInfo->dwPort,pMission,pfmLobbyMissionInfo->dwCookie,pfmLobbyMissionInfo->dwCookie,(pthis->IsConnected()) ? 1 : 0); char szAddr[16]; pthis->GetIPAddress(cnxnFrom, szAddr); // get the real addr debugf("\tFM_LS_LOBBYMISSIONINFO:%s sent port %d\n",&szAddr,pfmLobbyMissionInfo->dwPort); char *pfmdata = FM_VAR_REF(pfmLobbyMissionInfo, szServerAddr); // get the addr in the message Strcpy(pfmdata,szAddr); // overwrite with the real addr //end move code pMission->SetLobbyInfo(pfmLobbyMissionInfo); pMission->NotifyCreator(); } // else TODO: do something about waiting client, if there is one } break; case FM_LS_MISSION_GONE: { CASTPFM(pfmMissionGone, LS, MISSION_GONE, pfm); CFLMission * pMission = CFLMission::FromCookie(pfmMissionGone->dwCookie); debugf("deleting GONE mission: %x\n",pfmMissionGone->dwCookie); pServer->DeleteMission(pMission); } break; case FM_S_HEARTBEAT: // don't boot for missing roll call until we get one from them pServer->SetHere(); break; case FM_S_PLAYER_JOINED: { CASTPFM(pfmPlayerJoined, S, PLAYER_JOINED, pfm); CFLMission * pMission = CFLMission::FromCookie(pfmPlayerJoined->dwMissionCookie); const char* szCharacterName = FM_VAR_REF(pfmPlayerJoined, szCharacterName); const char* szCDKey = FM_VAR_REF(pfmPlayerJoined, szCDKey); if (NULL == szCharacterName || '\0' != szCharacterName[pfmPlayerJoined->cbszCharacterName-1]) /* || NULL == szCDKey || '\0' != szCDKey[pfmPlayerJoined->cbszCDKey-1] Imago 6/25/08 removed above */ { // corrupt data g_pLobbyApp->GetSite()->LogEvent(EVENTLOG_ERROR_TYPE, LE_CorruptPlayerJoinMsg, cnxnFrom.GetName()); } else if (NULL == pMission) { // the requested game does not exist g_pLobbyApp->GetSite()->LogEvent(EVENTLOG_WARNING_TYPE, LE_PlayerJoinInvalidMission, szCharacterName, cnxnFrom.GetName(), pfmPlayerJoined->dwMissionCookie); } else { if (g_pLobbyApp->EnforceCDKey()) { char * szUnencryptedCDKey = (char*)_alloca(strlen(szCDKey) + 1); ZUnscramble(szUnencryptedCDKey, szCDKey, szCharacterName); szCDKey = szUnencryptedCDKey; } g_pLobbyApp->SetPlayerMission(szCharacterName, szCDKey, pMission); } } break; case FM_S_PLAYER_QUIT: { CASTPFM(pfmPlayerQuit, S, PLAYER_QUIT, pfm); CFLMission * pMission = CFLMission::FromCookie(pfmPlayerQuit->dwMissionCookie); const char* szCharacterName = FM_VAR_REF(pfmPlayerQuit, szCharacterName); if (NULL == szCharacterName || '\0' != szCharacterName[pfmPlayerQuit->cbszCharacterName-1]) { // corrupt data g_pLobbyApp->GetSite()->LogEvent(EVENTLOG_ERROR_TYPE, LE_CorruptPlayerQuitMsg, cnxnFrom.GetName()); } else g_pLobbyApp->RemovePlayerFromMission(szCharacterName, pMission); } break; case FM_S_PAUSE: { CASTPFM(pfmPause, S, PAUSE, pfm); pServer->Pause(pfmPause->fPause); // KGJV #114 cant create game on paused server g_pLobbyApp->BuildStaticCoreInfo(); break; } default: ZError("unknown message\n"); } return S_OK; }