]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/helperfuncs.cpp
Changed fd_ref_table from 65536 to more correct MAX_DESCRIPTORS
[user/henk/code/inspircd.git] / src / helperfuncs.cpp
index 3bc2bb79aed664196b9a4bf46d4c1f8ffd0996f1..059f89be632b150382988bff552d91f40f588762 100644 (file)
@@ -56,12 +56,14 @@ extern InspIRCd* ServerInstance;
 extern time_t TIME;
 extern char lowermap[255];
 static char list[MAXBUF];
-extern userrec* fd_ref_table[65536];
-static char already_sent[65536];
+extern userrec* fd_ref_table[MAX_DESCRIPTORS];
+static char already_sent[MAX_DESCRIPTORS];
 extern std::vector<userrec*> all_opers;
 extern user_hash clientlist;
 extern chan_hash chanlist;
 
+extern std::vector<userrec*> local_users;
+
 void log(int level,char *text, ...)
 {
         va_list argsPtr;
@@ -73,11 +75,11 @@ void log(int level,char *text, ...)
 
         if (Config->log_file)
         {
-                char b[MAXBUF];
+                char b[26];
                 va_start (argsPtr, text);
                 vsnprintf(textbuffer, MAXBUF, text, argsPtr);
                 va_end(argsPtr);
-                strlcpy(b,asctime(timeinfo),MAXBUF);
+                strlcpy(b,asctime(timeinfo),26);
                 b[24] = ':';    // we know this is the end of the time string
                if (Config->log_file)
                        fprintf(Config->log_file,"%s %s\n",b,textbuffer);
@@ -121,6 +123,29 @@ void readfile(file_cache &F, const char* fname)
         log(DEBUG,"readfile: loaded %s, %lu lines",fname,(unsigned long)F.size());
 }
 
+void Write_NoFormat(int sock, const char *text)
+{
+       if ((sock < 0) || (!text))
+               return;
+
+       char tb[MAXBUF];
+       int bytes = snprintf(tb,MAXBUF,"%s\r\n",text);
+       chop(tb);
+       if (fd_ref_table[sock])
+       {
+               if (Config->GetIOHook(fd_ref_table[sock]->port))
+               {
+                       Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+               }
+               else
+               {
+                       fd_ref_table[sock]->AddWriteBuf(tb);
+               }
+               ServerInstance->stats->statsSent += bytes;
+       }
+       else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
+}
+
 void Write(int sock,char *text, ...)
 {
         if (sock < 0)
@@ -152,6 +177,28 @@ void Write(int sock,char *text, ...)
         else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
 }
 
+void WriteServ_NoFormat(int sock, const char* text)
+{
+       if ((sock < 0) || (!text))
+               return;
+       char tb[MAXBUF];
+       int bytes = snprintf(tb,MAXBUF,":%s %s\r\n",Config->ServerName,text);
+       chop(tb);
+       if (fd_ref_table[sock])
+       {
+               if (Config->GetIOHook(fd_ref_table[sock]->port))
+               {
+                       Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+               }
+               else
+               {
+                       fd_ref_table[sock]->AddWriteBuf(tb);
+               }
+               ServerInstance->stats->statsSent += bytes;
+       }
+       else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
+}
+
 /* write a server formatted numeric response to a single socket */
 
 void WriteServ(int sock, char* text, ...)
@@ -185,6 +232,28 @@ void WriteServ(int sock, char* text, ...)
         else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
 }
 
+void WriteFrom_NoFormat(int sock, userrec *user, const char* text)
+{
+       if ((sock < 0) || (!text) || (!user))
+               return;
+       char tb[MAXBUF];
+       int bytes = snprintf(tb,MAXBUF,":%s!%s@%s %s\r\n",user->nick,user->ident,user->dhost,text);
+       chop(tb);
+       if (fd_ref_table[sock])
+       {
+               if (Config->GetIOHook(fd_ref_table[sock]->port))
+               {
+                       Config->GetIOHook(fd_ref_table[sock]->port)->OnRawSocketWrite(sock,tb,bytes);
+               }
+               else
+               {
+                       fd_ref_table[sock]->AddWriteBuf(tb);
+               }
+               ServerInstance->stats->statsSent += bytes;
+       }
+       else log(DEFAULT,"ERROR! attempted write to a user with no fd_ref_table entry!!!");
+}
+
 /* write text from an originating user to originating user */
 
 void WriteFrom(int sock, userrec *user,char* text, ...)
