1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
18 #include "inspircd_io.h"
19 #include "inspircd_util.h"
20 #include "inspircd_config.h"
23 #include <sys/errno.h>
24 #include <sys/ioctl.h>
25 #include <sys/utsname.h>
30 #include <ext/hash_map>
42 #include "connection.h"
57 extern vector<Module*> modules;
58 extern vector<ircd_module*> factory;
59 extern std::vector<std::string> module_names;
63 extern char ServerName[MAXBUF];
64 extern char Network[MAXBUF];
65 extern char ServerDesc[MAXBUF];
66 extern char AdminName[MAXBUF];
67 extern char AdminEmail[MAXBUF];
68 extern char AdminNick[MAXBUF];
69 extern char diepass[MAXBUF];
70 extern char restartpass[MAXBUF];
71 extern char motd[MAXBUF];
72 extern char rules[MAXBUF];
73 extern char list[MAXBUF];
74 extern char PrefixQuit[MAXBUF];
75 extern char DieValue[MAXBUF];
77 extern bool AllowHalfop;
78 extern bool AllowProtect;
79 extern bool AllowFounder;
82 char* give_ops(userrec *user,char *dest,chanrec *chan,int status)
87 if ((!user) || (!dest) || (!chan))
89 log(DEFAULT,"*** BUG *** give_ops was given an invalid parameter");
95 log(DEFAULT,"the target nickname given to give_ops was invalid");
96 WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
102 log(DEFAULT,"the target nickname given to give_ops couldnt be found");
103 WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
110 FOREACH_RESULT(OnAccessCheck(user,d,chan,AC_OP));
112 if (MOD_RESULT == ACR_DENY)
114 if (MOD_RESULT == ACR_DEFAULT)
116 if ((status < STATUS_OP) && (!is_uline(user->server)))
118 log(DEBUG,"%s cant give ops to %s because they nave status %d and needs %d",user->nick,dest,status,STATUS_OP);
119 WriteServ(user->fd,"482 %s %s :You're not a channel operator",user->nick, chan->name);
125 for (int i = 0; i != MAXCHANS; i++)
127 if ((d->chans[i].channel != NULL) && (chan != NULL))
128 if (!strcasecmp(d->chans[i].channel->name,chan->name))
130 if (d->chans[i].uc_modes & UCMODE_OP)
132 /* mode already set on user, dont allow multiple */
133 log(DEFAULT,"The target user given to give_ops was already opped on the channel");
136 d->chans[i].uc_modes = d->chans[i].uc_modes | UCMODE_OP;
137 log(DEBUG,"gave ops: %s %s",d->chans[i].channel->name,d->nick);
141 log(DEFAULT,"The target channel given to give_ops was not in the users mode list");
146 char* give_hops(userrec *user,char *dest,chanrec *chan,int status)
151 if ((!user) || (!dest) || (!chan))
153 log(DEFAULT,"*** BUG *** give_hops was given an invalid parameter");
160 WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
165 WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
171 FOREACH_RESULT(OnAccessCheck(user,d,chan,AC_HALFOP));
173 if (MOD_RESULT == ACR_DENY)
175 if (MOD_RESULT == ACR_DEFAULT)
177 if ((status < STATUS_OP) && (!is_uline(user->server)))
179 WriteServ(user->fd,"482 %s %s :You're not a channel operator",user->nick, chan->name);
184 for (int i = 0; i != MAXCHANS; i++)
186 if ((d->chans[i].channel != NULL) && (chan != NULL))
187 if (!strcasecmp(d->chans[i].channel->name,chan->name))
189 if (d->chans[i].uc_modes & UCMODE_HOP)
191 /* mode already set on user, dont allow multiple */
194 d->chans[i].uc_modes = d->chans[i].uc_modes | UCMODE_HOP;
195 log(DEBUG,"gave h-ops: %s %s",d->chans[i].channel->name,d->nick);
203 char* give_voice(userrec *user,char *dest,chanrec *chan,int status)
208 if ((!user) || (!dest) || (!chan))
210 log(DEFAULT,"*** BUG *** give_voice was given an invalid parameter");
217 WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
222 WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
228 FOREACH_RESULT(OnAccessCheck(user,d,chan,AC_VOICE));
230 if (MOD_RESULT == ACR_DENY)
232 if (MOD_RESULT == ACR_DEFAULT)
234 if ((status < STATUS_HOP) && (!is_uline(user->server)))
236 WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, chan->name);
241 for (int i = 0; i != MAXCHANS; i++)
243 if ((d->chans[i].channel != NULL) && (chan != NULL))
244 if (!strcasecmp(d->chans[i].channel->name,chan->name))
246 if (d->chans[i].uc_modes & UCMODE_VOICE)
248 /* mode already set on user, dont allow multiple */
251 d->chans[i].uc_modes = d->chans[i].uc_modes | UCMODE_VOICE;
252 log(DEBUG,"gave voice: %s %s",d->chans[i].channel->name,d->nick);
260 char* take_ops(userrec *user,char *dest,chanrec *chan,int status)
265 if ((!user) || (!dest) || (!chan))
267 log(DEFAULT,"*** BUG *** take_ops was given an invalid parameter");
274 log(DEBUG,"take_ops was given an invalid target nickname of %s",dest);
275 WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
280 log(DEBUG,"take_ops couldnt resolve the target nickname: %s",dest);
281 WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
287 FOREACH_RESULT(OnAccessCheck(user,d,chan,AC_DEOP));
289 if (MOD_RESULT == ACR_DENY)
291 if (MOD_RESULT == ACR_DEFAULT)
293 if ((status < STATUS_OP) && (!is_uline(user->server)))
295 WriteServ(user->fd,"482 %s %s :You are not a channel operator",user->nick, chan->name);
300 for (int i = 0; i != MAXCHANS; i++)
302 if ((d->chans[i].channel != NULL) && (chan != NULL))
303 if (!strcasecmp(d->chans[i].channel->name,chan->name))
305 if ((d->chans[i].uc_modes & UCMODE_OP) == 0)
307 /* mode already set on user, dont allow multiple */
310 d->chans[i].uc_modes ^= UCMODE_OP;
311 log(DEBUG,"took ops: %s %s",d->chans[i].channel->name,d->nick);
315 log(DEBUG,"take_ops couldnt locate the target channel in the target users list");
320 char* take_hops(userrec *user,char *dest,chanrec *chan,int status)
325 if ((!user) || (!dest) || (!chan))
327 log(DEFAULT,"*** BUG *** take_hops was given an invalid parameter");
334 WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
339 WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
345 FOREACH_RESULT(OnAccessCheck(user,d,chan,AC_DEHALFOP));
347 if (MOD_RESULT == ACR_DENY)
349 if (MOD_RESULT == ACR_DEFAULT)
351 if ((status < STATUS_OP) && (!is_uline(user->server)))
353 WriteServ(user->fd,"482 %s %s :You are not a channel operator",user->nick, chan->name);
358 for (int i = 0; i != MAXCHANS; i++)
360 if ((d->chans[i].channel != NULL) && (chan != NULL))
361 if (!strcasecmp(d->chans[i].channel->name,chan->name))
363 if ((d->chans[i].uc_modes & UCMODE_HOP) == 0)
365 /* mode already set on user, dont allow multiple */
368 d->chans[i].uc_modes ^= UCMODE_HOP;
369 log(DEBUG,"took h-ops: %s %s",d->chans[i].channel->name,d->nick);
377 char* take_voice(userrec *user,char *dest,chanrec *chan,int status)
382 if ((!user) || (!dest) || (!chan))
384 log(DEFAULT,"*** BUG *** take_voice was given an invalid parameter");
391 WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
396 WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, dest);
402 FOREACH_RESULT(OnAccessCheck(user,d,chan,AC_DEVOICE));
404 if (MOD_RESULT == ACR_DENY)
406 if (MOD_RESULT == ACR_DEFAULT)
408 if ((status < STATUS_HOP) && (!is_uline(user->server)))
410 WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, chan->name);
415 for (int i = 0; i != MAXCHANS; i++)
417 if ((d->chans[i].channel != NULL) && (chan != NULL))
418 if (!strcasecmp(d->chans[i].channel->name,chan->name))
420 if ((d->chans[i].uc_modes & UCMODE_VOICE) == 0)
422 /* mode already set on user, dont allow multiple */
425 d->chans[i].uc_modes ^= UCMODE_VOICE;
426 log(DEBUG,"took voice: %s %s",d->chans[i].channel->name,d->nick);
434 char* add_ban(userrec *user,char *dest,chanrec *chan,int status)
436 if ((!user) || (!dest) || (!chan)) {
437 log(DEFAULT,"*** BUG *** add_ban was given an invalid parameter");
442 if ((!user) || (!dest) || (!chan))
444 if (strchr(dest,'!')==0)
446 if (strchr(dest,'@')==0)
448 for (int i = 0; i < strlen(dest); i++)
451 for (int i = 0; i < strlen(dest); i++)
455 for (int i = 0; i < strlen(dest); i++)
461 for (int i = 0; i < strlen(dest); i++)
466 log(DEBUG,"add_ban: %s %s",chan->name,user->nick);
469 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
471 if (!strcasecmp(i->data,dest))
473 // dont allow a user to set the same ban twice
478 b.set_time = time(NULL);
479 strncpy(b.data,dest,MAXBUF);
480 strncpy(b.set_by,user->nick,NICKMAX);
481 chan->bans.push_back(b);
485 char* take_ban(userrec *user,char *dest,chanrec *chan,int status)
487 if ((!user) || (!dest) || (!chan)) {
488 log(DEFAULT,"*** BUG *** take_ban was given an invalid parameter");
492 log(DEBUG,"del_ban: %s %s",chan->name,user->nick);
493 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
495 if (!strcasecmp(i->data,dest))
504 void process_modes(char **parameters,userrec* user,chanrec *chan,int status, int pcnt, bool servermode, bool silent, bool local)
507 log(DEFAULT,"*** BUG *** process_modes was given an invalid parameter");
511 char modelist[MAXBUF];
512 char outlist[MAXBUF];
514 char outpars[32][MAXBUF];
520 bool k_set = false, l_set = false;
528 FOREACH_RESULT(OnAccessCheck(user,NULL,chan,AC_GENERAL_MODE));
530 if (MOD_RESULT == ACR_DENY)
533 log(DEBUG,"process_modes: start: parameters=%d",pcnt);
535 strcpy(modelist,parameters[1]); /* mode list, e.g. +oo-o */
536 /* parameters[2] onwards are parameters for
537 * modes that require them :) */
541 log(DEBUG,"process_modes: modelist: %s",modelist);
543 for (ptr = 0; ptr < strlen(modelist); ptr++)
548 log(DEBUG,"process_modes: modechar: %c",modelist[ptr]);
549 char modechar = modelist[ptr];
550 switch (modelist[ptr])
555 if ((outlist[strlen(outlist)-1] == '+') || (outlist[strlen(outlist)-1] == '-'))
557 outlist[strlen(outlist)-1] = '-';
571 if ((outlist[strlen(outlist)-1] == '+') || (outlist[strlen(outlist)-1] == '-'))
573 outlist[strlen(outlist)-1] = '+';
585 if ((param >= pcnt)) break;
586 log(DEBUG,"Enough parameters left");
589 log(DEBUG,"calling give_ops");
590 r = give_ops(user,parameters[param++],chan,status);
594 log(DEBUG,"calling take_ops");
595 r = take_ops(user,parameters[param++],chan,status);
600 strcpy(outpars[pc++],r);
605 if (((param >= pcnt)) || (!AllowHalfop)) break;
608 r = give_hops(user,parameters[param++],chan,status);
612 r = take_hops(user,parameters[param++],chan,status);
617 strcpy(outpars[pc++],r);
623 if ((param >= pcnt)) break;
626 r = give_voice(user,parameters[param++],chan,status);
630 r = take_voice(user,parameters[param++],chan,status);
635 strcpy(outpars[pc++],r);
640 if ((param >= pcnt)) break;
643 r = add_ban(user,parameters[param++],chan,status);
647 r = take_ban(user,parameters[param++],chan,status);
652 strcpy(outpars[pc++],parameters[param-1]);
666 if (!strcmp(chan->key,""))
670 strcpy(key,parameters[param++]);
671 if (strlen(key)>32) {
674 strcpy(outpars[pc++],key);
675 strcpy(chan->key,key);
681 /* checks on -k are case sensitive and only accurate to the
682 first 32 characters */
684 strcpy(key,parameters[param++]);
685 if (strlen(key)>32) {
688 /* only allow -k if correct key given */
689 if (!strcmp(chan->key,key))
692 strcpy(chan->key,"");
693 strcpy(outpars[pc++],key);
708 if ((param >= pcnt)) break;
714 bool invalid = false;
715 for (int i = 0; i < strlen(parameters[param]); i++)
717 if ((parameters[param][i] < '0') || (parameters[param][i] > '9'))
722 if (atoi(parameters[param]) < 1)
730 chan->limit = atoi(parameters[param]);
732 // reported by mech: large values cause underflow
734 chan->limit = 0x7FFFFF;
739 strcpy(outpars[pc++],parameters[param++]);
746 if (chan->inviteonly != mdir)
750 chan->inviteonly = mdir;
754 if (chan->topiclock != mdir)
758 chan->topiclock = mdir;
762 if (chan->noexternal != mdir)
766 chan->noexternal = mdir;
770 if (chan->moderated != mdir)
774 chan->moderated = mdir;
778 if (chan->secret != mdir)
786 strcat(outlist,"-p+");
790 strcat(outlist,"+p-");
798 if (chan->c_private != mdir)
806 strcat(outlist,"-s+");
810 strcat(outlist,"+s-");
814 chan->c_private = mdir;
818 log(DEBUG,"Preprocessing custom mode %c",modechar);
821 if (((!strchr(chan->custom_modes,modechar)) && (!mdir)) || ((strchr(chan->custom_modes,modechar)) && (mdir)))
823 if (!ModeIsListMode(modechar,MT_CHANNEL))
825 log(DEBUG,"Mode %c isnt set on %s but trying to remove!",modechar,chan->name);
829 if (ModeDefined(modechar,MT_CHANNEL))
831 log(DEBUG,"A module has claimed this mode");
834 if ((ModeDefinedOn(modechar,MT_CHANNEL)>0) && (mdir))
836 p.push_back(parameters[param]);
838 if ((ModeDefinedOff(modechar,MT_CHANNEL)>0) && (!mdir))
840 p.push_back(parameters[param]);
843 bool handled = false;
846 log(DEBUG,"Not enough parameters for module-mode %c",modechar);
847 // we're supposed to have a parameter, but none was given... so dont handle the mode.
848 if (((ModeDefinedOn(modechar,MT_CHANNEL)>0) && (mdir)) || ((ModeDefinedOff(modechar,MT_CHANNEL)>0) && (!mdir)))
854 for (int i = 0; i <= MODCOUNT; i++)
858 int t = modules[i]->OnExtendedMode(user,chan,modechar,MT_CHANNEL,mdir,p);
861 log(DEBUG,"OnExtendedMode returned nonzero for a module");
862 char app[] = {modechar, 0};
863 if (ModeIsListMode(modechar,MT_CHANNEL))
873 strcat(outlist, app);
875 strcpy(outpars[pc++],parameters[param++]);
882 if ((modelist[ptr-1] == '+') || (modelist[ptr-1] == '-'))
884 strcat(outlist, app);
886 else if (!strchr(outlist,modechar))
888 strcat(outlist, app);
891 chan->SetCustomMode(modechar,mdir);
892 // include parameters in output if mode has them
893 if ((ModeDefinedOn(modechar,MT_CHANNEL)>0) && (mdir))
895 chan->SetCustomModeParam(modelist[ptr],parameters[param],mdir);
896 strcpy(outpars[pc++],parameters[param++]);
899 // break, because only one module can handle the mode.
911 /* this ensures only the *valid* modes are sent out onto the network */
912 while ((outlist[strlen(outlist)-1] == '-') || (outlist[strlen(outlist)-1] == '+'))
914 outlist[strlen(outlist)-1] = '\0';
916 if (strcmp(outlist,""))
918 strcpy(outstr,outlist);
919 for (ptr = 0; ptr < pc; ptr++)
922 strcat(outstr,outpars[ptr]);
926 log(DEBUG,"Local mode change");
927 WriteChannelLocal(chan, user, "MODE %s %s",chan->name,outstr);
935 WriteChannelWithServ(ServerName,chan,user,"MODE %s %s",chan->name,outstr);
936 // M token for a usermode must go to all servers
938 snprintf(buffer,MAXBUF,"M %s %s",chan->name, outstr);
939 NetSendToAll(buffer);
947 WriteChannel(chan,user,"MODE %s %s",chan->name,outstr);
948 // M token for a usermode must go to all servers
950 snprintf(buffer,MAXBUF,"m %s %s %s",user->nick,chan->name, outstr);
951 NetSendToAll(buffer);
958 // based on sourcemodes, return true or false to determine if umode is a valid mode a user may set on themselves or others.
960 bool allowed_umode(char umode, char* sourcemodes,bool adding)
962 log(DEBUG,"Allowed_umode: %c %s",umode,sourcemodes);
963 // RFC1459 specified modes
964 if ((umode == 'w') || (umode == 's') || (umode == 'i'))
966 log(DEBUG,"umode %c allowed by RFC1459 scemantics",umode);
970 // user may not +o themselves or others, but an oper may de-oper other opers or themselves
971 if ((strchr(sourcemodes,'o')) && (!adding))
973 log(DEBUG,"umode %c allowed by RFC1459 scemantics",umode);
976 else if (umode == 'o')
978 log(DEBUG,"umode %c allowed by RFC1459 scemantics",umode);
982 // process any module-defined modes that need oper
983 if ((ModeDefinedOper(umode,MT_CLIENT)) && (strchr(sourcemodes,'o')))
985 log(DEBUG,"umode %c allowed by module handler (oper only mode)",umode);
989 if (ModeDefined(umode,MT_CLIENT))
991 // process any module-defined modes that don't need oper
992 log(DEBUG,"umode %c allowed by module handler (non-oper mode)",umode);
993 if ((ModeDefinedOper(umode,MT_CLIENT)) && (!strchr(sourcemodes,'o')))
995 // no, this mode needs oper, and this user 'aint got what it takes!
1001 // anything else - return false.
1002 log(DEBUG,"umode %c not known by any ruleset",umode);
1006 bool process_module_umode(char umode, userrec* source, void* dest, bool adding)
1013 strncpy(s2->nick,ServerName,NICKMAX);
1014 strcpy(s2->modes,"o");
1021 if (ModeDefined(umode,MT_CLIENT))
1023 for (int i = 0; i <= MODCOUNT; i++)
1025 if (modules[i]->OnExtendedMode(source,(void*)dest,umode,MT_CLIENT,adding,p))
1027 log(DEBUG,"Module %s claims umode %c",module_names[i].c_str(),umode);
1031 log(DEBUG,"No module claims umode %c",umode);
1050 void handle_mode(char **parameters, int pcnt, userrec *user)
1056 char outpars[MAXBUF];
1058 dest = Find(parameters[0]);
1065 if ((dest) && (pcnt == 1))
1067 WriteServ(user->fd,"221 %s :+%s",dest->nick,dest->modes);
1071 if ((dest) && (pcnt > 1))
1073 char dmodes[MAXBUF];
1074 strncpy(dmodes,dest->modes,MAXBUF);
1075 log(DEBUG,"pulled up dest user modes: %s",dmodes);
1080 if (strchr(user->modes,'o'))
1091 WriteServ(user->fd,"482 %s :Can't change mode for other users",user->nick);
1095 strcpy(outpars,"+");
1098 if ((parameters[1][0] != '+') && (parameters[1][0] != '-'))
1101 for (int i = 0; i < strlen(parameters[1]); i++)
1103 if (parameters[1][i] == '+')
1107 if ((outpars[strlen(outpars)-1] == '+') || (outpars[strlen(outpars)-1] == '-'))
1109 outpars[strlen(outpars)-1] = '+';
1113 strcat(outpars,"+");
1119 if (parameters[1][i] == '-')
1123 if ((outpars[strlen(outpars)-1] == '+') || (outpars[strlen(outpars)-1] == '-'))
1125 outpars[strlen(outpars)-1] = '-';
1129 strcat(outpars,"-");
1137 if (strchr(user->modes,'o'))
1143 if ((parameters[1][i] == 'i') || (parameters[1][i] == 'w') || (parameters[1][i] == 's') || (allowed_umode(parameters[1][i],user->modes,direction)))
1152 if ((!strchr(dmodes,parameters[1][i])) && (allowed_umode(parameters[1][i],user->modes,true)))
1154 char umode = parameters[1][i];
1155 if ((process_module_umode(umode, user, dest, direction)) || (umode == 'i') || (umode == 's') || (umode == 'w') || (umode == 'o'))
1157 dmodes[strlen(dmodes)+1]='\0';
1158 dmodes[strlen(dmodes)] = parameters[1][i];
1159 outpars[strlen(outpars)+1]='\0';
1160 outpars[strlen(outpars)] = parameters[1][i];
1166 if ((allowed_umode(parameters[1][i],user->modes,false)) && (strchr(dmodes,parameters[1][i])))
1168 char umode = parameters[1][i];
1169 if ((process_module_umode(umode, user, dest, direction)) || (umode == 'i') || (umode == 's') || (umode == 'w') || (umode == 'o'))
1175 outpars[strlen(outpars)+1]='\0';
1176 outpars[strlen(outpars)] = parameters[1][i];
1179 for (q = 0; q < strlen(dmodes); q++)
1181 if (dmodes[q] != parameters[1][i])
1188 strcpy(dmodes,temp);
1195 if (strlen(outpars))
1201 while (i < strlen (outpars))
1203 b[z++] = outpars[i++];
1205 if (i<strlen(outpars)-1)
1207 if (((outpars[i] == '-') || (outpars[i] == '+')) && ((outpars[i+1] == '-') || (outpars[i+1] == '+')))
1209 // someones playing silly buggers and trying
1210 // to put a +- or -+ into the line...
1214 if (i == strlen(outpars)-1)
1216 if ((outpars[i] == '-') || (outpars[i] == '+'))
1224 if ((b[z] == '-') || (b[z] == '+'))
1227 if ((!strcmp(b,"+")) || (!strcmp(b,"-")))
1230 WriteTo(user, dest, "MODE %s :%s", dest->nick, b);
1232 // M token for a usermode must go to all servers
1233 char buffer[MAXBUF];
1234 snprintf(buffer,MAXBUF,"m %s %s %s",user->nick, dest->nick, b);
1235 NetSendToAll(buffer);
1237 if (strlen(dmodes)>MAXMODES)
1239 dmodes[MAXMODES-1] = '\0';
1241 log(DEBUG,"Stripped mode line");
1242 log(DEBUG,"Line dest is now %s",dmodes);
1243 strncpy(dest->modes,dmodes,MAXMODES);
1250 Ptr = FindChan(parameters[0]);
1255 /* just /modes #channel */
1256 WriteServ(user->fd,"324 %s %s +%s",user->nick, Ptr->name, chanmodes(Ptr));
1257 WriteServ(user->fd,"329 %s %s %d", user->nick, Ptr->name, Ptr->created);
1263 if ((!strcmp(parameters[1],"+b")) || (!strcmp(parameters[1],"b")))
1266 for (BanList::iterator i = Ptr->bans.begin(); i != Ptr->bans.end(); i++)
1268 WriteServ(user->fd,"367 %s %s %s %s %d",user->nick, Ptr->name, i->data, i->set_by, i->set_time);
1270 WriteServ(user->fd,"368 %s %s :End of channel ban list",user->nick, Ptr->name);
1276 FOREACH_RESULT(OnAccessCheck(user,NULL,Ptr,AC_GENERAL_MODE));
1278 if (MOD_RESULT == ACR_DENY)
1280 if (MOD_RESULT == ACR_DEFAULT)
1282 if ((cstatus(user,Ptr) < STATUS_HOP) && (Ptr))
1284 WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, Ptr->name);
1289 process_modes(parameters,user,Ptr,cstatus(user,Ptr),pcnt,false,false,false);
1293 WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]);
1300 void server_mode(char **parameters, int pcnt, userrec *user)
1306 char outpars[MAXBUF];
1308 dest = Find(parameters[0]);
1310 // fix: ChroNiCk found this - we cant use this as debug if its null!
1313 log(DEBUG,"server_mode on %s",dest->nick);
1316 if ((dest) && (pcnt > 1))
1318 log(DEBUG,"params > 1");
1320 char dmodes[MAXBUF];
1321 strncpy(dmodes,dest->modes,MAXBUF);
1323 strcpy(outpars,"+");
1326 if ((parameters[1][0] != '+') && (parameters[1][0] != '-'))
1329 for (int i = 0; i < strlen(parameters[1]); i++)
1331 if (parameters[1][i] == '+')
1335 if ((outpars[strlen(outpars)-1] == '+') || (outpars[strlen(outpars)-1] == '-'))
1337 outpars[strlen(outpars)-1] = '+';
1341 strcat(outpars,"+");
1347 if (parameters[1][i] == '-')
1351 if ((outpars[strlen(outpars)-1] == '+') || (outpars[strlen(outpars)-1] == '-'))
1353 outpars[strlen(outpars)-1] = '-';
1357 strcat(outpars,"-");
1364 log(DEBUG,"begin mode processing entry");
1370 log(DEBUG,"umode %c being added",parameters[1][i]);
1371 if ((!strchr(dmodes,parameters[1][i])) && (allowed_umode(parameters[1][i],user->modes,true)))
1373 char umode = parameters[1][i];
1374 log(DEBUG,"umode %c is an allowed umode",umode);
1375 if ((process_module_umode(umode, user, dest, direction)) || (umode == 'i') || (umode == 's') || (umode == 'w') || (umode == 'o'))
1377 dmodes[strlen(dmodes)+1]='\0';
1378 dmodes[strlen(dmodes)] = parameters[1][i];
1379 outpars[strlen(outpars)+1]='\0';
1380 outpars[strlen(outpars)] = parameters[1][i];
1386 // can only remove a mode they already have
1387 log(DEBUG,"umode %c being removed",parameters[1][i]);
1388 if ((allowed_umode(parameters[1][i],user->modes,false)) && (strchr(dmodes,parameters[1][i])))
1390 char umode = parameters[1][i];
1391 log(DEBUG,"umode %c is an allowed umode",umode);
1392 if ((process_module_umode(umode, user, dest, direction)) || (umode == 'i') || (umode == 's') || (umode == 'w') || (umode == 'o'))
1398 outpars[strlen(outpars)+1]='\0';
1399 outpars[strlen(outpars)] = parameters[1][i];
1402 for (q = 0; q < strlen(dmodes); q++)
1404 if (dmodes[q] != parameters[1][i])
1411 strcpy(dmodes,temp);
1418 if (strlen(outpars))
1424 while (i < strlen (outpars))
1426 b[z++] = outpars[i++];
1428 if (i<strlen(outpars)-1)
1430 if (((outpars[i] == '-') || (outpars[i] == '+')) && ((outpars[i+1] == '-') || (outpars[i+1] == '+')))
1432 // someones playing silly buggers and trying
1433 // to put a +- or -+ into the line...
1437 if (i == strlen(outpars)-1)
1439 if ((outpars[i] == '-') || (outpars[i] == '+'))
1447 if ((b[z] == '-') || (b[z] == '+'))
1450 if ((!strcmp(b,"+")) || (!strcmp(b,"-")))
1453 WriteTo(user, dest, "MODE %s :%s", dest->nick, b);
1455 // M token for a usermode must go to all servers
1456 char buffer[MAXBUF];
1457 snprintf(buffer,MAXBUF,"m %s %s %s",user->nick, dest->nick, b);
1458 NetSendToAll(buffer);
1460 if (strlen(dmodes)>MAXMODES)
1462 dmodes[MAXMODES-1] = '\0';
1464 log(DEBUG,"Stripped mode line");
1465 log(DEBUG,"Line dest is now %s",dmodes);
1466 strncpy(dest->modes,dmodes,MAXMODES);
1473 Ptr = FindChan(parameters[0]);
1476 process_modes(parameters,user,Ptr,STATUS_OP,pcnt,true,false,false);
1480 WriteServ(user->fd,"401 %s %s :No suck nick/channel",user->nick, parameters[0]);
1486 void merge_mode(char **parameters, int pcnt)
1492 char outpars[MAXBUF];
1494 dest = Find(parameters[0]);
1496 // fix: ChroNiCk found this - we cant use this as debug if its null!
1499 log(DEBUG,"merge_mode on %s",dest->nick);
1502 if ((dest) && (pcnt > 1))
1504 log(DEBUG,"params > 1");
1506 char dmodes[MAXBUF];
1507 strncpy(dmodes,dest->modes,MAXBUF);
1509 strcpy(outpars,"+");
1512 if ((parameters[1][0] != '+') && (parameters[1][0] != '-'))
1515 for (int i = 0; i < strlen(parameters[1]); i++)
1517 if (parameters[1][i] == '+')
1521 if ((outpars[strlen(outpars)-1] == '+') || (outpars[strlen(outpars)-1] == '-'))
1523 outpars[strlen(outpars)-1] = '+';
1527 strcat(outpars,"+");
1533 if (parameters[1][i] == '-')
1537 if ((outpars[strlen(outpars)-1] == '+') || (outpars[strlen(outpars)-1] == '-'))
1539 outpars[strlen(outpars)-1] = '-';
1543 strcat(outpars,"-");
1550 log(DEBUG,"begin mode processing entry");
1556 log(DEBUG,"umode %c being added",parameters[1][i]);
1557 if ((!strchr(dmodes,parameters[1][i])) && (allowed_umode(parameters[1][i],"o",true)))
1559 char umode = parameters[1][i];
1560 log(DEBUG,"umode %c is an allowed umode",umode);
1561 if ((process_module_umode(umode, NULL, dest, direction)) || (umode == 'i') || (umode == 's') || (umode == 'w') || (umode == 'o'))
1563 dmodes[strlen(dmodes)+1]='\0';
1564 dmodes[strlen(dmodes)] = parameters[1][i];
1565 outpars[strlen(outpars)+1]='\0';
1566 outpars[strlen(outpars)] = parameters[1][i];
1572 // can only remove a mode they already have
1573 log(DEBUG,"umode %c being removed",parameters[1][i]);
1574 if ((allowed_umode(parameters[1][i],"o",false)) && (strchr(dmodes,parameters[1][i])))
1576 char umode = parameters[1][i];
1577 log(DEBUG,"umode %c is an allowed umode",umode);
1578 if ((process_module_umode(umode, NULL, dest, direction)) || (umode == 'i') || (umode == 's') || (umode == 'w') || (umode == 'o'))
1584 outpars[strlen(outpars)+1]='\0';
1585 outpars[strlen(outpars)] = parameters[1][i];
1588 for (q = 0; q < strlen(dmodes); q++)
1590 if (dmodes[q] != parameters[1][i])
1597 strcpy(dmodes,temp);
1604 if (strlen(outpars))
1610 while (i < strlen (outpars))
1612 b[z++] = outpars[i++];
1614 if (i<strlen(outpars)-1)
1616 if (((outpars[i] == '-') || (outpars[i] == '+')) && ((outpars[i+1] == '-') || (outpars[i+1] == '+')))
1618 // someones playing silly buggers and trying
1619 // to put a +- or -+ into the line...
1623 if (i == strlen(outpars)-1)
1625 if ((outpars[i] == '-') || (outpars[i] == '+'))
1633 if ((b[z] == '-') || (b[z] == '+'))
1636 if ((!strcmp(b,"+")) || (!strcmp(b,"-")))
1639 if (strlen(dmodes)>MAXMODES)
1641 dmodes[MAXMODES-1] = '\0';
1643 log(DEBUG,"Stripped mode line");
1644 log(DEBUG,"Line dest is now %s",dmodes);
1645 strncpy(dest->modes,dmodes,MAXMODES);
1652 Ptr = FindChan(parameters[0]);
1656 strncpy(s2.nick,ServerName,NICKMAX);
1657 strcpy(s2.modes,"o");
1659 process_modes(parameters,&s2,Ptr,STATUS_OP,pcnt,true,true,false);
1664 void merge_mode2(char **parameters, int pcnt, userrec* user)
1670 char outpars[MAXBUF];
1672 dest = Find(parameters[0]);
1674 // fix: ChroNiCk found this - we cant use this as debug if its null!
1677 log(DEBUG,"merge_mode on %s",dest->nick);
1680 if ((dest) && (pcnt > 1))
1682 log(DEBUG,"params > 1");
1684 char dmodes[MAXBUF];
1685 strncpy(dmodes,dest->modes,MAXBUF);
1687 strcpy(outpars,"+");
1690 if ((parameters[1][0] != '+') && (parameters[1][0] != '-'))
1693 for (int i = 0; i < strlen(parameters[1]); i++)
1695 if (parameters[1][i] == '+')
1699 if ((outpars[strlen(outpars)-1] == '+') || (outpars[strlen(outpars)-1] == '-'))
1701 outpars[strlen(outpars)-1] = '+';
1705 strcat(outpars,"+");
1711 if (parameters[1][i] == '-')
1715 if ((outpars[strlen(outpars)-1] == '+') || (outpars[strlen(outpars)-1] == '-'))
1717 outpars[strlen(outpars)-1] = '-';
1721 strcat(outpars,"-");
1728 log(DEBUG,"begin mode processing entry");
1734 log(DEBUG,"umode %c being added",parameters[1][i]);
1735 if ((!strchr(dmodes,parameters[1][i])) && (allowed_umode(parameters[1][i],user->modes,true)))
1737 char umode = parameters[1][i];
1738 log(DEBUG,"umode %c is an allowed umode",umode);
1739 if ((process_module_umode(umode, NULL, dest, direction)) || (umode == 'i') || (umode == 's') || (umode == 'w') || (umode == 'o'))
1741 dmodes[strlen(dmodes)+1]='\0';
1742 dmodes[strlen(dmodes)] = parameters[1][i];
1743 outpars[strlen(outpars)+1]='\0';
1744 outpars[strlen(outpars)] = parameters[1][i];
1750 // can only remove a mode they already have
1751 log(DEBUG,"umode %c being removed",parameters[1][i]);
1752 if ((allowed_umode(parameters[1][i],user->modes,false)) && (strchr(dmodes,parameters[1][i])))
1754 char umode = parameters[1][i];
1755 log(DEBUG,"umode %c is an allowed umode",umode);
1756 if ((process_module_umode(umode, NULL, dest, direction)) || (umode == 'i') || (umode == 's') || (umode == 'w') || (umode == 'o'))
1762 outpars[strlen(outpars)+1]='\0';
1763 outpars[strlen(outpars)] = parameters[1][i];
1766 for (q = 0; q < strlen(dmodes); q++)
1768 if (dmodes[q] != parameters[1][i])
1775 strcpy(dmodes,temp);
1782 if (strlen(outpars))
1788 while (i < strlen (outpars))
1790 b[z++] = outpars[i++];
1792 if (i<strlen(outpars)-1)
1794 if (((outpars[i] == '-') || (outpars[i] == '+')) && ((outpars[i+1] == '-') || (outpars[i+1] == '+')))
1796 // someones playing silly buggers and trying
1797 // to put a +- or -+ into the line...
1801 if (i == strlen(outpars)-1)
1803 if ((outpars[i] == '-') || (outpars[i] == '+'))
1811 if ((b[z] == '-') || (b[z] == '+'))
1814 if ((!strcmp(b,"+")) || (!strcmp(b,"-")))
1817 WriteTo(user,dest,"MODE :%s",b);
1819 if (strlen(dmodes)>MAXMODES)
1821 dmodes[MAXMODES-1] = '\0';
1823 log(DEBUG,"Stripped mode line");
1824 log(DEBUG,"Line dest is now %s",dmodes);
1825 strncpy(dest->modes,dmodes,MAXMODES);
1832 Ptr = FindChan(parameters[0]);
1835 log(DEBUG,"merge_mode2: found channel %s",Ptr->name);
1838 if ((cstatus(user,Ptr) < STATUS_HOP) && (!is_uline(user->server)))
1842 process_modes(parameters,user,Ptr,cstatus(user,Ptr),pcnt,false,false,true);