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)
75 for (unsigned int i = 0; i < d->chans.size(); i++)
77 if ((d->chans[i].channel != NULL) && (chan != NULL))
78 if (d->chans[i].channel == chan)
80 if (d->chans[i].uc_modes & MASK)
84 d->chans[i].uc_modes = d->chans[i].uc_modes | MASK;
88 d->chans[i].channel->AddOppedUser((char*)d);
91 d->chans[i].channel->AddHalfoppedUser((char*)d);
94 d->chans[i].channel->AddVoicedUser((char*)d);
97 log(DEBUG,"grant: %s %s",d->chans[i].channel->name,d->nick);
104 char* ModeParser::Revoke(userrec *d,chanrec *chan,int MASK)
106 for (unsigned int i = 0; i < d->chans.size(); i++)
108 if ((d->chans[i].channel != NULL) && (chan != NULL))
109 if (d->chans[i].channel == chan)
111 if ((d->chans[i].uc_modes & MASK) == 0)
115 d->chans[i].uc_modes ^= MASK;
119 d->chans[i].channel->DelOppedUser((char*)d);
122 d->chans[i].channel->DelHalfoppedUser((char*)d);
125 d->chans[i].channel->DelVoicedUser((char*)d);
128 log(DEBUG,"revoke: %s %s",d->chans[i].channel->name,d->nick);
135 char* ModeParser::GiveOps(userrec *user,char *dest,chanrec *chan,int status)
137 userrec *d = this->SanityChecks(user,dest,chan,status);
144 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_OP));
146 if (MOD_RESULT == ACR_DENY)
148 if (MOD_RESULT == ACR_DEFAULT)
150 if ((status < STATUS_OP) && (!is_uline(user->server)))
152 WriteServ(user->fd,"482 %s %s :You're not a channel operator",user->nick, chan->name);
158 return this->Grant(d,chan,UCMODE_OP);
163 char* ModeParser::GiveHops(userrec *user,char *dest,chanrec *chan,int status)
165 userrec *d = this->SanityChecks(user,dest,chan,status);
172 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_HALFOP));
174 if (MOD_RESULT == ACR_DENY)
176 if (MOD_RESULT == ACR_DEFAULT)
178 if ((status < STATUS_OP) && (!is_uline(user->server)))
180 WriteServ(user->fd,"482 %s %s :You're not a channel operator",user->nick, chan->name);
186 return this->Grant(d,chan,UCMODE_HOP);
191 char* ModeParser::GiveVoice(userrec *user,char *dest,chanrec *chan,int status)
193 userrec *d = this->SanityChecks(user,dest,chan,status);
200 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_VOICE));
202 if (MOD_RESULT == ACR_DENY)
204 if (MOD_RESULT == ACR_DEFAULT)
206 if ((status < STATUS_HOP) && (!is_uline(user->server)))
208 WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, chan->name);
214 return this->Grant(d,chan,UCMODE_VOICE);
219 char* ModeParser::TakeOps(userrec *user,char *dest,chanrec *chan,int status)
221 userrec *d = this->SanityChecks(user,dest,chan,status);
228 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEOP));
230 if (MOD_RESULT == ACR_DENY)
232 if (MOD_RESULT == ACR_DEFAULT)
234 if ((status < STATUS_OP) && (!is_uline(user->server)) && (IS_LOCAL(user)))
236 WriteServ(user->fd,"482 %s %s :You are not a channel operator",user->nick, chan->name);
242 return this->Revoke(d,chan,UCMODE_OP);
247 char* ModeParser::TakeHops(userrec *user,char *dest,chanrec *chan,int status)
249 userrec *d = this->SanityChecks(user,dest,chan,status);
256 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEHALFOP));
258 if (MOD_RESULT == ACR_DENY)
260 if (MOD_RESULT == ACR_DEFAULT)
262 /* Tweak by Brain suggested by w00t, allow a halfop to dehalfop themselves */
263 if ((user != d) && ((status < STATUS_OP) && (!is_uline(user->server))))
265 WriteServ(user->fd,"482 %s %s :You are not a channel operator",user->nick, chan->name);
271 return this->Revoke(d,chan,UCMODE_HOP);
276 char* ModeParser::TakeVoice(userrec *user,char *dest,chanrec *chan,int status)
278 userrec *d = this->SanityChecks(user,dest,chan,status);
285 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEVOICE));
287 if (MOD_RESULT == ACR_DENY)
289 if (MOD_RESULT == ACR_DEFAULT)
291 if ((status < STATUS_HOP) && (!is_uline(user->server)))
293 WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, chan->name);
299 return this->Revoke(d,chan,UCMODE_VOICE);
304 char* ModeParser::AddBan(userrec *user,char *dest,chanrec *chan,int status)
307 int toomanyexclamation = 0;
310 if ((!user) || (!dest) || (!chan) || (!*dest))
312 log(DEFAULT,"*** BUG *** AddBan was given an invalid parameter");
316 for (char* i = dest; *i; i++)
318 if ((*i < 32) || (*i > 126))
324 toomanyexclamation++;
332 if (toomanyexclamation != 1 || toomanyat != 1)
334 * this stops sillyness like n!u!u!u@h, though note that most
335 * ircds don't actually verify banmask validity. --w00t
339 long maxbans = GetMaxBans(chan->name);
340 if ((unsigned)chan->bans.size() > (unsigned)maxbans)
342 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);
346 log(DEBUG,"AddBan: %s %s",chan->name,user->nick);
349 FOREACH_RESULT(I_OnAddBan,OnAddBan(user,chan,dest));
354 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
356 if (!strcasecmp(i->data,dest))
358 // dont allow a user to set the same ban twice
364 strlcpy(b.data,dest,MAXBUF);
367 strlcpy(b.set_by,user->nick,NICKMAX-1);
371 strlcpy(b.set_by,Config->ServerName,NICKMAX-1);
373 chan->bans.push_back(b);
377 char* ModeParser::TakeBan(userrec *user,char *dest,chanrec *chan,int status)
379 if ((!user) || (!dest) || (!chan) || (!*dest)) {
380 log(DEFAULT,"*** BUG *** TakeBan was given an invalid parameter");
384 log(DEBUG,"del_ban: %s %s",chan->name,user->nick);
385 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
387 if (!strcasecmp(i->data,dest))
390 FOREACH_RESULT(I_OnDelBan,OnDelBan(user,chan,dest));
400 // tidies up redundant modes, e.g. +nt-nt+i becomes +-+i,
401 // a section further down the chain tidies up the +-+- crap.
402 std::string ModeParser::CompressModes(std::string modes,bool channelmodes)
406 memset(counts,0,sizeof(counts));
407 memset(active,0,sizeof(active));
409 for (unsigned int i = 0; i < modes.length(); i++)
411 if ((modes[i] == '+') || (modes[i] == '-'))
415 if ((strchr("itnmsp",modes[i])) || ((ModeDefined(modes[i],MT_CHANNEL)) && (ModeDefinedOn(modes[i],MT_CHANNEL)==0) && (ModeDefinedOff(modes[i],MT_CHANNEL)==0)))
417 log(DEBUG,"Tidy mode %c",modes[i]);
418 counts[(unsigned int)modes[i]]++;
419 active[(unsigned int)modes[i]] = true;
424 log(DEBUG,"Tidy mode %c",modes[i]);
425 counts[(unsigned int)modes[i]]++;
426 active[(unsigned int)modes[i]] = true;
429 for (int j = 65; j < 127; j++)
431 if ((counts[j] > 1) && (active[j] == true))
433 std::string::size_type pos;
435 while((pos = modes.find((unsigned char)j)) != std::string::npos)
437 log(DEBUG, "Deleting occurence of mode %c...", (unsigned char)j);
439 log(DEBUG,"New mode line: %s", modes.c_str());
447 void ModeParser::ProcessModes(char **parameters,userrec* user,chanrec *chan,int status, int pcnt, bool servermode, bool silent, bool local)
449 if ((!parameters) || (pcnt < 2)) {
453 char outlist[MAXBUF];
461 bool k_set = false, l_set = false, previously_set_l = false, previously_unset_l = false, previously_set_k = false, previously_unset_k = false;
467 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,NULL,chan,AC_GENERAL_MODE));
468 if (MOD_RESULT == ACR_DENY)
472 std::string tidied = this->CompressModes(parameters[1],true);
473 strlcpy(mlist,tidied.c_str(),MAXBUF);
474 char* modelist = mlist;
476 *outlist = *modelist;
477 char* outl = outlist+1;
479 mdir = (*modelist == '+');
481 log(DEBUG,"process_modes: modelist: %s",modelist);
483 int len = tidied.length();
484 while (modelist[len-1] == ' ')
485 modelist[--len] = '\0';
487 for (char* modechar = (modelist + 1); *modechar; ptr++, modechar++)
491 /* If we have more than MAXMODES changes in one line,
492 * drop all after the MAXMODES
513 if ((param >= pcnt)) break;
514 log(DEBUG,"Enough parameters left");
519 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'o', parameters[param], true, 1));
522 r = GiveOps(user,parameters[param++],chan,status);
529 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'o', parameters[param], false, 1));
532 r = TakeOps(user,parameters[param++],chan,status);
544 if (((param >= pcnt)) || (!Config->AllowHalfop)) break;
549 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'h', parameters[param], true, 1));
552 r = GiveHops(user,parameters[param++],chan,status);
559 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'h', parameters[param], false, 1));
562 r = TakeHops(user,parameters[param++],chan,status);
575 if ((param >= pcnt)) break;
580 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'v', parameters[param], true, 1));
583 r = GiveVoice(user,parameters[param++],chan,status);
590 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'v', parameters[param], false, 1));
593 r = TakeVoice(user,parameters[param++],chan,status);
605 if ((param >= pcnt)) break;
610 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'b', parameters[param], true, 1));
613 r = AddBan(user,parameters[param++],chan,status);
620 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'b', parameters[param], false, 1));
623 r = TakeBan(user,parameters[param++],chan,status);
630 outpars[pc++] = parameters[param-1];
644 if (previously_unset_k)
646 previously_set_k = true;
651 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'k', parameters[param], true, 1));
656 strlcpy(key,parameters[param++],32);
658 strlcpy(chan->key,key,MAXBUF);
666 /* checks on -k are case sensitive and only accurate to the
667 first 32 characters */
668 if (previously_set_k)
670 previously_unset_k = true;
674 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'k', parameters[param], false, 1));
677 strlcpy(key,parameters[param++],32);
678 /* only allow -k if correct key given */
679 if (!strcmp(chan->key,key))
693 if (previously_set_l)
695 previously_unset_l = true;
697 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'l', "", false, 0));
708 if ((param >= pcnt)) break;
713 if (previously_unset_l)
715 previously_set_l = true;
716 bool invalid = false;
717 for (char* f = parameters[param]; *f; f++)
719 if ((*f < '0') || (*f > '9'))
724 /* If the limit is < 1, or the new limit is the current limit, dont allow */
725 if ((atoi(parameters[param]) < 1) || ((chan->limit > 0) && (atoi(parameters[param]) == chan->limit)))
734 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'l', parameters[param], true, 1));
738 chan->limit = atoi(parameters[param]);
740 // reported by mech: large values cause underflow
742 chan->limit = 0x7FFF;
748 outpars[pc++] = parameters[param++];
756 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'i', "", mdir, 0));
761 if (!(chan->binarymodes & CM_INVITEONLY)) *outl++ = 'i';
762 chan->binarymodes |= CM_INVITEONLY;
766 if (chan->binarymodes & CM_INVITEONLY) *outl++ = 'i';
767 chan->binarymodes &= ~CM_INVITEONLY;
774 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 't', "", mdir, 0));
779 if (!(chan->binarymodes & CM_TOPICLOCK)) *outl++ = 't';
780 chan->binarymodes |= CM_TOPICLOCK;
784 if (chan->binarymodes & CM_TOPICLOCK) *outl++ = 't';
785 chan->binarymodes &= ~CM_TOPICLOCK;
792 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'n', "", mdir, 0));
797 if (!(chan->binarymodes & CM_NOEXTERNAL)) *outl++ = 'n';
798 chan->binarymodes |= CM_NOEXTERNAL;
802 if (chan->binarymodes & CM_NOEXTERNAL) *outl++ = 'n';
803 chan->binarymodes &= ~CM_NOEXTERNAL;
810 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'm', "", mdir, 0));
815 if (!(chan->binarymodes & CM_MODERATED)) *outl++ = 'm';
816 chan->binarymodes |= CM_MODERATED;
820 if (chan->binarymodes & CM_MODERATED) *outl++ = 'm';
821 chan->binarymodes &= ~CM_MODERATED;
828 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 's', "", mdir, 0));
833 if (!(chan->binarymodes & CM_SECRET)) *outl++ = 's';
834 chan->binarymodes |= CM_SECRET;
835 if (chan->binarymodes & CM_PRIVATE)
837 chan->binarymodes &= ~CM_PRIVATE;
840 *outl++ = '-'; *outl++ = 'p'; *outl++ = '+';
846 if (chan->binarymodes & CM_SECRET) *outl++ = 's';
847 chan->binarymodes &= ~CM_SECRET;
854 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'p', "", mdir, 0));
859 if (!(chan->binarymodes & CM_PRIVATE)) *outl++ = 'p';
860 chan->binarymodes |= CM_PRIVATE;
861 if (chan->binarymodes & CM_SECRET)
863 chan->binarymodes &= ~CM_SECRET;
866 *outl++ = '-'; *outl++ = 's'; *outl++ = '+';
872 if (chan->binarymodes & CM_PRIVATE) *outl++ = 'p';
873 chan->binarymodes &= ~CM_PRIVATE;
881 bool x = chan->custom_modes[*modechar-65];
882 if ((!x && !mdir) || (x && mdir))
884 if (!ModeIsListMode(*modechar,MT_CHANNEL))
886 log(DEBUG,"Mode %c isnt set on %s but trying to remove!",*modechar,chan->name);
890 if (ModeDefined(*modechar,MT_CHANNEL))
892 /* A module has claimed this mode */
895 if ((ModeDefinedOn(*modechar,MT_CHANNEL)>0) && (mdir))
897 p.push_back(parameters[param]);
899 if ((ModeDefinedOff(*modechar,MT_CHANNEL)>0) && (!mdir))
901 p.push_back(parameters[param]);
904 bool handled = false;
907 // we're supposed to have a parameter, but none was given... so dont handle the mode.
908 if (((ModeDefinedOn(*modechar,MT_CHANNEL)>0) && (mdir)) || ((ModeDefinedOff(*modechar,MT_CHANNEL)>0) && (!mdir)))
910 log(DEBUG,"Not enough parameters for module-mode %c",*modechar);
915 // BIG ASS IDIOTIC CODER WARNING!
916 // Using OnRawMode on another modules mode's behavour
917 // will confuse the crap out of admins! just because you CAN
918 // do it, doesnt mean you SHOULD!
920 std::string para = "";
923 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, *modechar, para, mdir, pcnt));
926 for (int i = 0; i <= MODCOUNT; i++)
930 int t = modules[i]->OnExtendedMode(user,chan,*modechar,MT_CHANNEL,mdir,p);
933 log(DEBUG,"OnExtendedMode returned nonzero for a module");
934 if (ModeIsListMode(*modechar,MT_CHANNEL))
947 outpars[pc++] = parameters[param++];
953 chan->SetCustomMode(*modechar,mdir);
954 // include parameters in output if mode has them
955 if ((ModeDefinedOn(*modechar,MT_CHANNEL)>0) && (mdir))
959 chan->SetCustomModeParam(*modechar,parameters[param],mdir);
960 outpars[pc++] = parameters[param++];
964 // break, because only one module can handle the mode.
973 WriteServ(user->fd,"472 %s %c :is unknown mode char to me",user->nick,*modechar);
979 /* Null terminate it now we're done */
983 /************ Fast, but confusing string tidying ************/
985 while (*outl && (*outl < 'A'))
987 /* outl now points to the first mode character after +'s and -'s */
989 /* Now points at first mode-modifier + or - symbol */
991 /* Now we tidy off any trailing -'s etc */
994 while ((*--trim == '+') || (*trim == '-'))
996 /************ Done wih the string tidy functions ************/
999 /* The mode change must be at least two characters long (+ or - and at least one mode) */
1000 if (((*outl == '+') || (*outl == '-')) && *(outl+1))
1002 for (ptr = 0; ptr < pc; ptr++)
1004 charlcat(outl,' ',MAXBUF);
1005 strlcat(outl,outpars[ptr],MAXBUF-1);
1009 log(DEBUG,"Local mode change");
1010 WriteChannelLocal(chan, user, "MODE %s %s",chan->name,outl);
1011 FOREACH_MOD(I_OnMode,OnMode(user, chan, TYPE_CHANNEL, outl));
1019 WriteChannelWithServ(Config->ServerName,chan,"MODE %s %s",chan->name,outl);
1027 WriteChannel(chan,user,"MODE %s %s",chan->name,outl);
1028 FOREACH_MOD(I_OnMode,OnMode(user, chan, TYPE_CHANNEL, outl));
1035 // based on sourcemodes, return true or false to determine if umode is a valid mode a user may set on themselves or others.
1037 bool ModeParser::AllowedUmode(char umode, char* sourcemodes,bool adding,bool serveroverride)
1039 bool sourceoper = (strchr(sourcemodes,'o') != NULL);
1040 log(DEBUG,"Allowed_umode: %c %s",umode,sourcemodes);
1041 // Servers can +o and -o arbitrarily
1042 if ((serveroverride == true) && (umode == 'o'))
1046 // RFC1459 specified modes
1047 if ((umode == 'w') || (umode == 's') || (umode == 'i'))
1049 /* umode allowed by RFC1459 scemantics */
1053 /* user may not +o themselves or others, but an oper may de-oper other opers or themselves */
1054 if (sourceoper && !adding)
1058 else if (umode == 'o')
1060 /* Bad oper, bad bad! */
1064 /* process any module-defined modes that need oper */
1065 if ((ModeDefinedOper(umode,MT_CLIENT)) && (sourceoper))
1067 log(DEBUG,"umode %c allowed by module handler (oper only mode)",umode);
1070 else if (ModeDefined(umode,MT_CLIENT))
1072 // process any module-defined modes that don't need oper
1073 log(DEBUG,"umode %c allowed by module handler (non-oper mode)",umode);
1074 if ((ModeDefinedOper(umode,MT_CLIENT)) && (!sourceoper))
1076 // no, this mode needs oper, and this user 'aint got what it takes!
1082 // anything else - return false.
1083 log(DEBUG,"umode %c not known by any ruleset",umode);
1087 bool ModeParser::ProcessModuleUmode(char umode, userrec* source, void* dest, bool adding)
1094 strlcpy(s2->nick,Config->ServerName,NICKMAX-1);
1103 if (ModeDefined(umode,MT_CLIENT))
1105 for (int i = 0; i <= MODCOUNT; i++)
1107 if (modules[i]->OnExtendedMode(source,(void*)dest,umode,MT_CLIENT,adding,p))
1109 log(DEBUG,"Module %s claims umode %c",Config->module_names[i].c_str(),umode);
1113 log(DEBUG,"No module claims umode %c",umode);
1132 void cmd_mode::Handle (char **parameters, int pcnt, userrec *user)
1135 userrec* dest = Find(parameters[0]);
1138 char outpars[MAXBUF];
1139 bool next_ok = true;
1144 if ((dest) && (pcnt == 1))
1146 WriteServ(user->fd,"221 %s :+%s",dest->nick,dest->modes);
1149 else if ((dest) && (pcnt > 1))
1151 std::string tidied = ServerInstance->ModeGrok->CompressModes(parameters[1],false);
1152 parameters[1] = (char*)tidied.c_str();
1154 char dmodes[MAXBUF];
1155 strlcpy(dmodes,dest->modes,MAXMODES);
1156 log(DEBUG,"pulled up dest user modes: %s",dmodes);
1161 if ((*user->oper) || (is_uline(user->server)))
1172 WriteServ(user->fd,"482 %s :Can't change mode for other users",user->nick);
1176 outpars[0] = *parameters[1];
1178 direction = (*parameters[1] == '+');
1180 if ((*parameters[1] != '+') && (*parameters[1] != '-'))
1183 for (char* i = parameters[1]; *i; i++)
1185 if ((i != parameters[1]) && (*i != '+') && (*i != '-'))
1194 if ((direction != 1) && (next_ok))
1196 charlcat(outpars,'+',MAXBUF);
1203 if ((direction != 0) && (next_ok))
1205 charlcat(outpars,'-',MAXBUF);
1219 if ((*i == 'i') || (*i == 'w') || (*i == 's') || (ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,direction,false)))
1228 if ((!strchr(dmodes,*i)) && (ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,true,false)))
1230 if ((ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)) || (*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o'))
1232 charlcat(dmodes,*i,53);
1233 charlcat(outpars,*i,MAXMODES);
1236 FOREACH_MOD(I_OnGlobalOper,OnGlobalOper(dest));
1243 if ((ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,false,false)) && (strchr(dmodes,*i)))
1245 if ((ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)) || (*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o'))
1247 charlcat(outpars,*i,MAXMODES);
1248 charremove(dmodes,*i);
1266 for (char* i = outpars; *i;)
1269 if (((*i == '-') || (*i == '+')) && ((*(i+1) == '-') || (*(i+1) == '+')))
1271 // someones playing silly buggers and trying
1272 // to put a +- or -+ into the line...
1277 // Someone's trying to make the last character in
1278 // the line be a + or - symbol.
1279 if ((*i == '-') || (*i == '+'))
1287 if ((*b) && (!IS_SINGLE(b,'+')) && (!IS_SINGLE(b,'-')))
1289 WriteTo(user, dest, "MODE %s :%s", dest->nick, b);
1290 FOREACH_MOD(I_OnMode,OnMode(user, dest, TYPE_USER, b));
1293 log(DEBUG,"Stripped mode line");
1294 log(DEBUG,"Line dest is now %s",dmodes);
1295 strlcpy(dest->modes,dmodes,MAXMODES-1);
1303 Ptr = FindChan(parameters[0]);
1308 /* just /modes #channel */
1309 WriteServ(user->fd,"324 %s %s +%s",user->nick, Ptr->name, chanmodes(Ptr,has_channel(user,Ptr)));
1310 WriteServ(user->fd,"329 %s %s %d", user->nick, Ptr->name, Ptr->created);
1315 char* mode = parameters[1];
1319 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, Ptr, *mode, "", false, 0));
1324 for (BanList::iterator i = Ptr->bans.begin(); i != Ptr->bans.end(); i++)
1326 WriteServ(user->fd,"367 %s %s %s %s %d",user->nick, Ptr->name, i->data, i->set_by, i->set_time);
1328 WriteServ(user->fd,"368 %s %s :End of channel ban list",user->nick, Ptr->name);
1331 if ((ModeDefined(*mode,MT_CHANNEL)) && (ModeIsListMode(*mode,MT_CHANNEL)))
1333 // list of items for an extmode
1334 log(DEBUG,"Calling OnSendList for all modules, list output for mode %c",*mode);
1335 FOREACH_MOD(I_OnSendList,OnSendList(user,Ptr,*mode));
1341 if (((Ptr) && (!has_channel(user,Ptr))) && (!is_uline(user->server)) && (IS_LOCAL(user)))
1343 WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, Ptr->name);
1350 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,NULL,Ptr,AC_GENERAL_MODE));
1352 if (MOD_RESULT == ACR_DENY)
1354 if (MOD_RESULT == ACR_DEFAULT)
1356 if ((cstatus(user,Ptr) < STATUS_HOP) && (IS_LOCAL(user)))
1358 WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, Ptr->name);
1363 ServerInstance->ModeGrok->ProcessModes(parameters,user,Ptr,cstatus(user,Ptr),pcnt,false,false,false);
1368 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
1376 void ModeParser::ServerMode(char **parameters, int pcnt, userrec *user)
1379 userrec* dest = Find(parameters[0]);
1382 char outpars[MAXBUF];
1383 bool next_ok = true;
1385 if ((dest) && (pcnt > 1))
1387 std::string tidied = ServerInstance->ModeGrok->CompressModes(parameters[1],false);
1388 parameters[1] = (char*)tidied.c_str();
1390 char dmodes[MAXBUF];
1391 strlcpy(dmodes,dest->modes,MAXBUF);
1393 outpars[0] = *parameters[1];
1395 direction = (*parameters[1] == '+');
1397 if ((*parameters[1] != '+') && (*parameters[1] != '-'))
1400 for (char* i = parameters[1]; *i; i++)
1402 if ((i != parameters[1]) && (*i != '+') && (*i != '-'))
1411 if ((direction != 1) && (next_ok))
1414 charlcat(outpars,'+',MAXBUF);
1420 if ((direction != 0) && (next_ok))
1423 charlcat(outpars,'-',MAXBUF);
1429 log(DEBUG,"begin mode processing entry");
1435 log(DEBUG,"umode %c being added",*i);
1436 if ((!strchr(dmodes,*i)) && (ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,true,true)))
1438 log(DEBUG,"umode %c is an allowed umode",*i);
1439 if ((*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o') || (ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)))
1441 charlcat(dmodes,*i,MAXBUF);
1442 charlcat(outpars,*i,53);
1448 // can only remove a mode they already have
1449 log(DEBUG,"umode %c being removed",*i);
1450 if ((ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,false,true)) && (strchr(dmodes,*i)))
1452 log(DEBUG,"umode %c is an allowed umode",*i);
1453 if ((*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o') || (ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)))
1455 charlcat(outpars,*i,MAXBUF);
1456 charremove(dmodes,*i);
1469 for (char* i = outpars; *i;)
1472 if (((*i == '-') || (*i == '+')) && ((*(i+1) == '-') || (*(i+1) == '+')))
1474 // someones playing silly buggers and trying
1475 // to put a +- or -+ into the line...
1480 // Someone's trying to make the last character in
1481 // the line be a + or - symbol.
1482 if ((*i == '-') || (*i == '+'))
1490 if ((*b) && (!IS_SINGLE(b,'+')) && (!IS_SINGLE(b,'-')))
1492 WriteTo(user, dest, "MODE %s :%s", dest->nick, b);
1493 FOREACH_MOD(I_OnMode,OnMode(user, dest, TYPE_USER, b));
1496 log(DEBUG,"Stripped mode line");
1497 log(DEBUG,"Line dest is now %s",dmodes);
1498 strlcpy(dest->modes,dmodes,MAXMODES-1);
1505 Ptr = FindChan(parameters[0]);
1508 ServerInstance->ModeGrok->ProcessModes(parameters,user,Ptr,STATUS_OP,pcnt,true,false,false);
1512 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);