@@ -227,7 +296,7 @@ void WriteTo(userrec *source, userrec *dest,char *data, ...)
                 log(DEFAULT,"*** BUG *** WriteTo was given an invalid parameter");
                 return;
         }
-        if (dest->fd == FD_MAGIC_NUMBER)
+        if (!IS_LOCAL(dest))
                 return;
        char textbuffer[MAXBUF],tb[MAXBUF];
         va_list argsPtr;
@@ -243,10 +312,24 @@ void WriteTo(userrec *source, userrec *dest,char *data, ...)
         }
         else
         {
-                WriteFrom(dest->fd,source,"%s",textbuffer);
+                WriteFrom_NoFormat(dest->fd,source,textbuffer);
         }
 }
 
+void WriteTo_NoFormat(userrec *source, userrec *dest, const char *data)
+{
+       if ((!dest) || (!data))
+               return;
+       if (!source)
+       {
+               WriteServ(dest->fd,":%s %s",Config->ServerName,data);
+       }
+       else
+       {
+               WriteFrom_NoFormat(dest->fd,source,data);
+       }
+}
+
 /* write formatted text from a source user to all users on a channel
  * including the sender (NOT for privmsg, notice etc!) */
 
@@ -270,10 +353,29 @@ void WriteChannel(chanrec* Ptr, userrec* user, char* text, ...)
                 char* o = (*ulist)[j];
                 userrec* otheruser = (userrec*)o;
                 if (otheruser->fd != FD_MAGIC_NUMBER)
-                        WriteTo(user,otheruser,"%s",textbuffer);
+                        WriteTo_NoFormat(user,otheruser,textbuffer);
         }
 }
 
