-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);
-
- unsigned int y = u->chans.size();
- for (unsigned int i = 0; i < y; i++)
- {
- if (u->chans[i].channel)
- {
- std::vector<char*> *ulist = u->chans[i].channel->GetUsers();
- unsigned int x = ulist->size();
- for (unsigned int j = 0; j < x; j++)
- {
- char* o = (*ulist)[j];
- userrec* otheruser = (userrec*)o;
- if (u != otheruser)
- {
- if ((otheruser->fd > -1) && (!already_sent[otheruser->fd]))
- {
- already_sent[otheruser->fd] = 1;
- WriteFrom_NoFormat(otheruser->fd,u,text);
- }
- }
- }
- }
- }
-}
-
-
-
-void WriteOpers(char* text, ...)
-{
- if (!text)
- {
- log(DEFAULT,"*** BUG *** WriteOpers was given an invalid parameter");
- return;
- }
-
- char textbuffer[MAXBUF];
- va_list argsPtr;
- va_start (argsPtr, text);
- vsnprintf(textbuffer, MAXBUF, text, argsPtr);
- va_end(argsPtr);
-
- for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
- {
- userrec* a = *i;
- if (IS_LOCAL(a))
- {
- if (strchr(a->modes,'s'))
- {
- // send server notices to all with +s
- WriteServ(a->fd,"NOTICE %s :%s",a->nick,textbuffer);
- }
- }
- }
+ 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);
+ }
+ }
+ }
+ }
+ }
+}
+
+
+/* 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
+ * opers with globops, and you have 2000 users, thats 4000 iterations. WriteOpers
+ * uses the oper list, which means if you have 2000 users but only 5 opers,
+ * it iterates 5 times.
+ */
+void WriteOpers(const char* text, ...)
+{
+ char textbuffer[MAXBUF];
+ va_list argsPtr;
+
+ if (!text)
+ {
+ log(DEFAULT,"*** BUG *** WriteOpers was given an invalid parameter");
+ return;
+ }
+
+ va_start(argsPtr, text);
+ vsnprintf(textbuffer, MAXBUF, text, argsPtr);
+ va_end(argsPtr);
+
+ WriteOpers_NoFormat(textbuffer);
+}
+
+void WriteOpers_NoFormat(const char* text)
+{
+ if (!text)
+ {
+ log(DEFAULT,"*** BUG *** WriteOpers_NoFormat was given an invalid parameter");
+ return;
+ }
+
+ for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
+ {
+ userrec* a = *i;
+
+ if (IS_LOCAL(a))
+ {
+ if (a->modebits & UM_SERVERNOTICE)
+ {
+ // send server notices to all with +s
+ WriteServ(a->fd,"NOTICE %s :%s",a->nick,text);
+ }
+ }
+ }