X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fusermanager.cpp;h=40e0096a26a285f74a638315381e61c073aeccb6;hb=168ee804903e5ee10edc04e870e36a1256885e34;hp=968d5db0017fe282430c9405ae9b0b5e156d9b6f;hpb=77730fd5f09f8fc193205654c8bba84d34365670;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/usermanager.cpp b/src/usermanager.cpp index 968d5db00..40e0096a2 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->nextping) + return; + + // This user didn't answer the last ping, remove them. + if (!user->lastping) + { + 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; + } + + // Send a ping to the client. + ClientProtocol::Messages::Ping ping; + user->Send(ServerInstance->GetRFCEvents().ping, ping); + user->lastping = 0; + user->nextping = 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() @@ -76,6 +125,7 @@ void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs this->clientlist[New->nick] = New; this->AddClone(New); this->local_users.push_front(New); + FOREACH_MOD(OnUserInit, (New)); if (!SocketEngine::AddFd(eh, FD_WANT_FAST_READ | FD_WANT_EDGE_WRITE)) { @@ -132,7 +182,7 @@ void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs New->WriteNumeric(ERR_YOUREBANNEDCREEP, ServerInstance->Config->XLineMessage); if (ServerInstance->Config->HideBans) - this->QuitUser(New, b->Type + "-Lined", &b->Reason); + this->QuitUser(New, b->Type + "-lined", &b->Reason); else this->QuitUser(New, b->Reason); return; @@ -162,8 +212,6 @@ void UserManager::AddUser(int socket, ListenSocket* via, irc::sockets::sockaddrs FOREACH_MOD(OnSetUserIP, (New)); if (New->quitting) return; - - FOREACH_MOD(OnUserInit, (New)); } void UserManager::QuitUser(User* user, const std::string& quitreason, const std::string* operreason) @@ -221,6 +269,7 @@ void UserManager::QuitUser(User* user, const std::string& quitreason, const std: uuidlist.erase(user->uuid); user->PurgeEmptyChannels(); + user->UnOper(); } void UserManager::AddClone(User* user) @@ -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; } } }