+void WriteChannel_NoFormat(chanrec* Ptr, userrec* user, const char* text)
+{
+        if ((!Ptr) || (!user) || (!text))
+        {
+                log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter");
+                return;
+        }
+        std::vector<char*> *ulist = Ptr->GetUsers();
+        unsigned int x = ulist->size();
+        for (unsigned int j = 0; j < x; j++)
+        {
+                char* o = (*ulist)[j];
+                userrec* otheruser = (userrec*)o;
+                if (otheruser->fd != FD_MAGIC_NUMBER)
+                        WriteTo_NoFormat(user,otheruser,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 */
@@ -297,20 +399,49 @@ void WriteChannelLocal(chanrec* Ptr, userrec* user, char* text, ...)
         {
                 char* o = (*ulist)[j];
                 userrec* otheruser = (userrec*)o;
-                if ((otheruser->fd != FD_MAGIC_NUMBER) && (otheruser->fd != -1) && (otheruser != user))
+                if ((otheruser->fd != FD_MAGIC_NUMBER) && (otheruser != user))
+                {
+                        if (!user)
+                        {
+                                WriteServ_NoFormat(otheruser->fd,textbuffer);
+                        }
+                        else
+                        {
+                                WriteTo_NoFormat(user,otheruser,textbuffer);
+                        }
+                }
+        }
+}
+
+void WriteChannelLocal_NoFormat(chanrec* Ptr, userrec* user, const char* text)
+{
+        if ((!Ptr) || (!text))
+        {
+                log(DEFAULT,"*** BUG *** WriteChannel was given an invalid parameter");
+                return;
+        }
+        std::vector<char*> *ulist = Ptr->GetUsers();
+        unsigned int x = ulist->size();
+        for (unsigned int j = 0; j < x; j++)
+        {
+                char* o = (*ulist)[j];   
+                userrec* otheruser = (userrec*)o;
+                if ((otheruser->fd != FD_MAGIC_NUMBER) && (otheruser != user))
                 {
                         if (!user)
                         {
-                                WriteServ(otheruser->fd,"%s",textbuffer);
+                                WriteServ_NoFormat(otheruser->fd,text);
                         }
                         else
                         {
-                                WriteTo(user,otheruser,"%s",textbuffer);
+                                WriteTo_NoFormat(user,otheruser,text);
                         }
                 }
         }
 }
 
+
+
 void WriteChannelWithServ(char* ServName, chanrec* Ptr, char* text, ...)
 {
         if ((!Ptr) || (!text))
@@ -331,11 +462,31 @@ void WriteChannelWithServ(char* ServName, chanrec* Ptr, char* text, ...)
         {
                 char* o = (*ulist)[j];
                 userrec* otheruser = (userrec*)o;
-                if (otheruser->fd != FD_MAGIC_NUMBER)
-                        WriteServ(otheruser->fd,"%s",textbuffer);
+                if (IS_LOCAL(otheruser))
+                        WriteServ_NoFormat(otheruser->fd,textbuffer);
         }
 }
 
+void WriteChannelWithServ_NoFormat(char* ServName, chanrec* Ptr, const char* text)
+{
+        if ((!Ptr) || (!text))
+        {
+                log(DEFAULT,"*** BUG *** WriteChannelWithServ was given an invalid parameter");
+                return;
+        }
+        std::vector<char*> *ulist = Ptr->GetUsers();
+        unsigned int x = ulist->size();
+        for (unsigned int j = 0; j < x; j++)
+        {
+                char* o = (*ulist)[j];
+                userrec* otheruser = (userrec*)o;
+                if (IS_LOCAL(otheruser))
+                        WriteServ_NoFormat(otheruser->fd,text);
+        }
+}
+
+
+
 /* write formatted text from a source user to all users on a channel except
  * for the sender (for privmsg etc) */
 
@@ -358,15 +509,33 @@ void ChanExceptSender(chanrec* Ptr, userrec* user, char* text, ...)
         {
                 char* o = (*ulist)[j];
                 userrec* otheruser = (userrec*)o;
-                if ((otheruser->fd != FD_MAGIC_NUMBER) && (user != otheruser))
-                        WriteFrom(otheruser->fd,user,"%s",textbuffer);
+                if ((IS_LOCAL(otheruser)) && (user != otheruser))
+                        WriteFrom_NoFormat(otheruser->fd,user,textbuffer);
+        }
+}
+
+void ChanExceptSender_NoFormat(chanrec* Ptr, userrec* user, const char* text)
+{
+        if ((!Ptr) || (!user) || (!text))
+        {
+                log(DEFAULT,"*** BUG *** ChanExceptSender was given an invalid parameter");
+                return;
+        }
+        std::vector<char*> *ulist = Ptr->GetUsers();
+        unsigned int x = ulist->size();
+        for (unsigned int j = 0; j < x; j++)
+        {
+                char* o = (*ulist)[j];
+                userrec* otheruser = (userrec*)o;
+                if ((IS_LOCAL(otheruser)) && (user != otheruser))
+                        WriteFrom_NoFormat(otheruser->fd,user,text);
         }
 }
 
 std::string GetServerDescription(char* servername)
 {
        std::string description = "";
-       FOREACH_MOD OnGetServerDescription(servername,description);
+       FOREACH_MOD(I_OnGetServerDescription,OnGetServerDescription(servername,description));
        if (description != "")
        {
                return description;
@@ -400,7 +569,7 @@ void WriteCommon(userrec *u, char* text, ...)
         va_end(argsPtr);
 
         // FIX: Stops a message going to the same person more than once
-        memset(&already_sent,0,MAXCLIENTS);
+        memset(&already_sent,0,MAX_DESCRIPTORS);
 
         bool sent_to_at_least_one = false;
 
@@ -418,7 +587,52 @@ void WriteCommon(userrec *u, char* text, ...)
                                 if ((otheruser->fd > -1) && (!already_sent[otheruser->fd]))
                                 {
                                         already_sent[otheruser->fd] = 1;
-                                        WriteFrom(otheruser->fd,u,"%s",textbuffer);
+                                        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);
+        }
+}
+
+void WriteCommon_NoFormat(userrec *u, const 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;
+        }
+        // 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::vector<char*> *ulist = u->chans[i].channel->GetUsers();
+                        unsigned int x = ulist->size();
+                        for (unsigned int j = 0; j < x; j++)
+                        {
+                                char* o = (*ulist)[j];
+                                userrec* otheruser = (userrec*)o;
+                                if ((otheruser->fd > -1) && (!already_sent[otheruser->fd]))
+                                {
+                                        already_sent[otheruser->fd] = 1;
+                                        WriteFrom_NoFormat(otheruser->fd,u,text);
                                         sent_to_at_least_one = true;
                                 }
                         }
@@ -428,10 +642,12 @@ void WriteCommon(userrec *u, char* text, ...)
         // receives their OWN message for WriteCommon
         if (!sent_to_at_least_one)
         {
-                WriteFrom(u->fd,u,"%s",textbuffer);
+                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 */
 
@@ -454,7 +670,7 @@ void WriteCommonExcept(userrec *u, char* text, ...)
         vsnprintf(textbuffer, MAXBUF, text, argsPtr);
         va_end(argsPtr);
 
-        memset(&already_sent,0,MAXCLIENTS);
+        memset(&already_sent,0,MAX_DESCRIPTORS);
 
        unsigned int y = u->chans.size();
         for (unsigned int i = 0; i < y; i++)
@@ -472,7 +688,7 @@ void WriteCommonExcept(userrec *u, char* text, ...)
                                         if ((otheruser->fd > -1) && (!already_sent[otheruser->fd]))
                                         {
                                                 already_sent[otheruser->fd] = 1;
-                                                WriteFrom(otheruser->fd,u,"%s",textbuffer);
+                                                WriteFrom_NoFormat(otheruser->fd,u,textbuffer);
                                         }
                                 }
                         }
