// *************************************************************** // Function: UpdateLoop.cpp // *************************************************************** #include "Main.h" #include "LocalData.h" int Shutdown(); //Clean-up the server int ProcessPackets(); //Processes all packets from the login server void InternalCommunicationsProcess(); //Processes all the InternalCommunication transmissions recieved //************************************ // Name: UpdateLoop // // The main update loop for the login server. This is called after initialization. // // Parameters: // // Return: // true //************************************ bool UpdateLoop() { unsigned long brute_force_timer=(unsigned long)TimerGetTime(); while (true) { //Update the database stuff gDatabase.Update(); gDatabase.ProcessResults, LOCAL_DATA>(&gLoginInfo); //Update the network servers gpInternalComm->Update(); InternalCommunicationsProcess(); gpLoginServer->Update(); ProcessPackets(); //Check for brute force attacks, if any are detected...ban the perp if (TimerGetTime()-brute_force_timer>=gServerConfig.bfCheckInterval) { hash_map::iterator itr; for (itr=gBruteForceTracker.begin(); itr!=gBruteForceTracker.end(); itr++) { if (itr->second.tries>(unsigned int)gServerConfig.bfBanThreshold) { unsigned char ip_range[8]; memcpy(ip_range, itr->second.ip, 4); memcpy(ip_range+4, itr->second.ip, 4); gpLoginServer->IssueBan(ip_range, gServerConfig.bfBanLength, "Brute force attack"); gpInternalComm->IssueBan(ip_range, gServerConfig.bfBanLength, "Brute force attack"); if (itr->second.admin) { gpInternalComm->Kick(itr->second.networkId); } else { gpLoginServer->Kick(itr->second.networkId); } } } gBruteForceTracker.clear(); brute_force_timer=(unsigned long)TimerGetTime(); } if (gServerConfig.throttleCpu) { Sleep(1);//may want to remove at a later data? } if (gpInternalComm->mFatalError) gShuttingDown=true; if (gpLoginServer->mFatalError) gShuttingDown=true; if (gShuttingDown) break; } //Shutdown the server Shutdown(); return true; }