]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/helperfuncs.cpp
Removed debug
[user/henk/code/inspircd.git] / src / helperfuncs.cpp
index d9b4c7fa82026f14ad5c75ddbef347fc193b44a5..037a7a3af9d01aeae99347675ae230d7a7cce3f1 100644 (file)
@@ -52,28 +52,24 @@ using namespace std;
 extern int MODCOUNT;
 extern std::vector<Module*> modules;
 extern ServerConfig *Config;
+extern InspIRCd* ServerInstance;
 extern time_t TIME;
 extern char lowermap[255];
 static char list[MAXBUF];
 extern userrec* fd_ref_table[65536];
-extern serverstats* stats;
 static char already_sent[65536];
 extern std::vector<userrec*> all_opers;
 extern user_hash clientlist;
 extern chan_hash chanlist;
-extern command_table cmdlist;
 
 void log(int level,char *text, ...)
 {
-        char textbuffer[MAXBUF];
         va_list argsPtr;
-        time_t rawtime;
         struct tm * timeinfo;
         if (level < Config->LogLevel)
                 return;
-
-        time(&rawtime);
-        timeinfo = localtime(&rawtime);
+       char textbuffer[MAXBUF];
+        timeinfo = localtime(&TIME);
 
         if (Config->log_file)
         {
@@ -134,10 +130,8 @@ void Write(int sock,char *text, ...)
                 log(DEFAULT,"*** BUG *** Write was given an invalid parameter");
                 return;
         }
-        char textbuffer[MAXBUF];
         va_list argsPtr;
-        char tb[MAXBUF];
-
+       char textbuffer[MAXBUF],tb[MAXBUF];
         va_start (argsPtr, text);
         vsnprintf(textbuffer, MAXBUF, text, argsPtr);
         va_end(argsPtr);
@@ -145,10 +139,15 @@ void Write(int sock,char *text, ...)
         chop(tb);
         if (fd_ref_table[sock])
         {
-                int MOD_RESULT = 0;
-                FOREACH_RESULT(OnRawSocketWrite(sock,tb,bytes));
-                fd_ref_table[sock]->AddWriteBuf(tb);
-                stats->statsSent += bytes;
+               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!!!");
 }
@@ -164,20 +163,24 @@ void WriteServ(int sock, char* text, ...)
                 log(DEFAULT,"*** BUG *** WriteServ was given an invalid parameter");
                 return;
         }
-        char textbuffer[MAXBUF],tb[MAXBUF];
         va_list argsPtr;
         va_start (argsPtr, text);
-
+       char textbuffer[MAXBUF],tb[MAXBUF];
         vsnprintf(textbuffer, MAXBUF, text, argsPtr);
         va_end(argsPtr);
         int bytes = snprintf(tb,MAXBUF,":%s %s\r\n",Config->ServerName,textbuffer);
         chop(tb);
         if (fd_ref_table[sock])
         {
-                int MOD_RESULT = 0;
-                FOREACH_RESULT(OnRawSocketWrite(sock,tb,bytes));
-                fd_ref_table[sock]->AddWriteBuf(tb);
-                stats->statsSent += bytes;
+               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!!!");
 }
@@ -193,20 +196,24 @@ void WriteFrom(int sock, userrec *user,char* text, ...)
                 log(DEFAULT,"*** BUG *** WriteFrom was given an invalid parameter");
                 return;
         }
-        char textbuffer[MAXBUF],tb[MAXBUF];
         va_list argsPtr;
         va_start (argsPtr, text);
-
+       char textbuffer[MAXBUF],tb[MAXBUF];
         vsnprintf(textbuffer, MAXBUF, text, argsPtr);
         va_end(argsPtr);
         int bytes = snprintf(tb,MAXBUF,":%s!%s@%s %s\r\n",user->nick,user->ident,user->dhost,textbuffer);
         chop(tb);
         if (fd_ref_table[sock])
         {
-                int MOD_RESULT = 0;
-                FOREACH_RESULT(OnRawSocketWrite(sock,tb,bytes));
-                fd_ref_table[sock]->AddWriteBuf(tb);
-                stats->statsSent += bytes;
+               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!!!");
 }
@@ -222,7 +229,7 @@ void WriteTo(userrec *source, userrec *dest,char *data, ...)
         }
         if (dest->fd == FD_MAGIC_NUMBER)
                 return;
-        char textbuffer[MAXBUF],tb[MAXBUF];
+       char textbuffer[MAXBUF],tb[MAXBUF];
         va_list argsPtr;
         va_start (argsPtr, data);
         vsnprintf(textbuffer, MAXBUF, data, argsPtr);