@@ -480,6 +696,47 @@ void WriteCommonExcept(userrec *u, char* text, ...)
         }
 }
 
+void WriteCommonExcept_NoFormat(userrec *u, const 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;
+        }
+
+        memset(&already_sent,0,MAX_DESCRIPTORS);
+
+        unsigned int y = u->chans.size();
+        for (unsigned int i = 0; i < y; i++)
+        {
+                if (u->chans[i].channel)
+                {
+                        std::vector<char*> *ulist = u->chans[i].channel->GetUsers();
+                        unsigned int x = ulist->size();
+                        for (unsigned int j = 0; j < x; j++)
+                        {
+                                char* o = (*ulist)[j];
+                                userrec* otheruser = (userrec*)o;
+                                if (u != otheruser)
+                                {
+                                        if ((otheruser->fd > -1) && (!already_sent[otheruser->fd]))
+                                        {
+                                                already_sent[otheruser->fd] = 1;
+                                                WriteFrom_NoFormat(otheruser->fd,u,text);
+                                        }
+                                }
+                        }
+                }
+        }
+}
+
+
+
 void WriteOpers(char* text, ...)
 {
         if (!text)
@@ -497,7 +754,7 @@ void WriteOpers(char* text, ...)
         for (std::vector<userrec*>::iterator i = all_opers.begin(); i != all_opers.end(); i++)
         {
                 userrec* a = *i;
-                if ((a) && (a->fd != FD_MAGIC_NUMBER))
+                if (IS_LOCAL(a))
                 {
                         if (strchr(a->modes,'s'))
                         {
@@ -519,12 +776,10 @@ void ServerNoticeAll(char* text, ...)
        vsnprintf(textbuffer, MAXBUF, text, argsPtr);
        va_end(argsPtr);
 
-       for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
+       for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
        {
-               if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
-               {
-                       WriteServ(i->second->fd,"NOTICE $%s :%s",Config->ServerName,textbuffer);
-               }
+               userrec* t = (userrec*)(*i);
+               WriteServ(t->fd,"NOTICE $%s :%s",Config->ServerName,textbuffer);
        }
 }
 
@@ -539,12 +794,10 @@ void ServerPrivmsgAll(char* text, ...)
        vsnprintf(textbuffer, MAXBUF, text, argsPtr);
        va_end(argsPtr);
 
-       for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
+       for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
        {
-               if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
-               {
-                       WriteServ(i->second->fd,"PRIVMSG $%s :%s",Config->ServerName,textbuffer);
-               }
+               userrec* t = (userrec*)(*i);
+               WriteServ(t->fd,"PRIVMSG $%s :%s",Config->ServerName,textbuffer);
        }
 }
 
@@ -563,41 +816,37 @@ void WriteMode(const char* modes, int flags, const char* text, ...)
         va_end(argsPtr);
         int modelen = strlen(modes);
 
-        for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
+        for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
         {
-                if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
+               userrec* t = (userrec*)(*i);
+                bool send_to_user = false;
+                if (flags == WM_AND)
                 {
-                        bool send_to_user = false;
-
-                        if (flags == WM_AND)
+                        send_to_user = true;
+                        for (int n = 0; n < modelen; n++)
                         {
-                                send_to_user = true;
-                                for (int n = 0; n < modelen; n++)
+                                if (!hasumode(t,modes[n]))
                                 {
-                                        if (!hasumode(i->second,modes[n]))
-                                        {
-                                                send_to_user = false;
-                                                break;
-                                        }
+                                        send_to_user = false;
+                                        break;
                                 }
                         }
-                        else if (flags == WM_OR)
+                }
+                else if (flags == WM_OR)
+                {
+                        send_to_user = false;
+                        for (int n = 0; n < modelen; n++)
                         {
-                                send_to_user = false;
-                                for (int n = 0; n < modelen; n++)
+                                if (hasumode(t,modes[n]))
                                 {
-                                        if (hasumode(i->second,modes[n]))
-                                        {
-                                                send_to_user = true;
-                                                break;
-                                        }
+                                        send_to_user = true;
+                                        break;
                                 }
                         }
-
-                        if (send_to_user)
-                        {
-                                WriteServ(i->second->fd,"NOTICE %s :%s",i->second->nick,textbuffer);
-                        }
+                }
+                if (send_to_user)
+                {
+                        WriteServ(t->fd,"NOTICE %s :%s",t->nick,textbuffer);
                 }
         }
 }
@@ -616,12 +865,10 @@ void NoticeAll(userrec *source, bool local_only, char* text, ...)
         vsnprintf(textbuffer, MAXBUF, text, argsPtr);
         va_end(argsPtr);
 
-        for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
+        for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
         {
-                if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
-                {
-                        WriteFrom(i->second->fd,source,"NOTICE $* :%s",textbuffer);
-                }
+                userrec* t = (userrec*)(*i);
+                WriteFrom(t->fd,source,"NOTICE $* :%s",textbuffer);
         }
 
 }
