]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/helperfuncs.cpp
kick_channel -> chanrec::KickUser(), server_kick_channel -> chanrec::ServerKickUser()
[user/henk/code/inspircd.git] / src / helperfuncs.cpp
index 19ae22dc24825ce5ccb995c366c583b76cf5091e..1ebf890087dc9f036a2f2244639871f0c3f9e7e2 100644 (file)
@@ -51,7 +51,7 @@ extern InspIRCd* ServerInstance;
 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;
@@ -64,7 +64,7 @@ static char TIMESTR[26];
 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'
@@ -165,11 +165,11 @@ void Write_NoFormat(int sock, const char *text)
        {
                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)
                        {
@@ -213,11 +213,11 @@ void Write(int sock, char *text, ...)
                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)
                        {
@@ -249,11 +249,11 @@ void WriteServ_NoFormat(int sock, const char* text)
        {
                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)
                        {
@@ -313,11 +313,11 @@ void WriteFrom_NoFormat(int sock, userrec *user, const char* text)
        {
                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)
                        {
@@ -360,11 +360,11 @@ void WriteFrom(int sock, userrec *user,char* text, ...)
                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)
                        {
@@ -699,7 +699,7 @@ void WriteCommon(userrec *u, char* text, ...)
                return;
        }
 
-       if (u->registered != 7)
+       if (u->registered != REG_ALL)
        {
                log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
                return;
@@ -709,14 +709,8 @@ void WriteCommon(userrec *u, char* text, ...)
        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++)
        {
@@ -726,7 +720,7 @@ void WriteCommon(userrec *u, char* text, ...)
 
                        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);
@@ -756,7 +750,7 @@ void WriteCommon_NoFormat(userrec *u, const char* text)
                return;
        }
 
-       if (u->registered != 7)
+       if (u->registered != REG_ALL)
        {
                log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
                return;
@@ -764,11 +758,6 @@ void WriteCommon_NoFormat(userrec *u, const char* text)
 
        // 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++)
        {
@@ -778,7 +767,7 @@ void WriteCommon_NoFormat(userrec *u, const char* text)
 
                        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);
@@ -817,7 +806,7 @@ void WriteCommonExcept(userrec *u, char* text, ...)
                return;
        }
 
-       if (u->registered != 7)
+       if (u->registered != REG_ALL)
        {
                log(DEFAULT,"*** BUG *** WriteCommon on an unregistered user");
                return;
@@ -869,11 +858,6 @@ void WriteCommonExcept(userrec *u, char* text, ...)
        }
 
        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++)
        {
@@ -885,7 +869,7 @@ void WriteCommonExcept(userrec *u, char* text, ...)
                        {
                                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;
 
@@ -910,18 +894,13 @@ void WriteCommonExcept_NoFormat(userrec *u, const char* 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++)
        {
@@ -933,7 +912,7 @@ void WriteCommonExcept_NoFormat(userrec *u, const char* text)
                        {
                                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);
@@ -1426,7 +1405,7 @@ ConnectClass GetClass(userrec *user)
 {
        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;
                }
@@ -1446,7 +1425,7 @@ void send_error(char *s)
        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);
                }
@@ -1506,7 +1485,7 @@ int registered_usercount(void)
 
        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;
@@ -1518,8 +1497,7 @@ int usercount_invisible(void)
 
        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;
@@ -1544,7 +1522,7 @@ int usercount_unknown(void)
        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++;
        }
 
@@ -1563,7 +1541,7 @@ long local_count()
        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++;
        }