X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fusers.cpp;h=0dfe54f65d2ece1a7c43c2bfe6a1d8fac73493a1;hb=94e530b1cb59ba806dfb497a1e27d44e5d2e02d5;hp=f8a95af49a195197042218fb16176f955030c39d;hpb=343f12b9b2d4e519b09877f76a00f6a0714509f2;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/users.cpp b/src/users.cpp index f8a95af49..0dfe54f65 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -21,10 +21,17 @@ #include "bancache.h" #include "commands/cmd_whowas.h" -static unsigned long already_sent[MAX_DESCRIPTORS] = {0}; +static unsigned long* already_sent = NULL; + + +void InitializeAlreadySent(SocketEngine* SE) +{ + already_sent = new unsigned long[SE->GetMaxFds()]; + memset(already_sent, 0, sizeof(already_sent)); +} /* XXX: Used for speeding up WriteCommon operations */ -unsigned long uniq_id = 0; +unsigned long uniq_id = 1; std::string User::ProcessNoticeMasks(const char *sm) { @@ -224,7 +231,7 @@ User::~User() if (this->MyClass) { this->MyClass->RefCount--; - ServerInstance->Logs->Log("USERS", DEBUG, "User destructor -- connect refcount now: %u", this->MyClass->RefCount); + ServerInstance->Logs->Log("USERS", DEBUG, "User destructor -- connect refcount now: %lu", this->MyClass->RefCount); } if (this->AllowedOperCommands) { @@ -308,8 +315,11 @@ char* User::MakeHostIP() void User::CloseSocket() { - ServerInstance->SE->Shutdown(this, 2); - ServerInstance->SE->Close(this); + if (this->fd > -1) + { + ServerInstance->SE->Shutdown(this, 2); + ServerInstance->SE->Close(this); + } } char* User::GetFullHost() @@ -520,7 +530,7 @@ bool User::AddBuffer(std::string a) if (this->MyClass && (recvq.length() > this->MyClass->GetRecvqMax())) { this->SetWriteError("RecvQ exceeded"); - ServerInstance->SNO->WriteToSnoMask('A', "User %s RecvQ of %d exceeds connect class maximum of %d",this->nick,recvq.length(),this->MyClass->GetRecvqMax()); + ServerInstance->SNO->WriteToSnoMask('A', "User %s RecvQ of %lu exceeds connect class maximum of %lu",this->nick,(unsigned long int)recvq.length(),this->MyClass->GetRecvqMax()); return false; } @@ -597,7 +607,7 @@ void User::AddWriteBuf(const std::string &data) * to repeatedly add the text to the sendq! */ this->SetWriteError("SendQ exceeded"); - ServerInstance->SNO->WriteToSnoMask('A', "User %s SendQ of %d exceeds connect class maximum of %d",this->nick,sendq.length() + data.length(),this->MyClass->GetSendqMax()); + ServerInstance->SNO->WriteToSnoMask('A', "User %s SendQ of %lu exceeds connect class maximum of %lu",this->nick,(unsigned long int)sendq.length() + data.length(),this->MyClass->GetSendqMax()); return; } @@ -907,12 +917,11 @@ void User::FullConnect() this->WriteServ("NOTICE Auth :Welcome to \002%s\002!",ServerInstance->Config->Network); this->WriteNumeric(001, "%s :Welcome to the %s IRC Network %s!%s@%s",this->nick, ServerInstance->Config->Network, this->nick, this->ident, this->host); - this->WriteNumeric(002, "%s :Your host is %s, running version %s",this->nick,ServerInstance->Config->ServerName,VERSION); + this->WriteNumeric(002, "%s :Your host is %s, running version InspIRCd-1.2",this->nick,ServerInstance->Config->ServerName); this->WriteNumeric(003, "%s :This server was created %s %s", this->nick, __TIME__, __DATE__); - this->WriteNumeric(004, "%s %s %s %s %s %s", this->nick, ServerInstance->Config->ServerName, VERSION, ServerInstance->Modes->UserModeList().c_str(), ServerInstance->Modes->ChannelModeList().c_str(), ServerInstance->Modes->ParaModeList().c_str()); + this->WriteNumeric(004, "%s %s InspIRCd-1.2 %s %s %s", this->nick, ServerInstance->Config->ServerName, ServerInstance->Modes->UserModeList().c_str(), ServerInstance->Modes->ChannelModeList().c_str(), ServerInstance->Modes->ParaModeList().c_str()); ServerInstance->Config->Send005(this); - this->WriteNumeric(42, "%s %s :your unique ID", this->nick, this->uuid); @@ -980,46 +989,35 @@ void User::InvalidateCache() bool User::ForceNickChange(const char* newnick) { - /* - * XXX this makes no sense.. - * why do we do nothing for change on users not REG_ALL? - * why do we trigger events twice for everyone previously (and just them now) - * i think the first if () needs removing totally, or? -- w00t - */ - if (this->registered != REG_ALL) - { - int MOD_RESULT = 0; + int MOD_RESULT = 0; - this->InvalidateCache(); + this->InvalidateCache(); - FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(this, newnick)); + FOREACH_RESULT(I_OnUserPreNick,OnUserPreNick(this, newnick)); - if (MOD_RESULT) - { - ServerInstance->stats->statsCollisions++; - return false; - } + if (MOD_RESULT) + { + ServerInstance->stats->statsCollisions++; + return false; + } - if (ServerInstance->XLines->MatchesLine("Q",newnick)) - { - ServerInstance->stats->statsCollisions++; - return false; - } + if (ServerInstance->XLines->MatchesLine("Q",newnick)) + { + ServerInstance->stats->statsCollisions++; + return false; } - else + + std::deque dummy; + Command* nickhandler = ServerInstance->Parser->GetHandler("NICK"); + if (nickhandler) // wtfbbq, when would this not be here { - std::deque dummy; - Command* nickhandler = ServerInstance->Parser->GetHandler("NICK"); - if (nickhandler) // wtfbbq, when would this not be here - { - nickhandler->HandleInternal(1, dummy); - bool result = (ServerInstance->Parser->CallHandler("NICK", &newnick, 1, this) == CMD_SUCCESS); - nickhandler->HandleInternal(0, dummy); - return result; - } + nickhandler->HandleInternal(1, dummy); + bool result = (ServerInstance->Parser->CallHandler("NICK", &newnick, 1, this) == CMD_SUCCESS); + nickhandler->HandleInternal(0, dummy); + return result; } - // Unreachable. + // Unreachable, we hope return false; } @@ -1322,6 +1320,9 @@ void User::WriteCommon(const std::string &text) uniq_id++; + if (!already_sent) + InitializeAlreadySent(ServerInstance->SE); + /* We dont want to be doing this n times, just once */ snprintf(tb,MAXBUF,":%s %s",this->GetFullHost(),text.c_str()); std::string out = tb; @@ -1376,6 +1377,10 @@ void User::WriteCommonQuit(const std::string &normal_text, const std::string &op return; uniq_id++; + + if (!already_sent) + InitializeAlreadySent(ServerInstance->SE); + snprintf(tb1,MAXBUF,":%s QUIT :%s",this->GetFullHost(),normal_text.c_str()); snprintf(tb2,MAXBUF,":%s QUIT :%s",this->GetFullHost(),oper_text.c_str()); std::string out1 = tb1; @@ -1407,6 +1412,10 @@ void User::WriteCommonExcept(const std::string &text) return; uniq_id++; + + if (!already_sent) + InitializeAlreadySent(ServerInstance->SE); + snprintf(tb1,MAXBUF,":%s %s",this->GetFullHost(),text.c_str()); out1 = tb1; @@ -1430,7 +1439,7 @@ void User::WriteCommonExcept(const std::string &text) void User::WriteWallOps(const std::string &text) { - if (!IS_OPER(this) && IS_LOCAL(this)) + if (!IS_LOCAL(this)) return; std::string wallop("WALLOPS :"); @@ -1446,6 +1455,9 @@ void User::WriteWallOps(const std::string &text) void User::WriteWallOps(const char* text, ...) { + if (!IS_LOCAL(this)) + return; + char textbuffer[MAXBUF]; va_list argsPtr; @@ -1708,7 +1720,7 @@ ConnectClass* User::SetClass(const std::string &explicit_name) /* deny change if change will take class over the limit */ if (found->limit && (found->RefCount + 1 >= found->limit)) { - ServerInstance->Logs->Log("USERS", DEBUG, "OOPS: Connect class limit (%u) hit, denying", found->limit); + ServerInstance->Logs->Log("USERS", DEBUG, "OOPS: Connect class limit (%lu) hit, denying", found->limit); return this->MyClass; } @@ -1718,12 +1730,12 @@ ConnectClass* User::SetClass(const std::string &explicit_name) if (found == this->MyClass) // no point changing this shit :P return this->MyClass; this->MyClass->RefCount--; - ServerInstance->Logs->Log("USERS", DEBUG, "Untying user from connect class -- refcount: %u", this->MyClass->RefCount); + ServerInstance->Logs->Log("USERS", DEBUG, "Untying user from connect class -- refcount: %lu", this->MyClass->RefCount); } this->MyClass = found; this->MyClass->RefCount++; - ServerInstance->Logs->Log("USERS", DEBUG, "User tied to new class -- connect refcount now: %u", this->MyClass->RefCount); + ServerInstance->Logs->Log("USERS", DEBUG, "User tied to new class -- connect refcount now: %lu", this->MyClass->RefCount); } return this->MyClass;