]> git.netwichtig.de Git - user/henk/code/inspircd.git/blobdiff - src/mode.cpp
Changed length of user::modes buffer from 512 to much more sensible 54
[user/henk/code/inspircd.git] / src / mode.cpp
index 610ea21e416f435de6f6e655f284ed12183dd136..d33da7e7d31cb6dbc006cda2ae5ad50484ec4f1e 100644 (file)
  * ---------------------------------------------------
  */
 
+using namespace std;
+
+#include "inspircd_config.h"
 #include "inspircd.h"
 #include "inspircd_io.h"
 #include "inspircd_util.h"
-#include "inspircd_config.h"
 #include <unistd.h>
-#include <fcntl.h>
 #include <sys/errno.h>
-#include <sys/ioctl.h>
-#include <sys/utsname.h>
-#include <cstdio>
 #include <time.h>
 #include <string>
 #ifdef GCC3
 #include <map>
 #include <sstream>
 #include <vector>
-#include <errno.h>
 #include <deque>
-#include <errno.h>
-#include <unistd.h>
-#include <sched.h>
 #include "connection.h"
 #include "users.h"
 #include "servers.h"
@@ -51,8 +45,7 @@
 #include "commands.h"
 #include "xline.h"
 #include "inspstring.h"
-
-using namespace std;
+#include "helperfuncs.h"
 
 extern int MODCOUNT;
 extern std::vector<Module*> modules;
@@ -552,12 +545,13 @@ std::string compress_modes(std::string modes,bool channelmodes)
                        static char v[2];
                        v[0] = (unsigned char)j;
                        v[1] = '\0';
-                       std::string::size_type pos = modes.find(std::string(v));
+                       std::string mode_str = v;
+                       std::string::size_type pos = modes.find(mode_str);
                        if (pos != std::string::npos)
                        {
                                log(DEBUG,"all occurances of mode %c to be deleted...",(unsigned char)j);
-                               while (modes.find(std::string(v)) != std::string::npos)
-                                       modes.erase(modes.find(std::string(v)),1);
+                               while (modes.find(mode_str) != std::string::npos)
+                                       modes.erase(modes.find(mode_str),1);
                                log(DEBUG,"New mode line: %s",modes.c_str());
                        }
                }
@@ -881,7 +875,7 @@ void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int
                                                        
                                                        // reported by mech: large values cause underflow
                                                        if (chan->limit < 0)
-                                                               chan->limit = 0x7FFFFF;
+                                                               chan->limit = 0x7FFF;
                                                }
                                                        
                                                if (chan->limit)
@@ -898,11 +892,16 @@ void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int
                                         FOREACH_RESULT(OnRawMode(user, chan, 'i', "", mdir, 0));
                                         if (!MOD_RESULT)
                                         {
-                                               if (chan->inviteonly != mdir)
+                                               if (mdir)
                                                {
-                                                       strlcat(outlist,"i",MAXBUF);
+                                                       if (!(chan->binarymodes & CM_INVITEONLY)) strlcat(outlist,"i",MAXBUF);
+                                                       chan->binarymodes |= CM_INVITEONLY;
+                                               }
+                                               else
+                                               {
+                                                       if (chan->binarymodes & CM_INVITEONLY) strlcat(outlist,"i",MAXBUF);
+                                                       chan->binarymodes &= ~CM_INVITEONLY;
                                                }
-                                               chan->inviteonly = mdir;
                                        }
                                break;
                                
@@ -911,11 +910,16 @@ void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int
                                         FOREACH_RESULT(OnRawMode(user, chan, 't', "", mdir, 0));
                                         if (!MOD_RESULT)
                                         {
-                                               if (chan->topiclock != mdir)
-                                               {
-                                                       strlcat(outlist,"t",MAXBUF);
-                                               }
-                                               chan->topiclock = mdir;
+                                               if (mdir)
+                                                {
+                                                       if (!(chan->binarymodes & CM_TOPICLOCK)) strlcat(outlist,"t",MAXBUF);
+                                                        chan->binarymodes |= CM_TOPICLOCK;
+                                                }
+                                                else
+                                                {
+                                                       if (chan->binarymodes & CM_NOEXTERNAL) strlcat(outlist,"t",MAXBUF);
+                                                        chan->binarymodes &= ~CM_TOPICLOCK;
+                                                }
                                        }
                                break;
                                
@@ -924,11 +928,16 @@ void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int
                                         FOREACH_RESULT(OnRawMode(user, chan, 'n', "", mdir, 0));
                                         if (!MOD_RESULT)
                                         {
-                                               if (chan->noexternal != mdir)
-                                               {
-                                                       strlcat(outlist,"n",MAXBUF);
-                                               }
-                                               chan->noexternal = mdir;
+                                                if (mdir)
+                                                {
+                                                       if (!(chan->binarymodes & CM_NOEXTERNAL)) strlcat(outlist,"n",MAXBUF);
+                                                        chan->binarymodes |= CM_NOEXTERNAL;
+                                                }
+                                                else
+                                                {
+                                                       if (chan->binarymodes & CM_NOEXTERNAL) strlcat(outlist,"n",MAXBUF);
+                                                        chan->binarymodes &= ~CM_NOEXTERNAL;
+                                                }
                                        }
                                break;
                                
