* +------------------------------------+
*
* InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
- * E-mail:
- * <brain@chatspike.net>
- * <Craig@chatspike.net>
+ * E-mail:
+ * <brain@chatspike.net>
+ * <Craig@chatspike.net>
*
* Written by Craig Edwards, Craig McLure, and others.
* This program is free but copyrighted software; see
- * the file COPYING for details.
+ * the file COPYING for details.
*
* ---------------------------------------------------
*/
extern time_t TIME;
extern char lowermap[255];
extern userrec* fd_ref_table[MAX_DESCRIPTORS];
-static char 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 char TIMESTR[26];
static time_t LAST = 0;
+/* XXX: Used for speeding up WriteCommon operations */
+unsigned long uniq_id = 0;
+
/** log()
* Write a line of text `text' to the logfile (and stdout, if in nofork) if the level `level'
* is greater than the configured loglevel.
{
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)
{
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);
- // FIX: Stops a message going to the same person more than once
- memset(&already_sent,0,MAX_DESCRIPTORS);
+ // 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++)
{
for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
{
- if ((i->second->fd > -1) && (!already_sent[i->second->fd]))
+ if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
{
- already_sent[i->second->fd] = 1;
+ already_sent[i->second->fd] = uniq_id;
WriteFrom_NoFormat(i->second->fd,u,textbuffer);
sent_to_at_least_one = true;
}
return;
}
- if (u->registered != 7)
+ if (u->registered != REG_ALL)
{
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);
+ // XXX: See comment in WriteCommon
+ 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]))
+ if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
{
- already_sent[i->second->fd] = 1;
+ already_sent[i->second->fd] = uniq_id;
WriteFrom_NoFormat(i->second->fd,u,text);
sent_to_at_least_one = true;
}
return;
}
- if (u->registered != 7)
+ if (u->registered != REG_ALL)
{
log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
return;
}
}
- 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]))
+ if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
{
- already_sent[i->second->fd] = 1;
+ already_sent[i->second->fd] = uniq_id;
if (quit_munge)
{
return;
}
- if (u->registered != 7)
+ if (u->registered != REG_ALL)
{
log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
return;
}
- 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]))
+ if ((IS_LOCAL(i->second)) && (already_sent[i->second->fd] != uniq_id))
{
- already_sent[i->second->fd] = 1;
+ already_sent[i->second->fd] = uniq_id;
WriteFrom_NoFormat(i->second->fd,u,text);
}
}
// firstly decrement the count on each channel
for (std::vector<ucrec*>::iterator f = u->chans.begin(); f != u->chans.end(); f++)
{
- if (((ucrec*)(*f))->channel)
+ ucrec* uc = (ucrec*)(*f);
+ if (uc->channel)
{
- if (((ucrec*)(*f))->channel->DelUser(u) == 0)
+ if (uc->channel->DelUser(u) == 0)
{
/* No users left in here, mark it for deletion */
- to_delete.push_back(((ucrec*)(*f))->channel);
- ((ucrec*)(*f))->channel = NULL;
+ to_delete.push_back(uc->channel);
+ uc->channel = NULL;
}
}
}
{
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++;
}
void ShowMOTD(userrec *user)
{
- static char mbuf[MAXBUF];
- static char crud[MAXBUF];
-
if (!Config->MOTD.size())
{
WriteServ(user->fd,"422 %s :Message of the day file is missing.",user->nick);
WriteServ(user->fd,"375 %s :%s message of the day", user->nick, Config->ServerName);
for (unsigned int i = 0; i < Config->MOTD.size(); i++)
- WriteServ(user->fd,"372 %s :- ",user->nick,Config->MOTD[i].c_str());
+ WriteServ(user->fd,"372 %s :- %s",user->nick,Config->MOTD[i].c_str());
WriteServ(user->fd,"376 %s :End of message of the day.", user->nick);
}
Config->ConfValue(Config->config_data, "module","name",count,configToken,MAXBUF);
printf("[\033[1;32m*\033[0m] Loading module:\t\033[1;32m%s\033[0m\n",configToken);
- if (!ServerInstance->LoadModule(configToken))
+ if (!ServerInstance->LoadModule(configToken))
{
log(DEFAULT,"Exiting due to a module loader error.");
printf("\nThere was an error loading a module: %s\n\n",ServerInstance->ModuleError());