@@ -257,7 +264,8 @@ void WriteChannel(chanrec* Ptr, userrec* user, char* text, ...)
         va_end(argsPtr);
 
         std::vector<char*> *ulist = Ptr->GetUsers();
-        for (unsigned int j = 0; j < ulist->size(); j++)
+       unsigned int x = ulist->size();
+        for (unsigned int j = 0; j < x; j++)
         {
                 char* o = (*ulist)[j];
                 userrec* otheruser = (userrec*)o;
@@ -284,7 +292,8 @@ void WriteChannelLocal(chanrec* Ptr, userrec* user, char* text, ...)
         va_end(argsPtr);
 
         std::vector<char*> *ulist = Ptr->GetUsers();
-        for (unsigned int j = 0; j < ulist->size(); j++)
+       unsigned int x = ulist->size();
+        for (unsigned int j = 0; j < x; j++)
         {
                 char* o = (*ulist)[j];
                 userrec* otheruser = (userrec*)o;
@@ -317,7 +326,8 @@ void WriteChannelWithServ(char* ServName, chanrec* Ptr, char* text, ...)
 
 
         std::vector<char*> *ulist = Ptr->GetUsers();
-        for (unsigned int j = 0; j < ulist->size(); j++)
+       unsigned int x = ulist->size();
+        for (unsigned int j = 0; j < x; j++)
         {
                 char* o = (*ulist)[j];
                 userrec* otheruser = (userrec*)o;
@@ -343,7 +353,8 @@ void ChanExceptSender(chanrec* Ptr, userrec* user, char* text, ...)
         va_end(argsPtr);
 
         std::vector<char*> *ulist = Ptr->GetUsers();
-        for (unsigned int j = 0; j < ulist->size(); j++)
+       unsigned int x = ulist->size();
+        for (unsigned int j = 0; j < x; j++)
         {
                 char* o = (*ulist)[j];
                 userrec* otheruser = (userrec*)o;
@@ -389,20 +400,22 @@ 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,65536);
+        memset(&already_sent,0,MAXCLIENTS);
 
         bool sent_to_at_least_one = false;
 
-        for (unsigned int i = 0; i < u->chans.size(); i++)
+       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();
-                        for (unsigned int j = 0; j < ulist->size(); j++)
+                       unsigned int x = ulist->size();
+                        for (unsigned int j = 0; j < x; j++)
                         {
                                 char* o = (*ulist)[j];
                                 userrec* otheruser = (userrec*)o;
-                                if ((otheruser->fd > 0) && (!already_sent[otheruser->fd]))
+                                if ((otheruser->fd > -1) && (!already_sent[otheruser->fd]))
                                 {
                                         already_sent[otheruser->fd] = 1;
                                         WriteFrom(otheruser->fd,u,"%s",textbuffer);
@@ -441,20 +454,22 @@ void WriteCommonExcept(userrec *u, char* text, ...)
         vsnprintf(textbuffer, MAXBUF, text, argsPtr);
         va_end(argsPtr);
 
-        memset(&already_sent,0,65536);
+        memset(&already_sent,0,MAXCLIENTS);
 
-        for (unsigned int i = 0; i < u->chans.size(); i++)
+       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();
-                        for (unsigned int j = 0; j < ulist->size(); j++)
+                       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 > 0) && (!already_sent[otheruser->fd]))
+                                        if ((otheruser->fd > -1) && (!already_sent[otheruser->fd]))
                                         {
                                                 already_sent[otheruser->fd] = 1;
                                                 WriteFrom(otheruser->fd,u,"%s",textbuffer);
@@ -1049,8 +1064,15 @@ void ShowMOTD(userrec *user)
         snprintf(mbuf,MAXBUF,":%s 376 %s :End of message of the day.\r\n", Config->ServerName, user->nick);
         WholeMOTD = WholeMOTD + mbuf;
         // only one write operation
-        user->AddWriteBuf(WholeMOTD);
-        stats->statsSent += WholeMOTD.length();
+       if (Config->GetIOHook(user->port))
+       {
+               Config->GetIOHook(user->port)->OnRawSocketWrite(user->fd,(char*)WholeMOTD.c_str(),WholeMOTD.length());
+       }
+       else
+       {
+               user->AddWriteBuf(WholeMOTD);
+       }
+        ServerInstance->stats->statsSent += WholeMOTD.length();
 }
 
 void ShowRULES(userrec *user)
@@ -1080,79 +1102,6 @@ bool AllModulesReportReady(userrec* user)
         return true;
 }
 
-void createcommand(char* cmd, handlerfunc f, char flags, int minparams,char* source)
-{
-        command_t comm;
-        /* create the command and push it onto the table */
-        strlcpy(comm.command,cmd,MAXBUF);
-        strlcpy(comm.source,source,MAXBUF);
-        comm.handler_function = f;
-        comm.flags_needed = flags;
-        comm.min_params = minparams;
-        comm.use_count = 0;
-        comm.total_bytes = 0;
-        cmdlist.push_back(comm);
-        log(DEBUG,"Added command %s (%lu parameters)",cmd,(unsigned long)minparams);
-}
-
-
-void SetupCommandTable(void)
-{
-        createcommand("USER",handle_user,0,4,"<core>");
-        createcommand("NICK",handle_nick,0,1,"<core>");
-        createcommand("QUIT",handle_quit,0,0,"<core>");
-        createcommand("VERSION",handle_version,0,0,"<core>");
-        createcommand("PING",handle_ping,0,1,"<core>");
-        createcommand("PONG",handle_pong,0,1,"<core>");
-        createcommand("ADMIN",handle_admin,0,0,"<core>");
-        createcommand("PRIVMSG",handle_privmsg,0,2,"<core>");
-        createcommand("INFO",handle_info,0,0,"<core>");
-        createcommand("TIME",handle_time,0,0,"<core>");
-        createcommand("WHOIS",handle_whois,0,1,"<core>");
-        createcommand("WALLOPS",handle_wallops,'o',1,"<core>");
-        createcommand("NOTICE",handle_notice,0,2,"<core>");
-        createcommand("JOIN",handle_join,0,1,"<core>");
-        createcommand("NAMES",handle_names,0,0,"<core>");
-        createcommand("PART",handle_part,0,1,"<core>");
-        createcommand("KICK",handle_kick,0,2,"<core>");
-        createcommand("MODE",handle_mode,0,1,"<core>");
-        createcommand("TOPIC",handle_topic,0,1,"<core>");
-        createcommand("WHO",handle_who,0,1,"<core>");
-        createcommand("MOTD",handle_motd,0,0,"<core>");
-        createcommand("RULES",handle_rules,0,0,"<core>");
-        createcommand("OPER",handle_oper,0,2,"<core>");
-        createcommand("LIST",handle_list,0,0,"<core>");
-        createcommand("DIE",handle_die,'o',1,"<core>");
-        createcommand("RESTART",handle_restart,'o',1,"<core>");
-        createcommand("KILL",handle_kill,'o',2,"<core>");
-        createcommand("REHASH",handle_rehash,'o',0,"<core>");
-        createcommand("LUSERS",handle_lusers,0,0,"<core>");
-        createcommand("STATS",handle_stats,0,1,"<core>");
-        createcommand("USERHOST",handle_userhost,0,1,"<core>");
-        createcommand("AWAY",handle_away,0,0,"<core>");
-        createcommand("ISON",handle_ison,0,0,"<core>");
-        createcommand("SUMMON",handle_summon,0,0,"<core>");
-        createcommand("USERS",handle_users,0,0,"<core>");
-        createcommand("INVITE",handle_invite,0,0,"<core>");
-        createcommand("PASS",handle_pass,0,1,"<core>");
-        createcommand("TRACE",handle_trace,'o',0,"<core>");
-        createcommand("WHOWAS",handle_whowas,0,1,"<core>");
-        createcommand("CONNECT",handle_connect,'o',1,"<core>");
-        createcommand("SQUIT",handle_squit,'o',0,"<core>");
-        createcommand("MODULES",handle_modules,0,0,"<core>");
-        createcommand("LINKS",handle_links,0,0,"<core>");
-        createcommand("MAP",handle_map,0,0,"<core>");
-        createcommand("KLINE",handle_kline,'o',1,"<core>");
-        createcommand("GLINE",handle_gline,'o',1,"<core>");
-        createcommand("ZLINE",handle_zline,'o',1,"<core>");
-        createcommand("QLINE",handle_qline,'o',1,"<core>");
-        createcommand("ELINE",handle_eline,'o',1,"<core>");
-        createcommand("LOADMODULE",handle_loadmodule,'o',1,"<core>");
-        createcommand("UNLOADMODULE",handle_unloadmodule,'o',1,"<core>");
-        createcommand("SERVER",handle_server,0,0,"<core>");
-       createcommand("COMMANDS",handle_commands,0,0,"<core>");
-}
-
 bool DirValid(char* dirandfile)
 {
         char work[MAXBUF];