-void WriteCommon(userrec *u, 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;
- }
-
- char textbuffer[MAXBUF];
- va_list argsPtr;
- 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);
-
- bool sent_to_at_least_one = false;
-
- unsigned int y = u->chans.size();
- for (unsigned int i = 0; i < y; i++)
- {
- if (u->chans[i].channel)
- {
- std::map<char*,char*> *ulist= u->chans[i].channel->GetUsers();
- for (std::map<char*,char*>::iterator i = ulist->begin(); i != ulist->end(); i++)
- {
- char* o = i->second;
- userrec* otheruser = (userrec*)o;
- if ((otheruser->fd > -1) && (!already_sent[otheruser->fd]))
- {
- already_sent[otheruser->fd] = 1;
- WriteFrom_NoFormat(otheruser->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);
- }
-}