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(d);
91 d->chans[i].channel->AddHalfoppedUser(d);
94 d->chans[i].channel->AddVoicedUser(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(d);
122 d->chans[i].channel->DelHalfoppedUser(d);
125 d->chans[i].channel->DelVoicedUser(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));
401 /** ModeParser::CompressModes()
402 * Tidies up redundant modes,
403 * e.g. +nt-nt+i becomes +-+i
404 * A section further down the chain tidies up the +-+- crap.
406 std::string ModeParser::CompressModes(std::string modes,bool channelmodes)
409 * OK, iterate over the mode string and count how many times a certain mode appears in it.
410 * Then, erase all instances of any character that appears more than once.
411 * This only operates on modes with no parameters, you can still +v-v+v-v+v-v to your heart's content.
414 /* Do we really need an int here? Can you fit enough modes in a line to overflow a short? */
417 memset(counts, 0, sizeof(counts));
418 memset(active, 0, sizeof(active));
420 for(unsigned char* i = (unsigned char*)modes.c_str(); *i; i++)
422 if((*i == '+') || (*i == '-'))
425 if(!channelmodes || (channelmodes && (strchr("itnmsp", *i) || (ModeDefined(*i, MT_CHANNEL) && !ModeDefinedOn(*i,MT_CHANNEL) && !ModeDefinedOff(*i,MT_CHANNEL)))))
427 log(DEBUG,"Tidy mode %c", *i);
433 for(unsigned char j = 65; j < 127; j++)
435 if ((counts[j] > 1) && (active[j] == true))
437 std::string::size_type pos;
439 while((pos = modes.find(j)) != std::string::npos)
441 log(DEBUG, "Deleting occurence of mode %c...", j);
443 log(DEBUG,"New mode line: %s", modes.c_str());
451 void ModeParser::ProcessModes(char **parameters,userrec* user,chanrec *chan,int status, int pcnt, bool servermode, bool silent, bool local)
453 if ((!parameters) || (pcnt < 2)) {
457 char outlist[MAXBUF];
465 bool k_set = false, l_set = false, previously_set_l = false, previously_unset_l = false, previously_set_k = false, previously_unset_k = false;
471 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,NULL,chan,AC_GENERAL_MODE));
472 if (MOD_RESULT == ACR_DENY)
476 std::string tidied = this->CompressModes(parameters[1],true);
477 strlcpy(mlist,tidied.c_str(),MAXBUF);
478 char* modelist = mlist;
480 *outlist = *modelist;
481 char* outl = outlist+1;
483 mdir = (*modelist == '+');
485 log(DEBUG,"process_modes: modelist: %s",modelist);
487 int len = tidied.length();
488 while (modelist[len-1] == ' ')
489 modelist[--len] = '\0';
491 for (char* modechar = (modelist + 1); *modechar; ptr++, modechar++)
495 /* If we have more than MAXMODES changes in one line,
496 * drop all after the MAXMODES
517 if ((param >= pcnt)) break;
518 log(DEBUG,"Enough parameters left");
523 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'o', parameters[param], true, 1));
526 r = GiveOps(user,parameters[param++],chan,status);
533 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'o', parameters[param], false, 1));
536 r = TakeOps(user,parameters[param++],chan,status);
548 if (((param >= pcnt)) || (!Config->AllowHalfop)) break;
553 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'h', parameters[param], true, 1));
556 r = GiveHops(user,parameters[param++],chan,status);
563 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'h', parameters[param], false, 1));
566 r = TakeHops(user,parameters[param++],chan,status);
579 if ((param >= pcnt)) break;
584 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'v', parameters[param], true, 1));
587 r = GiveVoice(user,parameters[param++],chan,status);
594 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'v', parameters[param], false, 1));
597 r = TakeVoice(user,parameters[param++],chan,status);
609 if ((param >= pcnt)) break;
614 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'b', parameters[param], true, 1));
617 r = AddBan(user,parameters[param++],chan,status);
624 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'b', parameters[param], false, 1));
627 r = TakeBan(user,parameters[param++],chan,status);
634 outpars[pc++] = parameters[param-1];
648 if (previously_unset_k)
650 previously_set_k = true;
655 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'k', parameters[param], true, 1));
660 strlcpy(key,parameters[param++],32);
662 strlcpy(chan->key,key,MAXBUF);
670 /* checks on -k are case sensitive and only accurate to the
671 first 32 characters */
672 if (previously_set_k)
674 previously_unset_k = true;
678 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'k', parameters[param], false, 1));
681 strlcpy(key,parameters[param++],32);
682 /* only allow -k if correct key given */
683 if (!strcmp(chan->key,key))
697 if (previously_set_l)
699 previously_unset_l = true;
701 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'l', "", false, 0));
712 if ((param >= pcnt)) break;
717 if (previously_unset_l)
719 previously_set_l = true;
720 bool invalid = false;
721 for (char* f = parameters[param]; *f; f++)
723 if ((*f < '0') || (*f > '9'))
728 /* If the limit is < 1, or the new limit is the current limit, dont allow */
729 if ((atoi(parameters[param]) < 1) || ((chan->limit > 0) && (atoi(parameters[param]) == chan->limit)))
738 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'l', parameters[param], true, 1));
742 chan->limit = atoi(parameters[param]);
744 // reported by mech: large values cause underflow
746 chan->limit = 0x7FFF;
752 outpars[pc++] = parameters[param++];
760 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'i', "", mdir, 0));
765 if (!(chan->binarymodes & CM_INVITEONLY)) *outl++ = 'i';
766 chan->binarymodes |= CM_INVITEONLY;
770 if (chan->binarymodes & CM_INVITEONLY) *outl++ = 'i';
771 chan->binarymodes &= ~CM_INVITEONLY;
778 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 't', "", mdir, 0));
783 if (!(chan->binarymodes & CM_TOPICLOCK)) *outl++ = 't';
784 chan->binarymodes |= CM_TOPICLOCK;
788 if (chan->binarymodes & CM_TOPICLOCK) *outl++ = 't';
789 chan->binarymodes &= ~CM_TOPICLOCK;
796 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'n', "", mdir, 0));
801 if (!(chan->binarymodes & CM_NOEXTERNAL)) *outl++ = 'n';
802 chan->binarymodes |= CM_NOEXTERNAL;
806 if (chan->binarymodes & CM_NOEXTERNAL) *outl++ = 'n';
807 chan->binarymodes &= ~CM_NOEXTERNAL;
814 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'm', "", mdir, 0));
819 if (!(chan->binarymodes & CM_MODERATED)) *outl++ = 'm';
820 chan->binarymodes |= CM_MODERATED;
824 if (chan->binarymodes & CM_MODERATED) *outl++ = 'm';
825 chan->binarymodes &= ~CM_MODERATED;
832 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 's', "", mdir, 0));
837 if (!(chan->binarymodes & CM_SECRET)) *outl++ = 's';
838 chan->binarymodes |= CM_SECRET;
839 if (chan->binarymodes & CM_PRIVATE)
841 chan->binarymodes &= ~CM_PRIVATE;
844 *outl++ = '-'; *outl++ = 'p'; *outl++ = '+';
850 if (chan->binarymodes & CM_SECRET) *outl++ = 's';
851 chan->binarymodes &= ~CM_SECRET;
858 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'p', "", mdir, 0));
863 if (!(chan->binarymodes & CM_PRIVATE)) *outl++ = 'p';
864 chan->binarymodes |= CM_PRIVATE;
865 if (chan->binarymodes & CM_SECRET)
867 chan->binarymodes &= ~CM_SECRET;
870 *outl++ = '-'; *outl++ = 's'; *outl++ = '+';
876 if (chan->binarymodes & CM_PRIVATE) *outl++ = 'p';
877 chan->binarymodes &= ~CM_PRIVATE;
885 bool x = chan->custom_modes[*modechar-65];
886 if ((!x && !mdir) || (x && mdir))
888 if (!ModeIsListMode(*modechar,MT_CHANNEL))
890 log(DEBUG,"Mode %c isnt set on %s but trying to remove!",*modechar,chan->name);
894 if (ModeDefined(*modechar,MT_CHANNEL))
896 /* A module has claimed this mode */
899 if ((ModeDefinedOn(*modechar,MT_CHANNEL)>0) && (mdir))
901 p.push_back(parameters[param]);
903 if ((ModeDefinedOff(*modechar,MT_CHANNEL)>0) && (!mdir))
905 p.push_back(parameters[param]);
908 bool handled = false;
911 // we're supposed to have a parameter, but none was given... so dont handle the mode.
912 if (((ModeDefinedOn(*modechar,MT_CHANNEL)>0) && (mdir)) || ((ModeDefinedOff(*modechar,MT_CHANNEL)>0) && (!mdir)))
914 log(DEBUG,"Not enough parameters for module-mode %c",*modechar);
919 // BIG ASS IDIOTIC CODER WARNING!
920 // Using OnRawMode on another modules mode's behavour
921 // will confuse the crap out of admins! just because you CAN
922 // do it, doesnt mean you SHOULD!
924 std::string para = "";
927 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, *modechar, para, mdir, pcnt));
930 for (int i = 0; i <= MODCOUNT; i++)
934 int t = modules[i]->OnExtendedMode(user,chan,*modechar,MT_CHANNEL,mdir,p);
937 log(DEBUG,"OnExtendedMode returned nonzero for a module");
938 if (ModeIsListMode(*modechar,MT_CHANNEL))
951 outpars[pc++] = parameters[param++];
957 chan->SetCustomMode(*modechar,mdir);
958 // include parameters in output if mode has them
959 if ((ModeDefinedOn(*modechar,MT_CHANNEL)>0) && (mdir))
963 chan->SetCustomModeParam(*modechar,parameters[param],mdir);
964 outpars[pc++] = parameters[param++];
968 // break, because only one module can handle the mode.
977 WriteServ(user->fd,"472 %s %c :is unknown mode char to me",user->nick,*modechar);
983 /* Null terminate it now we're done */
987 /************ Fast, but confusing string tidying ************/
989 while (*outl && (*outl < 'A'))
991 /* outl now points to the first mode character after +'s and -'s */
993 /* Now points at first mode-modifier + or - symbol */
995 /* Now we tidy off any trailing -'s etc */
998 while ((*--trim == '+') || (*trim == '-'))
1000 /************ Done wih the string tidy functions ************/
1003 /* The mode change must be at least two characters long (+ or - and at least one mode) */
1004 if (((*outl == '+') || (*outl == '-')) && *(outl+1))
1006 for (ptr = 0; ptr < pc; ptr++)
1008 charlcat(outl,' ',MAXBUF);
1009 strlcat(outl,outpars[ptr],MAXBUF-1);
1013 log(DEBUG,"Local mode change");
1014 WriteChannelLocal(chan, user, "MODE %s %s",chan->name,outl);
1015 FOREACH_MOD(I_OnMode,OnMode(user, chan, TYPE_CHANNEL, outl));
1023 WriteChannelWithServ(Config->ServerName,chan,"MODE %s %s",chan->name,outl);
1031 WriteChannel(chan,user,"MODE %s %s",chan->name,outl);
1032 FOREACH_MOD(I_OnMode,OnMode(user, chan, TYPE_CHANNEL, outl));
1039 // based on sourcemodes, return true or false to determine if umode is a valid mode a user may set on themselves or others.
1041 bool ModeParser::AllowedUmode(char umode, char* sourcemodes,bool adding,bool serveroverride)
1043 bool sourceoper = (strchr(sourcemodes,'o') != NULL);
1044 log(DEBUG,"Allowed_umode: %c %s",umode,sourcemodes);
1045 // Servers can +o and -o arbitrarily
1046 if ((serveroverride == true) && (umode == 'o'))
1050 // RFC1459 specified modes
1051 if ((umode == 'w') || (umode == 's') || (umode == 'i'))
1053 /* umode allowed by RFC1459 scemantics */
1057 /* user may not +o themselves or others, but an oper may de-oper other opers or themselves */
1058 if (sourceoper && !adding)
1062 else if (umode == 'o')
1064 /* Bad oper, bad bad! */
1068 /* process any module-defined modes that need oper */
1069 if ((ModeDefinedOper(umode,MT_CLIENT)) && (sourceoper))
1071 log(DEBUG,"umode %c allowed by module handler (oper only mode)",umode);
1074 else if (ModeDefined(umode,MT_CLIENT))
1076 // process any module-defined modes that don't need oper
1077 log(DEBUG,"umode %c allowed by module handler (non-oper mode)",umode);
1078 if ((ModeDefinedOper(umode,MT_CLIENT)) && (!sourceoper))
1080 // no, this mode needs oper, and this user 'aint got what it takes!
1086 // anything else - return false.
1087 log(DEBUG,"umode %c not known by any ruleset",umode);
1091 bool ModeParser::ProcessModuleUmode(char umode, userrec* source, void* dest, bool adding)
1098 strlcpy(s2->nick,Config->ServerName,NICKMAX-1);
1107 if (ModeDefined(umode,MT_CLIENT))
1109 for (int i = 0; i <= MODCOUNT; i++)
1111 if (modules[i]->OnExtendedMode(source,(void*)dest,umode,MT_CLIENT,adding,p))
1113 log(DEBUG,"Module %s claims umode %c",Config->module_names[i].c_str(),umode);
1117 log(DEBUG,"No module claims umode %c",umode);
1136 void cmd_mode::Handle (char **parameters, int pcnt, userrec *user)
1139 userrec* dest = Find(parameters[0]);
1142 char outpars[MAXBUF];
1143 bool next_ok = true;
1148 if ((dest) && (pcnt == 1))
1150 WriteServ(user->fd,"221 %s :+%s",dest->nick,dest->modes);
1153 else if ((dest) && (pcnt > 1))
1155 std::string tidied = ServerInstance->ModeGrok->CompressModes(parameters[1],false);
1156 parameters[1] = (char*)tidied.c_str();
1158 char dmodes[MAXBUF];
1159 strlcpy(dmodes,dest->modes,MAXMODES);
1160 log(DEBUG,"pulled up dest user modes: %s",dmodes);
1165 if ((*user->oper) || (is_uline(user->server)))
1176 WriteServ(user->fd,"482 %s :Can't change mode for other users",user->nick);
1180 outpars[0] = *parameters[1];
1182 direction = (*parameters[1] == '+');
1184 if ((*parameters[1] != '+') && (*parameters[1] != '-'))
1187 for (char* i = parameters[1]; *i; i++)
1189 if ((i != parameters[1]) && (*i != '+') && (*i != '-'))
1198 if ((direction != 1) && (next_ok))
1200 charlcat(outpars,'+',MAXBUF);
1207 if ((direction != 0) && (next_ok))
1209 charlcat(outpars,'-',MAXBUF);
1223 if ((*i == 'i') || (*i == 'w') || (*i == 's') || (ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,direction,false)))
1232 if ((!strchr(dmodes,*i)) && (ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,true,false)))
1234 if ((ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)) || (*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o'))
1236 charlcat(dmodes,*i,53);
1237 charlcat(outpars,*i,MAXMODES);
1240 FOREACH_MOD(I_OnGlobalOper,OnGlobalOper(dest));
1247 if ((ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,false,false)) && (strchr(dmodes,*i)))
1249 if ((ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)) || (*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o'))
1251 charlcat(outpars,*i,MAXMODES);
1252 charremove(dmodes,*i);
1270 for (char* i = outpars; *i;)
1273 if (((*i == '-') || (*i == '+')) && ((*(i+1) == '-') || (*(i+1) == '+')))
1275 // someones playing silly buggers and trying
1276 // to put a +- or -+ into the line...
1281 // Someone's trying to make the last character in
1282 // the line be a + or - symbol.
1283 if ((*i == '-') || (*i == '+'))
1291 if ((*b) && (!IS_SINGLE(b,'+')) && (!IS_SINGLE(b,'-')))
1293 WriteTo(user, dest, "MODE %s :%s", dest->nick, b);
1294 FOREACH_MOD(I_OnMode,OnMode(user, dest, TYPE_USER, b));
1297 log(DEBUG,"Stripped mode line");
1298 log(DEBUG,"Line dest is now %s",dmodes);
1299 strlcpy(dest->modes,dmodes,MAXMODES-1);
1307 Ptr = FindChan(parameters[0]);
1312 /* just /modes #channel */
1313 WriteServ(user->fd,"324 %s %s +%s",user->nick, Ptr->name, chanmodes(Ptr,Ptr->HasUser(user)));
1314 WriteServ(user->fd,"329 %s %s %d", user->nick, Ptr->name, Ptr->created);
1319 char* mode = parameters[1];
1323 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, Ptr, *mode, "", false, 0));
1328 for (BanList::iterator i = Ptr->bans.begin(); i != Ptr->bans.end(); i++)
1330 WriteServ(user->fd,"367 %s %s %s %s %d",user->nick, Ptr->name, i->data, i->set_by, i->set_time);
1332 WriteServ(user->fd,"368 %s %s :End of channel ban list",user->nick, Ptr->name);
1335 if ((ModeDefined(*mode,MT_CHANNEL)) && (ModeIsListMode(*mode,MT_CHANNEL)))
1337 // list of items for an extmode
1338 log(DEBUG,"Calling OnSendList for all modules, list output for mode %c",*mode);
1339 FOREACH_MOD(I_OnSendList,OnSendList(user,Ptr,*mode));
1345 if ((IS_LOCAL(user)) && (!is_uline(user->server)) && (!Ptr->HasUser(user)))
1347 WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, Ptr->name);
1354 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,NULL,Ptr,AC_GENERAL_MODE));
1356 if (MOD_RESULT == ACR_DENY)
1358 if (MOD_RESULT == ACR_DEFAULT)
1360 if ((IS_LOCAL(user)) && (cstatus(user,Ptr) < STATUS_HOP))
1362 WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, Ptr->name);
1367 ServerInstance->ModeGrok->ProcessModes(parameters,user,Ptr,cstatus(user,Ptr),pcnt,false,false,false);
1372 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
1380 void ModeParser::ServerMode(char **parameters, int pcnt, userrec *user)
1383 userrec* dest = Find(parameters[0]);
1386 char outpars[MAXBUF];
1387 bool next_ok = true;
1389 if ((dest) && (pcnt > 1))
1391 std::string tidied = ServerInstance->ModeGrok->CompressModes(parameters[1],false);
1392 parameters[1] = (char*)tidied.c_str();
1394 char dmodes[MAXBUF];
1395 strlcpy(dmodes,dest->modes,MAXBUF);
1397 outpars[0] = *parameters[1];
1399 direction = (*parameters[1] == '+');
1401 if ((*parameters[1] != '+') && (*parameters[1] != '-'))
1404 for (char* i = parameters[1]; *i; i++)
1406 if ((i != parameters[1]) && (*i != '+') && (*i != '-'))
1415 if ((direction != 1) && (next_ok))
1418 charlcat(outpars,'+',MAXBUF);
1424 if ((direction != 0) && (next_ok))
1427 charlcat(outpars,'-',MAXBUF);
1433 log(DEBUG,"begin mode processing entry");
1439 log(DEBUG,"umode %c being added",*i);
1440 if ((!strchr(dmodes,*i)) && (ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,true,true)))
1442 log(DEBUG,"umode %c is an allowed umode",*i);
1443 if ((*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o') || (ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)))
1445 charlcat(dmodes,*i,MAXBUF);
1446 charlcat(outpars,*i,53);
1452 // can only remove a mode they already have
1453 log(DEBUG,"umode %c being removed",*i);
1454 if ((ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,false,true)) && (strchr(dmodes,*i)))
1456 log(DEBUG,"umode %c is an allowed umode",*i);
1457 if ((*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o') || (ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)))
1459 charlcat(outpars,*i,MAXBUF);
1460 charremove(dmodes,*i);
1473 for (char* i = outpars; *i;)
1476 if (((*i == '-') || (*i == '+')) && ((*(i+1) == '-') || (*(i+1) == '+')))
1478 // someones playing silly buggers and trying
1479 // to put a +- or -+ into the line...
1484 // Someone's trying to make the last character in
1485 // the line be a + or - symbol.
1486 if ((*i == '-') || (*i == '+'))
1494 if ((*b) && (!IS_SINGLE(b,'+')) && (!IS_SINGLE(b,'-')))
1496 WriteTo(user, dest, "MODE %s :%s", dest->nick, b);
1497 FOREACH_MOD(I_OnMode,OnMode(user, dest, TYPE_USER, b));
1500 log(DEBUG,"Stripped mode line");
1501 log(DEBUG,"Line dest is now %s",dmodes);
1502 strlcpy(dest->modes,dmodes,MAXMODES-1);
1509 Ptr = FindChan(parameters[0]);
1512 ServerInstance->ModeGrok->ProcessModes(parameters,user,Ptr,STATUS_OP,pcnt,true,false,false);
1516 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);