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));
408 for (unsigned int i = 0; i < modes.length(); i++)
410 if ((modes[i] == '+') || (modes[i] == '-'))
414 if ((strchr("itnmsp",modes[i])) || ((ModeDefined(modes[i],MT_CHANNEL)) && (ModeDefinedOn(modes[i],MT_CHANNEL)==0) && (ModeDefinedOff(modes[i],MT_CHANNEL)==0)))
416 log(DEBUG,"Tidy mode %c",modes[i]);
417 counts[(unsigned int)modes[i]]++;
418 active[(unsigned int)modes[i]] = true;
423 log(DEBUG,"Tidy mode %c",modes[i]);
424 counts[(unsigned int)modes[i]]++;
425 active[(unsigned int)modes[i]] = true;
428 for (int j = 65; j < 127; j++)
430 if ((counts[j] > 1) && (active[j] == true))
433 v[0] = (unsigned char)j;
435 std::string mode_str = v;
436 std::string::size_type pos = modes.find(mode_str);
437 if (pos != std::string::npos)
439 log(DEBUG,"all occurances of mode %c to be deleted...",(unsigned char)j);
440 while (modes.find(mode_str) != std::string::npos)
441 modes.erase(modes.find(mode_str),1);
442 log(DEBUG,"New mode line: %s",modes.c_str());
449 void ModeParser::ProcessModes(char **parameters,userrec* user,chanrec *chan,int status, int pcnt, bool servermode, bool silent, bool local)
451 if ((!parameters) || (pcnt < 2)) {
455 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 char* modelist = parameters[1]; /* mode list, e.g. +oo-o *
474 * parameters[2] onwards are parameters for
475 * modes that require them :) */
476 *outlist = *modelist;
477 char* outl = outlist+1;
479 mdir = (*modelist == '+');
481 log(DEBUG,"process_modes: modelist: %s",modelist);
483 std::string tidied = this->CompressModes(modelist,true);
484 strlcpy(modelist,tidied.c_str(),MAXBUF);
486 int len = tidied.length();
487 while (modelist[len-1] == ' ')
488 modelist[--len] = '\0';
490 for (char* modechar = (modelist + 1); *modechar; ptr++, modechar++)
494 /* If we have more than MAXMODES changes in one line,
495 * drop all after the MAXMODES
516 if ((param >= pcnt)) break;
517 log(DEBUG,"Enough parameters left");
522 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'o', parameters[param], true, 1));
525 r = GiveOps(user,parameters[param++],chan,status);
532 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'o', parameters[param], false, 1));
535 r = TakeOps(user,parameters[param++],chan,status);
547 if (((param >= pcnt)) || (!Config->AllowHalfop)) break;
552 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'h', parameters[param], true, 1));
555 r = GiveHops(user,parameters[param++],chan,status);
562 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'h', parameters[param], false, 1));
565 r = TakeHops(user,parameters[param++],chan,status);
578 if ((param >= pcnt)) break;
583 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'v', parameters[param], true, 1));
586 r = GiveVoice(user,parameters[param++],chan,status);
593 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'v', parameters[param], false, 1));
596 r = TakeVoice(user,parameters[param++],chan,status);
608 if ((param >= pcnt)) break;
613 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'b', parameters[param], true, 1));
616 r = AddBan(user,parameters[param++],chan,status);
623 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'b', parameters[param], false, 1));
626 r = TakeBan(user,parameters[param++],chan,status);
633 outpars[pc++] = parameters[param-1];
647 if (previously_unset_k)
649 previously_set_k = true;
654 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'k', parameters[param], true, 1));
659 strlcpy(key,parameters[param++],32);
661 strlcpy(chan->key,key,MAXBUF);
669 /* checks on -k are case sensitive and only accurate to the
670 first 32 characters */
671 if (previously_set_k)
673 previously_unset_k = true;
677 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'k', parameters[param], false, 1));
680 strlcpy(key,parameters[param++],32);
681 /* only allow -k if correct key given */
682 if (!strcmp(chan->key,key))
696 if (previously_set_l)
698 previously_unset_l = true;
700 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'l', "", false, 0));
711 if ((param >= pcnt)) break;
716 if (previously_unset_l)
718 previously_set_l = true;
719 bool invalid = false;
720 for (char* f = parameters[param]; *f; f++)
722 if ((*f < '0') || (*f > '9'))
727 /* If the limit is < 1, or the new limit is the current limit, dont allow */
728 if ((atoi(parameters[param]) < 1) || ((chan->limit > 0) && (atoi(parameters[param]) == chan->limit)))
737 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'l', parameters[param], true, 1));
741 chan->limit = atoi(parameters[param]);
743 // reported by mech: large values cause underflow
745 chan->limit = 0x7FFF;
751 outpars[pc++] = parameters[param++];
759 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'i', "", mdir, 0));
764 if (!(chan->binarymodes & CM_INVITEONLY)) *outl++ = 'i';
765 chan->binarymodes |= CM_INVITEONLY;
769 if (chan->binarymodes & CM_INVITEONLY) *outl++ = 'i';
770 chan->binarymodes &= ~CM_INVITEONLY;
777 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 't', "", mdir, 0));
782 if (!(chan->binarymodes & CM_TOPICLOCK)) *outl++ = 't';
783 chan->binarymodes |= CM_TOPICLOCK;
787 if (chan->binarymodes & CM_TOPICLOCK) *outl++ = 't';
788 chan->binarymodes &= ~CM_TOPICLOCK;
795 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'n', "", mdir, 0));
800 if (!(chan->binarymodes & CM_NOEXTERNAL)) *outl++ = 'n';
801 chan->binarymodes |= CM_NOEXTERNAL;
805 if (chan->binarymodes & CM_NOEXTERNAL) *outl++ = 'n';
806 chan->binarymodes &= ~CM_NOEXTERNAL;
813 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'm', "", mdir, 0));
818 if (!(chan->binarymodes & CM_MODERATED)) *outl++ = 'm';
819 chan->binarymodes |= CM_MODERATED;
823 if (chan->binarymodes & CM_MODERATED) *outl++ = 'm';
824 chan->binarymodes &= ~CM_MODERATED;
831 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 's', "", mdir, 0));
836 if (!(chan->binarymodes & CM_SECRET)) *outl++ = 's';
837 chan->binarymodes |= CM_SECRET;
838 if (chan->binarymodes & CM_PRIVATE)
840 chan->binarymodes &= ~CM_PRIVATE;
843 *outl++ = '-'; *outl++ = 'p'; *outl++ = '+';
849 if (chan->binarymodes & CM_SECRET) *outl++ = 's';
850 chan->binarymodes &= ~CM_SECRET;
857 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'p', "", mdir, 0));
862 if (!(chan->binarymodes & CM_PRIVATE)) *outl++ = 'p';
863 chan->binarymodes |= CM_PRIVATE;
864 if (chan->binarymodes & CM_SECRET)
866 chan->binarymodes &= ~CM_SECRET;
869 *outl++ = '-'; *outl++ = 's'; *outl++ = '+';
875 if (chan->binarymodes & CM_PRIVATE) *outl++ = 'p';
876 chan->binarymodes &= ~CM_PRIVATE;
884 bool x = strchr(chan->custom_modes,*modechar);
885 if ((!x && !mdir) || (x && mdir))
887 if (!ModeIsListMode(*modechar,MT_CHANNEL))
889 log(DEBUG,"Mode %c isnt set on %s but trying to remove!",*modechar,chan->name);
893 if (ModeDefined(*modechar,MT_CHANNEL))
895 /* A module has claimed this mode */
898 if ((ModeDefinedOn(*modechar,MT_CHANNEL)>0) && (mdir))
900 p.push_back(parameters[param]);
902 if ((ModeDefinedOff(*modechar,MT_CHANNEL)>0) && (!mdir))
904 p.push_back(parameters[param]);
907 bool handled = false;
910 // we're supposed to have a parameter, but none was given... so dont handle the mode.
911 if (((ModeDefinedOn(*modechar,MT_CHANNEL)>0) && (mdir)) || ((ModeDefinedOff(*modechar,MT_CHANNEL)>0) && (!mdir)))
913 log(DEBUG,"Not enough parameters for module-mode %c",*modechar);
918 // BIG ASS IDIOTIC CODER WARNING!
919 // Using OnRawMode on another modules mode's behavour
920 // will confuse the crap out of admins! just because you CAN
921 // do it, doesnt mean you SHOULD!
923 std::string para = "";
926 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, *modechar, para, mdir, pcnt));
929 for (int i = 0; i <= MODCOUNT; i++)
933 int t = modules[i]->OnExtendedMode(user,chan,*modechar,MT_CHANNEL,mdir,p);
936 log(DEBUG,"OnExtendedMode returned nonzero for a module");
937 if (ModeIsListMode(*modechar,MT_CHANNEL))
950 outpars[pc++] = parameters[param++];
958 chan->SetCustomMode(*modechar,mdir);
959 // include parameters in output if mode has them
960 if ((ModeDefinedOn(*modechar,MT_CHANNEL)>0) && (mdir))
962 chan->SetCustomModeParam(modelist[ptr],parameters[param],mdir);
963 outpars[pc++] = parameters[param++];
967 // break, because only one module can handle the mode.
976 WriteServ(user->fd,"472 %s %c :is unknown mode char to me",user->nick,*modechar);
982 /* Null terminate it now we're done */
986 /************ Fast, but confusing string tidying ************/
988 while (*outl && (*outl < 'A'))
990 /* outl now points to the first mode character after +'s and -'s */
992 /* Now points at first mode-modifier + or - symbol */
994 /* Now we tidy off any trailing -'s etc */
997 while ((*--trim == '+') || (*trim == '-'))
999 /************ Done wih the string tidy functions ************/
1002 /* The mode change must be at least two characters long (+ or - and at least one mode) */
1003 if (((*outl == '+') || (*outl == '-')) && *(outl+1))
1005 for (ptr = 0; ptr < pc; ptr++)
1007 charlcat(outl,' ',MAXBUF);
1008 strlcat(outl,outpars[ptr],MAXBUF-1);
1012 log(DEBUG,"Local mode change");
1013 WriteChannelLocal(chan, user, "MODE %s %s",chan->name,outl);
1014 FOREACH_MOD(I_OnMode,OnMode(user, chan, TYPE_CHANNEL, outl));
1022 WriteChannelWithServ(Config->ServerName,chan,"MODE %s %s",chan->name,outl);
1030 WriteChannel(chan,user,"MODE %s %s",chan->name,outl);
1031 FOREACH_MOD(I_OnMode,OnMode(user, chan, TYPE_CHANNEL, outl));
1038 // based on sourcemodes, return true or false to determine if umode is a valid mode a user may set on themselves or others.
1040 bool ModeParser::AllowedUmode(char umode, char* sourcemodes,bool adding,bool serveroverride)
1042 bool sourceoper = (strchr(sourcemodes,'o') != NULL);
1043 log(DEBUG,"Allowed_umode: %c %s",umode,sourcemodes);
1044 // Servers can +o and -o arbitrarily
1045 if ((serveroverride == true) && (umode == 'o'))
1049 // RFC1459 specified modes
1050 if ((umode == 'w') || (umode == 's') || (umode == 'i'))
1052 /* umode allowed by RFC1459 scemantics */
1056 /* user may not +o themselves or others, but an oper may de-oper other opers or themselves */
1057 if (sourceoper && !adding)
1061 else if (umode == 'o')
1063 /* Bad oper, bad bad! */
1067 /* process any module-defined modes that need oper */
1068 if ((ModeDefinedOper(umode,MT_CLIENT)) && (sourceoper))
1070 log(DEBUG,"umode %c allowed by module handler (oper only mode)",umode);
1073 else if (ModeDefined(umode,MT_CLIENT))
1075 // process any module-defined modes that don't need oper
1076 log(DEBUG,"umode %c allowed by module handler (non-oper mode)",umode);
1077 if ((ModeDefinedOper(umode,MT_CLIENT)) && (!sourceoper))
1079 // no, this mode needs oper, and this user 'aint got what it takes!
1085 // anything else - return false.
1086 log(DEBUG,"umode %c not known by any ruleset",umode);
1090 bool ModeParser::ProcessModuleUmode(char umode, userrec* source, void* dest, bool adding)
1097 strlcpy(s2->nick,Config->ServerName,NICKMAX-1);
1106 if (ModeDefined(umode,MT_CLIENT))
1108 for (int i = 0; i <= MODCOUNT; i++)
1110 if (modules[i]->OnExtendedMode(source,(void*)dest,umode,MT_CLIENT,adding,p))
1112 log(DEBUG,"Module %s claims umode %c",Config->module_names[i].c_str(),umode);
1116 log(DEBUG,"No module claims umode %c",umode);
1135 void cmd_mode::Handle (char **parameters, int pcnt, userrec *user)
1138 userrec* dest = Find(parameters[0]);
1141 char outpars[MAXBUF];
1142 bool next_ok = true;
1147 if ((dest) && (pcnt == 1))
1149 WriteServ(user->fd,"221 %s :+%s",dest->nick,dest->modes);
1152 else if ((dest) && (pcnt > 1))
1154 std::string tidied = ServerInstance->ModeGrok->CompressModes(parameters[1],false);
1155 parameters[1] = (char*)tidied.c_str();
1157 char dmodes[MAXBUF];
1158 strlcpy(dmodes,dest->modes,MAXMODES);
1159 log(DEBUG,"pulled up dest user modes: %s",dmodes);
1164 if ((*user->oper) || (is_uline(user->server)))
1175 WriteServ(user->fd,"482 %s :Can't change mode for other users",user->nick);
1179 outpars[0] = *parameters[1];
1181 direction = (*parameters[1] == '+');
1183 if ((*parameters[1] != '+') && (*parameters[1] != '-'))
1186 for (char* i = parameters[1]; *i; i++)
1188 if ((i != parameters[1]) && (*i != '+') && (*i != '-'))
1197 if ((direction != 1) && (next_ok))
1199 charlcat(outpars,'+',MAXBUF);
1206 if ((direction != 0) && (next_ok))
1208 charlcat(outpars,'-',MAXBUF);
1222 if ((*i == 'i') || (*i == 'w') || (*i == 's') || (ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,direction,false)))
1231 if ((!strchr(dmodes,*i)) && (ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,true,false)))
1233 if ((ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)) || (*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o'))
1235 charlcat(dmodes,*i,53);
1236 charlcat(outpars,*i,MAXMODES);
1239 FOREACH_MOD(I_OnGlobalOper,OnGlobalOper(dest));
1246 if ((ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,false,false)) && (strchr(dmodes,*i)))
1248 if ((ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)) || (*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o'))
1250 charlcat(outpars,*i,MAXMODES);
1251 charremove(dmodes,*i);
1269 for (char* i = outpars; *i;)
1272 if (((*i == '-') || (*i == '+')) && ((*(i+1) == '-') || (*(i+1) == '+')))
1274 // someones playing silly buggers and trying
1275 // to put a +- or -+ into the line...
1280 // Someone's trying to make the last character in
1281 // the line be a + or - symbol.
1282 if ((*i == '-') || (*i == '+'))
1290 if ((*b) && (!IS_SINGLE(b,'+')) && (!IS_SINGLE(b,'-')))
1292 WriteTo(user, dest, "MODE %s :%s", dest->nick, b);
1293 FOREACH_MOD(I_OnMode,OnMode(user, dest, TYPE_USER, b));
1296 log(DEBUG,"Stripped mode line");
1297 log(DEBUG,"Line dest is now %s",dmodes);
1298 strlcpy(dest->modes,dmodes,MAXMODES-1);
1306 Ptr = FindChan(parameters[0]);
1311 /* just /modes #channel */
1312 WriteServ(user->fd,"324 %s %s +%s",user->nick, Ptr->name, chanmodes(Ptr,has_channel(user,Ptr)));
1313 WriteServ(user->fd,"329 %s %s %d", user->nick, Ptr->name, Ptr->created);
1318 char* mode = parameters[1];
1322 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, Ptr, *mode, "", false, 0));
1327 for (BanList::iterator i = Ptr->bans.begin(); i != Ptr->bans.end(); i++)
1329 WriteServ(user->fd,"367 %s %s %s %s %d",user->nick, Ptr->name, i->data, i->set_by, i->set_time);
1331 WriteServ(user->fd,"368 %s %s :End of channel ban list",user->nick, Ptr->name);
1334 if ((ModeDefined(*mode,MT_CHANNEL)) && (ModeIsListMode(*mode,MT_CHANNEL)))
1336 // list of items for an extmode
1337 log(DEBUG,"Calling OnSendList for all modules, list output for mode %c",*mode);
1338 FOREACH_MOD(I_OnSendList,OnSendList(user,Ptr,*mode));
1344 if (((Ptr) && (!has_channel(user,Ptr))) && (!is_uline(user->server)) && (IS_LOCAL(user)))
1346 WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, Ptr->name);
1353 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,NULL,Ptr,AC_GENERAL_MODE));
1355 if (MOD_RESULT == ACR_DENY)
1357 if (MOD_RESULT == ACR_DEFAULT)
1359 if ((cstatus(user,Ptr) < STATUS_HOP) && (IS_LOCAL(user)))
1361 WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, Ptr->name);
1366 ServerInstance->ModeGrok->ProcessModes(parameters,user,Ptr,cstatus(user,Ptr),pcnt,false,false,false);
1371 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
1379 void ModeParser::ServerMode(char **parameters, int pcnt, userrec *user)
1382 userrec* dest = Find(parameters[0]);
1385 char outpars[MAXBUF];
1386 bool next_ok = true;
1388 if ((dest) && (pcnt > 1))
1390 std::string tidied = ServerInstance->ModeGrok->CompressModes(parameters[1],false);
1391 parameters[1] = (char*)tidied.c_str();
1393 char dmodes[MAXBUF];
1394 strlcpy(dmodes,dest->modes,MAXBUF);
1396 outpars[0] = *parameters[1];
1398 direction = (*parameters[1] == '+');
1400 if ((*parameters[1] != '+') && (*parameters[1] != '-'))
1403 for (char* i = parameters[1]; *i; i++)
1405 if ((i != parameters[1]) && (*i != '+') && (*i != '-'))
1414 if ((direction != 1) && (next_ok))
1417 charlcat(outpars,'+',MAXBUF);
1423 if ((direction != 0) && (next_ok))
1426 charlcat(outpars,'-',MAXBUF);
1432 log(DEBUG,"begin mode processing entry");
1438 log(DEBUG,"umode %c being added",*i);
1439 if ((!strchr(dmodes,*i)) && (ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,true,true)))
1441 log(DEBUG,"umode %c is an allowed umode",*i);
1442 if ((*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o') || (ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)))
1444 charlcat(dmodes,*i,MAXBUF);
1445 charlcat(outpars,*i,53);
1451 // can only remove a mode they already have
1452 log(DEBUG,"umode %c being removed",*i);
1453 if ((ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,false,true)) && (strchr(dmodes,*i)))
1455 log(DEBUG,"umode %c is an allowed umode",*i);
1456 if ((*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o') || (ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)))
1458 charlcat(outpars,*i,MAXBUF);
1459 charremove(dmodes,*i);
1472 for (char* i = outpars; *i;)
1475 if (((*i == '-') || (*i == '+')) && ((*(i+1) == '-') || (*(i+1) == '+')))
1477 // someones playing silly buggers and trying
1478 // to put a +- or -+ into the line...
1483 // Someone's trying to make the last character in
1484 // the line be a + or - symbol.
1485 if ((*i == '-') || (*i == '+'))
1493 if ((*b) && (!IS_SINGLE(b,'+')) && (!IS_SINGLE(b,'-')))
1495 WriteTo(user, dest, "MODE %s :%s", dest->nick, b);
1496 FOREACH_MOD(I_OnMode,OnMode(user, dest, TYPE_USER, b));
1499 log(DEBUG,"Stripped mode line");
1500 log(DEBUG,"Line dest is now %s",dmodes);
1501 strlcpy(dest->modes,dmodes,MAXMODES-1);
1508 Ptr = FindChan(parameters[0]);
1511 ServerInstance->ModeGrok->ProcessModes(parameters,user,Ptr,STATUS_OP,pcnt,true,false,false);
1515 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);