From 77c3841a49886ac544fa3a0286ec760839992e67 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 10 Oct 2022 20:55:39 -0700 Subject: [PATCH] [Process Management] Change all executables to use the default event loop run (#2471) * Loginserver change to event loop run. * eqlaunch, loginserver, queryserv, world --- eqlaunch/eqlaunch.cpp | 24 ++++++++++++++++-------- loginserver/main.cpp | 18 +++++++++++++----- queryserv/queryserv.cpp | 17 +++++++++++++---- world/main.cpp | 19 ++++++++++++++----- 4 files changed, 56 insertions(+), 22 deletions(-) diff --git a/eqlaunch/eqlaunch.cpp b/eqlaunch/eqlaunch.cpp index b3a7743e0..ea41b1803 100644 --- a/eqlaunch/eqlaunch.cpp +++ b/eqlaunch/eqlaunch.cpp @@ -105,11 +105,17 @@ int main(int argc, char *argv[]) { Log(Logs::Detail, Logs::Launcher, "Starting main loop..."); ProcLauncher *launch = ProcLauncher::get(); + RunLoops = true; - while(RunLoops) { + auto loop_fn = [&](EQ::Timer* t) { //Advance the timer to our current point in time Timer::SetCurrentTime(); + if (!RunLoops) { + EQ::EventLoop::Get().Shutdown(); + return; + } + /* * Let the process manager look for dead children */ @@ -120,29 +126,31 @@ int main(int argc, char *argv[]) { */ zone = zones.begin(); zend = zones.end(); - for(; zone != zend; ++zone) { - if(!zone->second->Process()) + for (; zone != zend; ++zone) { + if (!zone->second->Process()) to_remove.insert(zone->first); } /* * Kill off any zones which have stopped */ - while(!to_remove.empty()) { + while (!to_remove.empty()) { std::string rem = *to_remove.begin(); to_remove.erase(rem); zone = zones.find(rem); - if(zone == zones.end()) { + if (zone == zones.end()) { //wtf... continue; } delete zone->second; zones.erase(rem); } + }; - EQ::EventLoop::Get().Process(); - Sleep(5); - } + EQ::Timer process_timer(loop_fn); + process_timer.Start(32, true); + + EQ::EventLoop::Get().Run(); //try to be semi-nice about this... without waiting too long zone = zones.begin(); diff --git a/loginserver/main.cpp b/loginserver/main.cpp index 12390392f..2db5e71a4 100644 --- a/loginserver/main.cpp +++ b/loginserver/main.cpp @@ -289,13 +289,21 @@ int main(int argc, char **argv) LogInfo("[Config] [Security] IsPasswordLoginAllowed [{0}]", server.options.IsPasswordLoginAllowed()); LogInfo("[Config] [Security] IsUpdatingInsecurePasswords [{0}]", server.options.IsUpdatingInsecurePasswords()); - while (run_server) { + auto loop_fn = [&](EQ::Timer* t) { Timer::SetCurrentTime(); - server.client_manager->Process(); - EQ::EventLoop::Get().Process(); - Sleep(5); - } + if (!run_server) { + EQ::EventLoop::Get().Shutdown(); + return; + } + + server.client_manager->Process(); + }; + + EQ::Timer process_timer(loop_fn); + process_timer.Start(32, true); + + EQ::EventLoop::Get().Run(); LogInfo("Server Shutdown"); diff --git a/queryserv/queryserv.cpp b/queryserv/queryserv.cpp index 74c6bf607..95d2e69bd 100644 --- a/queryserv/queryserv.cpp +++ b/queryserv/queryserv.cpp @@ -104,15 +104,24 @@ int main() /* Load Looking For Guild Manager */ lfguildmanager.LoadDatabase(); - while (RunLoops) { + auto loop_fn = [&](EQ::Timer* t) { Timer::SetCurrentTime(); + + if (!RunLoops) { + EQ::EventLoop::Get().Shutdown(); + return; + } + if (LFGuildExpireTimer.Check()) { lfguildmanager.ExpireEntries(); } + }; + + EQ::Timer process_timer(loop_fn); + process_timer.Start(32, true); + + EQ::EventLoop::Get().Run(); - EQ::EventLoop::Get().Process(); - Sleep(5); - } LogSys.CloseFileLogs(); } diff --git a/world/main.cpp b/world/main.cpp index 51b3baff7..a919d41ed 100644 --- a/world/main.cpp +++ b/world/main.cpp @@ -371,8 +371,14 @@ int main(int argc, char **argv) } ); - while (RunLoops) { + auto loop_fn = [&](EQ::Timer* t) { Timer::SetCurrentTime(); + + if (!RunLoops) { + EQ::EventLoop::Get().Shutdown(); + return; + } + eqs = nullptr; //give the stream identifier a chance to do its work.... @@ -381,7 +387,7 @@ int main(int argc, char **argv) //check the stream identifier for any now-identified streams while ((eqsi = stream_identifier.PopIdentified())) { //now that we know what patch they are running, start up their client object - struct in_addr in{}; + struct in_addr in {}; in.s_addr = eqsi->GetRemoteIP(); if (RuleB(World, UseBannedIPsTable)) { //Lieka: Check to see if we have the responsibility for blocking IPs. LogInfo("Checking inbound connection [{}] against BannedIPs table", inet_ntoa(in)); @@ -447,10 +453,13 @@ int main(int argc, char **argv) ); UpdateWindowTitle(window_title); } + }; + + EQ::Timer process_timer(loop_fn); + process_timer.Start(32, true); + + EQ::EventLoop::Get().Run(); - EQ::EventLoop::Get().Process(); - Sleep(5); - } LogInfo("World main loop completed"); LogInfo("Shutting down zone connections (if any)"); zoneserver_list.KillAll();