* ---------------------------------------------------
*/
+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"
#include "commands.h"
#include "xline.h"
#include "inspstring.h"
-
-using namespace std;
+#include "helperfuncs.h"
extern int MODCOUNT;
extern std::vector<Module*> modules;
char* give_ops(userrec *user,char *dest,chanrec *chan,int status)
{
userrec *d;
- int i;
if ((!user) || (!dest) || (!chan))
{
if (!isnick(dest))
{
log(DEFAULT,"the target nickname given to give_ops was invalid");
- WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
+ WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, dest);
return NULL;
}
d = Find(dest);
if (!d)
{
log(DEFAULT,"the target nickname given to give_ops couldnt be found");
- WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
+ WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, dest);
return NULL;
}
else
char* give_hops(userrec *user,char *dest,chanrec *chan,int status)
{
userrec *d;
- int i;
if ((!user) || (!dest) || (!chan))
{
d = Find(dest);
if (!isnick(dest))
{
- WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
+ WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, dest);
return NULL;
}
if (!d)
{
- WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
+ WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, dest);
return NULL;
}
else
char* give_voice(userrec *user,char *dest,chanrec *chan,int status)
{
userrec *d;
- int i;
if ((!user) || (!dest) || (!chan))
{
d = Find(dest);
if (!isnick(dest))
{
- WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
+ WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, dest);
return NULL;
}
if (!d)
{
- WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
+ WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, dest);
return NULL;
}
else
char* take_ops(userrec *user,char *dest,chanrec *chan,int status)
{
userrec *d;
- int i;
if ((!user) || (!dest) || (!chan))
{
if (!isnick(dest))
{
log(DEBUG,"take_ops was given an invalid target nickname of %s",dest);
- WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
+ WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, dest);
return NULL;
}
if (!d)
{
log(DEBUG,"take_ops couldnt resolve the target nickname: %s",dest);
- WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
+ WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, dest);
return NULL;
}
else
char* take_hops(userrec *user,char *dest,chanrec *chan,int status)
{
userrec *d;
- int i;
if ((!user) || (!dest) || (!chan))
{
d = Find(dest);
if (!isnick(dest))
{
- WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
+ WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, dest);
return NULL;
}
if (!d)
{
- WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
+ WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, dest);
return NULL;
}
else
char* take_voice(userrec *user,char *dest,chanrec *chan,int status)
{
userrec *d;
- int i;
if ((!user) || (!dest) || (!chan))
{
d = Find(dest);
if (!isnick(dest))
{
- WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
+ WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, dest);
return NULL;
}
if (!d)
{
- WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
+ WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, dest);
return NULL;
}
else
BanItem b;
if ((!user) || (!dest) || (!chan))
return NULL;
+ int l = strlen(dest);
if (strchr(dest,'!')==0)
return NULL;
if (strchr(dest,'@')==0)
return NULL;
- for (int i = 0; i < strlen(dest); i++)
+ for (int i = 0; i < l; i++)
if (dest[i] < 32)
return NULL;
- for (int i = 0; i < strlen(dest); i++)
+ for (int i = 0; i < l; i++)
if (dest[i] > 126)
return NULL;
int c = 0;
- for (int i = 0; i < strlen(dest); i++)
+ for (int i = 0; i < l; i++)
if (dest[i] == '!')
c++;
if (c>1)
return NULL;
c = 0;
- for (int i = 0; i < strlen(dest); i++)
+ for (int i = 0; i < l; i++)
if (dest[i] == '@')
c++;
if (c>1)
log(DEBUG,"add_ban: %s %s",chan->name,user->nick);
+ int MOD_RESULT = 0;
+ FOREACH_RESULT(OnAddBan(user,chan,dest));
+ if (MOD_RESULT)
+ return NULL;
+
TidyBan(dest);
for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
{
{
if (!strcasecmp(i->data,dest))
{
+ int MOD_RESULT = 0;
+ FOREACH_RESULT(OnDelBan(user,chan,dest));
+ if (MOD_RESULT)
+ return NULL;
chan->bans.erase(i);
return dest;
}
return NULL;
}
+// tidies up redundant modes, e.g. +nt-nt+i becomes +-+i,
+// a section further down the chain tidies up the +-+- crap.
+std::string compress_modes(std::string modes,bool channelmodes)
+{
+ int counts[127];
+ bool active[127];
+ int delta = 1;
+ memset(counts,0,sizeof(counts));
+ memset(active,0,sizeof(active));
+ log(DEBUG,"compress_modes: %s",modes.c_str());
+ for (int i = 0; i < modes.length(); i++)
+ {
+ if ((modes[i] == '+') || (modes[i] == '-'))
+ continue;
+ if (channelmodes)
+ {
+ if ((strchr("itnmsp",modes[i])) || ((ModeDefined(modes[i],MT_CHANNEL)) && (ModeDefinedOn(modes[i],MT_CHANNEL)==0) && (ModeDefinedOff(modes[i],MT_CHANNEL)==0)))
+ {
+ log(DEBUG,"Tidy mode %c",modes[i]);
+ counts[(unsigned int)modes[i]]++;
+ active[(unsigned int)modes[i]] = true;
+ }
+ }
+ else
+ {
+ log(DEBUG,"Tidy mode %c",modes[i]);
+ counts[(unsigned int)modes[i]]++;
+ active[(unsigned int)modes[i]] = true;
+ }
+ }
+ for (int j = 65; j < 127; j++)
+ {
+ if ((counts[j] > 1) && (active[j] == true))
+ {
+ static char v[2];
+ v[0] = (unsigned char)j;
+ v[1] = '\0';
+ 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(mode_str) != std::string::npos)
+ modes.erase(modes.find(mode_str),1);
+ log(DEBUG,"New mode line: %s",modes.c_str());
+ }
+ }
+ }
+ return modes;
+}
+
void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int pcnt, bool servermode, bool silent, bool local)
{
if (!parameters) {
int ptr = 0;
int mdir = 1;
char* r = NULL;
- bool k_set = false, l_set = false;
+ bool k_set = false, l_set = false, previously_set_l = false, previously_unset_l = false, previously_set_k = false, previously_unset_k = false;
if (pcnt < 2)
{
log(DEBUG,"process_modes: modelist: %s",modelist);
- for (ptr = 0; ptr < strlen(modelist); ptr++)
+ std::string tidied = compress_modes(modelist,true);
+ strlcpy(modelist,tidied.c_str(),MAXBUF);
+
+ int len = strlen(modelist);
+ while (modelist[len-1] == ' ')
+ modelist[--len] = '\0';
+ for (ptr = 0; ptr < len; ptr++)
{
r = NULL;
case '-':
if (mdir != 0)
{
- if ((outlist[strlen(outlist)-1] == '+') || (outlist[strlen(outlist)-1] == '-'))
+ int t = strlen(outlist)-1;
+ if ((outlist[t] == '+') || (outlist[t] == '-'))
{
- outlist[strlen(outlist)-1] = '-';
+ outlist[t] = '-';
}
else
{
case '+':
if (mdir != 1)
{
- if ((outlist[strlen(outlist)-1] == '+') || (outlist[strlen(outlist)-1] == '-'))
+ int t = strlen(outlist)-1;
+ if ((outlist[t] == '+') || (outlist[t] == '-'))
{
- outlist[strlen(outlist)-1] = '+';
+ outlist[t] = '+';
}
else
{
{
if (k_set)
break;
+
+ if (previously_unset_k)
+ break;
+ previously_set_k = true;
if (!strcmp(chan->key,""))
{
{
strcat(outlist,"k");
char key[MAXBUF];
- strlcpy(key,parameters[param++],MAXBUF);
- if (strlen(key)>32) {
- key[31] = '\0';
- }
+ strlcpy(key,parameters[param++],32);
strlcpy(outpars[pc++],key,MAXBUF);
strlcpy(chan->key,key,MAXBUF);
k_set = true;
{
/* checks on -k are case sensitive and only accurate to the
first 32 characters */
+ if (previously_set_k)
+ break;
+ previously_unset_k = true;
+
char key[MAXBUF];
MOD_RESULT = 0;
FOREACH_RESULT(OnRawMode(user, chan, 'k', parameters[param], false, 1));
if (!MOD_RESULT)
{
- strlcpy(key,parameters[param++],MAXBUF);
- if (strlen(key)>32)
- {
- key[31] = '\0';
- }
+ strlcpy(key,parameters[param++],32);
/* only allow -k if correct key given */
if (!strcmp(chan->key,key))
{
case 'l':
if (mdir == 0)
{
+ if (previously_set_l)
+ break;
+ previously_unset_l = true;
MOD_RESULT = 0;
FOREACH_RESULT(OnRawMode(user, chan, 'l', "", false, 0));
if (!MOD_RESULT)
{
if (l_set)
break;
-
+ if (previously_unset_l)
+ break;
+ previously_set_l = true;
bool invalid = false;
for (int i = 0; i < strlen(parameters[param]); i++)
{
// reported by mech: large values cause underflow
if (chan->limit < 0)
- chan->limit = 0x7FFFFF;
+ chan->limit = 0x7FFF;
}
if (chan->limit)
FOREACH_RESULT(OnRawMode(user, chan, 'i', "", mdir, 0));
if (!MOD_RESULT)
{
- if (chan->inviteonly != mdir)
+ if (mdir)
+ {
+ if (!(chan->binarymodes & CM_INVITEONLY)) strlcat(outlist,"i",MAXBUF);
+ chan->binarymodes |= CM_INVITEONLY;
+ }
+ else
{
- strlcat(outlist,"i",MAXBUF);
+ if (chan->binarymodes & CM_INVITEONLY) strlcat(outlist,"i",MAXBUF);
+ chan->binarymodes &= ~CM_INVITEONLY;
}
- chan->inviteonly = mdir;
}
break;
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;
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;
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;
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;
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;
{
if (t == -1)
{
- pc++;
+ //pc++;
+ param++;
}
else
{
}
/* this ensures only the *valid* modes are sent out onto the network */
- while ((outlist[strlen(outlist)-1] == '-') || (outlist[strlen(outlist)-1] == '+'))
+ int xt = strlen(outlist)-1;
+ while ((outlist[xt] == '-') || (outlist[xt] == '+'))
{
- outlist[strlen(outlist)-1] = '\0';
+ outlist[xt] = '\0';
+ xt = strlen(outlist)-1;
}
- if (strcmp(outlist,""))
+ if (outlist[0])
{
strlcpy(outstr,outlist,MAXBUF);
for (ptr = 0; ptr < pc; ptr++)
{
if (!silent)
{
- WriteChannelWithServ(ServerName,chan,user,"MODE %s %s",chan->name,outstr);
+ WriteChannelWithServ(ServerName,chan,"MODE %s %s",chan->name,outstr);
// M token for a usermode must go to all servers
char buffer[MAXBUF];
snprintf(buffer,MAXBUF,"M %s %s",chan->name, outstr);
{
s2 = new userrec;
strlcpy(s2->nick,ServerName,NICKMAX);
- strcpy(s2->modes,"o");
+ strcpy(s2->modes,"o",52);
s2->fd = -1;
source = s2;
faked = true;
{
chanrec* Ptr;
userrec* dest;
- int can_change,i;
+ int can_change;
int direction = 1;
char outpars[MAXBUF];
if ((dest) && (pcnt > 1))
{
+ std::string tidied = compress_modes(parameters[1],false);
+ 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;
if (user != dest)
{
for (int i = 0; i < strlen(parameters[1]); i++)
{
+ if (parameters[1][i] == ' ')
+ continue;
if (parameters[1][i] == '+')
{
if (direction != 1)
{
- if ((outpars[strlen(outpars)-1] == '+') || (outpars[strlen(outpars)-1] == '-'))
+ int t = strlen(outpars)-1;
+ if ((outpars[t] == '+') || (outpars[t] == '-'))
{
- outpars[strlen(outpars)-1] = '+';
+ outpars[t] = '+';
}
else
{
{
if (direction != 0)
{
- if ((outpars[strlen(outpars)-1] == '+') || (outpars[strlen(outpars)-1] == '-'))
+ int t = strlen(outpars)-1;
+ if ((outpars[t] == '+') || (outpars[t] == '-'))
{
- outpars[strlen(outpars)-1] = '-';
+ outpars[t] = '-';
}
else
{
char umode = parameters[1][i];
if ((process_module_umode(umode, user, dest, direction)) || (umode == 'i') || (umode == 's') || (umode == 'w') || (umode == 'o'))
{
- dmodes[strlen(dmodes)+1]='\0';
- dmodes[strlen(dmodes)] = parameters[1][i];
- outpars[strlen(outpars)+1]='\0';
- outpars[strlen(outpars)] = parameters[1][i];
+ int q = strlen(dmodes);
+ int r = strlen(outpars);
+ dmodes[q+1]='\0';
+ dmodes[q] = parameters[1][i];
+ outpars[r+1]='\0';
+ outpars[r] = parameters[1][i];
+ if (parameters[1][i] == 'o')
+ {
+ FOREACH_MOD OnGlobalOper(dest);
+ }
}
}
}
char temp[MAXBUF];
char moo[MAXBUF];
- outpars[strlen(outpars)+1]='\0';
- outpars[strlen(outpars)] = parameters[1][i];
+ int r = strlen(outpars);
+ outpars[r+1]='\0';
+ outpars[r] = parameters[1][i];
strcpy(temp,"");
for (q = 0; q < strlen(dmodes); q++)
strlcat(temp,moo,MAXBUF);
}
}
- strlcpy(dmodes,temp,MAXBUF);
+ strlcpy(dmodes,temp,52);
+
+ if (umode == 'o')
+ DeleteOper(dest);
}
}
}
}
}
}
- if (strlen(outpars))
+ if (outpars[0])
{
char b[MAXBUF];
strlcpy(b,"",MAXBUF);
z = strlen(b)-1;
if ((b[z] == '-') || (b[z] == '+'))
- b[z] == '\0';
+ b[z] = '\0';
- if ((!strcmp(b,"+")) || (!strcmp(b,"-")))
+ if ((!b[0]) || (!strcmp(b,"+")) || (!strcmp(b,"-")))
return;
- WriteTo(user, dest, "MODE %s :%s", dest->nick, b);
-
- // M token for a usermode must go to all servers
- char buffer[MAXBUF];
- snprintf(buffer,MAXBUF,"m %s %s %s",user->nick, dest->nick, b);
- NetSendToAll(buffer);
+ if (strcmp(b,""))
+ {
+ WriteTo(user, dest, "MODE %s :%s", dest->nick, b);
+ // M token for a usermode must go to all servers
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF,"m %s %s %s",user->nick, dest->nick, b);
+ NetSendToAll(buffer);
+ }
if (strlen(dmodes)>MAXMODES)
{
}
log(DEBUG,"Stripped mode line");
log(DEBUG,"Line dest is now %s",dmodes);
- strlcpy(dest->modes,dmodes,MAXMODES);
+ strlcpy(dest->modes,dmodes,52);
}
{
/* just /modes #channel */
WriteServ(user->fd,"324 %s %s +%s",user->nick, Ptr->name, chanmodes(Ptr));
+ WriteServ(user->fd,"329 %s %s %d", user->nick, Ptr->name, Ptr->created);
return;
}
else
}
else
{
- WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]);
+ WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
}
}
{
chanrec* Ptr;
userrec* dest;
- int can_change,i;
+ int can_change;
int direction = 1;
char outpars[MAXBUF];
if ((dest) && (pcnt > 1))
{
- log(DEBUG,"params > 1");
+ std::string tidied = compress_modes(parameters[1],false);
+ parameters[1] = (char*)tidied.c_str();
char dmodes[MAXBUF];
- strlcpy(dmodes,dest->modes,MAXBUF);
+ strlcpy(dmodes,dest->modes,52);
strcpy(outpars,"+");
direction = 1;
for (int i = 0; i < strlen(parameters[1]); i++)
{
+ if (parameters[1][i] == ' ')
+ continue;
if (parameters[1][i] == '+')
{
if (direction != 1)
{
- if ((outpars[strlen(outpars)-1] == '+') || (outpars[strlen(outpars)-1] == '-'))
+ int t = strlen(outpars)-1;
+ if ((outpars[t] == '+') || (outpars[t] == '-'))
{
- outpars[strlen(outpars)-1] = '+';
+ outpars[t] = '+';
}
else
{
{
if (direction != 0)
{
- if ((outpars[strlen(outpars)-1] == '+') || (outpars[strlen(outpars)-1] == '-'))
+ int t = strlen(outpars)-1;
+ if ((outpars[t] == '+') || (outpars[t] == '-'))
{
- outpars[strlen(outpars)-1] = '-';
+ outpars[t] = '-';
}
else
{
log(DEBUG,"umode %c is an allowed umode",umode);
if ((process_module_umode(umode, user, dest, direction)) || (umode == 'i') || (umode == 's') || (umode == 'w') || (umode == 'o'))
{
- dmodes[strlen(dmodes)+1]='\0';
- dmodes[strlen(dmodes)] = parameters[1][i];
- outpars[strlen(outpars)+1]='\0';
- outpars[strlen(outpars)] = parameters[1][i];
+ int v1 = strlen(dmodes);
+ int v2 = strlen(outpars);
+ dmodes[v1+1]='\0';
+ dmodes[v1] = parameters[1][i];
+ outpars[v2+1]='\0';
+ outpars[v2] = parameters[1][i];
}
}
}
char temp[MAXBUF];
char moo[MAXBUF];
- outpars[strlen(outpars)+1]='\0';
- outpars[strlen(outpars)] = parameters[1][i];
+ int v1 = strlen(outpars);
+ outpars[v1+1]='\0';
+ outpars[v1] = parameters[1][i];
strcpy(temp,"");
for (q = 0; q < strlen(dmodes); q++)
strlcat(temp,moo,MAXBUF);
}
}
- strlcpy(dmodes,temp,MAXBUF);
+ strlcpy(dmodes,temp,52);
}
}
}
}
}
}
- if (strlen(outpars))
+ if (outpars[0])
{
char b[MAXBUF];
strlcpy(b,"",MAXBUF);
z = strlen(b)-1;
if ((b[z] == '-') || (b[z] == '+'))
- b[z] == '\0';
+ b[z] = '\0';
- if ((!strcmp(b,"+")) || (!strcmp(b,"-")))
+ if ((!b[0]) || (!strcmp(b,"+")) || (!strcmp(b,"-")))
return;
- WriteTo(user, dest, "MODE %s :%s", dest->nick, b);
-
- // M token for a usermode must go to all servers
- char buffer[MAXBUF];
- snprintf(buffer,MAXBUF,"m %s %s %s",user->nick, dest->nick, b);
- NetSendToAll(buffer);
+ if (strcmp(b,""))
+ {
+ WriteTo(user, dest, "MODE %s :%s", dest->nick, b);
+ // M token for a usermode must go to all servers
+ char buffer[MAXBUF];
+ snprintf(buffer,MAXBUF,"m %s %s %s",user->nick, dest->nick, b);
+ NetSendToAll(buffer);
+ }
if (strlen(dmodes)>MAXMODES)
{
}
else
{
- WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]);
+ WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
}
}
{
chanrec* Ptr;
userrec* dest;
- int can_change,i;
+ int can_change;
int direction = 1;
char outpars[MAXBUF];
if ((dest) && (pcnt > 1))
{
- log(DEBUG,"params > 1");
+ std::string tidied = compress_modes(parameters[1],false);
+ parameters[1] = (char*)tidied.c_str();
char dmodes[MAXBUF];
- strlcpy(dmodes,dest->modes,MAXBUF);
+ strlcpy(dmodes,dest->modes,52);
strcpy(outpars,"+");
direction = 1;
for (int i = 0; i < strlen(parameters[1]); i++)
{
+ if (parameters[1][i] == ' ')
+ continue;
if (parameters[1][i] == '+')
{
if (direction != 1)
{
- if ((outpars[strlen(outpars)-1] == '+') || (outpars[strlen(outpars)-1] == '-'))
+ int t = strlen(outpars)-1;
+ if ((outpars[t] == '+') || (outpars[t] == '-'))
{
- outpars[strlen(outpars)-1] = '+';
+ outpars[t] = '+';
}
else
{
{
if (direction != 0)
{
- if ((outpars[strlen(outpars)-1] == '+') || (outpars[strlen(outpars)-1] == '-'))
+ int t = strlen(outpars)-1;
+ if ((outpars[t] == '+') || (outpars[t] == '-'))
{
- outpars[strlen(outpars)-1] = '-';
+ outpars[t] = '-';
}
else
{
log(DEBUG,"umode %c is an allowed umode",umode);
if ((process_module_umode(umode, NULL, dest, direction)) || (umode == 'i') || (umode == 's') || (umode == 'w') || (umode == 'o'))
{
- dmodes[strlen(dmodes)+1]='\0';
- dmodes[strlen(dmodes)] = parameters[1][i];
- outpars[strlen(outpars)+1]='\0';
- outpars[strlen(outpars)] = parameters[1][i];
+ int v1 = strlen(dmodes);
+ int v2 = strlen(outpars);
+ dmodes[v1+1]='\0';
+ dmodes[v1] = parameters[1][i];
+ outpars[v2+1]='\0';
+ outpars[v2] = parameters[1][i];
}
}
}
char temp[MAXBUF];
char moo[MAXBUF];
- outpars[strlen(outpars)+1]='\0';
- outpars[strlen(outpars)] = parameters[1][i];
+ int v1 = strlen(outpars);
+ outpars[v1+1]='\0';
+ outpars[v1] = parameters[1][i];
strcpy(temp,"");
for (q = 0; q < strlen(dmodes); q++)
strlcat(temp,moo,MAXBUF);
}
}
- strlcpy(dmodes,temp,MAXBUF);
+ strlcpy(dmodes,temp,52);
}
}
}
}
}
}
- if (strlen(outpars))
+ if (outpars[0])
{
char b[MAXBUF];
strcpy(b,"");
z = strlen(b)-1;
if ((b[z] == '-') || (b[z] == '+'))
- b[z] == '\0';
+ b[z] = '\0';
if ((!strcmp(b,"+")) || (!strcmp(b,"-")))
return;
{
chanrec* Ptr;
userrec* dest;
- int can_change,i;
+ int can_change;
int direction = 1;
char outpars[MAXBUF];
// fix: ChroNiCk found this - we cant use this as debug if its null!
if (dest)
{
- log(DEBUG,"merge_mode on %s",dest->nick);
+ log(DEBUG,"merge_mode2 on %s",dest->nick);
}
if ((dest) && (pcnt > 1))
{
- log(DEBUG,"params > 1");
+ std::string tidied = compress_modes(parameters[1],false);
+ parameters[1] = (char*)tidied.c_str();
char dmodes[MAXBUF];
- strlcpy(dmodes,dest->modes,MAXBUF);
+ strlcpy(dmodes,dest->modes,52);
strcpy(outpars,"+");
direction = 1;
for (int i = 0; i < strlen(parameters[1]); i++)
{
+ if (parameters[1][i] == ' ')
+ continue;
if (parameters[1][i] == '+')
{
if (direction != 1)
{
- if ((outpars[strlen(outpars)-1] == '+') || (outpars[strlen(outpars)-1] == '-'))
+ int t = strlen(outpars)-1;
+ if ((outpars[t] == '+') || (outpars[t] == '-'))
{
- outpars[strlen(outpars)-1] = '+';
+ outpars[t] = '+';
}
else
{
{
if (direction != 0)
{
- if ((outpars[strlen(outpars)-1] == '+') || (outpars[strlen(outpars)-1] == '-'))
+ int t = strlen(outpars)-1;
+ if ((outpars[t] == '+') || (outpars[t] == '-'))
{
- outpars[strlen(outpars)-1] = '-';
+ outpars[t] = '-';
}
else
{
log(DEBUG,"umode %c is an allowed umode",umode);
if ((process_module_umode(umode, NULL, dest, direction)) || (umode == 'i') || (umode == 's') || (umode == 'w') || (umode == 'o'))
{
- dmodes[strlen(dmodes)+1]='\0';
- dmodes[strlen(dmodes)] = parameters[1][i];
- outpars[strlen(outpars)+1]='\0';
- outpars[strlen(outpars)] = parameters[1][i];
+ int v1 = strlen(dmodes);
+ int v2 = strlen(outpars);
+ dmodes[v1+1]='\0';
+ dmodes[v1] = parameters[1][i];
+ outpars[v2+1]='\0';
+ outpars[v2] = parameters[1][i];
log(DEBUG,"OUTPARS='%s', DMODES='%s'",outpars,dmodes);
}
}
char temp[MAXBUF];
char moo[MAXBUF];
- outpars[strlen(outpars)+1]='\0';
- outpars[strlen(outpars)] = parameters[1][i];
+ int v1 = strlen(outpars);
+ outpars[v1+1]='\0';
+ outpars[v1] = parameters[1][i];
strcpy(temp,"");
for (q = 0; q < strlen(dmodes); q++)
strlcat(temp,moo,MAXBUF);
}
}
- strlcpy(dmodes,temp,MAXBUF);
+ strlcpy(dmodes,temp,52);
}
}
}
}
}
log(DEBUG,"DONE! OUTPARS='%s', DMODES='%s'",outpars,dmodes);
- if (strlen(outpars))
+ if (outpars[0])
{
char b[MAXBUF];
strcpy(b,"");
z = strlen(b)-1;
if ((b[z] == '-') || (b[z] == '+'))
- b[z] == '\0';
+ 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)
{
log(DEBUG,"Stripped mode line");
log(DEBUG,"Line dest is now %s",dmodes);
strlcpy(dest->modes,dmodes,MAXMODES);
-
}
return;