extern time_t TIME;
extern char lowermap[255];
extern userrec* fd_ref_table[MAX_DESCRIPTORS];
-static int already_sent[MAX_DESCRIPTORS];
+static unsigned long already_sent[MAX_DESCRIPTORS] = {0};
extern std::vector<userrec*> all_opers;
extern user_hash clientlist;
extern chan_hash chanlist;
static time_t LAST = 0;
/* XXX: Used for speeding up WriteCommon operations */
-int uniq_id = 0;
+unsigned long uniq_id = 0;
/** log()
* Write a line of text `text' to the logfile (and stdout, if in nofork) if the level `level'
{
bytes = snprintf(tb,MAXBUF,"%s\r\n",text);
- if (Config->GetIOHook(fd_ref_table[sock]->port))
+ if (Config->GetIOHook(fd_ref_table[sock]->GetPort()))
{
try
{
- Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+ Config->GetIOHook(fd_ref_table[sock]->GetPort())->OnRawSocketWrite(sock,tb,bytes);
}
catch (ModuleException& modexcept)
{
va_end(argsPtr);
bytes = snprintf(tb,MAXBUF,"%s\r\n",textbuffer);
- if (Config->GetIOHook(fd_ref_table[sock]->port))
+ if (Config->GetIOHook(fd_ref_table[sock]->GetPort()))
{
try
{
- Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+ Config->GetIOHook(fd_ref_table[sock]->GetPort())->OnRawSocketWrite(sock,tb,bytes);
}
catch (ModuleException& modexcept)
{
{
bytes = snprintf(tb,MAXBUF,":%s %s\r\n",Config->ServerName,text);
- if (Config->GetIOHook(fd_ref_table[sock]->port))
+ if (Config->GetIOHook(fd_ref_table[sock]->GetPort()))
{
try
{
- Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+ Config->GetIOHook(fd_ref_table[sock]->GetPort())->OnRawSocketWrite(sock,tb,bytes);
}
catch (ModuleException& modexcept)
{
{
bytes = snprintf(tb,MAXBUF,":%s %s\r\n",user->GetFullHost(),text);
- if (Config->GetIOHook(fd_ref_table[sock]->port))
+ if (Config->GetIOHook(fd_ref_table[sock]->GetPort()))
{
try
{
- Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+ Config->GetIOHook(fd_ref_table[sock]->GetPort())->OnRawSocketWrite(sock,tb,bytes);
}
catch (ModuleException& modexcept)
{
va_end(argsPtr);
bytes = snprintf(tb,MAXBUF,":%s %s\r\n",user->GetFullHost(),textbuffer);
- if (Config->GetIOHook(fd_ref_table[sock]->port))
+ if (Config->GetIOHook(fd_ref_table[sock]->GetPort()))
{
try
{
- Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+ Config->GetIOHook(fd_ref_table[sock]->GetPort())->OnRawSocketWrite(sock,tb,bytes);
}
catch (ModuleException& modexcept)
{
}
}
-/* write formatted text from a source user to all users on a channel
- * including the sender (NOT for privmsg, notice etc!) */
-
-void WriteChannel(chanrec* Ptr, userrec* user, char* text, ...)
-{
- char textbuffer[MAXBUF];
- va_list argsPtr;
- CUList *ulist;
-
- if ((!Ptr) || (!user) || (!text))
- {
- log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter");
- return;
- }
-
- va_start(argsPtr, text);
- vsnprintf(textbuffer, MAXBUF, text, argsPtr);
- va_end(argsPtr);
-
- ulist = Ptr->GetUsers();
-
- for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
- {
- if (i->second->fd != FD_MAGIC_NUMBER)
- WriteTo_NoFormat(user,i->second,textbuffer);
- }
-}
-
-void WriteChannel_NoFormat(chanrec* Ptr, userrec* user, const char* text)
-{
- CUList *ulist;
-
- if ((!Ptr) || (!user) || (!text))
- {
- log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter");
- return;
- }
-
- ulist = Ptr->GetUsers();
-
- for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
- {
- if (i->second->fd != FD_MAGIC_NUMBER)
- WriteTo_NoFormat(user,i->second,text);
- }
-}
-
-
-/* write formatted text from a source user to all users on a channel
- * including the sender (NOT for privmsg, notice etc!) doesnt send to
- * users on remote servers */
-
-void WriteChannelLocal(chanrec* Ptr, userrec* user, char* text, ...)
-{
- char textbuffer[MAXBUF];
- va_list argsPtr;
- CUList *ulist;
-
- if ((!Ptr) || (!text))
- {
- log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter");
- return;
- }
-
- va_start(argsPtr, text);
- vsnprintf(textbuffer, MAXBUF, text, argsPtr);
- va_end(argsPtr);
-
- ulist = Ptr->GetUsers();
-
- for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
- {
- if ((i->second->fd != FD_MAGIC_NUMBER) && (i->second != user))
- {
- if (!user)
- {
- WriteServ_NoFormat(i->second->fd,textbuffer);
- }
- else
- {
- WriteTo_NoFormat(user,i->second,textbuffer);
- }
- }
- }
-}
-
-void WriteChannelLocal_NoFormat(chanrec* Ptr, userrec* user, const char* text)
-{
- CUList *ulist;
-
- if ((!Ptr) || (!text))
- {
- log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter");
- return;
- }
-
- ulist = Ptr->GetUsers();
-
- for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
- {
- if ((i->second->fd != FD_MAGIC_NUMBER) && (i->second != user))
- {
- if (!user)
- {
- WriteServ_NoFormat(i->second->fd,text);
- }
- else
- {
- WriteTo_NoFormat(user,i->second,text);
- }
- }
- }
-}
-
-
-
-void WriteChannelWithServ(const char* ServName, chanrec* Ptr, const char* text, ...)
-{
- char textbuffer[MAXBUF];
- va_list argsPtr;
- CUList *ulist;
-
- if ((!Ptr) || (!text))
- {
- log(DEFAULT,"*** BUG *** WriteChannelWithServ was given an invalid parameter");
- return;
- }
-
- va_start(argsPtr, text);
- vsnprintf(textbuffer, MAXBUF, text, argsPtr);
- va_end(argsPtr);
-
- ulist = Ptr->GetUsers();
-
- for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
- {
- if (IS_LOCAL(i->second))
- WriteServ_NoFormat(i->second->fd,textbuffer);
- }
-}
-
-void WriteChannelWithServ_NoFormat(const char* ServName, chanrec* Ptr, const char* text)
-{
- CUList *ulist;
-
- if ((!Ptr) || (!text))
- {
- log(DEFAULT,"*** BUG *** WriteChannelWithServ was given an invalid parameter");
- return;
- }
-
- ulist = Ptr->GetUsers();
-
- for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
- {
- 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 = "";
return;
}
- if (u->registered != 7)
+ if (u->registered != REG_ALL)
{
log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
return;
vsnprintf(textbuffer, MAXBUF, text, argsPtr);
va_end(argsPtr);
- // XXX: Save on memset calls by only requiring memset every 4 billion or so
- // messages. This clever trick thought of during discussion with nazzy and w00t.
+ // XXX: Save on memset calls by using an ID. This clever trick thought of during discussion with nazzy and w00t.
uniq_id++;
- if (!uniq_id)
- {
- memset(&already_sent,0,MAX_DESCRIPTORS);
- uniq_id++;
- }
for (std::vector<ucrec*>::const_iterator v = u->chans.begin(); v != u->chans.end(); v++)
{
for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- if ((i->second->fd > -1) && (already_sent[i->second->fd] != uniq_id))
+ if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
{
already_sent[i->second->fd] = uniq_id;
WriteFrom_NoFormat(i->second->fd,u,textbuffer);
return;
}
- if (u->registered != 7)
+ if (u->registered != REG_ALL)
{
log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
return;
// XXX: See comment in WriteCommon
uniq_id++;
- if (!uniq_id)
- {
- memset(&already_sent,0,MAX_DESCRIPTORS);
- uniq_id++;
- }
for (std::vector<ucrec*>::const_iterator v = u->chans.begin(); v != u->chans.end(); v++)
{
for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- if ((i->second->fd > -1) && (already_sent[i->second->fd] != uniq_id))
+ if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
{
already_sent[i->second->fd] = uniq_id;
WriteFrom_NoFormat(i->second->fd,u,text);
return;
}
- if (u->registered != 7)
+ if (u->registered != REG_ALL)
{
log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
return;
}
uniq_id++;
- if (!uniq_id)
- {
- memset(&already_sent,0,MAX_DESCRIPTORS);
- uniq_id++;
- }
for (std::vector<ucrec*>::const_iterator v = u->chans.begin(); v != u->chans.end(); v++)
{
{
if (u != i->second)
{
- if ((i->second->fd > -1) && (already_sent[i->second->fd] != uniq_id))
+ if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
{
already_sent[i->second->fd] = uniq_id;
return;
}
- if (u->registered != 7)
+ if (u->registered != REG_ALL)
{
log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
return;
}
uniq_id++;
- if (!uniq_id)
- {
- memset(&already_sent,0,MAX_DESCRIPTORS);
- uniq_id++;
- }
for (std::vector<ucrec*>::const_iterator v = u->chans.begin(); v != u->chans.end(); v++)
{
{
if (u != i->second)
{
- if ((i->second->fd > -1) && (already_sent[i->second->fd] != uniq_id))
+ if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
{
already_sent[i->second->fd] = uniq_id;
WriteFrom_NoFormat(i->second->fd,u,text);
{
for (ClassVector::iterator i = Config->Classes.begin(); i != Config->Classes.end(); i++)
{
- if ((match(inet_ntoa(user->ip4),i->host.c_str())) || (match(user->host,i->host.c_str())))
+ if ((match(user->GetIPString(),i->host.c_str(),true)) || (match(user->host,i->host.c_str())))
{
return *i;
}
for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
{
userrec* t = (userrec*)(*i);
- if (t->registered == 7)
+ if (t->registered == REG_ALL)
{
WriteServ(t->fd,"NOTICE %s :%s",t->nick,s);
}
for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
{
- if (i->second->registered == 7) c++;
+ c += (i->second->registered == REG_ALL);
}
return c;
for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
{
- if ((i->second->registered == 7) && (i->second->modes[UM_INVISIBLE]))
- c++;
+ c += ((i->second->registered == REG_ALL) && (i->second->modes[UM_INVISIBLE]));
}
return c;
for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
{
userrec* t = (userrec*)(*i);
- if (t->registered != 7)
+ if (t->registered != REG_ALL)
c++;
}
for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
{
userrec* t = (userrec*)(*i);
- if (t->registered == 7)
+ if (t->registered == REG_ALL)
c++;
}