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];
463 bool k_set = false, l_set = false, previously_set_l = false, previously_unset_l = false, previously_set_k = false, previously_unset_k = false;
469 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,NULL,chan,AC_GENERAL_MODE));
470 if (MOD_RESULT == ACR_DENY)
474 std::string tidied = this->CompressModes(parameters[1],true);
475 strlcpy(mlist,tidied.c_str(),MAXBUF);
476 char* modelist = mlist;
478 *outlist = *modelist;
479 char* outl = outlist+1;
481 mdir = (*modelist == '+');
483 log(DEBUG,"process_modes: modelist: %s",modelist);
485 int len = tidied.length();
486 while (modelist[len-1] == ' ')
487 modelist[--len] = '\0';
489 for (char* modechar = (modelist + 1); *modechar; ptr++, modechar++)
493 /* If we have more than MAXMODES changes in one line,
494 * drop all after the MAXMODES
515 if ((param >= pcnt)) break;
516 log(DEBUG,"Enough parameters left");
521 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'o', parameters[param], true, 1));
524 r = GiveOps(user,parameters[param++],chan,status);
531 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'o', parameters[param], false, 1));
534 r = TakeOps(user,parameters[param++],chan,status);
546 if (((param >= pcnt)) || (!Config->AllowHalfop)) break;
551 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'h', parameters[param], true, 1));
554 r = GiveHops(user,parameters[param++],chan,status);
561 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'h', parameters[param], false, 1));
564 r = TakeHops(user,parameters[param++],chan,status);
577 if ((param >= pcnt)) break;
582 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'v', parameters[param], true, 1));
585 r = GiveVoice(user,parameters[param++],chan,status);
592 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'v', parameters[param], false, 1));
595 r = TakeVoice(user,parameters[param++],chan,status);
607 if ((param >= pcnt)) break;
612 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'b', parameters[param], true, 1));
615 r = AddBan(user,parameters[param++],chan,status);
622 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'b', parameters[param], false, 1));
625 r = TakeBan(user,parameters[param++],chan,status);
632 outpars[pc++] = parameters[param-1];
646 if (previously_unset_k)
648 previously_set_k = true;
653 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'k', parameters[param], true, 1));
658 strlcpy(key,parameters[param++],32);
660 strlcpy(chan->key,key,MAXBUF);
668 /* checks on -k are case sensitive and only accurate to the
669 first 32 characters */
670 if (previously_set_k)
672 previously_unset_k = true;
676 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'k', parameters[param], false, 1));
679 strlcpy(key,parameters[param++],32);
680 /* only allow -k if correct key given */
681 if (!strcmp(chan->key,key))
695 if (previously_set_l)
697 previously_unset_l = true;
699 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'l', "", false, 0));
710 if ((param >= pcnt)) break;
715 if (previously_unset_l)
717 previously_set_l = true;
718 bool invalid = false;
719 for (char* f = parameters[param]; *f; f++)
721 if ((*f < '0') || (*f > '9'))
726 /* If the limit is < 1, or the new limit is the current limit, dont allow */
727 if ((atoi(parameters[param]) < 1) || ((chan->limit > 0) && (atoi(parameters[param]) == chan->limit)))
736 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'l', parameters[param], true, 1));
740 chan->limit = atoi(parameters[param]);
742 // reported by mech: large values cause underflow
744 chan->limit = 0x7FFF;
750 outpars[pc++] = parameters[param++];
758 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'i', "", mdir, 0));
763 if (!(chan->binarymodes & CM_INVITEONLY)) *outl++ = 'i';
764 chan->binarymodes |= CM_INVITEONLY;
768 if (chan->binarymodes & CM_INVITEONLY) *outl++ = 'i';
769 chan->binarymodes &= ~CM_INVITEONLY;
776 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 't', "", mdir, 0));
781 if (!(chan->binarymodes & CM_TOPICLOCK)) *outl++ = 't';
782 chan->binarymodes |= CM_TOPICLOCK;
786 if (chan->binarymodes & CM_TOPICLOCK) *outl++ = 't';
787 chan->binarymodes &= ~CM_TOPICLOCK;
794 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'n', "", mdir, 0));
799 if (!(chan->binarymodes & CM_NOEXTERNAL)) *outl++ = 'n';
800 chan->binarymodes |= CM_NOEXTERNAL;
804 if (chan->binarymodes & CM_NOEXTERNAL) *outl++ = 'n';
805 chan->binarymodes &= ~CM_NOEXTERNAL;
812 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'm', "", mdir, 0));
817 if (!(chan->binarymodes & CM_MODERATED)) *outl++ = 'm';
818 chan->binarymodes |= CM_MODERATED;
822 if (chan->binarymodes & CM_MODERATED) *outl++ = 'm';
823 chan->binarymodes &= ~CM_MODERATED;
830 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 's', "", mdir, 0));
835 if (!(chan->binarymodes & CM_SECRET)) *outl++ = 's';
836 chan->binarymodes |= CM_SECRET;
837 if (chan->binarymodes & CM_PRIVATE)
839 chan->binarymodes &= ~CM_PRIVATE;
842 *outl++ = '-'; *outl++ = 'p'; *outl++ = '+';
848 if (chan->binarymodes & CM_SECRET) *outl++ = 's';
849 chan->binarymodes &= ~CM_SECRET;
856 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'p', "", mdir, 0));
861 if (!(chan->binarymodes & CM_PRIVATE)) *outl++ = 'p';
862 chan->binarymodes |= CM_PRIVATE;
863 if (chan->binarymodes & CM_SECRET)
865 chan->binarymodes &= ~CM_SECRET;
868 *outl++ = '-'; *outl++ = 's'; *outl++ = '+';
874 if (chan->binarymodes & CM_PRIVATE) *outl++ = 'p';
875 chan->binarymodes &= ~CM_PRIVATE;
883 bool x = chan->custom_modes[*modechar-65];
884 if ((!x && !mdir) || (x && mdir))
886 if (!ModeIsListMode(*modechar,MT_CHANNEL))
888 log(DEBUG,"Mode %c isnt set on %s but trying to remove!",*modechar,chan->name);
892 if (ModeDefined(*modechar,MT_CHANNEL))
894 /* A module has claimed this mode */
897 if ((ModeDefinedOn(*modechar,MT_CHANNEL)>0) && (mdir))
899 p.push_back(parameters[param]);
901 if ((ModeDefinedOff(*modechar,MT_CHANNEL)>0) && (!mdir))
903 p.push_back(parameters[param]);
906 bool handled = false;
909 // we're supposed to have a parameter, but none was given... so dont handle the mode.
910 if (((ModeDefinedOn(*modechar,MT_CHANNEL)>0) && (mdir)) || ((ModeDefinedOff(*modechar,MT_CHANNEL)>0) && (!mdir)))
912 log(DEBUG,"Not enough parameters for module-mode %c",*modechar);
917 // BIG ASS IDIOTIC CODER WARNING!
918 // Using OnRawMode on another modules mode's behavour
919 // will confuse the crap out of admins! just because you CAN
920 // do it, doesnt mean you SHOULD!
922 std::string para = "";
925 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, *modechar, para, mdir, pcnt));
928 for (int i = 0; i <= MODCOUNT; i++)
932 int t = modules[i]->OnExtendedMode(user,chan,*modechar,MT_CHANNEL,mdir,p);
935 log(DEBUG,"OnExtendedMode returned nonzero for a module");
936 if (ModeIsListMode(*modechar,MT_CHANNEL))
949 outpars[pc++] = parameters[param++];
955 chan->SetCustomMode(*modechar,mdir);
956 // include parameters in output if mode has them
957 if ((ModeDefinedOn(*modechar,MT_CHANNEL)>0) && (mdir))
961 chan->SetCustomModeParam(*modechar,parameters[param],mdir);
962 outpars[pc++] = parameters[param++];
966 // break, because only one module can handle the mode.
975 WriteServ(user->fd,"472 %s %c :is unknown mode char to me",user->nick,*modechar);
981 /* Null terminate it now we're done */
985 /************ Fast, but confusing string tidying ************/
987 while (*outl && (*outl < 'A'))
989 /* outl now points to the first mode character after +'s and -'s */
991 /* Now points at first mode-modifier + or - symbol */
993 /* Now we tidy off any trailing -'s etc */
996 while ((*--trim == '+') || (*trim == '-'))
998 /************ Done wih the string tidy functions ************/
1001 /* The mode change must be at least two characters long (+ or - and at least one mode) */
1002 if (((*outl == '+') || (*outl == '-')) && *(outl+1))
1004 for (ptr = 0; ptr < pc; ptr++)
1006 charlcat(outl,' ',MAXBUF);
1007 strlcat(outl,outpars[ptr],MAXBUF-1);
1011 log(DEBUG,"Local mode change");
1012 WriteChannelLocal(chan, user, "MODE %s %s",chan->name,outl);
1013 FOREACH_MOD(I_OnMode,OnMode(user, chan, TYPE_CHANNEL, outl));
1021 WriteChannelWithServ(Config->ServerName,chan,"MODE %s %s",chan->name,outl);
1029 WriteChannel(chan,user,"MODE %s %s",chan->name,outl);
1030 FOREACH_MOD(I_OnMode,OnMode(user, chan, TYPE_CHANNEL, outl));
1037 // based on sourcemodes, return true or false to determine if umode is a valid mode a user may set on themselves or others.
1039 bool ModeParser::AllowedUmode(char umode, char* sourcemodes,bool adding,bool serveroverride)
1041 bool sourceoper = (strchr(sourcemodes,'o') != NULL);
1042 log(DEBUG,"Allowed_umode: %c %s",umode,sourcemodes);
1043 // Servers can +o and -o arbitrarily
1044 if ((serveroverride == true) && (umode == 'o'))
1048 // RFC1459 specified modes
1049 if ((umode == 'w') || (umode == 's') || (umode == 'i'))
1051 /* umode allowed by RFC1459 scemantics */
1055 /* user may not +o themselves or others, but an oper may de-oper other opers or themselves */
1056 if (sourceoper && !adding)
1060 else if (umode == 'o')
1062 /* Bad oper, bad bad! */
1066 /* process any module-defined modes that need oper */
1067 if ((ModeDefinedOper(umode,MT_CLIENT)) && (sourceoper))
1069 log(DEBUG,"umode %c allowed by module handler (oper only mode)",umode);
1072 else if (ModeDefined(umode,MT_CLIENT))
1074 // process any module-defined modes that don't need oper
1075 log(DEBUG,"umode %c allowed by module handler (non-oper mode)",umode);
1076 if ((ModeDefinedOper(umode,MT_CLIENT)) && (!sourceoper))
1078 // no, this mode needs oper, and this user 'aint got what it takes!
1084 // anything else - return false.
1085 log(DEBUG,"umode %c not known by any ruleset",umode);
1089 bool ModeParser::ProcessModuleUmode(char umode, userrec* source, void* dest, bool adding)
1096 strlcpy(s2->nick,Config->ServerName,NICKMAX-1);
1105 if (ModeDefined(umode,MT_CLIENT))
1107 for (int i = 0; i <= MODCOUNT; i++)
1109 if (modules[i]->OnExtendedMode(source,(void*)dest,umode,MT_CLIENT,adding,p))
1111 log(DEBUG,"Module %s claims umode %c",Config->module_names[i].c_str(),umode);
1115 log(DEBUG,"No module claims umode %c",umode);
1134 void cmd_mode::Handle (char **parameters, int pcnt, userrec *user)
1137 userrec* dest = Find(parameters[0]);
1140 char outpars[MAXBUF];
1141 bool next_ok = true;
1146 if ((dest) && (pcnt == 1))
1148 WriteServ(user->fd,"221 %s :+%s",dest->nick,dest->modes);
1151 else if ((dest) && (pcnt > 1))
1153 std::string tidied = ServerInstance->ModeGrok->CompressModes(parameters[1],false);
1154 parameters[1] = (char*)tidied.c_str();
1156 char dmodes[MAXBUF];
1157 strlcpy(dmodes,dest->modes,MAXMODES);
1158 log(DEBUG,"pulled up dest user modes: %s",dmodes);
1163 if ((*user->oper) || (is_uline(user->server)))
1174 WriteServ(user->fd,"482 %s :Can't change mode for other users",user->nick);
1178 outpars[0] = *parameters[1];
1180 direction = (*parameters[1] == '+');
1182 if ((*parameters[1] != '+') && (*parameters[1] != '-'))
1185 for (char* i = parameters[1]; *i; i++)
1187 if ((i != parameters[1]) && (*i != '+') && (*i != '-'))
1196 if ((direction != 1) && (next_ok))
1198 charlcat(outpars,'+',MAXBUF);
1205 if ((direction != 0) && (next_ok))
1207 charlcat(outpars,'-',MAXBUF);
1221 if ((*i == 'i') || (*i == 'w') || (*i == 's') || (ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,direction,false)))
1230 if ((!strchr(dmodes,*i)) && (ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,true,false)))
1232 if ((ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)) || (*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o'))
1234 charlcat(dmodes,*i,53);
1235 charlcat(outpars,*i,MAXMODES);
1238 FOREACH_MOD(I_OnGlobalOper,OnGlobalOper(dest));
1245 if ((ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,false,false)) && (strchr(dmodes,*i)))
1247 if ((ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)) || (*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o'))
1249 charlcat(outpars,*i,MAXMODES);
1250 charremove(dmodes,*i);
1268 for (char* i = outpars; *i;)
1271 if (((*i == '-') || (*i == '+')) && ((*(i+1) == '-') || (*(i+1) == '+')))
1273 // someones playing silly buggers and trying
1274 // to put a +- or -+ into the line...
1279 // Someone's trying to make the last character in
1280 // the line be a + or - symbol.
1281 if ((*i == '-') || (*i == '+'))
1289 if ((*b) && (!IS_SINGLE(b,'+')) && (!IS_SINGLE(b,'-')))
1291 WriteTo(user, dest, "MODE %s :%s", dest->nick, b);
1292 FOREACH_MOD(I_OnMode,OnMode(user, dest, TYPE_USER, b));
1295 log(DEBUG,"Stripped mode line");
1296 log(DEBUG,"Line dest is now %s",dmodes);
1297 strlcpy(dest->modes,dmodes,MAXMODES-1);
1305 Ptr = FindChan(parameters[0]);
1310 /* just /modes #channel */
1311 WriteServ(user->fd,"324 %s %s +%s",user->nick, Ptr->name, chanmodes(Ptr,has_channel(user,Ptr)));
1312 WriteServ(user->fd,"329 %s %s %d", user->nick, Ptr->name, Ptr->created);
1317 char* mode = parameters[1];
1321 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, Ptr, *mode, "", false, 0));
1326 for (BanList::iterator i = Ptr->bans.begin(); i != Ptr->bans.end(); i++)
1328 WriteServ(user->fd,"367 %s %s %s %s %d",user->nick, Ptr->name, i->data, i->set_by, i->set_time);
1330 WriteServ(user->fd,"368 %s %s :End of channel ban list",user->nick, Ptr->name);
1333 if ((ModeDefined(*mode,MT_CHANNEL)) && (ModeIsListMode(*mode,MT_CHANNEL)))
1335 // list of items for an extmode
1336 log(DEBUG,"Calling OnSendList for all modules, list output for mode %c",*mode);
1337 FOREACH_MOD(I_OnSendList,OnSendList(user,Ptr,*mode));
1343 if (((Ptr) && (!has_channel(user,Ptr))) && (!is_uline(user->server)) && (IS_LOCAL(user)))
1345 WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, Ptr->name);
1352 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,NULL,Ptr,AC_GENERAL_MODE));
1354 if (MOD_RESULT == ACR_DENY)
1356 if (MOD_RESULT == ACR_DEFAULT)
1358 if ((cstatus(user,Ptr) < STATUS_HOP) && (IS_LOCAL(user)))
1360 WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, Ptr->name);
1365 ServerInstance->ModeGrok->ProcessModes(parameters,user,Ptr,cstatus(user,Ptr),pcnt,false,false,false);
1370 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
1378 void ModeParser::ServerMode(char **parameters, int pcnt, userrec *user)
1381 userrec* dest = Find(parameters[0]);
1384 char outpars[MAXBUF];
1385 bool next_ok = true;
1387 if ((dest) && (pcnt > 1))
1389 std::string tidied = ServerInstance->ModeGrok->CompressModes(parameters[1],false);
1390 parameters[1] = (char*)tidied.c_str();
1392 char dmodes[MAXBUF];
1393 strlcpy(dmodes,dest->modes,MAXBUF);
1395 outpars[0] = *parameters[1];
1397 direction = (*parameters[1] == '+');
1399 if ((*parameters[1] != '+') && (*parameters[1] != '-'))
1402 for (char* i = parameters[1]; *i; i++)
1404 if ((i != parameters[1]) && (*i != '+') && (*i != '-'))
1413 if ((direction != 1) && (next_ok))
1416 charlcat(outpars,'+',MAXBUF);
1422 if ((direction != 0) && (next_ok))
1425 charlcat(outpars,'-',MAXBUF);
1431 log(DEBUG,"begin mode processing entry");
1437 log(DEBUG,"umode %c being added",*i);
1438 if ((!strchr(dmodes,*i)) && (ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,true,true)))
1440 log(DEBUG,"umode %c is an allowed umode",*i);
1441 if ((*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o') || (ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)))
1443 charlcat(dmodes,*i,MAXBUF);
1444 charlcat(outpars,*i,53);
1450 // can only remove a mode they already have
1451 log(DEBUG,"umode %c being removed",*i);
1452 if ((ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,false,true)) && (strchr(dmodes,*i)))
1454 log(DEBUG,"umode %c is an allowed umode",*i);
1455 if ((*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o') || (ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)))
1457 charlcat(outpars,*i,MAXBUF);
1458 charremove(dmodes,*i);
1471 for (char* i = outpars; *i;)
1474 if (((*i == '-') || (*i == '+')) && ((*(i+1) == '-') || (*(i+1) == '+')))
1476 // someones playing silly buggers and trying
1477 // to put a +- or -+ into the line...
1482 // Someone's trying to make the last character in
1483 // the line be a + or - symbol.
1484 if ((*i == '-') || (*i == '+'))
1492 if ((*b) && (!IS_SINGLE(b,'+')) && (!IS_SINGLE(b,'-')))
1494 WriteTo(user, dest, "MODE %s :%s", dest->nick, b);
1495 FOREACH_MOD(I_OnMode,OnMode(user, dest, TYPE_USER, b));
1498 log(DEBUG,"Stripped mode line");
1499 log(DEBUG,"Line dest is now %s",dmodes);
1500 strlcpy(dest->modes,dmodes,MAXMODES-1);
1507 Ptr = FindChan(parameters[0]);
1510 ServerInstance->ModeGrok->ProcessModes(parameters,user,Ptr,STATUS_OP,pcnt,true,false,false);
1514 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);