X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fusers.cpp;h=7f56994d4e8fb4d8c19aedf73ad644999551a620;hb=4132a44396d8fa3d23f87b5cbea5b928aa09769f;hp=ead862b7d7fbad402a1995203e4d7c57a18b67a6;hpb=3013a9dfbf0c8c980dd59183c38a702e8179ee13;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/users.cpp b/src/users.cpp index ead862b7d..7f56994d4 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -227,37 +227,56 @@ void UserIOHandler::OnDataReady() user->nick.c_str(), (unsigned long)recvq.length(), user->MyClass->GetRecvqMax()); return; } + unsigned long sendqmax = ULONG_MAX; if (!user->HasPrivPermission("users/flood/increased-buffers")) sendqmax = user->MyClass->GetSendqSoftMax(); + unsigned long penaltymax = ULONG_MAX; if (!user->HasPrivPermission("users/flood/no-fakelag")) penaltymax = user->MyClass->GetPenaltyThreshold() * 1000; + // The maximum size of an IRC message minus the terminating CR+LF. + const size_t maxmessage = ServerInstance->Config->Limits.MaxLine - 2; + std::string line; + line.reserve(maxmessage); + + bool eol_found; + std::string::size_type qpos; + while (user->CommandFloodPenalty < penaltymax && getSendQSize() < sendqmax) { - std::string line; - line.reserve(ServerInstance->Config->Limits.MaxLine); - std::string::size_type qpos = 0; - while (qpos < recvq.length()) + qpos = 0; + eol_found = false; + + const size_t qlen = recvq.length(); + while (qpos < qlen) { char c = recvq[qpos++]; switch (c) { - case '\0': - c = ' '; - break; - case '\r': - continue; - case '\n': - goto eol_found; + case '\0': + c = ' '; + break; + case '\r': + continue; + case '\n': + eol_found = true; + break; } - if (line.length() < ServerInstance->Config->Limits.MaxLine - 2) + + if (eol_found) + break; + + if (line.length() < maxmessage) line.push_back(c); } - // if we got here, the recvq ran out before we found a newline - return; -eol_found: + + // if we return here, we haven't found a newline and make no modifications to recvq + // so we can wait for more data + if (!eol_found) + return; + // just found a newline. Terminate the string, and pull it out of recvq recvq.erase(0, qpos); @@ -269,7 +288,11 @@ eol_found: ServerInstance->Parser.ProcessBuffer(line, user); if (user->quitting) return; + + // clear() does not reclaim memory associated with the string, so our .reserve() call is safe + line.clear(); } + if (user->CommandFloodPenalty >= penaltymax && !user->MyClass->fakelag) ServerInstance->Users->QuitUser(user, "Excess Flood"); } @@ -648,14 +671,7 @@ void LocalUser::OverruleNick() int LocalUser::GetServerPort() { - switch (this->server_sa.sa.sa_family) - { - case AF_INET6: - return htons(this->server_sa.in6.sin6_port); - case AF_INET: - return htons(this->server_sa.in4.sin_port); - } - return 0; + return this->server_sa.port(); } const std::string& User::GetIPString() @@ -1018,15 +1034,27 @@ bool User::ChangeDisplayedHost(const std::string& shost) void User::ChangeRealHost(const std::string& host, bool resetdisplay) { - if (displayhost == host) + // If the real host is the new host and we are not resetting the + // display host then we have nothing to do. + const bool changehost = (realhost != host); + if (!changehost && !resetdisplay) return; + // If the displayhost is not set and we are not resetting it then + // we need to copy it to the displayhost field. if (displayhost.empty() && !resetdisplay) displayhost = realhost; + // If the displayhost is the new host or we are resetting it then + // we clear its contents to save memory. else if (displayhost == host || resetdisplay) displayhost.clear(); + // If we are just resetting the display host then we don't need to + // do anything else. + if (!changehost) + return; + realhost = host; this->InvalidateCache(); } @@ -1163,15 +1191,15 @@ void User::PurgeEmptyChannels() const std::string& FakeUser::GetFullHost() { - if (!ServerInstance->Config->HideWhoisServer.empty()) - return ServerInstance->Config->HideWhoisServer; + if (!ServerInstance->Config->HideServer.empty()) + return ServerInstance->Config->HideServer; return server->GetName(); } const std::string& FakeUser::GetFullRealHost() { - if (!ServerInstance->Config->HideWhoisServer.empty()) - return ServerInstance->Config->HideWhoisServer; + if (!ServerInstance->Config->HideServer.empty()) + return ServerInstance->Config->HideServer; return server->GetName(); }