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;
430 for(unsigned char j = 65; j < 127; j++)
432 if ((counts[j] > 1) && (active[j] == true))
434 std::string::size_type pos;
436 while((pos = modes.find(j)) != std::string::npos)
438 log(DEBUG, "Deleting occurence of mode %c...", j);
440 log(DEBUG,"New mode line: %s", modes.c_str());
448 void ModeParser::ProcessModes(char **parameters,userrec* user,chanrec *chan,int status, int pcnt, bool servermode, bool silent, bool local)
450 if ((!parameters) || (pcnt < 2)) {
454 char outlist[MAXBUF];
462 bool k_set = false, l_set = false, previously_set_l = false, previously_unset_l = false, previously_set_k = false, previously_unset_k = false;
468 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,NULL,chan,AC_GENERAL_MODE));
469 if (MOD_RESULT == ACR_DENY)
473 std::string tidied = this->CompressModes(parameters[1],true);
474 strlcpy(mlist,tidied.c_str(),MAXBUF);
475 char* modelist = mlist;
477 *outlist = *modelist;
478 char* outl = outlist+1;
480 mdir = (*modelist == '+');
482 log(DEBUG,"process_modes: modelist: %s",modelist);
484 int len = tidied.length();
485 while (modelist[len-1] == ' ')
486 modelist[--len] = '\0';
488 for (char* modechar = (modelist + 1); *modechar; ptr++, modechar++)
492 /* If we have more than MAXMODES changes in one line,
493 * drop all after the MAXMODES
514 if ((param >= pcnt)) break;
515 log(DEBUG,"Enough parameters left");
520 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'o', parameters[param], true, 1));
523 r = GiveOps(user,parameters[param++],chan,status);
530 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'o', parameters[param], false, 1));
533 r = TakeOps(user,parameters[param++],chan,status);
545 if (((param >= pcnt)) || (!Config->AllowHalfop)) break;
550 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'h', parameters[param], true, 1));
553 r = GiveHops(user,parameters[param++],chan,status);
560 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'h', parameters[param], false, 1));
563 r = TakeHops(user,parameters[param++],chan,status);
576 if ((param >= pcnt)) break;
581 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'v', parameters[param], true, 1));
584 r = GiveVoice(user,parameters[param++],chan,status);
591 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'v', parameters[param], false, 1));
594 r = TakeVoice(user,parameters[param++],chan,status);
606 if ((param >= pcnt)) break;
611 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'b', parameters[param], true, 1));
614 r = AddBan(user,parameters[param++],chan,status);
621 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'b', parameters[param], false, 1));
624 r = TakeBan(user,parameters[param++],chan,status);
631 outpars[pc++] = parameters[param-1];
645 if (previously_unset_k)
647 previously_set_k = true;
652 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'k', parameters[param], true, 1));
657 strlcpy(key,parameters[param++],32);
659 strlcpy(chan->key,key,MAXBUF);
667 /* checks on -k are case sensitive and only accurate to the
668 first 32 characters */
669 if (previously_set_k)
671 previously_unset_k = true;
675 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'k', parameters[param], false, 1));
678 strlcpy(key,parameters[param++],32);
679 /* only allow -k if correct key given */
680 if (!strcmp(chan->key,key))
694 if (previously_set_l)
696 previously_unset_l = true;
698 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'l', "", false, 0));
709 if ((param >= pcnt)) break;
714 if (previously_unset_l)
716 previously_set_l = true;
717 bool invalid = false;
718 for (char* f = parameters[param]; *f; f++)
720 if ((*f < '0') || (*f > '9'))
725 /* If the limit is < 1, or the new limit is the current limit, dont allow */
726 if ((atoi(parameters[param]) < 1) || ((chan->limit > 0) && (atoi(parameters[param]) == chan->limit)))
735 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'l', parameters[param], true, 1));
739 chan->limit = atoi(parameters[param]);
741 // reported by mech: large values cause underflow
743 chan->limit = 0x7FFF;
749 outpars[pc++] = parameters[param++];
757 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'i', "", mdir, 0));
762 if (!(chan->binarymodes & CM_INVITEONLY)) *outl++ = 'i';
763 chan->binarymodes |= CM_INVITEONLY;
767 if (chan->binarymodes & CM_INVITEONLY) *outl++ = 'i';
768 chan->binarymodes &= ~CM_INVITEONLY;
775 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 't', "", mdir, 0));
780 if (!(chan->binarymodes & CM_TOPICLOCK)) *outl++ = 't';
781 chan->binarymodes |= CM_TOPICLOCK;
785 if (chan->binarymodes & CM_TOPICLOCK) *outl++ = 't';
786 chan->binarymodes &= ~CM_TOPICLOCK;
793 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'n', "", mdir, 0));
798 if (!(chan->binarymodes & CM_NOEXTERNAL)) *outl++ = 'n';
799 chan->binarymodes |= CM_NOEXTERNAL;
803 if (chan->binarymodes & CM_NOEXTERNAL) *outl++ = 'n';
804 chan->binarymodes &= ~CM_NOEXTERNAL;
811 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'm', "", mdir, 0));
816 if (!(chan->binarymodes & CM_MODERATED)) *outl++ = 'm';
817 chan->binarymodes |= CM_MODERATED;
821 if (chan->binarymodes & CM_MODERATED) *outl++ = 'm';
822 chan->binarymodes &= ~CM_MODERATED;
829 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 's', "", mdir, 0));
834 if (!(chan->binarymodes & CM_SECRET)) *outl++ = 's';
835 chan->binarymodes |= CM_SECRET;
836 if (chan->binarymodes & CM_PRIVATE)
838 chan->binarymodes &= ~CM_PRIVATE;
841 *outl++ = '-'; *outl++ = 'p'; *outl++ = '+';
847 if (chan->binarymodes & CM_SECRET) *outl++ = 's';
848 chan->binarymodes &= ~CM_SECRET;
855 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'p', "", mdir, 0));
860 if (!(chan->binarymodes & CM_PRIVATE)) *outl++ = 'p';
861 chan->binarymodes |= CM_PRIVATE;
862 if (chan->binarymodes & CM_SECRET)
864 chan->binarymodes &= ~CM_SECRET;
867 *outl++ = '-'; *outl++ = 's'; *outl++ = '+';
873 if (chan->binarymodes & CM_PRIVATE) *outl++ = 'p';
874 chan->binarymodes &= ~CM_PRIVATE;
882 bool x = chan->custom_modes[*modechar-65];
883 if ((!x && !mdir) || (x && mdir))
885 if (!ModeIsListMode(*modechar,MT_CHANNEL))
887 log(DEBUG,"Mode %c isnt set on %s but trying to remove!",*modechar,chan->name);
891 if (ModeDefined(*modechar,MT_CHANNEL))
893 /* A module has claimed this mode */
896 if ((ModeDefinedOn(*modechar,MT_CHANNEL)>0) && (mdir))
898 p.push_back(parameters[param]);
900 if ((ModeDefinedOff(*modechar,MT_CHANNEL)>0) && (!mdir))
902 p.push_back(parameters[param]);
905 bool handled = false;
908 // we're supposed to have a parameter, but none was given... so dont handle the mode.
909 if (((ModeDefinedOn(*modechar,MT_CHANNEL)>0) && (mdir)) || ((ModeDefinedOff(*modechar,MT_CHANNEL)>0) && (!mdir)))
911 log(DEBUG,"Not enough parameters for module-mode %c",*modechar);
916 // BIG ASS IDIOTIC CODER WARNING!
917 // Using OnRawMode on another modules mode's behavour
918 // will confuse the crap out of admins! just because you CAN
919 // do it, doesnt mean you SHOULD!
921 std::string para = "";
924 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, *modechar, para, mdir, pcnt));
927 for (int i = 0; i <= MODCOUNT; i++)
931 int t = modules[i]->OnExtendedMode(user,chan,*modechar,MT_CHANNEL,mdir,p);
934 log(DEBUG,"OnExtendedMode returned nonzero for a module");
935 if (ModeIsListMode(*modechar,MT_CHANNEL))
948 outpars[pc++] = parameters[param++];
954 chan->SetCustomMode(*modechar,mdir);
955 // include parameters in output if mode has them
956 if ((ModeDefinedOn(*modechar,MT_CHANNEL)>0) && (mdir))
960 chan->SetCustomModeParam(*modechar,parameters[param],mdir);
961 outpars[pc++] = parameters[param++];
965 // break, because only one module can handle the mode.
974 WriteServ(user->fd,"472 %s %c :is unknown mode char to me",user->nick,*modechar);
980 /* Null terminate it now we're done */
984 /************ Fast, but confusing string tidying ************/
986 while (*outl && (*outl < 'A'))
988 /* outl now points to the first mode character after +'s and -'s */
990 /* Now points at first mode-modifier + or - symbol */
992 /* Now we tidy off any trailing -'s etc */
995 while ((*--trim == '+') || (*trim == '-'))
997 /************ Done wih the string tidy functions ************/
1000 /* The mode change must be at least two characters long (+ or - and at least one mode) */
1001 if (((*outl == '+') || (*outl == '-')) && *(outl+1))
1003 for (ptr = 0; ptr < pc; ptr++)
1005 charlcat(outl,' ',MAXBUF);
1006 strlcat(outl,outpars[ptr],MAXBUF-1);
1010 log(DEBUG,"Local mode change");
1011 WriteChannelLocal(chan, user, "MODE %s %s",chan->name,outl);
1012 FOREACH_MOD(I_OnMode,OnMode(user, chan, TYPE_CHANNEL, outl));
1020 WriteChannelWithServ(Config->ServerName,chan,"MODE %s %s",chan->name,outl);
1028 WriteChannel(chan,user,"MODE %s %s",chan->name,outl);
1029 FOREACH_MOD(I_OnMode,OnMode(user, chan, TYPE_CHANNEL, outl));
1036 // based on sourcemodes, return true or false to determine if umode is a valid mode a user may set on themselves or others.
1038 bool ModeParser::AllowedUmode(char umode, char* sourcemodes,bool adding,bool serveroverride)
1040 bool sourceoper = (strchr(sourcemodes,'o') != NULL);
1041 log(DEBUG,"Allowed_umode: %c %s",umode,sourcemodes);
1042 // Servers can +o and -o arbitrarily
1043 if ((serveroverride == true) && (umode == 'o'))
1047 // RFC1459 specified modes
1048 if ((umode == 'w') || (umode == 's') || (umode == 'i'))
1050 /* umode allowed by RFC1459 scemantics */
1054 /* user may not +o themselves or others, but an oper may de-oper other opers or themselves */
1055 if (sourceoper && !adding)
1059 else if (umode == 'o')
1061 /* Bad oper, bad bad! */
1065 /* process any module-defined modes that need oper */
1066 if ((ModeDefinedOper(umode,MT_CLIENT)) && (sourceoper))
1068 log(DEBUG,"umode %c allowed by module handler (oper only mode)",umode);
1071 else if (ModeDefined(umode,MT_CLIENT))
1073 // process any module-defined modes that don't need oper
1074 log(DEBUG,"umode %c allowed by module handler (non-oper mode)",umode);
1075 if ((ModeDefinedOper(umode,MT_CLIENT)) && (!sourceoper))
1077 // no, this mode needs oper, and this user 'aint got what it takes!
1083 // anything else - return false.
1084 log(DEBUG,"umode %c not known by any ruleset",umode);
1088 bool ModeParser::ProcessModuleUmode(char umode, userrec* source, void* dest, bool adding)
1095 strlcpy(s2->nick,Config->ServerName,NICKMAX-1);
1104 if (ModeDefined(umode,MT_CLIENT))
1106 for (int i = 0; i <= MODCOUNT; i++)
1108 if (modules[i]->OnExtendedMode(source,(void*)dest,umode,MT_CLIENT,adding,p))
1110 log(DEBUG,"Module %s claims umode %c",Config->module_names[i].c_str(),umode);
1114 log(DEBUG,"No module claims umode %c",umode);
1133 void cmd_mode::Handle (char **parameters, int pcnt, userrec *user)
1136 userrec* dest = Find(parameters[0]);
1139 char outpars[MAXBUF];
1140 bool next_ok = true;
1145 if ((dest) && (pcnt == 1))
1147 WriteServ(user->fd,"221 %s :+%s",dest->nick,dest->modes);
1150 else if ((dest) && (pcnt > 1))
1152 std::string tidied = ServerInstance->ModeGrok->CompressModes(parameters[1],false);
1153 parameters[1] = (char*)tidied.c_str();
1155 char dmodes[MAXBUF];
1156 strlcpy(dmodes,dest->modes,MAXMODES);
1157 log(DEBUG,"pulled up dest user modes: %s",dmodes);
1162 if ((*user->oper) || (is_uline(user->server)))
1173 WriteServ(user->fd,"482 %s :Can't change mode for other users",user->nick);
1177 outpars[0] = *parameters[1];
1179 direction = (*parameters[1] == '+');
1181 if ((*parameters[1] != '+') && (*parameters[1] != '-'))
1184 for (char* i = parameters[1]; *i; i++)
1186 if ((i != parameters[1]) && (*i != '+') && (*i != '-'))
1195 if ((direction != 1) && (next_ok))
1197 charlcat(outpars,'+',MAXBUF);
1204 if ((direction != 0) && (next_ok))
1206 charlcat(outpars,'-',MAXBUF);
1220 if ((*i == 'i') || (*i == 'w') || (*i == 's') || (ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,direction,false)))
1229 if ((!strchr(dmodes,*i)) && (ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,true,false)))
1231 if ((ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)) || (*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o'))
1233 charlcat(dmodes,*i,53);
1234 charlcat(outpars,*i,MAXMODES);
1237 FOREACH_MOD(I_OnGlobalOper,OnGlobalOper(dest));
1244 if ((ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,false,false)) && (strchr(dmodes,*i)))
1246 if ((ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)) || (*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o'))
1248 charlcat(outpars,*i,MAXMODES);
1249 charremove(dmodes,*i);
1267 for (char* i = outpars; *i;)
1270 if (((*i == '-') || (*i == '+')) && ((*(i+1) == '-') || (*(i+1) == '+')))
1272 // someones playing silly buggers and trying
1273 // to put a +- or -+ into the line...
1278 // Someone's trying to make the last character in
1279 // the line be a + or - symbol.
1280 if ((*i == '-') || (*i == '+'))
1288 if ((*b) && (!IS_SINGLE(b,'+')) && (!IS_SINGLE(b,'-')))
1290 WriteTo(user, dest, "MODE %s :%s", dest->nick, b);
1291 FOREACH_MOD(I_OnMode,OnMode(user, dest, TYPE_USER, b));
1294 log(DEBUG,"Stripped mode line");
1295 log(DEBUG,"Line dest is now %s",dmodes);
1296 strlcpy(dest->modes,dmodes,MAXMODES-1);
1304 Ptr = FindChan(parameters[0]);
1309 /* just /modes #channel */
1310 WriteServ(user->fd,"324 %s %s +%s",user->nick, Ptr->name, chanmodes(Ptr,has_channel(user,Ptr)));
1311 WriteServ(user->fd,"329 %s %s %d", user->nick, Ptr->name, Ptr->created);
1316 char* mode = parameters[1];
1320 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, Ptr, *mode, "", false, 0));
1325 for (BanList::iterator i = Ptr->bans.begin(); i != Ptr->bans.end(); i++)
1327 WriteServ(user->fd,"367 %s %s %s %s %d",user->nick, Ptr->name, i->data, i->set_by, i->set_time);
1329 WriteServ(user->fd,"368 %s %s :End of channel ban list",user->nick, Ptr->name);
1332 if ((ModeDefined(*mode,MT_CHANNEL)) && (ModeIsListMode(*mode,MT_CHANNEL)))
1334 // list of items for an extmode
1335 log(DEBUG,"Calling OnSendList for all modules, list output for mode %c",*mode);
1336 FOREACH_MOD(I_OnSendList,OnSendList(user,Ptr,*mode));
1342 if (((Ptr) && (!has_channel(user,Ptr))) && (!is_uline(user->server)) && (IS_LOCAL(user)))
1344 WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, Ptr->name);
1351 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,NULL,Ptr,AC_GENERAL_MODE));
1353 if (MOD_RESULT == ACR_DENY)
1355 if (MOD_RESULT == ACR_DEFAULT)
1357 if ((cstatus(user,Ptr) < STATUS_HOP) && (IS_LOCAL(user)))
1359 WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, Ptr->name);
1364 ServerInstance->ModeGrok->ProcessModes(parameters,user,Ptr,cstatus(user,Ptr),pcnt,false,false,false);
1369 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
1377 void ModeParser::ServerMode(char **parameters, int pcnt, userrec *user)
1380 userrec* dest = Find(parameters[0]);
1383 char outpars[MAXBUF];
1384 bool next_ok = true;
1386 if ((dest) && (pcnt > 1))
1388 std::string tidied = ServerInstance->ModeGrok->CompressModes(parameters[1],false);
1389 parameters[1] = (char*)tidied.c_str();
1391 char dmodes[MAXBUF];
1392 strlcpy(dmodes,dest->modes,MAXBUF);
1394 outpars[0] = *parameters[1];
1396 direction = (*parameters[1] == '+');
1398 if ((*parameters[1] != '+') && (*parameters[1] != '-'))
1401 for (char* i = parameters[1]; *i; i++)
1403 if ((i != parameters[1]) && (*i != '+') && (*i != '-'))
1412 if ((direction != 1) && (next_ok))
1415 charlcat(outpars,'+',MAXBUF);
1421 if ((direction != 0) && (next_ok))
1424 charlcat(outpars,'-',MAXBUF);
1430 log(DEBUG,"begin mode processing entry");
1436 log(DEBUG,"umode %c being added",*i);
1437 if ((!strchr(dmodes,*i)) && (ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,true,true)))
1439 log(DEBUG,"umode %c is an allowed umode",*i);
1440 if ((*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o') || (ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)))
1442 charlcat(dmodes,*i,MAXBUF);
1443 charlcat(outpars,*i,53);
1449 // can only remove a mode they already have
1450 log(DEBUG,"umode %c being removed",*i);
1451 if ((ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,false,true)) && (strchr(dmodes,*i)))
1453 log(DEBUG,"umode %c is an allowed umode",*i);
1454 if ((*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o') || (ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)))
1456 charlcat(outpars,*i,MAXBUF);
1457 charremove(dmodes,*i);
1470 for (char* i = outpars; *i;)
1473 if (((*i == '-') || (*i == '+')) && ((*(i+1) == '-') || (*(i+1) == '+')))
1475 // someones playing silly buggers and trying
1476 // to put a +- or -+ into the line...
1481 // Someone's trying to make the last character in
1482 // the line be a + or - symbol.
1483 if ((*i == '-') || (*i == '+'))
1491 if ((*b) && (!IS_SINGLE(b,'+')) && (!IS_SINGLE(b,'-')))
1493 WriteTo(user, dest, "MODE %s :%s", dest->nick, b);
1494 FOREACH_MOD(I_OnMode,OnMode(user, dest, TYPE_USER, b));
1497 log(DEBUG,"Stripped mode line");
1498 log(DEBUG,"Line dest is now %s",dmodes);
1499 strlcpy(dest->modes,dmodes,MAXMODES-1);
1506 Ptr = FindChan(parameters[0]);
1509 ServerInstance->ModeGrok->ProcessModes(parameters,user,Ptr,STATUS_OP,pcnt,true,false,false);
1513 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);