From f5b2265c2e6868431abbaa301aa1d64e8d49d8b0 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Thu, 14 Feb 2019 20:36:55 +0000 Subject: Refactor UserManager::DoBackgroundUserStuff(). --- src/usermanager.cpp | 101 ++++++++++++++++++++++++++++------------------------ 1 file changed, 55 insertions(+), 46 deletions(-) (limited to 'src/usermanager.cpp') diff --git a/src/usermanager.cpp b/src/usermanager.cpp index 053a308cb..4ab13fc95 100644 --- a/src/usermanager.cpp +++ b/src/usermanager.cpp @@ -48,6 +48,55 @@ namespace user->ForEachNeighbor(*this, false); } }; + + void CheckPingTimeout(LocalUser* user) + { + // Check if it is time to ping the user yet. + if (ServerInstance->Time() < user->nping) + return; + + // This user didn't answer the last ping, remove them. + if (!user->lastping) + { + time_t secs = ServerInstance->Time() - (user->nping - user->MyClass->GetPingTime()); + const std::string message = "Ping timeout: " + ConvToStr(secs) + (secs != 1 ? " seconds" : " second"); + ServerInstance->Users.QuitUser(user, message); + return; + } + + // Send a ping to the client. + ClientProtocol::Messages::Ping ping; + user->Send(ServerInstance->GetRFCEvents().ping, ping); + user->lastping = 0; + user->nping = ServerInstance->Time() + user->MyClass->GetPingTime(); + } + + void CheckRegistrationTimeout(LocalUser* user) + { + if (user->GetClass() && (ServerInstance->Time() > (user->signon + user->GetClass()->GetRegTimeout()))) + { + // Either the user did not send NICK/USER or a module blocked registration in + // OnCheckReady until the client timed out. + ServerInstance->Users.QuitUser(user, "Registration timeout"); + } + } + + void CheckModulesReady(LocalUser* user) + { + ModResult res; + FIRST_MOD_RESULT(OnCheckReady, res, (user)); + if (res == MOD_RES_PASSTHRU) + { + // User has sent NICK/USER and modules are ready. + user->FullConnect(); + return; + } + + // If the user has been quit in OnCheckReady then we shouldn't quit + // them again for having a registration timeout. + if (!user->quitting) + CheckRegistrationTimeout(user); + } } UserManager::UserManager() @@ -285,17 +334,6 @@ void UserManager::ServerNoticeAll(const char* text, ...) } } -/* this returns true when all modules are satisfied that the user should be allowed onto the irc server - * (until this returns true, a user will block in the waiting state, waiting to connect up to the - * registration timeout maximum seconds) - */ -bool UserManager::AllModulesReportReady(LocalUser* user) -{ - ModResult res; - FIRST_MOD_RESULT(OnCheckReady, res, (user)); - return (res == MOD_RES_PASSTHRU); -} - /** * This function is called once a second from the mainloop. * It is intended to do background checking on all the users, e.g. do @@ -322,45 +360,16 @@ void UserManager::DoBackgroundUserStuff() switch (curr->registered) { case REG_ALL: - if (ServerInstance->Time() >= curr->nping) - { - // This user didn't answer the last ping, remove them - if (!curr->lastping) - { - time_t time = ServerInstance->Time() - (curr->nping - curr->MyClass->GetPingTime()); - const std::string message = "Ping timeout: " + ConvToStr(time) + (time != 1 ? " seconds" : " second"); - this->QuitUser(curr, message); - continue; - } - ClientProtocol::Messages::Ping ping; - curr->Send(ServerInstance->GetRFCEvents().ping, ping); - curr->lastping = 0; - curr->nping = ServerInstance->Time() + curr->MyClass->GetPingTime(); - } + CheckPingTimeout(curr); break; + case REG_NICKUSER: - if (AllModulesReportReady(curr)) - { - /* User has sent NICK/USER, modules are okay, DNS finished. */ - curr->FullConnect(); - continue; - } - - // If the user has been quit in OnCheckReady then we shouldn't - // quit them again for having a registration timeout. - if (curr->quitting) - continue; + CheckModulesReady(curr); break; - } - if (curr->registered != REG_ALL && curr->MyClass && (ServerInstance->Time() > (curr->signon + curr->MyClass->GetRegTimeout()))) - { - /* - * registration timeout -- didnt send USER/NICK/HOST - * in the time specified in their connection class. - */ - this->QuitUser(curr, "Registration timeout"); - continue; + default: + CheckRegistrationTimeout(curr); + break; } } } -- cgit v1.3.1-10-gc9f91 From 168ee804903e5ee10edc04e870e36a1256885e34 Mon Sep 17 00:00:00 2001 From: Peter Powell Date: Fri, 15 Feb 2019 10:56:08 +0000 Subject: Rename User::nping to nextping for consistency with lastping. --- include/users.h | 5 ++--- src/command_parse.cpp | 2 +- src/usermanager.cpp | 6 +++--- src/users.cpp | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) (limited to 'src/usermanager.cpp') diff --git a/include/users.h b/include/users.h index 3937f74aa..39e7e90f0 100644 --- a/include/users.h +++ b/include/users.h @@ -791,9 +791,8 @@ class CoreExport LocalUser : public User, public insp::intrusive_list_nodenping = ServerInstance->Time() + user->MyClass->GetPingTime(); + user->nextping = ServerInstance->Time() + user->MyClass->GetPingTime(); if (handler->flags_needed) { diff --git a/src/usermanager.cpp b/src/usermanager.cpp index 4ab13fc95..40e0096a2 100644 --- a/src/usermanager.cpp +++ b/src/usermanager.cpp @@ -52,13 +52,13 @@ namespace void CheckPingTimeout(LocalUser* user) { // Check if it is time to ping the user yet. - if (ServerInstance->Time() < user->nping) + if (ServerInstance->Time() < user->nextping) return; // This user didn't answer the last ping, remove them. if (!user->lastping) { - time_t secs = ServerInstance->Time() - (user->nping - user->MyClass->GetPingTime()); + time_t secs = ServerInstance->Time() - (user->nextping - user->MyClass->GetPingTime()); const std::string message = "Ping timeout: " + ConvToStr(secs) + (secs != 1 ? " seconds" : " second"); ServerInstance->Users.QuitUser(user, message); return; @@ -68,7 +68,7 @@ namespace ClientProtocol::Messages::Ping ping; user->Send(ServerInstance->GetRFCEvents().ping, ping); user->lastping = 0; - user->nping = ServerInstance->Time() + user->MyClass->GetPingTime(); + user->nextping = ServerInstance->Time() + user->MyClass->GetPingTime(); } void CheckRegistrationTimeout(LocalUser* user) diff --git a/src/users.cpp b/src/users.cpp index 582abe17e..4050337c7 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -97,7 +97,7 @@ LocalUser::LocalUser(int myfd, irc::sockets::sockaddrs* client, irc::sockets::so , quitting_sendq(false) , lastping(true) , exempt(false) - , nping(0) + , nextping(0) , idle_lastmsg(0) , CommandFloodPenalty(0) , already_sent(0) @@ -503,7 +503,7 @@ void LocalUser::CheckClass(bool clone_count) } } - this->nping = ServerInstance->Time() + a->GetPingTime(); + this->nextping = ServerInstance->Time() + a->GetPingTime(); } bool LocalUser::CheckLines(bool doZline) -- cgit v1.3.1-10-gc9f91