-/* 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 != 7)
- {
- log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
- return;
- }
-
- va_start(argsPtr, text);
- vsnprintf(textbuffer, MAXBUF, text, argsPtr);
- va_end(argsPtr);
-
- // FIX: Stops a message going to the same person more than once
- memset(&already_sent,0,MAX_DESCRIPTORS);
-
- 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 ((i->second->fd > -1) && (!already_sent[i->second->fd]))
- {
- already_sent[i->second->fd] = 1;
- WriteFrom_NoFormat(i->second->fd,u,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)
- {
- WriteFrom_NoFormat(u->fd,u,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 != 7)
- {
- log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
- return;
- }
-
- // FIX: Stops a message going to the same person more than once
- memset(&already_sent,0,MAX_DESCRIPTORS);
-
- 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 ((i->second->fd > -1) && (!already_sent[i->second->fd]))
- {
- already_sent[i->second->fd] = 1;
- WriteFrom_NoFormat(i->second->fd,u,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)
- {
- WriteFrom_NoFormat(u->fd,u,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 != 7)
- {
- 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;
- }
- }
- }
-
- memset(&already_sent,0,MAX_DESCRIPTORS);
-
- 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 ((i->second->fd > -1) && (!already_sent[i->second->fd]))
- {
- already_sent[i->second->fd] = 1;
-
- if (quit_munge)
- {
- WriteFrom_NoFormat(i->second->fd,u,*i->second->oper ? oper_quit : textbuffer);
- }
- else
- WriteFrom_NoFormat(i->second->fd,u,textbuffer);
- }
- }
- }
- }
- }
-}
-
-void WriteCommonExcept_NoFormat(userrec *u, const char* text)
-{
- if (!u)
- {
- log(DEFAULT,"*** BUG *** WriteCommon was given an invalid parameter");
- return;
- }
-
- if (u->registered != 7)
- {
- log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
- return;
- }
-
- memset(&already_sent,0,MAX_DESCRIPTORS);
-
- 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 ((i->second->fd > -1) && (!already_sent[i->second->fd]))
- {
- already_sent[i->second->fd] = 1;
- WriteFrom_NoFormat(i->second->fd,u,text);
- }
- }
- }
- }
- }
-}
-
-