@@ -641,14 +888,12 @@ void WriteWallOps(userrec *source, bool local_only, char* text, ...)
         vsnprintf(textbuffer, MAXBUF, text, argsPtr);
         va_end(argsPtr);
 
-        for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
+        for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
         {
-                if ((i->second) && (i->second->fd != FD_MAGIC_NUMBER))
+               userrec* t = (userrec*)(*i);
+                if ((IS_LOCAL(t)) && (strchr(t->modes,'w')))
                 {
-                        if (strchr(i->second->modes,'w'))
-                        {
-                                WriteTo(source,i->second,"WALLOPS :%s",textbuffer);
-                        }
+                        WriteTo(source,t,"WALLOPS :%s",textbuffer);
                 }
         }
 }
@@ -855,14 +1100,14 @@ void userlist(userrec *user,chanrec *c)
                 {
                         /* list overflowed into
                          * multiple numerics */
-                        WriteServ(user->fd,"%s",list);
+                        WriteServ_NoFormat(user->fd,list);
                         snprintf(list,MAXBUF,"353 %s = %s :", user->nick, c->name);
                 }
         }
         /* if whats left in the list isnt empty, send it */
         if (list[strlen(list)-1] != ':')
         {
-                WriteServ(user->fd,"%s",list);
+                WriteServ_NoFormat(user->fd,list);
         }
 }
 
