1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd is copyright (C) 2002-2006 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 * ---------------------------------------------------
19 #include "inspircd_config.h"
21 #include "inspircd_io.h"
23 #include <sys/errno.h>
27 #include <ext/hash_map>
35 #include "connection.h"
45 #include "inspstring.h"
46 #include "helperfuncs.h"
50 extern std::vector<Module*> modules;
51 extern std::vector<ircd_module*> factory;
52 extern InspIRCd* ServerInstance;
53 extern ServerConfig* Config;
57 userrec* ModeParser::SanityChecks(userrec *user,char *dest,chanrec *chan,int status)
60 if ((!user) || (!dest) || (!chan) || (!*dest))
67 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, dest);
73 char* ModeParser::Grant(userrec *d,chanrec *chan,int MASK)
78 for (std::vector<ucrec*>::const_iterator i = d->chans.begin(); i != d->chans.end(); i++)
80 if (((ucrec*)(*i))->channel == chan)
82 if (((ucrec*)(*i))->uc_modes & MASK)
86 ((ucrec*)(*i))->uc_modes = ((ucrec*)(*i))->uc_modes | MASK;
90 ((ucrec*)(*i))->channel->AddOppedUser(d);
93 ((ucrec*)(*i))->channel->AddHalfoppedUser(d);
96 ((ucrec*)(*i))->channel->AddVoicedUser(d);
99 log(DEBUG,"grant: %s %s",((ucrec*)(*i))->channel->name,d->nick);
106 char* ModeParser::Revoke(userrec *d,chanrec *chan,int MASK)
111 for (std::vector<ucrec*>::const_iterator i = d->chans.begin(); i != d->chans.end(); i++)
113 if (((ucrec*)(*i))->channel == chan)
115 if ((((ucrec*)(*i))->uc_modes & MASK) == 0)
119 ((ucrec*)(*i))->uc_modes ^= MASK;
123 ((ucrec*)(*i))->channel->DelOppedUser(d);
126 ((ucrec*)(*i))->channel->DelHalfoppedUser(d);
129 ((ucrec*)(*i))->channel->DelVoicedUser(d);
132 log(DEBUG,"revoke: %s %s",((ucrec*)(*i))->channel->name,d->nick);
139 char* ModeParser::GiveOps(userrec *user,char *dest,chanrec *chan,int status)
141 userrec *d = this->SanityChecks(user,dest,chan,status);
148 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_OP));
150 if (MOD_RESULT == ACR_DENY)
152 if (MOD_RESULT == ACR_DEFAULT)
154 if ((status < STATUS_OP) && (!is_uline(user->server)))
156 WriteServ(user->fd,"482 %s %s :You're not a channel operator",user->nick, chan->name);
162 return this->Grant(d,chan,UCMODE_OP);
167 char* ModeParser::GiveHops(userrec *user,char *dest,chanrec *chan,int status)
169 userrec *d = this->SanityChecks(user,dest,chan,status);
176 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_HALFOP));
178 if (MOD_RESULT == ACR_DENY)
180 if (MOD_RESULT == ACR_DEFAULT)
182 if ((status < STATUS_OP) && (!is_uline(user->server)))
184 WriteServ(user->fd,"482 %s %s :You're not a channel operator",user->nick, chan->name);
190 return this->Grant(d,chan,UCMODE_HOP);
195 char* ModeParser::GiveVoice(userrec *user,char *dest,chanrec *chan,int status)
197 userrec *d = this->SanityChecks(user,dest,chan,status);
204 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_VOICE));
206 if (MOD_RESULT == ACR_DENY)
208 if (MOD_RESULT == ACR_DEFAULT)
210 if ((status < STATUS_HOP) && (!is_uline(user->server)))
212 WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, chan->name);
218 return this->Grant(d,chan,UCMODE_VOICE);
223 char* ModeParser::TakeOps(userrec *user,char *dest,chanrec *chan,int status)
225 userrec *d = this->SanityChecks(user,dest,chan,status);
232 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEOP));
234 if (MOD_RESULT == ACR_DENY)
236 if (MOD_RESULT == ACR_DEFAULT)
238 if ((status < STATUS_OP) && (!is_uline(user->server)) && (IS_LOCAL(user)))
240 WriteServ(user->fd,"482 %s %s :You are not a channel operator",user->nick, chan->name);
246 return this->Revoke(d,chan,UCMODE_OP);
251 char* ModeParser::TakeHops(userrec *user,char *dest,chanrec *chan,int status)
253 userrec *d = this->SanityChecks(user,dest,chan,status);
260 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEHALFOP));
262 if (MOD_RESULT == ACR_DENY)
264 if (MOD_RESULT == ACR_DEFAULT)
266 /* Tweak by Brain suggested by w00t, allow a halfop to dehalfop themselves */
267 if ((user != d) && ((status < STATUS_OP) && (!is_uline(user->server))))
269 WriteServ(user->fd,"482 %s %s :You are not a channel operator",user->nick, chan->name);
275 return this->Revoke(d,chan,UCMODE_HOP);
280 char* ModeParser::TakeVoice(userrec *user,char *dest,chanrec *chan,int status)
282 userrec *d = this->SanityChecks(user,dest,chan,status);
289 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEVOICE));
291 if (MOD_RESULT == ACR_DENY)
293 if (MOD_RESULT == ACR_DEFAULT)
295 if ((status < STATUS_HOP) && (!is_uline(user->server)))
297 WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, chan->name);
303 return this->Revoke(d,chan,UCMODE_VOICE);
308 char* ModeParser::AddBan(userrec *user,char *dest,chanrec *chan,int status)
311 int toomanyexclamation = 0;
314 if ((!user) || (!dest) || (!chan) || (!*dest))
316 log(DEFAULT,"*** BUG *** AddBan was given an invalid parameter");
320 for (char* i = dest; *i; i++)
322 if ((*i < 32) || (*i > 126))
328 toomanyexclamation++;
336 if (toomanyexclamation != 1 || toomanyat != 1)
338 * this stops sillyness like n!u!u!u@h, though note that most
339 * ircds don't actually verify banmask validity. --w00t
343 long maxbans = GetMaxBans(chan->name);
344 if ((unsigned)chan->bans.size() > (unsigned)maxbans)
346 WriteServ(user->fd,"478 %s %s :Channel ban list for %s is full (maximum entries for this channel is %d)",user->nick, chan->name,chan->name,maxbans);
350 log(DEBUG,"AddBan: %s %s",chan->name,user->nick);
353 FOREACH_RESULT(I_OnAddBan,OnAddBan(user,chan,dest));
358 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
360 if (!strcasecmp(i->data,dest))
362 // dont allow a user to set the same ban twice
368 strlcpy(b.data,dest,MAXBUF);
371 strlcpy(b.set_by,user->nick,NICKMAX-1);
375 strlcpy(b.set_by,Config->ServerName,NICKMAX-1);
377 chan->bans.push_back(b);
381 char* ModeParser::TakeBan(userrec *user,char *dest,chanrec *chan,int status)
383 if ((!user) || (!dest) || (!chan) || (!*dest)) {
384 log(DEFAULT,"*** BUG *** TakeBan was given an invalid parameter");
388 log(DEBUG,"del_ban: %s %s",chan->name,user->nick);
389 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
391 if (!strcasecmp(i->data,dest))
394 FOREACH_RESULT(I_OnDelBan,OnDelBan(user,chan,dest));
405 /** ModeParser::CompressModes()
406 * Tidies up redundant modes,
407 * e.g. +nt-nt+i becomes +-+i
408 * A section further down the chain tidies up the +-+- crap.
410 std::string ModeParser::CompressModes(std::string modes,bool channelmodes)
413 * OK, iterate over the mode string and count how many times a certain mode appears in it.
414 * Then, erase all instances of any character that appears more than once.
415 * This only operates on modes with no parameters, you can still +v-v+v-v+v-v to your heart's content.
418 /* Do we really need an int here? Can you fit enough modes in a line to overflow a short? */
421 memset(counts, 0, sizeof(counts));
422 memset(active, 0, sizeof(active));
424 for(unsigned char* i = (unsigned char*)modes.c_str(); *i; i++)
426 if((*i == '+') || (*i == '-'))
429 if(!channelmodes || (channelmodes && (strchr("itnmsp", *i) || (ModeDefined(*i, MT_CHANNEL) && !ModeDefinedOn(*i,MT_CHANNEL) && !ModeDefinedOff(*i,MT_CHANNEL)))))
431 log(DEBUG,"Tidy mode %c", *i);
437 for(unsigned char j = 65; j < 127; j++)
439 if ((counts[j] > 1) && (active[j] == true))
441 std::string::size_type pos;
443 while((pos = modes.find(j)) != std::string::npos)
445 log(DEBUG, "Deleting occurence of mode %c...", j);
447 log(DEBUG,"New mode line: %s", modes.c_str());
455 void ModeParser::ProcessModes(char **parameters,userrec* user,chanrec *chan,int status, int pcnt, bool servermode, bool silent, bool local)
457 if ((!parameters) || (pcnt < 2)) {
461 char outlist[MAXBUF];
469 bool k_set = false, l_set = false, previously_set_l = false, previously_unset_l = false, previously_set_k = false, previously_unset_k = false;
475 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,NULL,chan,AC_GENERAL_MODE));
476 if (MOD_RESULT == ACR_DENY)
480 std::string tidied = this->CompressModes(parameters[1],true);
481 strlcpy(mlist,tidied.c_str(),MAXBUF);
482 char* modelist = mlist;
484 *outlist = *modelist;
485 char* outl = outlist+1;
487 mdir = (*modelist == '+');
489 log(DEBUG,"process_modes: modelist: %s",modelist);
491 int len = tidied.length();
492 while (modelist[len-1] == ' ')
493 modelist[--len] = '\0';
495 for (char* modechar = (modelist + 1); *modechar; ptr++, modechar++)
499 /* If we have more than MAXMODES changes in one line,
500 * drop all after the MAXMODES
521 if ((param >= pcnt)) break;
522 log(DEBUG,"Enough parameters left");
527 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'o', parameters[param], true, 1));
530 r = GiveOps(user,parameters[param++],chan,status);
537 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'o', parameters[param], false, 1));
540 r = TakeOps(user,parameters[param++],chan,status);
552 if (((param >= pcnt)) || (!Config->AllowHalfop)) break;
557 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'h', parameters[param], true, 1));
560 r = GiveHops(user,parameters[param++],chan,status);
567 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'h', parameters[param], false, 1));
570 r = TakeHops(user,parameters[param++],chan,status);
583 if ((param >= pcnt)) break;
588 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'v', parameters[param], true, 1));
591 r = GiveVoice(user,parameters[param++],chan,status);
598 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'v', parameters[param], false, 1));
601 r = TakeVoice(user,parameters[param++],chan,status);
613 if ((param >= pcnt)) break;
618 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'b', parameters[param], true, 1));
621 r = AddBan(user,parameters[param++],chan,status);
628 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'b', parameters[param], false, 1));
631 r = TakeBan(user,parameters[param++],chan,status);
638 outpars[pc++] = parameters[param-1];
652 if (previously_unset_k)
654 previously_set_k = true;
656 if (!chan->modes[CM_KEY])
659 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'k', parameters[param], true, 1));
664 strlcpy(key,parameters[param++],32);
666 strlcpy(chan->key,key,MAXBUF);
667 chan->modes[CM_KEY] = 1;
675 /* checks on -k are case sensitive and only accurate to the
676 first 32 characters */
677 if (previously_set_k)
679 previously_unset_k = true;
683 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'k', parameters[param], false, 1));
686 strlcpy(key,parameters[param++],32);
687 /* only allow -k if correct key given */
688 if (!strcmp(chan->key,key))
692 chan->modes[CM_KEY] = 0;
703 if (previously_set_l)
705 previously_unset_l = true;
707 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'l', "", false, 0));
710 if (chan->modes[CM_LIMIT])
714 chan->modes[CM_LIMIT] = 0;
719 if ((param >= pcnt)) break;
724 if (previously_unset_l)
726 previously_set_l = true;
727 bool invalid = false;
728 for (char* f = parameters[param]; *f; f++)
730 if ((*f < '0') || (*f > '9'))
735 /* If the limit is < 1, or the new limit is the current limit, dont allow */
736 if ((atoi(parameters[param]) < 1) || ((chan->limit > 0) && (atoi(parameters[param]) == chan->limit)))
745 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'l', parameters[param], true, 1));
749 chan->limit = atoi(parameters[param]);
751 // reported by mech: large values cause underflow
753 chan->limit = 0x7FFF;
759 chan->modes[CM_LIMIT] = 1;
760 outpars[pc++] = parameters[param++];
768 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'i', "", mdir, 0));
773 if (!(chan->modes[CM_INVITEONLY])) *outl++ = 'i';
774 chan->modes[CM_INVITEONLY] = 1;
778 if (chan->modes[CM_INVITEONLY]) *outl++ = 'i';
779 chan->modes[CM_INVITEONLY] = 0;
786 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 't', "", mdir, 0));
791 if (!(chan->modes[CM_TOPICLOCK])) *outl++ = 't';
792 chan->modes[CM_TOPICLOCK] = 1;
796 if (chan->modes[CM_TOPICLOCK]) *outl++ = 't';
797 chan->modes[CM_TOPICLOCK] = 0;
804 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'n', "", mdir, 0));
809 if (!(chan->modes[CM_NOEXTERNAL])) *outl++ = 'n';
810 chan->modes[CM_NOEXTERNAL] = 1;
814 if (chan->modes[CM_NOEXTERNAL]) *outl++ = 'n';
815 chan->modes[CM_NOEXTERNAL] = 0;
822 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'm', "", mdir, 0));
827 if (!(chan->modes[CM_MODERATED])) *outl++ = 'm';
828 chan->modes[CM_MODERATED] = 1;
832 if (chan->modes[CM_MODERATED]) *outl++ = 'm';
833 chan->modes[CM_MODERATED] = 0;
840 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 's', "", mdir, 0));
845 if (!(chan->modes[CM_SECRET])) *outl++ = 's';
846 chan->modes[CM_SECRET] = 1;
847 if (chan->modes[CM_PRIVATE])
849 chan->modes[CM_PRIVATE] = 0;
852 *outl++ = '-'; *outl++ = 'p'; *outl++ = '+';
858 if (chan->modes[CM_SECRET]) *outl++ = 's';
859 chan->modes[CM_SECRET] = 0;
866 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'p', "", mdir, 0));
871 if(!(chan->modes[CM_PRIVATE]))
874 chan->modes[CM_PRIVATE] = 1;
876 if(chan->modes[CM_SECRET])
878 chan->modes[CM_SECRET] = 0;
887 if(chan->modes[CM_PRIVATE])
890 chan->modes[CM_PRIVATE] = 0;
898 bool x = chan->modes[*modechar-65];
899 if ((!x && !mdir) || (x && mdir))
901 if (!ModeIsListMode(*modechar,MT_CHANNEL))
903 log(DEBUG,"Mode %c isnt set on %s but trying to remove!",*modechar,chan->name);
907 if (ModeDefined(*modechar,MT_CHANNEL))
909 /* A module has claimed this mode */
912 if ((ModeDefinedOn(*modechar,MT_CHANNEL)>0) && (mdir))
914 p.push_back(parameters[param]);
916 if ((ModeDefinedOff(*modechar,MT_CHANNEL)>0) && (!mdir))
918 p.push_back(parameters[param]);
921 bool handled = false;
924 // we're supposed to have a parameter, but none was given... so dont handle the mode.
925 if (((ModeDefinedOn(*modechar,MT_CHANNEL)>0) && (mdir)) || ((ModeDefinedOff(*modechar,MT_CHANNEL)>0) && (!mdir)))
927 log(DEBUG,"Not enough parameters for module-mode %c",*modechar);
932 // BIG ASS IDIOTIC CODER WARNING!
933 // Using OnRawMode on another modules mode's behavour
934 // will confuse the crap out of admins! just because you CAN
935 // do it, doesnt mean you SHOULD!
937 std::string para = "";
941 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, *modechar, para, mdir, pcnt));
944 for (int i = 0; i <= MODCOUNT; i++)
948 int t = modules[i]->OnExtendedMode(user,chan,*modechar,MT_CHANNEL,mdir,p);
951 log(DEBUG,"OnExtendedMode returned nonzero for a module");
952 if (ModeIsListMode(*modechar,MT_CHANNEL))
965 outpars[pc++] = parameters[param++];
971 chan->SetCustomMode(*modechar,mdir);
972 // include parameters in output if mode has them
973 if ((ModeDefinedOn(*modechar,MT_CHANNEL)>0) && (mdir))
977 chan->SetCustomModeParam(*modechar,parameters[param],mdir);
978 outpars[pc++] = parameters[param++];
982 // break, because only one module can handle the mode.
991 WriteServ(user->fd,"472 %s %c :is unknown mode char to me",user->nick,*modechar);
997 /* Null terminate it now we're done */
1001 /************ Fast, but confusing string tidying ************/
1003 while (*outl && (*outl < 'A'))
1005 /* outl now points to the first mode character after +'s and -'s */
1007 /* Now points at first mode-modifier + or - symbol */
1009 /* Now we tidy off any trailing -'s etc */
1012 while ((*--trim == '+') || (*trim == '-'))
1014 /************ Done wih the string tidy functions ************/
1017 /* The mode change must be at least two characters long (+ or - and at least one mode) */
1018 if (((*outl == '+') || (*outl == '-')) && *(outl+1))
1020 for (ptr = 0; ptr < pc; ptr++)
1022 charlcat(outl,' ',MAXBUF);
1023 strlcat(outl,outpars[ptr],MAXBUF-1);
1027 log(DEBUG,"Local mode change");
1028 WriteChannelLocal(chan, user, "MODE %s %s",chan->name,outl);
1029 FOREACH_MOD(I_OnMode,OnMode(user, chan, TYPE_CHANNEL, outl));
1037 WriteChannelWithServ(Config->ServerName,chan,"MODE %s %s",chan->name,outl);
1045 WriteChannel(chan,user,"MODE %s %s",chan->name,outl);
1046 FOREACH_MOD(I_OnMode,OnMode(user, chan, TYPE_CHANNEL, outl));
1053 // based on sourcemodes, return true or false to determine if umode is a valid mode a user may set on themselves or others.
1055 bool ModeParser::AllowedUmode(char umode, char* sourcemodes,bool adding,bool serveroverride)
1057 bool sourceoper = (strchr(sourcemodes,'o') != NULL);
1058 log(DEBUG,"Allowed_umode: %c %s",umode,sourcemodes);
1059 // Servers can +o and -o arbitrarily
1060 if ((serveroverride == true) && (umode == 'o'))
1064 // RFC1459 specified modes
1065 if ((umode == 'w') || (umode == 's') || (umode == 'i'))
1067 /* umode allowed by RFC1459 scemantics */
1071 /* user may not +o themselves or others, but an oper may de-oper other opers or themselves */
1072 if (sourceoper && !adding)
1076 else if (umode == 'o')
1078 /* Bad oper, bad bad! */
1082 /* process any module-defined modes that need oper */
1083 if ((ModeDefinedOper(umode,MT_CLIENT)) && (sourceoper))
1085 log(DEBUG,"umode %c allowed by module handler (oper only mode)",umode);
1088 else if (ModeDefined(umode,MT_CLIENT))
1090 // process any module-defined modes that don't need oper
1091 log(DEBUG,"umode %c allowed by module handler (non-oper mode)",umode);
1092 if ((ModeDefinedOper(umode,MT_CLIENT)) && (!sourceoper))
1094 // no, this mode needs oper, and this user 'aint got what it takes!
1100 // anything else - return false.
1101 log(DEBUG,"umode %c not known by any ruleset",umode);
1105 bool ModeParser::ProcessModuleUmode(char umode, userrec* source, void* dest, bool adding)
1112 strlcpy(s2->nick,Config->ServerName,NICKMAX-1);
1121 if (ModeDefined(umode,MT_CLIENT))
1123 for (int i = 0; i <= MODCOUNT; i++)
1125 if (modules[i]->OnExtendedMode(source,(void*)dest,umode,MT_CLIENT,adding,p))
1127 log(DEBUG,"Module %s claims umode %c",Config->module_names[i].c_str(),umode);
1131 log(DEBUG,"No module claims umode %c",umode);
1150 void cmd_mode::Handle (char **parameters, int pcnt, userrec *user)
1153 userrec* dest = Find(parameters[0]);
1157 char outpars[MAXBUF];
1158 bool next_ok = true;
1163 if ((dest) && (pcnt == 1))
1165 WriteServ(user->fd,"221 %s :+%s",dest->nick,dest->modes);
1168 else if ((dest) && (pcnt > 1))
1170 std::string tidied = ServerInstance->ModeGrok->CompressModes(parameters[1],false);
1171 parameters[1] = (char*)tidied.c_str();
1173 char dmodes[MAXBUF];
1174 strlcpy(dmodes,dest->modes,MAXMODES);
1175 log(DEBUG,"pulled up dest user modes: %s",dmodes);
1180 if ((*user->oper) || (is_uline(user->server)))
1191 WriteServ(user->fd,"482 %s :Can't change mode for other users",user->nick);
1195 outpars[0] = *parameters[1];
1197 direction = (*parameters[1] == '+');
1199 if ((*parameters[1] != '+') && (*parameters[1] != '-'))
1202 for (char* i = parameters[1]; *i; i++)
1204 if ((i != parameters[1]) && (*i != '+') && (*i != '-'))
1213 if ((direction != 1) && (next_ok))
1215 charlcat(outpars,'+',MAXBUF);
1222 if ((direction != 0) && (next_ok))
1224 charlcat(outpars,'-',MAXBUF);
1238 if ((*i == 'i') || (*i == 'w') || (*i == 's') || (ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,direction,false)))
1247 if ((!strchr(dmodes,*i)) && (ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,true,false)))
1249 if ((ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)) || (*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o'))
1251 charlcat(dmodes,*i,53);
1252 charlcat(outpars,*i,MAXMODES);
1256 FOREACH_MOD(I_OnGlobalOper,OnGlobalOper(dest));
1259 dest->modebits |= UM_INVISIBLE;
1262 dest->modebits |= UM_SERVERNOTICE;
1265 dest->modebits |= UM_WALLOPS;
1275 if ((ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,false,false)) && (strchr(dmodes,*i)))
1277 if ((ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)) || (*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o'))
1279 charlcat(outpars,*i,MAXMODES);
1280 charremove(dmodes,*i);
1288 dest->modebits &= ~UM_INVISIBLE;
1291 dest->modebits &= ~UM_SERVERNOTICE;
1294 dest->modebits &= ~UM_WALLOPS;
1311 for (char* i = outpars; *i;)
1314 if (((*i == '-') || (*i == '+')) && ((*(i+1) == '-') || (*(i+1) == '+')))
1316 // someones playing silly buggers and trying
1317 // to put a +- or -+ into the line...
1322 // Someone's trying to make the last character in
1323 // the line be a + or - symbol.
1324 if ((*i == '-') || (*i == '+'))
1332 if ((*b) && (!IS_SINGLE(b,'+')) && (!IS_SINGLE(b,'-')))
1334 WriteTo(user, dest, "MODE %s :%s", dest->nick, b);
1335 FOREACH_MOD(I_OnMode,OnMode(user, dest, TYPE_USER, b));
1338 log(DEBUG,"Stripped mode line");
1339 log(DEBUG,"Line dest is now %s",dmodes);
1340 strlcpy(dest->modes,dmodes,MAXMODES-1);
1348 chan = FindChan(parameters[0]);
1353 /* just /modes #channel */
1354 WriteServ(user->fd,"324 %s %s +%s",user->nick, chan->name, chanmodes(chan, chan->HasUser(user)));
1355 WriteServ(user->fd,"329 %s %s %d", user->nick, chan->name, chan->created);
1360 char* mode = parameters[1];
1367 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, *mode, "", false, 0));
1372 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
1374 WriteServ(user->fd,"367 %s %s %s %s %d",user->nick, chan->name, i->data, i->set_by, i->set_time);
1376 WriteServ(user->fd,"368 %s %s :End of channel ban list",user->nick, chan->name);
1380 if ((ModeDefined(*mode,MT_CHANNEL)) && (ModeIsListMode(*mode,MT_CHANNEL)))
1382 // list of items for an extmode
1383 log(DEBUG,"Calling OnSendList for all modules, list output for mode %c",*mode);
1384 FOREACH_MOD(I_OnSendList,OnSendList(user,chan,*mode));
1390 if ((IS_LOCAL(user)) && (!is_uline(user->server)) && (!chan->HasUser(user)))
1392 WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, chan->name);
1397 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user, NULL, chan, AC_GENERAL_MODE));
1399 if(MOD_RESULT == ACR_DENY)
1402 if(MOD_RESULT == ACR_DEFAULT)
1404 if ((IS_LOCAL(user)) && (cstatus(user,chan) < STATUS_HOP))
1406 WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, chan->name);
1411 ServerInstance->ModeGrok->ProcessModes(parameters,user,chan,cstatus(user,chan),pcnt,false,false,false);
1415 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
1423 void ModeParser::ServerMode(char **parameters, int pcnt, userrec *user)
1426 userrec* dest = Find(parameters[0]);
1429 char outpars[MAXBUF];
1430 bool next_ok = true;
1432 if ((dest) && (pcnt > 1))
1434 std::string tidied = ServerInstance->ModeGrok->CompressModes(parameters[1],false);
1435 parameters[1] = (char*)tidied.c_str();
1437 char dmodes[MAXBUF];
1438 strlcpy(dmodes,dest->modes,MAXBUF);
1440 outpars[0] = *parameters[1];
1442 direction = (*parameters[1] == '+');
1444 if ((*parameters[1] != '+') && (*parameters[1] != '-'))
1447 for (char* i = parameters[1]; *i; i++)
1449 if ((i != parameters[1]) && (*i != '+') && (*i != '-'))
1458 if ((direction != 1) && (next_ok))
1461 charlcat(outpars,'+',MAXBUF);
1467 if ((direction != 0) && (next_ok))
1470 charlcat(outpars,'-',MAXBUF);
1476 log(DEBUG,"begin mode processing entry");
1482 log(DEBUG,"umode %c being added",*i);
1483 if ((!strchr(dmodes,*i)) && (ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,true,true)))
1485 log(DEBUG,"umode %c is an allowed umode",*i);
1486 if ((*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o') || (ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)))
1488 charlcat(dmodes,*i,MAXBUF);
1489 charlcat(outpars,*i,53);
1493 dest->modebits |= UM_INVISIBLE;
1496 dest->modebits |= UM_SERVERNOTICE;
1499 dest->modebits |= UM_WALLOPS;
1509 // can only remove a mode they already have
1510 log(DEBUG,"umode %c being removed",*i);
1511 if ((ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,false,true)) && (strchr(dmodes,*i)))
1513 log(DEBUG,"umode %c is an allowed umode",*i);
1514 if ((*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o') || (ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)))
1516 charlcat(outpars,*i,MAXBUF);
1517 charremove(dmodes,*i);
1521 dest->modebits &= ~UM_INVISIBLE;
1524 dest->modebits &= ~UM_SERVERNOTICE;
1527 dest->modebits &= ~UM_WALLOPS;
1544 for (char* i = outpars; *i;)
1547 if (((*i == '-') || (*i == '+')) && ((*(i+1) == '-') || (*(i+1) == '+')))
1549 // someones playing silly buggers and trying
1550 // to put a +- or -+ into the line...
1555 // Someone's trying to make the last character in
1556 // the line be a + or - symbol.
1557 if ((*i == '-') || (*i == '+'))
1565 if ((*b) && (!IS_SINGLE(b,'+')) && (!IS_SINGLE(b,'-')))
1567 WriteTo(user, dest, "MODE %s :%s", dest->nick, b);
1568 FOREACH_MOD(I_OnMode,OnMode(user, dest, TYPE_USER, b));
1571 log(DEBUG,"Stripped mode line");
1572 log(DEBUG,"Line dest is now %s",dmodes);
1573 strlcpy(dest->modes,dmodes,MAXMODES-1);
1580 Ptr = FindChan(parameters[0]);
1583 ServerInstance->ModeGrok->ProcessModes(parameters,user,Ptr,STATUS_OP,pcnt,true,false,false);
1587 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);