@@ -937,11 +946,16 @@ void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int
                                         FOREACH_RESULT(OnRawMode(user, chan, 'm', "", mdir, 0));
                                         if (!MOD_RESULT)
                                         {
-                                               if (chan->moderated != mdir)
-                                               {
-                                                       strlcat(outlist,"m",MAXBUF);
-                                               }
-                                               chan->moderated = mdir;
+                                                if (mdir)
+                                                {
+                                                        if (!(chan->binarymodes & CM_MODERATED)) strlcat(outlist,"m",MAXBUF);
+                                                        chan->binarymodes |= CM_MODERATED;
+                                                }
+                                                else
+                                                {
+                                                        if (chan->binarymodes & CM_MODERATED) strlcat(outlist,"m",MAXBUF);
+                                                        chan->binarymodes &= ~CM_MODERATED;
+                                                }
                                        }
                                break;
                                
@@ -950,23 +964,24 @@ void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int
                                         FOREACH_RESULT(OnRawMode(user, chan, 's', "", mdir, 0));
                                         if (!MOD_RESULT)
                                         {
-                                               if (chan->secret != mdir)
-                                               {
-                                                       strcat(outlist,"s");
-                                                       if (chan->c_private)
-                                                       {
-                                                               chan->c_private = 0;
-                                                               if (mdir)
-                                                               {
-                                                                       strlcat(outlist,"-p+",MAXBUF);
-                                                               }
-                                                               else
-                                                               {
-                                                                       strlcat(outlist,"+p-",MAXBUF);
-                                                               }
-                                                       }
-                                               }
-                                               chan->secret = mdir;
+                                                if (mdir)
+                                                {
+                                                        if (!(chan->binarymodes & CM_SECRET)) strlcat(outlist,"s",MAXBUF);
+                                                        chan->binarymodes |= CM_SECRET;
+                                                        if (chan->binarymodes & CM_PRIVATE)
+                                                        {
+                                                                chan->binarymodes &= ~CM_PRIVATE;
+                                                                if (mdir)
+                                                                {
+                                                                        strlcat(outlist,"-p+",MAXBUF);
+                                                                }
+                                                        }
+                                                }
+                                                else
+                                                {
+                                                        if (chan->binarymodes & CM_SECRET) strlcat(outlist,"s",MAXBUF);
+                                                        chan->binarymodes &= ~CM_SECRET;
+                                                }
                                        }
                                break;
                                
@@ -975,23 +990,24 @@ void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int
                                         FOREACH_RESULT(OnRawMode(user, chan, 'p', "", mdir, 0));
                                         if (!MOD_RESULT)
                                         {
-                                               if (chan->c_private != mdir)
-                                               {
-                                                       strlcat(outlist,"p",MAXBUF);
-                                                       if (chan->secret)
-                                                       {
-                                                               chan->secret = 0;
-                                                               if (mdir)
-                                                               {
-                                                                       strlcat(outlist,"-s+",MAXBUF);
-                                                               }
-                                                               else
-                                                               {
-                                                                       strlcat(outlist,"+s-",MAXBUF);
-                                                               }
-                                                       }
-                                               }
-                                               chan->c_private = mdir;
+                                                if (mdir)
+                                                {
+                                                        if (!(chan->binarymodes & CM_PRIVATE)) strlcat(outlist,"p",MAXBUF);
+                                                        chan->binarymodes |= CM_PRIVATE;
+                                                        if (chan->binarymodes & CM_SECRET)
+                                                        {
+                                                                chan->binarymodes &= ~CM_SECRET;
+                                                                if (mdir)
+                                                                {
+                                                                        strlcat(outlist,"-s+",MAXBUF);
+                                                                }
+                                                        }
+                                                }
+                                                else
+                                                {
+                                                        if (chan->binarymodes & CM_PRIVATE) strlcat(outlist,"p",MAXBUF);
+                                                        chan->binarymodes &= ~CM_PRIVATE;
+                                                }
                                        }
                                break;
                                
