+ if (IS_LOCAL(i->second))
+ WriteServ_NoFormat(i->second->fd,text);
+ }
+}
+
+
+
+/* write formatted text from a source user to all users on a channel except
+ * for the sender (for privmsg etc) */
+
+void ChanExceptSender(chanrec* Ptr, userrec* user, char status, char* text, ...)
+{
+ char textbuffer[MAXBUF];
+ va_list argsPtr;
+ CUList *ulist;
+
+ if ((!Ptr) || (!user) || (!text))
+ {
+ log(DEFAULT,"*** BUG *** ChanExceptSender was given an invalid parameter");
+ return;
+ }
+
+ va_start(argsPtr, text);
+ vsnprintf(textbuffer, MAXBUF, text, argsPtr);
+ va_end(argsPtr);
+
+ switch (status)
+ {
+ case '@':
+ ulist = Ptr->GetOppedUsers();
+ break;
+ case '%':
+ ulist = Ptr->GetHalfoppedUsers();
+ break;
+ case '+':
+ ulist = Ptr->GetVoicedUsers();
+ break;
+ default:
+ ulist = Ptr->GetUsers();
+ break;
+ }
+
+ log(DEBUG,"%d users to write to",ulist->size());
+
+ for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
+ {
+ if ((IS_LOCAL(i->second)) && (user != i->second))
+ WriteFrom_NoFormat(i->second->fd,user,textbuffer);
+ }
+}
+
+void ChanExceptSender_NoFormat(chanrec* Ptr, userrec* user, char status, const char* text)
+{
+ CUList *ulist;
+
+ if ((!Ptr) || (!user) || (!text))
+ {
+ log(DEFAULT,"*** BUG *** ChanExceptSender was given an invalid parameter");
+ return;
+ }
+
+ switch (status)
+ {
+ case '@':
+ ulist = Ptr->GetOppedUsers();
+ break;
+ case '%':
+ ulist = Ptr->GetHalfoppedUsers();
+ break;
+ case '+':
+ ulist = Ptr->GetVoicedUsers();
+ break;
+ default:
+ ulist = Ptr->GetUsers();
+ break;
+ }
+
+ for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
+ {
+ if ((IS_LOCAL(i->second)) && (user != i->second))
+ WriteFrom_NoFormat(i->second->fd,user,text);
+ }
+}
+
+std::string GetServerDescription(const char* servername)
+{
+ std::string description = "";
+
+ FOREACH_MOD(I_OnGetServerDescription,OnGetServerDescription(servername,description));
+
+ if (description != "")
+ {
+ return description;
+ }
+ else
+ {
+ // not a remote server that can be found, it must be me.
+ return Config->ServerDesc;
+ }
+}
+
+/* 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);
+
+ // 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 ((i->second->fd > -1) && (already_sent[i->second->fd] != uniq_id))
+ {
+ already_sent[i->second->fd] = uniq_id;
+ 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;
+ }
+
+ // 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 ((i->second->fd > -1) && (already_sent[i->second->fd] != uniq_id))
+ {
+ already_sent[i->second->fd] = uniq_id;
+ 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;
+