@@ -881,11 +1126,9 @@ int usercount_i(chanrec *c)
 
         for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
         {
-                if (i->second)
-                {
                         if (has_channel(i->second,c))
                         {
-                                if (isnick(i->second->nick))
+                                if (i->second->registered == 7)
                                 {
                                         if ((!has_channel(i->second,c)) && (strchr(i->second->modes,'i')))
                                         {
@@ -896,7 +1139,6 @@ int usercount_i(chanrec *c)
                                         count++;
                                 }
                         }
-                }
         }
         log(DEBUG,"usercount_i: %s %lu",c->name,(unsigned long)count);
         return count;
@@ -905,66 +1147,42 @@ int usercount_i(chanrec *c)
 
 int usercount(chanrec *c)
 {
-        if (!c)
-        {
-                log(DEFAULT,"*** BUG *** usercount was given an invalid parameter");
-                return 0;
-        }
-        int count = c->GetUserCounter();
-        log(DEBUG,"usercount: %s %lu",c->name,(unsigned long)count);
-        return count;
+        return (c ? c->GetUserCounter() : 0);
 }
 
 
 // looks up a users password for their connection class (<ALLOW>/<DENY> tags)
 
-char* Passwd(userrec *user)
-{
-        for (ClassVector::iterator i = Config->Classes.begin(); i != Config->Classes.end(); i++)
-        {
-                if ((i->type == CC_ALLOW) && match(user->host,i->host.c_str()))
-                {
-                        return (char*)i->pass.c_str();
-                }
-        }
-        return "";
-}
-
-bool IsDenied(userrec *user)
+ConnectClass GetClass(userrec *user)
 {
         for (ClassVector::iterator i = Config->Classes.begin(); i != Config->Classes.end(); i++)
         {
-                if ((i->type == CC_DENY) && match(user->host,i->host.c_str()))
+                if (match(user->host,i->host.c_str()))
                 {
-                        return true;
+                        return *i;
                 }
         }
-        return false;
+        return *(Config->Classes.begin());
 }
 
-
-
-
 /* sends out an error notice to all connected clients (not to be used
  * lightly!) */
 
 void send_error(char *s)
 {
         log(DEBUG,"send_error: %s",s);
-        for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
+        for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
         {
-                if (IS_LOCAL(i->second))
-               {
-                       if (i->second->registered == 7)
-                       {
-                               WriteServ(i->second->fd,"NOTICE %s :%s",i->second->nick,s);
-                       }
-                       else
-                       {
-                               // fix - unregistered connections receive ERROR, not NOTICE
-                               Write(i->second->fd,"ERROR :%s",s);
-                       }
-               }
+               userrec* t = (userrec*)(*i);
+               if (t->registered == 7)
+                {
+                               WriteServ(t->fd,"NOTICE %s :%s",t->nick,s);
+                       }
+                else
+                {
+                        // fix - unregistered connections receive ERROR, not NOTICE
+                        Write(t->fd,"ERROR :%s",s);
+                }
         }
 }
 
@@ -1004,28 +1222,23 @@ int usercount_invisible(void)
         int c = 0;
         for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
         {
-                if ((isnick(i->second->nick)) && (strchr(i->second->modes,'i'))) c++;
+                if ((i->second->registered == 7) && (strchr(i->second->modes,'i'))) c++;
         }
         return c;
 }
 
 int usercount_opers(void)
 {
-        int c = 0;
-        for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
-        {
-                if ((isnick(i->second->nick)) && (strchr(i->second->modes,'o'))) c++;
-        }
-        return c;
+        return all_opers.size();
 }
 
 int usercount_unknown(void)
 {
         int c = 0;
-
-        for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
+        for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
         {
-                if ((i->second->fd > -1) && (i->second->registered != 7))
+               userrec* t = (userrec*)(*i);
+                if (t->registered != 7)
                         c++;
         }
         return c;
@@ -1039,9 +1252,10 @@ long chancount(void)
 long local_count()
 {
         int c = 0;
-        for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
+        for (std::vector<userrec*>::const_iterator i = local_users.begin(); i != local_users.end(); i++)
         {
-                if ((isnick(i->second->nick)) && (i->second->fd > -1)) c++;
+               userrec* t = (userrec*)(*i);
+                if (t->registered == 7) c++;
         }
         return c;
 }
@@ -1093,11 +1307,16 @@ void ShowRULES(userrec *user)
 // registration timeout maximum seconds)
 bool AllModulesReportReady(userrec* user)
 {
+       if (!Config->global_implementation[I_OnCheckReady])
+               return true;
         for (int i = 0; i <= MODCOUNT; i++)
         {
-                int res = modules[i]->OnCheckReady(user);
-                if (!res)
-                        return false;
+               if (Config->implement_lists[i][I_OnCheckReady])
+               {
+                       int res = modules[i]->OnCheckReady(user);
+                       if (!res)
+                               return false;
+               }
         }
         return true;
 }