@@ -1057,7 +1073,8 @@ void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int
                                                                                {
                                                                                        if (t == -1)
                                                                                        {
-                                                                                               pc++;
+                                                                                               //pc++;
+                                                                                               param++;
                                                                                        }
                                                                                        else
                                                                                        {
@@ -1211,7 +1228,7 @@ bool process_module_umode(char umode, userrec* source, void* dest, bool adding)
        {
                s2 = new userrec;
                strlcpy(s2->nick,ServerName,NICKMAX);
-               strcpy(s2->modes,"o");
+               strcpy(s2->modes,"o",52);
                s2->fd = -1;
                source = s2;
                faked = true;
@@ -1274,7 +1291,7 @@ void handle_mode(char **parameters, int pcnt, userrec *user)
                parameters[1] = (char*)tidied.c_str();
 
                char dmodes[MAXBUF];
-               strlcpy(dmodes,dest->modes,MAXBUF);
+               strlcpy(dmodes,dest->modes,52);
                log(DEBUG,"pulled up dest user modes: %s",dmodes);
 
                can_change = 0;
@@ -1399,7 +1416,7 @@ void handle_mode(char **parameters, int pcnt, userrec *user)
                                                                                strlcat(temp,moo,MAXBUF);
                                                                        }
                                                                }
-                                                               strlcpy(dmodes,temp,MAXBUF);
+                                                               strlcpy(dmodes,temp,52);
 
                                                                if (umode == 'o')
                                                                        DeleteOper(dest);
@@ -1459,7 +1476,7 @@ void handle_mode(char **parameters, int pcnt, userrec *user)
                        }
                        log(DEBUG,"Stripped mode line");
                        log(DEBUG,"Line dest is now %s",dmodes);
-                       strlcpy(dest->modes,dmodes,MAXMODES);
+                       strlcpy(dest->modes,dmodes,52);
 
                }
 
@@ -1562,7 +1579,7 @@ void server_mode(char **parameters, int pcnt, userrec *user)
                 parameters[1] = (char*)tidied.c_str();
 
                char dmodes[MAXBUF];
-               strlcpy(dmodes,dest->modes,MAXBUF);
+               strlcpy(dmodes,dest->modes,52);
 
                strcpy(outpars,"+");
                direction = 1;
@@ -1659,7 +1676,7 @@ void server_mode(char **parameters, int pcnt, userrec *user)
                                                                                strlcat(temp,moo,MAXBUF);
                                                                        }
                                                                }
-                                                               strlcpy(dmodes,temp,MAXBUF);
+                                                               strlcpy(dmodes,temp,52);
                                                        }
                                                }
                                        }
@@ -1758,7 +1775,7 @@ void merge_mode(char **parameters, int pcnt)
                 parameters[1] = (char*)tidied.c_str();
 
                char dmodes[MAXBUF];
-               strlcpy(dmodes,dest->modes,MAXBUF);
+               strlcpy(dmodes,dest->modes,52);
 
                strcpy(outpars,"+");
                direction = 1;
@@ -1855,7 +1872,7 @@ void merge_mode(char **parameters, int pcnt)
                                                                                strlcat(temp,moo,MAXBUF);
                                                                        }
                                                                }
-                                                               strlcpy(dmodes,temp,MAXBUF);
+                                                               strlcpy(dmodes,temp,52);
                                                        }
                                                }
                                        }
@@ -1944,7 +1961,7 @@ void merge_mode2(char **parameters, int pcnt, userrec* user)
                 parameters[1] = (char*)tidied.c_str();
 
                char dmodes[MAXBUF];
-               strlcpy(dmodes,dest->modes,MAXBUF);
+               strlcpy(dmodes,dest->modes,52);
 
                strcpy(outpars,"+");
                direction = 1;
@@ -2047,7 +2064,7 @@ void merge_mode2(char **parameters, int pcnt, userrec* user)
                                                                                strlcat(temp,moo,MAXBUF);
                                                                        }
                                                                }
-                                                               strlcpy(dmodes,temp,MAXBUF);
+                                                               strlcpy(dmodes,temp,52);
                                                        }
                                                }
                                        }
@@ -2087,12 +2104,15 @@ void merge_mode2(char **parameters, int pcnt, userrec* user)
                        if ((b[z] == '-') || (b[z] == '+'))
                                b[z] = '\0';
 
-                       if ((!strcmp(b,"+")) || (!strcmp(b,"-")))
-                               return;
 
-                       // was sending 'b'
-                       WriteTo(user,dest,"MODE %s :%s",dest->nick,b);
-                       log(DEBUG,"Sent: :%s MODE %s",user->nick,b);
+                        if ((!b[0]) || (!strcmp(b,"+")) || (!strcmp(b,"-")))
+                                return;
+
+                        if (strcmp(b,""))
+                        {
+                               WriteTo(user,dest,"MODE %s :%s",dest->nick,b);
+                               log(DEBUG,"Sent: :%s MODE %s",user->nick,b);
+                       }
 
                        if (strlen(dmodes)>MAXMODES)
                        {
@@ -2101,7 +2121,6 @@ void merge_mode2(char **parameters, int pcnt, userrec* user)
                        log(DEBUG,"Stripped mode line");
                        log(DEBUG,"Line dest is now %s",dmodes);
                        strlcpy(dest->modes,dmodes,MAXMODES);
-
                }
 
                return;