diff options
-rw-r--r-- | include/globals.h | 2 | ||||
-rw-r--r-- | include/helperfuncs.h | 5 | ||||
-rw-r--r-- | include/modules.h | 9 | ||||
-rw-r--r-- | include/users.h | 8 | ||||
-rw-r--r-- | src/cmd_kill.cpp | 2 | ||||
-rw-r--r-- | src/cmd_nick.cpp | 4 | ||||
-rw-r--r-- | src/cmd_quit.cpp | 6 | ||||
-rw-r--r-- | src/helperfuncs.cpp | 244 | ||||
-rw-r--r-- | src/modules.cpp | 12 | ||||
-rw-r--r-- | src/users.cpp | 157 |
10 files changed, 167 insertions, 282 deletions
diff --git a/include/globals.h b/include/globals.h index 6c51e1834..299a1f438 100644 --- a/include/globals.h +++ b/include/globals.h @@ -34,8 +34,6 @@ typedef std::multimap< std::string, KeyValList > ConfigDataHash; void WriteOpers(char* text, ...); void do_log(int level, char *text, ...); int common_channels(userrec *u, userrec *u2); -void WriteCommon(userrec *u, char* text, ...); -void WriteCommonExcept(userrec *u, char* text, ...); void WriteWallOps(userrec *source, bool local_only, char* text, ...); int isnick(const char *n); chanrec* FindChan(const char* chan); diff --git a/include/helperfuncs.h b/include/helperfuncs.h index 64b668769..d35f0ae6e 100644 --- a/include/helperfuncs.h +++ b/include/helperfuncs.h @@ -48,12 +48,7 @@ void do_log(int level, const char *text, ...); void readfile(file_cache &F, const char* fname); -void WriteCommon(userrec *u, char* text, ...); -void WriteCommonExcept(userrec *u, char* text, ...); void WriteOpers(const char* text, ...); - -void WriteCommon_NoFormat(userrec *u, const char* text); -void WriteCommonExcept_NoFormat(userrec *u, const char* text); void WriteOpers_NoFormat(const char* text); std::string GetServerDescription(const char* servername); diff --git a/include/modules.h b/include/modules.h index a7f18fecd..88fe81adc 100644 --- a/include/modules.h +++ b/include/modules.h @@ -1333,15 +1333,6 @@ class Server : public Extensible */ virtual bool CommonChannels(userrec* u1, userrec* u2); - /** Sends text from a user to one or more channels (mulicast). - * This method writes a line of text to all users which share a common channel with a given - * user, with the user's nick/ident/host combination prepended, as used in PRIVMSG etc - * commands (see RFC 1459). If the IncludeSender flag is set, then the text is also sent - * back to the user from which it originated, as seen in NICK (see RFC 1459). Otherwise, it - * is only sent to the other recipients, as seen in QUIT. - */ - virtual void SendCommon(userrec* User, const std::string &text, bool IncludeSender); - /** Sends a WALLOPS message. * This method writes a WALLOPS message to all users with the +w flag, originating from the * specified user. diff --git a/include/users.h b/include/users.h index 2ea805745..bd60726c0 100644 --- a/include/users.h +++ b/include/users.h @@ -602,6 +602,14 @@ class userrec : public connection */ void WriteTo(userrec *dest, const char *data, ...); + void WriteCommon(const std::string &text); + + void WriteCommon(char* text, ...); + + void WriteCommonExcept(char* text, ...); + + void WriteCommonExcept(const std::string &text); + /** Default destructor */ virtual ~userrec(); diff --git a/src/cmd_kill.cpp b/src/cmd_kill.cpp index f2728e72e..44ea42277 100644 --- a/src/cmd_kill.cpp +++ b/src/cmd_kill.cpp @@ -54,7 +54,7 @@ void cmd_kill::Handle (const char** parameters, int pcnt, userrec *user) // remote kill WriteOpers("*** Remote kill by %s: %s!%s@%s (%s)", user->nick, u->nick, u->ident, u->host, parameters[1]); snprintf(killreason, MAXQUIT,"[%s] Killed (%s (%s))", Config->ServerName, user->nick, parameters[1]); - WriteCommonExcept(u, "QUIT :%s", killreason); + u->WriteCommonExcept("QUIT :%s", killreason); FOREACH_MOD(I_OnRemoteKill, OnRemoteKill(user, u, killreason)); user_hash::iterator iter = clientlist.find(u->nick); diff --git a/src/cmd_nick.cpp b/src/cmd_nick.cpp index 626b97a79..6f3329b8c 100644 --- a/src/cmd_nick.cpp +++ b/src/cmd_nick.cpp @@ -79,7 +79,7 @@ void cmd_nick::Handle (const char** parameters, int pcnt, userrec *user) if (MOD_RESULT) return; if (user->registered == REG_ALL) - WriteCommon(user,"NICK %s",parameters[0]); + user->WriteCommon("NICK %s",parameters[0]); strlcpy(user->nick, parameters[0], NICKMAX - 1); FOREACH_MOD(I_OnUserPostNick,OnUserPostNick(user,oldnick)); return; @@ -117,7 +117,7 @@ void cmd_nick::Handle (const char** parameters, int pcnt, userrec *user) return; } - WriteCommon(user,"NICK %s",parameters[0]); + user->WriteCommon("NICK %s",parameters[0]); } diff --git a/src/cmd_quit.cpp b/src/cmd_quit.cpp index 64e85a66c..b9ca84fef 100644 --- a/src/cmd_quit.cpp +++ b/src/cmd_quit.cpp @@ -68,12 +68,12 @@ void cmd_quit::Handle (const char** parameters, int pcnt, userrec *user) { user->Write("ERROR :Closing link (%s@%s) [%s%s]",user->ident,user->host,Config->PrefixQuit,parameters[0]); WriteOpers("*** Client exiting: %s!%s@%s [%s%s]",user->nick,user->ident,user->host,Config->PrefixQuit,parameters[0]); - WriteCommonExcept(user,"QUIT :%s%s",Config->PrefixQuit,parameters[0]); + user->WriteCommonExcept("QUIT :%s%s",Config->PrefixQuit,parameters[0]); } else { WriteOpers("*** Client exiting at %s: %s!%s@%s [%s]",user->server,user->nick,user->ident,user->host,parameters[0]); - WriteCommonExcept(user,"QUIT :%s",parameters[0]); + user->WriteCommonExcept("QUIT :%s",parameters[0]); } FOREACH_MOD(I_OnUserQuit,OnUserQuit(user,std::string(Config->PrefixQuit)+std::string(parameters[0]))); @@ -82,7 +82,7 @@ void cmd_quit::Handle (const char** parameters, int pcnt, userrec *user) { user->Write("ERROR :Closing link (%s@%s) [QUIT]",user->ident,user->host); WriteOpers("*** Client exiting: %s!%s@%s [Client exited]",user->nick,user->ident,user->host); - WriteCommonExcept(user,"QUIT :Client exited"); + user->WriteCommonExcept("QUIT :Client exited"); FOREACH_MOD(I_OnUserQuit,OnUserQuit(user,"Client exited")); } diff --git a/src/helperfuncs.cpp b/src/helperfuncs.cpp index 841006613..6cf969a82 100644 --- a/src/helperfuncs.cpp +++ b/src/helperfuncs.cpp @@ -51,7 +51,6 @@ extern InspIRCd* ServerInstance; extern time_t TIME; extern char lowermap[255]; extern userrec* fd_ref_table[MAX_DESCRIPTORS]; -static unsigned long already_sent[MAX_DESCRIPTORS] = {0}; extern std::vector<userrec*> all_opers; extern user_hash clientlist; extern chan_hash chanlist; @@ -63,9 +62,6 @@ extern std::vector<userrec*> local_users; static char TIMESTR[26]; static time_t LAST = 0; -/* XXX: Used for speeding up WriteCommon operations */ -unsigned long uniq_id = 0; - /** log() * Write a line of text `text' to the logfile (and stdout, if in nofork) if the level `level' * is greater than the configured loglevel. @@ -167,246 +163,6 @@ std::string GetServerDescription(const char* servername) } } -/* write a formatted string to all users who share at least one common - * channel, including the source user e.g. for use in NICK */ - -void WriteCommon(userrec *u, char* text, ...) -{ - char textbuffer[MAXBUF]; - va_list argsPtr; - bool sent_to_at_least_one = false; - - if (!u) - { - log(DEFAULT,"*** BUG *** WriteCommon was given an invalid parameter"); - return; - } - - if (u->registered != REG_ALL) - { - log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user"); - return; - } - - va_start(argsPtr, text); - vsnprintf(textbuffer, MAXBUF, text, argsPtr); - va_end(argsPtr); - - // XXX: Save on memset calls by using an ID. This clever trick thought of during discussion with nazzy and w00t. - uniq_id++; - - for (std::vector<ucrec*>::const_iterator v = u->chans.begin(); v != u->chans.end(); v++) - { - if (((ucrec*)(*v))->channel) - { - CUList *ulist= ((ucrec*)(*v))->channel->GetUsers(); - - for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++) - { - if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id)) - { - already_sent[i->second->fd] = uniq_id; - i->second->WriteFrom(u,std::string(textbuffer)); - sent_to_at_least_one = true; - } - } - } - } - - /* - * if the user was not in any channels, no users will receive the text. Make sure the user - * receives their OWN message for WriteCommon - */ - if (!sent_to_at_least_one) - { - u->WriteFrom(u,std::string(textbuffer)); - } -} - -void WriteCommon_NoFormat(userrec *u, const char* text) -{ - bool sent_to_at_least_one = false; - - if (!u) - { - log(DEFAULT,"*** BUG *** WriteCommon was given an invalid parameter"); - return; - } - - if (u->registered != REG_ALL) - { - log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user"); - return; - } - - // XXX: See comment in WriteCommon - uniq_id++; - - for (std::vector<ucrec*>::const_iterator v = u->chans.begin(); v != u->chans.end(); v++) - { - if (((ucrec*)(*v))->channel) - { - CUList *ulist= ((ucrec*)(*v))->channel->GetUsers(); - - for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++) - { - if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id)) - { - already_sent[i->second->fd] = uniq_id; - i->second->WriteFrom(u,std::string(text)); - sent_to_at_least_one = true; - } - } - } - } - - /* - * if the user was not in any channels, no users will receive the text. Make sure the user - * receives their OWN message for WriteCommon - */ - if (!sent_to_at_least_one) - { - u->WriteFrom(u,std::string(text)); - } -} - - -/* write a formatted string to all users who share at least one common - * channel, NOT including the source user e.g. for use in QUIT - */ - -void WriteCommonExcept(userrec *u, char* text, ...) -{ - char textbuffer[MAXBUF]; - char oper_quit[MAXBUF]; - bool quit_munge = false; - va_list argsPtr; - int total; - - if (!u) - { - log(DEFAULT,"*** BUG *** WriteCommon was given an invalid parameter"); - return; - } - - if (u->registered != REG_ALL) - { - log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user"); - return; - } - - va_start(argsPtr, text); - total = vsnprintf(textbuffer, MAXBUF, text, argsPtr); - va_end(argsPtr); - - if ((Config->HideSplits) && (total > 6)) - { - /* Yeah yeah, this is ugly. But its fast, live with it. */ - char* check = textbuffer; - - if ((*check++ == 'Q') && (*check++ == 'U') && (*check++ == 'I') && (*check++ == 'T') && (*check++ == ' ') && (*check++ == ':')) - { - std::stringstream split(check); - std::string server_one; - std::string server_two; - - split >> server_one; - split >> server_two; - - if ((FindServerName(server_one)) && (FindServerName(server_two))) - { - strlcpy(oper_quit,textbuffer,MAXQUIT); - strlcpy(check,"*.net *.split",MAXQUIT); - quit_munge = true; - } - } - } - - if ((Config->HideBans) && (total > 13) && (!quit_munge)) - { - char* check = textbuffer; - - /* XXX - as above */ - if ((*check++ == 'Q') && (*check++ == 'U') && (*check++ == 'I') && (*check++ == 'T') && (*check++ == ' ') && (*check++ == ':')) - { - check++; - - if ((*check++ == '-') && (*check++ == 'L') && (*check++ == 'i') && (*check++ == 'n') && (*check++ == 'e') && (*check++ == 'd') && (*check++ == ':')) - { - strlcpy(oper_quit,textbuffer,MAXQUIT); - *(--check) = 0; // We don't need to strlcpy, we just chop it from the : - quit_munge = true; - } - } - } - - uniq_id++; - - for (std::vector<ucrec*>::const_iterator v = u->chans.begin(); v != u->chans.end(); v++) - { - if (((ucrec*)(*v))->channel) - { - CUList *ulist= ((ucrec*)(*v))->channel->GetUsers(); - - for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++) - { - if (u != i->second) - { - if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id)) - { - already_sent[i->second->fd] = uniq_id; - - if (quit_munge) - { - i->second->WriteFrom(u,*i->second->oper ? std::string(oper_quit) : std::string(textbuffer)); - } - else - i->second->WriteFrom(u,std::string(textbuffer)); - } - } - } - } - } -} - -void WriteCommonExcept_NoFormat(userrec *u, const char* text) -{ - if (!u) - { - log(DEFAULT,"*** BUG *** WriteCommon was given an invalid parameter"); - return; - } - - if (u->registered != REG_ALL) - { - log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user"); - return; - } - - uniq_id++; - - for (std::vector<ucrec*>::const_iterator v = u->chans.begin(); v != u->chans.end(); v++) - { - if (((ucrec*)(*v))->channel) - { - CUList *ulist= ((ucrec*)(*v))->channel->GetUsers(); - - for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++) - { - if (u != i->second) - { - if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id)) - { - already_sent[i->second->fd] = uniq_id; - i->second->WriteFrom(u,text); - } - } - } - } - } -} - - /* XXX - We don't use WriteMode for this because WriteMode is very slow and * this isnt. Basically WriteMode has to iterate ALL the users 'n' times for * the number of modes provided, e.g. if you send WriteMode 'og' to write to diff --git a/src/modules.cpp b/src/modules.cpp index 65a9f3d9f..ea45c5d9e 100644 --- a/src/modules.cpp +++ b/src/modules.cpp @@ -465,18 +465,6 @@ void Server::DumpText(userrec* User, const std::string &LinePrefix, stringstream User->WriteServ(CompleteLine); } -void Server::SendCommon(userrec* User, const std::string &text, bool IncludeSender) -{ - if (IncludeSender) - { - WriteCommon_NoFormat(User,text.c_str()); - } - else - { - WriteCommonExcept_NoFormat(User,text.c_str()); - } -} - void Server::SendWallops(userrec* User, const std::string &text) { WriteWallOps(User,false,"%s",text.c_str()); diff --git a/src/users.cpp b/src/users.cpp index dd075b044..ec197fd60 100644 --- a/src/users.cpp +++ b/src/users.cpp @@ -45,11 +45,10 @@ extern userrec* fd_ref_table[MAX_DESCRIPTORS]; extern ServerConfig *Config; extern user_hash clientlist; extern Server* MyServer; - -irc::whowas::whowas_users whowas; - extern std::vector<userrec*> local_users; +irc::whowas::whowas_users whowas; +static unsigned long already_sent[MAX_DESCRIPTORS] = {0}; std::vector<userrec*> all_opers; typedef std::map<irc::string,char*> opertype_t; @@ -58,6 +57,9 @@ typedef opertype_t operclass_t; opertype_t opertypes; operclass_t operclass; +/* XXX: Used for speeding up WriteCommon operations */ +unsigned long uniq_id = 0; + bool InitTypes(const char* tag) { for (opertype_t::iterator n = opertypes.begin(); n != opertypes.end(); n++) @@ -670,7 +672,7 @@ void userrec::QuitUser(userrec *user,const std::string &quitreason) { purge_empty_chans(user); FOREACH_MOD(I_OnUserQuit,OnUserQuit(user,reason)); - WriteCommonExcept(user,"QUIT :%s",reason.c_str()); + user->WriteCommonExcept("QUIT :%s",reason.c_str()); } if (IS_LOCAL(user)) @@ -1388,3 +1390,150 @@ void userrec::WriteTo(userrec *dest, const std::string &data) } +void userrec::WriteCommon(char* text, ...) +{ + char textbuffer[MAXBUF]; + va_list argsPtr; + + if (this->registered != REG_ALL) + return; + + va_start(argsPtr, text); + vsnprintf(textbuffer, MAXBUF, text, argsPtr); + va_end(argsPtr); + + this->WriteCommon(std::string(textbuffer)); +} + +void userrec::WriteCommon(const std::string &text) +{ + bool sent_to_at_least_one = false; + + if (this->registered != REG_ALL) + return; + + uniq_id++; + + for (std::vector<ucrec*>::const_iterator v = this->chans.begin(); v != this->chans.end(); v++) + { + ucrec *n = *v; + if (n->channel) + { + CUList *ulist= n->channel->GetUsers(); + + for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++) + { + if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id)) + { + already_sent[i->second->fd] = uniq_id; + i->second->WriteFrom(this, std::string(text)); + sent_to_at_least_one = true; + } + } + } + } + + /* + * if the user was not in any channels, no users will receive the text. Make sure the user + * receives their OWN message for WriteCommon + */ + if (!sent_to_at_least_one) + { + this->WriteFrom(this,std::string(text)); + } +} + + +/* write a formatted string to all users who share at least one common + * channel, NOT including the source user e.g. for use in QUIT + */ + +void userrec::WriteCommonExcept(char* text, ...) +{ + char textbuffer[MAXBUF]; + va_list argsPtr; + + va_start(argsPtr, text); + vsnprintf(textbuffer, MAXBUF, text, argsPtr); + va_end(argsPtr); + + this->WriteCommonExcept(std::string(textbuffer)); +} + +void userrec::WriteCommonExcept(const std::string &text) +{ + bool quit_munge = true; + char oper_quit[MAXBUF]; + char textbuffer[MAXBUF]; + + strlcpy(textbuffer, text.c_str(), MAXBUF); + + if (this->registered != REG_ALL) + return; + + uniq_id++; + + /* TODO: We need some form of WriteCommonExcept that will send two lines, one line to + * opers and the other line to non-opers, then all this hidebans and hidesplits gunk + * can go byebye. + */ + if (Config->HideSplits) + { + char* check = textbuffer + 6; + + if (!strncasecmp(textbuffer, "QUIT :",6)) + { + std::stringstream split(check); + std::string server_one; + std::string server_two; + + split >> server_one; + split >> server_two; + + if ((FindServerName(server_one)) && (FindServerName(server_two))) + { + strlcpy(oper_quit,textbuffer,MAXQUIT); + strlcpy(check,"*.net *.split",MAXQUIT); + quit_munge = true; + } + } + } + + if ((Config->HideBans) && (!quit_munge)) + { + if ((!strncasecmp(textbuffer, "QUIT :G-Lined:",14)) || (!strncasecmp(textbuffer, "QUIT :K-Lined:",14)) + || (!strncasecmp(textbuffer, "QUIT :Q-Lined:",14)) || (!strncasecmp(textbuffer, "QUIT :Z-Lined:",14))) + { + char* check = textbuffer + 13; + strlcpy(oper_quit,textbuffer,MAXQUIT); + *check = 0; // We don't need to strlcpy, we just chop it from the : + quit_munge = true; + } + } + + for (std::vector<ucrec*>::const_iterator v = this->chans.begin(); v != this->chans.end(); v++) + { + ucrec* n = *v; + if (n->channel) + { + CUList *ulist= n->channel->GetUsers(); + + for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++) + { + if (this != i->second) + { + if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id)) + { + already_sent[i->second->fd] = uniq_id; + if (quit_munge) + i->second->WriteFrom(this, *i->second->oper ? std::string(oper_quit) : std::string(textbuffer)); + else + i->second->WriteFrom(this, std::string(textbuffer)); + } + } + } + } + } + +} + |