diff options
author | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-08-08 20:08:02 +0000 |
---|---|---|
committer | brain <brain@e03df62e-2008-0410-955e-edbf42e46eb7> | 2006-08-08 20:08:02 +0000 |
commit | a318eee150eb0e1a862d362a5e9011431f0595d6 (patch) | |
tree | af914e3ccdba10a37fd6ef46d645d55ee138ef57 /src/helperfuncs.cpp | |
parent | d54f233a5ea7d6fae389f0b2ef8bfc8b80f472e4 (diff) |
WriteCommon() and WriteCommonExcept() -> userrec::WriteCommon(), userrec::WriteCommonExcept()
WriteCommon_NoFormat() and WriteCommonExcept_NoFormat() -> std::string variants
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@4800 e03df62e-2008-0410-955e-edbf42e46eb7
Diffstat (limited to 'src/helperfuncs.cpp')
-rw-r--r-- | src/helperfuncs.cpp | 244 |
1 files changed, 0 insertions, 244 deletions
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 |