]> 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 c358b4bf55688579ae7f30a0c103ed6d47e34a4b..059f89be632b150382988bff552d91f40f588762 100644 (file)
@@ -56,8 +56,8 @@ 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;
@@ -123,7 +123,7 @@ 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,char *text)
+void Write_NoFormat(int sock, const char *text)
 {
        if ((sock < 0) || (!text))
                return;
@@ -177,7 +177,7 @@ 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, char* text)
+void WriteServ_NoFormat(int sock, const char* text)
 {
        if ((sock < 0) || (!text))
                return;
@@ -232,7 +232,7 @@ 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,char* text)
+void WriteFrom_NoFormat(int sock, userrec *user, const char* text)
 {
        if ((sock < 0) || (!text) || (!user))
                return;
@@ -316,7 +316,7 @@ void WriteTo(userrec *source, userrec *dest,char *data, ...)
         }
 }
 
-void WriteTo_NoFormat(userrec *source, userrec *dest,char *data)
+void WriteTo_NoFormat(userrec *source, userrec *dest, const char *data)
 {
        if ((!dest) || (!data))
                return;
@@ -357,6 +357,25 @@ void WriteChannel(chanrec* Ptr, userrec* user, char* text, ...)
         }
 }
 
+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 */
@@ -380,7 +399,7 @@ 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)
                         {
@@ -394,6 +413,35 @@ void WriteChannelLocal(chanrec* Ptr, userrec* user, char* text, ...)
         }
 }
 
+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_NoFormat(otheruser->fd,text);
+                        }
+                        else
+                        {
+                                WriteTo_NoFormat(user,otheruser,text);
+                        }
+                }
+        }
+}
+
+
+
 void WriteChannelWithServ(char* ServName, chanrec* Ptr, char* text, ...)
 {
         if ((!Ptr) || (!text))
@@ -419,6 +467,26 @@ void WriteChannelWithServ(char* ServName, chanrec* Ptr, char* text, ...)
         }
 }
 
+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) */
 
@@ -446,6 +514,24 @@ void ChanExceptSender(chanrec* Ptr, userrec* user, char* text, ...)
         }
 }
 
+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 = "";
@@ -511,10 +597,57 @@ 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,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;
+                                }
+                        }
+                }
+        }
+        // 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,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 */
 
@@ -563,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)
@@ -926,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);
         }
 }
 
@@ -979,33 +1153,18 @@ int usercount(chanrec *c)
 
 // looks up a users password for their connection class (<ALLOW>/<DENY> tags)
 
-char* Passwd(userrec *user)
+ConnectClass GetClass(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()))
+                if (match(user->host,i->host.c_str()))
                 {
-                        return (char*)i->pass.c_str();
+                        return *i;
                 }
         }
-        return "";
+        return *(Config->Classes.begin());
 }
 
-bool IsDenied(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()))
-                {
-                        return true;
-                }
-        }
-        return false;
-}
-
-
-
-
 /* sends out an error notice to all connected clients (not to be used
  * lightly!) */