]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/helperfuncs.cpp
WriteChannel* functions and ChanExceptSender* functions are now methods of chanrec...
[user/henk/code/inspircd.git] / src / helperfuncs.cpp
index 6250b62851a619a0e0fffab9018ac329e6ff6532..e7ecb56a14f5594712219440d9242ec1868af511 100644 (file)
@@ -3,13 +3,13 @@
  *       +------------------------------------+
  *
  *  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.
  *
  * ---------------------------------------------------
  */
@@ -51,7 +51,7 @@ extern InspIRCd* ServerInstance;
 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;
@@ -63,6 +63,9 @@ extern std::vector<userrec*> local_users;
 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.
@@ -161,13 +164,12 @@ void Write_NoFormat(int sock, const char *text)
        if (fd_ref_table[sock])
        {
                bytes = snprintf(tb,MAXBUF,"%s\r\n",text);
-               chop(tb);
 
-               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)
                        {
@@ -210,13 +212,12 @@ void Write(int sock, char *text, ...)
                vsnprintf(textbuffer, MAXBUF, text, argsPtr);
                va_end(argsPtr);
                bytes = snprintf(tb,MAXBUF,"%s\r\n",textbuffer);
-               chop(tb);
 
-               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)
                        {
@@ -247,13 +248,12 @@ void WriteServ_NoFormat(int sock, const char* text)
        if (fd_ref_table[sock])
        {
                bytes = snprintf(tb,MAXBUF,":%s %s\r\n",Config->ServerName,text);
-               chop(tb);
 
-               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)
                        {
@@ -312,13 +312,12 @@ void WriteFrom_NoFormat(int sock, userrec *user, const char* text)
        if (fd_ref_table[sock])
        {
                bytes = snprintf(tb,MAXBUF,":%s %s\r\n",user->GetFullHost(),text);
-               chop(tb);
 
-               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,13 +359,12 @@ void WriteFrom(int sock, userrec *user,char* text, ...)
                vsnprintf(textbuffer, MAXBUF, text, argsPtr);
                va_end(argsPtr);
                bytes = snprintf(tb,MAXBUF,":%s %s\r\n",user->GetFullHost(),textbuffer);
-               chop(tb);
 
-               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)
                        {
@@ -403,7 +401,6 @@ void WriteTo(userrec *source, userrec *dest,char *data, ...)
        va_start(argsPtr, data);
        vsnprintf(textbuffer, MAXBUF, data, argsPtr);
        va_end(argsPtr);
-       chop(textbuffer);
 
        // if no source given send it from the server.
        if (!source)
@@ -431,245 +428,6 @@ void WriteTo_NoFormat(userrec *source, userrec *dest, const char *data)
        }
 }
 
-/* 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 = "";
@@ -702,7 +460,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;
@@ -712,8 +470,8 @@ void WriteCommon(userrec *u, char* text, ...)
        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++)
        {
@@ -723,9 +481,9 @@ 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]))
+                               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;
                                }
@@ -753,14 +511,14 @@ 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;
        }
 
-       // 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++)
        {
@@ -770,9 +528,9 @@ 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]))
+                               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;
                                }
@@ -809,7 +567,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;
@@ -860,7 +618,7 @@ void WriteCommonExcept(userrec *u, char* text, ...)
                }
        }
 
-       memset(&already_sent,0,MAX_DESCRIPTORS);
+       uniq_id++;
 
        for (std::vector<ucrec*>::const_iterator v = u->chans.begin(); v != u->chans.end(); v++)
        {
@@ -872,9 +630,9 @@ void WriteCommonExcept(userrec *u, char* text, ...)
                        {
                                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)
                                                {
@@ -897,13 +655,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;
        }
 
-       memset(&already_sent,0,MAX_DESCRIPTORS);
+       uniq_id++;
 
        for (std::vector<ucrec*>::const_iterator v = u->chans.begin(); v != u->chans.end(); v++)
        {
@@ -915,9 +673,9 @@ void WriteCommonExcept_NoFormat(userrec *u, const char* text)
                        {
                                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);
                                        }
                                }
@@ -966,7 +724,7 @@ void WriteOpers_NoFormat(const char* text)
 
                if (IS_LOCAL(a))
                {
-                       if (a->modebits & UM_SERVERNOTICE)
+                       if (a->modes[UM_SERVERNOTICE])
                        {
                                // send server notices to all with +s
                                WriteServ(a->fd,"NOTICE %s :%s",a->nick,text);
@@ -1045,7 +803,7 @@ void WriteMode(const char* modes, int flags, const char* text, ...)
 
                        for (int n = 0; n < modelen; n++)
                        {
-                               if (!hasumode(t,modes[n]))
+                               if (!t->modes[modes[n]-65])
                                {
                                        send_to_user = false;
                                        break;
@@ -1058,7 +816,7 @@ void WriteMode(const char* modes, int flags, const char* text, ...)
 
                        for (int n = 0; n < modelen; n++)
                        {
-                               if (hasumode(t,modes[n]))
+                               if (t->modes[modes[n]-65])
                                {
                                        send_to_user = true;
                                        break;
@@ -1121,7 +879,7 @@ void WriteWallOps(userrec *source, bool local_only, char* text, ...)
        {
                userrec* t = (userrec*)(*i);
 
-               if ((IS_LOCAL(t)) && (t->modebits & UM_WALLOPS))
+               if ((IS_LOCAL(t)) && (t->modes[UM_WALLOPS]))
                {
                        WriteTo_NoFormat(source,t,formatbuffer);
                }
@@ -1217,13 +975,14 @@ void purge_empty_chans(userrec* u)
        // 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;
                        }
                }
        }
@@ -1334,7 +1093,7 @@ void userlist(userrec *user,chanrec *c)
 
        for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
        {
-               if ((!has_user) && (i->second->modebits & UM_INVISIBLE))
+               if ((!has_user) && (i->second->modes[UM_INVISIBLE]))
                {
                        /*
                         * user is +i, and source not on the channel, does not show
@@ -1385,7 +1144,7 @@ int usercount_i(chanrec *c)
        CUList *ulist= c->GetUsers();
        for (CUList::iterator i = ulist->begin(); i != ulist->end(); i++)
        {
-               if (!(i->second->modebits & UM_INVISIBLE))
+               if (!(i->second->modes[UM_INVISIBLE]))
                        count++;
        }
 
@@ -1407,7 +1166,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;
                }
@@ -1427,7 +1186,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);
                }
@@ -1487,7 +1246,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;
@@ -1499,8 +1258,7 @@ int usercount_invisible(void)
 
        for (user_hash::const_iterator i = clientlist.begin(); i != clientlist.end(); i++)
        {
-               if ((i->second->registered == 7) && (i->second->modebits & UM_INVISIBLE))
-                       c++;
+               c += ((i->second->registered == REG_ALL) && (i->second->modes[UM_INVISIBLE]));
        }
 
        return c;
@@ -1525,7 +1283,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++;
        }
 
@@ -1544,7 +1302,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++;
        }
 
@@ -1553,44 +1311,17 @@ long local_count()
 
 void ShowMOTD(userrec *user)
 {
-       static char mbuf[MAXBUF];
-       static char crud[MAXBUF];
-       std::string WholeMOTD = "";
-
        if (!Config->MOTD.size())
        {
                WriteServ(user->fd,"422 %s :Message of the day file is missing.",user->nick);
                return;
        }
-
-       snprintf(crud,MAXBUF,":%s 372 %s :- ", Config->ServerName, user->nick);
-       snprintf(mbuf,MAXBUF,":%s 375 %s :- %s message of the day\r\n", Config->ServerName, user->nick, Config->ServerName);
-       WholeMOTD = WholeMOTD + mbuf;
+       WriteServ(user->fd,"375 %s :%s message of the day", user->nick, Config->ServerName);
 
        for (unsigned int i = 0; i < Config->MOTD.size(); i++)
-               WholeMOTD = WholeMOTD + std::string(crud) + Config->MOTD[i].c_str() + std::string("\r\n");
-
-       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
-       if (Config->GetIOHook(user->port))
-       {
-               try
-               {
-                       Config->GetIOHook(user->port)->OnRawSocketWrite(user->fd,(char*)WholeMOTD.c_str(),WholeMOTD.length());
-               }
-               catch (ModuleException& modexcept)
-               {
-                       log(DEBUG,"Module exception caught: %s",modexcept.GetReason());
-               }
-       }
-       else
-       {
-               user->AddWriteBuf(WholeMOTD);
-       }
+               WriteServ(user->fd,"372 %s :- %s",user->nick,Config->MOTD[i].c_str());
 
-       ServerInstance->stats->statsSent += WholeMOTD.length();
+       WriteServ(user->fd,"376 %s :End of message of the day.", user->nick);
 }
 
 void ShowRULES(userrec *user)
@@ -1900,7 +1631,7 @@ void LoadAllModules(InspIRCd* ServerInstance)
                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());