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)
78 for (std::vector<ucrec*>::const_iterator i = d->chans.begin(); i != d->chans.end(); i++)
80 if (((ucrec*)(*i))->channel == chan)
82 if (((ucrec*)(*i))->uc_modes & MASK)
86 ((ucrec*)(*i))->uc_modes = ((ucrec*)(*i))->uc_modes | MASK;
90 ((ucrec*)(*i))->channel->AddOppedUser(d);
93 ((ucrec*)(*i))->channel->AddHalfoppedUser(d);
96 ((ucrec*)(*i))->channel->AddVoicedUser(d);
99 log(DEBUG,"grant: %s %s",((ucrec*)(*i))->channel->name,d->nick);
106 char* ModeParser::Revoke(userrec *d,chanrec *chan,int MASK)
111 for (std::vector<ucrec*>::const_iterator i = d->chans.begin(); i != d->chans.end(); i++)
113 if (((ucrec*)(*i))->channel == chan)
115 if ((((ucrec*)(*i))->uc_modes & MASK) == 0)
119 ((ucrec*)(*i))->uc_modes ^= MASK;
123 ((ucrec*)(*i))->channel->DelOppedUser(d);
126 ((ucrec*)(*i))->channel->DelHalfoppedUser(d);
129 ((ucrec*)(*i))->channel->DelVoicedUser(d);
132 log(DEBUG,"revoke: %s %s",((ucrec*)(*i))->channel->name,d->nick);
139 char* ModeParser::GiveOps(userrec *user,char *dest,chanrec *chan,int status)
141 userrec *d = this->SanityChecks(user,dest,chan,status);
148 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_OP));
150 if (MOD_RESULT == ACR_DENY)
152 if (MOD_RESULT == ACR_DEFAULT)
154 if ((status < STATUS_OP) && (!is_uline(user->server)))
156 WriteServ(user->fd,"482 %s %s :You're not a channel operator",user->nick, chan->name);
162 return this->Grant(d,chan,UCMODE_OP);
167 char* ModeParser::GiveHops(userrec *user,char *dest,chanrec *chan,int status)
169 userrec *d = this->SanityChecks(user,dest,chan,status);
176 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_HALFOP));
178 if (MOD_RESULT == ACR_DENY)
180 if (MOD_RESULT == ACR_DEFAULT)
182 if ((status < STATUS_OP) && (!is_uline(user->server)))
184 WriteServ(user->fd,"482 %s %s :You're not a channel operator",user->nick, chan->name);
190 return this->Grant(d,chan,UCMODE_HOP);
195 char* ModeParser::GiveVoice(userrec *user,char *dest,chanrec *chan,int status)
197 userrec *d = this->SanityChecks(user,dest,chan,status);
204 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_VOICE));
206 if (MOD_RESULT == ACR_DENY)
208 if (MOD_RESULT == ACR_DEFAULT)
210 if ((status < STATUS_HOP) && (!is_uline(user->server)))
212 WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, chan->name);
218 return this->Grant(d,chan,UCMODE_VOICE);
223 char* ModeParser::TakeOps(userrec *user,char *dest,chanrec *chan,int status)
225 userrec *d = this->SanityChecks(user,dest,chan,status);
232 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEOP));
234 if (MOD_RESULT == ACR_DENY)
236 if (MOD_RESULT == ACR_DEFAULT)
238 if ((status < STATUS_OP) && (!is_uline(user->server)) && (IS_LOCAL(user)))
240 WriteServ(user->fd,"482 %s %s :You are not a channel operator",user->nick, chan->name);
246 return this->Revoke(d,chan,UCMODE_OP);
251 char* ModeParser::TakeHops(userrec *user,char *dest,chanrec *chan,int status)
253 userrec *d = this->SanityChecks(user,dest,chan,status);
260 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEHALFOP));
262 if (MOD_RESULT == ACR_DENY)
264 if (MOD_RESULT == ACR_DEFAULT)
266 /* Tweak by Brain suggested by w00t, allow a halfop to dehalfop themselves */
267 if ((user != d) && ((status < STATUS_OP) && (!is_uline(user->server))))
269 WriteServ(user->fd,"482 %s %s :You are not a channel operator",user->nick, chan->name);
275 return this->Revoke(d,chan,UCMODE_HOP);
280 char* ModeParser::TakeVoice(userrec *user,char *dest,chanrec *chan,int status)
282 userrec *d = this->SanityChecks(user,dest,chan,status);
289 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,d,chan,AC_DEVOICE));
291 if (MOD_RESULT == ACR_DENY)
293 if (MOD_RESULT == ACR_DEFAULT)
295 if ((status < STATUS_HOP) && (!is_uline(user->server)))
297 WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, chan->name);
303 return this->Revoke(d,chan,UCMODE_VOICE);
308 char* ModeParser::AddBan(userrec *user,char *dest,chanrec *chan,int status)
311 int toomanyexclamation = 0;
314 if ((!user) || (!dest) || (!chan) || (!*dest))
316 log(DEFAULT,"*** BUG *** AddBan was given an invalid parameter");
320 for (char* i = dest; *i; i++)
322 if ((*i < 32) || (*i > 126))
328 toomanyexclamation++;
336 if (toomanyexclamation != 1 || toomanyat != 1)
338 * this stops sillyness like n!u!u!u@h, though note that most
339 * ircds don't actually verify banmask validity. --w00t
343 long maxbans = GetMaxBans(chan->name);
344 if ((unsigned)chan->bans.size() > (unsigned)maxbans)
346 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);
350 log(DEBUG,"AddBan: %s %s",chan->name,user->nick);
353 FOREACH_RESULT(I_OnAddBan,OnAddBan(user,chan,dest));
358 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
360 if (!strcasecmp(i->data,dest))
362 // dont allow a user to set the same ban twice
368 strlcpy(b.data,dest,MAXBUF);
371 strlcpy(b.set_by,user->nick,NICKMAX-1);
375 strlcpy(b.set_by,Config->ServerName,NICKMAX-1);
377 chan->bans.push_back(b);
381 char* ModeParser::TakeBan(userrec *user,char *dest,chanrec *chan,int status)
383 if ((!user) || (!dest) || (!chan) || (!*dest)) {
384 log(DEFAULT,"*** BUG *** TakeBan was given an invalid parameter");
388 log(DEBUG,"del_ban: %s %s",chan->name,user->nick);
389 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
391 if (!strcasecmp(i->data,dest))
394 FOREACH_RESULT(I_OnDelBan,OnDelBan(user,chan,dest));
405 /** ModeParser::CompressModes()
406 * Tidies up redundant modes,
407 * e.g. +nt-nt+i becomes +-+i
408 * A section further down the chain tidies up the +-+- crap.
410 std::string ModeParser::CompressModes(std::string modes,bool channelmodes)
413 * OK, iterate over the mode string and count how many times a certain mode appears in it.
414 * Then, erase all instances of any character that appears more than once.
415 * This only operates on modes with no parameters, you can still +v-v+v-v+v-v to your heart's content.
418 /* Do we really need an int here? Can you fit enough modes in a line to overflow a short? */
421 memset(counts, 0, sizeof(counts));
422 memset(active, 0, sizeof(active));
424 for(unsigned char* i = (unsigned char*)modes.c_str(); *i; i++)
426 if((*i == '+') || (*i == '-'))
429 if(!channelmodes || (channelmodes && (strchr("itnmsp", *i) || (ModeDefined(*i, MT_CHANNEL) && !ModeDefinedOn(*i,MT_CHANNEL) && !ModeDefinedOff(*i,MT_CHANNEL)))))
431 log(DEBUG,"Tidy mode %c", *i);
437 for(unsigned char j = 65; j < 127; j++)
439 if ((counts[j] > 1) && (active[j] == true))
441 std::string::size_type pos;
443 while((pos = modes.find(j)) != std::string::npos)
445 log(DEBUG, "Deleting occurence of mode %c...", j);
447 log(DEBUG,"New mode line: %s", modes.c_str());
455 void ModeParser::ProcessModes(char **parameters,userrec* user,chanrec *chan,int status, int pcnt, bool servermode, bool silent, bool local)
457 if ((!parameters) || (pcnt < 2)) {
461 char outlist[MAXBUF];
469 bool k_set = false, l_set = false, previously_set_l = false, previously_unset_l = false, previously_set_k = false, previously_unset_k = false;
475 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user,NULL,chan,AC_GENERAL_MODE));
476 if (MOD_RESULT == ACR_DENY)
480 std::string tidied = this->CompressModes(parameters[1],true);
481 strlcpy(mlist,tidied.c_str(),MAXBUF);
482 char* modelist = mlist;
484 *outlist = *modelist;
485 char* outl = outlist+1;
487 mdir = (*modelist == '+');
489 log(DEBUG,"process_modes: modelist: %s",modelist);
491 int len = tidied.length();
492 while (modelist[len-1] == ' ')
493 modelist[--len] = '\0';
495 for (char* modechar = (modelist + 1); *modechar; ptr++, modechar++)
499 /* If we have more than MAXMODES changes in one line,
500 * drop all after the MAXMODES
521 if ((param >= pcnt)) break;
522 log(DEBUG,"Enough parameters left");
527 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'o', parameters[param], true, 1));
530 r = GiveOps(user,parameters[param++],chan,status);
537 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'o', parameters[param], false, 1));
540 r = TakeOps(user,parameters[param++],chan,status);
552 if (((param >= pcnt)) || (!Config->AllowHalfop)) break;
557 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'h', parameters[param], true, 1));
560 r = GiveHops(user,parameters[param++],chan,status);
567 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'h', parameters[param], false, 1));
570 r = TakeHops(user,parameters[param++],chan,status);
583 if ((param >= pcnt)) break;
588 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'v', parameters[param], true, 1));
591 r = GiveVoice(user,parameters[param++],chan,status);
598 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'v', parameters[param], false, 1));
601 r = TakeVoice(user,parameters[param++],chan,status);
613 if ((param >= pcnt)) break;
618 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'b', parameters[param], true, 1));
621 r = AddBan(user,parameters[param++],chan,status);
628 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'b', parameters[param], false, 1));
631 r = TakeBan(user,parameters[param++],chan,status);
638 outpars[pc++] = parameters[param-1];
652 if (previously_unset_k)
654 previously_set_k = true;
659 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'k', parameters[param], true, 1));
664 strlcpy(key,parameters[param++],32);
666 strlcpy(chan->key,key,MAXBUF);
674 /* checks on -k are case sensitive and only accurate to the
675 first 32 characters */
676 if (previously_set_k)
678 previously_unset_k = true;
682 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'k', parameters[param], false, 1));
685 strlcpy(key,parameters[param++],32);
686 /* only allow -k if correct key given */
687 if (!strcmp(chan->key,key))
701 if (previously_set_l)
703 previously_unset_l = true;
705 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'l', "", false, 0));
716 if ((param >= pcnt)) break;
721 if (previously_unset_l)
723 previously_set_l = true;
724 bool invalid = false;
725 for (char* f = parameters[param]; *f; f++)
727 if ((*f < '0') || (*f > '9'))
732 /* If the limit is < 1, or the new limit is the current limit, dont allow */
733 if ((atoi(parameters[param]) < 1) || ((chan->limit > 0) && (atoi(parameters[param]) == chan->limit)))
742 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'l', parameters[param], true, 1));
746 chan->limit = atoi(parameters[param]);
748 // reported by mech: large values cause underflow
750 chan->limit = 0x7FFF;
756 outpars[pc++] = parameters[param++];
764 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'i', "", mdir, 0));
769 if (!(chan->binarymodes & CM_INVITEONLY)) *outl++ = 'i';
770 chan->binarymodes |= CM_INVITEONLY;
774 if (chan->binarymodes & CM_INVITEONLY) *outl++ = 'i';
775 chan->binarymodes &= ~CM_INVITEONLY;
782 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 't', "", mdir, 0));
787 if (!(chan->binarymodes & CM_TOPICLOCK)) *outl++ = 't';
788 chan->binarymodes |= CM_TOPICLOCK;
792 if (chan->binarymodes & CM_TOPICLOCK) *outl++ = 't';
793 chan->binarymodes &= ~CM_TOPICLOCK;
800 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'n', "", mdir, 0));
805 if (!(chan->binarymodes & CM_NOEXTERNAL)) *outl++ = 'n';
806 chan->binarymodes |= CM_NOEXTERNAL;
810 if (chan->binarymodes & CM_NOEXTERNAL) *outl++ = 'n';
811 chan->binarymodes &= ~CM_NOEXTERNAL;
818 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'm', "", mdir, 0));
823 if (!(chan->binarymodes & CM_MODERATED)) *outl++ = 'm';
824 chan->binarymodes |= CM_MODERATED;
828 if (chan->binarymodes & CM_MODERATED) *outl++ = 'm';
829 chan->binarymodes &= ~CM_MODERATED;
836 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 's', "", mdir, 0));
841 if (!(chan->binarymodes & CM_SECRET)) *outl++ = 's';
842 chan->binarymodes |= CM_SECRET;
843 if (chan->binarymodes & CM_PRIVATE)
845 chan->binarymodes &= ~CM_PRIVATE;
848 *outl++ = '-'; *outl++ = 'p'; *outl++ = '+';
854 if (chan->binarymodes & CM_SECRET) *outl++ = 's';
855 chan->binarymodes &= ~CM_SECRET;
862 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, 'p', "", mdir, 0));
867 if(!(chan->binarymodes & CM_PRIVATE))
870 chan->binarymodes |= CM_PRIVATE;
872 if(chan->binarymodes & CM_SECRET)
874 chan->binarymodes &= ~CM_SECRET;
883 if(chan->binarymodes & CM_PRIVATE)
886 chan->binarymodes &= ~CM_PRIVATE;
894 bool x = chan->custom_modes[*modechar-65];
895 if ((!x && !mdir) || (x && mdir))
897 if (!ModeIsListMode(*modechar,MT_CHANNEL))
899 log(DEBUG,"Mode %c isnt set on %s but trying to remove!",*modechar,chan->name);
903 if (ModeDefined(*modechar,MT_CHANNEL))
905 /* A module has claimed this mode */
908 if ((ModeDefinedOn(*modechar,MT_CHANNEL)>0) && (mdir))
910 p.push_back(parameters[param]);
912 if ((ModeDefinedOff(*modechar,MT_CHANNEL)>0) && (!mdir))
914 p.push_back(parameters[param]);
917 bool handled = false;
920 // we're supposed to have a parameter, but none was given... so dont handle the mode.
921 if (((ModeDefinedOn(*modechar,MT_CHANNEL)>0) && (mdir)) || ((ModeDefinedOff(*modechar,MT_CHANNEL)>0) && (!mdir)))
923 log(DEBUG,"Not enough parameters for module-mode %c",*modechar);
928 // BIG ASS IDIOTIC CODER WARNING!
929 // Using OnRawMode on another modules mode's behavour
930 // will confuse the crap out of admins! just because you CAN
931 // do it, doesnt mean you SHOULD!
933 std::string para = "";
937 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, *modechar, para, mdir, pcnt));
940 for (int i = 0; i <= MODCOUNT; i++)
944 int t = modules[i]->OnExtendedMode(user,chan,*modechar,MT_CHANNEL,mdir,p);
947 log(DEBUG,"OnExtendedMode returned nonzero for a module");
948 if (ModeIsListMode(*modechar,MT_CHANNEL))
961 outpars[pc++] = parameters[param++];
967 chan->SetCustomMode(*modechar,mdir);
968 // include parameters in output if mode has them
969 if ((ModeDefinedOn(*modechar,MT_CHANNEL)>0) && (mdir))
973 chan->SetCustomModeParam(*modechar,parameters[param],mdir);
974 outpars[pc++] = parameters[param++];
978 // break, because only one module can handle the mode.
987 WriteServ(user->fd,"472 %s %c :is unknown mode char to me",user->nick,*modechar);
993 /* Null terminate it now we're done */
997 /************ Fast, but confusing string tidying ************/
999 while (*outl && (*outl < 'A'))
1001 /* outl now points to the first mode character after +'s and -'s */
1003 /* Now points at first mode-modifier + or - symbol */
1005 /* Now we tidy off any trailing -'s etc */
1008 while ((*--trim == '+') || (*trim == '-'))
1010 /************ Done wih the string tidy functions ************/
1013 /* The mode change must be at least two characters long (+ or - and at least one mode) */
1014 if (((*outl == '+') || (*outl == '-')) && *(outl+1))
1016 for (ptr = 0; ptr < pc; ptr++)
1018 charlcat(outl,' ',MAXBUF);
1019 strlcat(outl,outpars[ptr],MAXBUF-1);
1023 log(DEBUG,"Local mode change");
1024 WriteChannelLocal(chan, user, "MODE %s %s",chan->name,outl);
1025 FOREACH_MOD(I_OnMode,OnMode(user, chan, TYPE_CHANNEL, outl));
1033 WriteChannelWithServ(Config->ServerName,chan,"MODE %s %s",chan->name,outl);
1041 WriteChannel(chan,user,"MODE %s %s",chan->name,outl);
1042 FOREACH_MOD(I_OnMode,OnMode(user, chan, TYPE_CHANNEL, outl));
1049 // based on sourcemodes, return true or false to determine if umode is a valid mode a user may set on themselves or others.
1051 bool ModeParser::AllowedUmode(char umode, char* sourcemodes,bool adding,bool serveroverride)
1053 bool sourceoper = (strchr(sourcemodes,'o') != NULL);
1054 log(DEBUG,"Allowed_umode: %c %s",umode,sourcemodes);
1055 // Servers can +o and -o arbitrarily
1056 if ((serveroverride == true) && (umode == 'o'))
1060 // RFC1459 specified modes
1061 if ((umode == 'w') || (umode == 's') || (umode == 'i'))
1063 /* umode allowed by RFC1459 scemantics */
1067 /* user may not +o themselves or others, but an oper may de-oper other opers or themselves */
1068 if (sourceoper && !adding)
1072 else if (umode == 'o')
1074 /* Bad oper, bad bad! */
1078 /* process any module-defined modes that need oper */
1079 if ((ModeDefinedOper(umode,MT_CLIENT)) && (sourceoper))
1081 log(DEBUG,"umode %c allowed by module handler (oper only mode)",umode);
1084 else if (ModeDefined(umode,MT_CLIENT))
1086 // process any module-defined modes that don't need oper
1087 log(DEBUG,"umode %c allowed by module handler (non-oper mode)",umode);
1088 if ((ModeDefinedOper(umode,MT_CLIENT)) && (!sourceoper))
1090 // no, this mode needs oper, and this user 'aint got what it takes!
1096 // anything else - return false.
1097 log(DEBUG,"umode %c not known by any ruleset",umode);
1101 bool ModeParser::ProcessModuleUmode(char umode, userrec* source, void* dest, bool adding)
1108 strlcpy(s2->nick,Config->ServerName,NICKMAX-1);
1117 if (ModeDefined(umode,MT_CLIENT))
1119 for (int i = 0; i <= MODCOUNT; i++)
1121 if (modules[i]->OnExtendedMode(source,(void*)dest,umode,MT_CLIENT,adding,p))
1123 log(DEBUG,"Module %s claims umode %c",Config->module_names[i].c_str(),umode);
1127 log(DEBUG,"No module claims umode %c",umode);
1146 void cmd_mode::Handle (char **parameters, int pcnt, userrec *user)
1149 userrec* dest = Find(parameters[0]);
1153 char outpars[MAXBUF];
1154 bool next_ok = true;
1159 if ((dest) && (pcnt == 1))
1161 WriteServ(user->fd,"221 %s :+%s",dest->nick,dest->modes);
1164 else if ((dest) && (pcnt > 1))
1166 std::string tidied = ServerInstance->ModeGrok->CompressModes(parameters[1],false);
1167 parameters[1] = (char*)tidied.c_str();
1169 char dmodes[MAXBUF];
1170 strlcpy(dmodes,dest->modes,MAXMODES);
1171 log(DEBUG,"pulled up dest user modes: %s",dmodes);
1176 if ((*user->oper) || (is_uline(user->server)))
1187 WriteServ(user->fd,"482 %s :Can't change mode for other users",user->nick);
1191 outpars[0] = *parameters[1];
1193 direction = (*parameters[1] == '+');
1195 if ((*parameters[1] != '+') && (*parameters[1] != '-'))
1198 for (char* i = parameters[1]; *i; i++)
1200 if ((i != parameters[1]) && (*i != '+') && (*i != '-'))
1209 if ((direction != 1) && (next_ok))
1211 charlcat(outpars,'+',MAXBUF);
1218 if ((direction != 0) && (next_ok))
1220 charlcat(outpars,'-',MAXBUF);
1234 if ((*i == 'i') || (*i == 'w') || (*i == 's') || (ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,direction,false)))
1243 if ((!strchr(dmodes,*i)) && (ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,true,false)))
1245 if ((ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)) || (*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o'))
1247 charlcat(dmodes,*i,53);
1248 charlcat(outpars,*i,MAXMODES);
1252 FOREACH_MOD(I_OnGlobalOper,OnGlobalOper(dest));
1255 dest->modebits |= UM_INVISIBLE;
1258 dest->modebits |= UM_SERVERNOTICE;
1261 dest->modebits |= UM_WALLOPS;
1271 if ((ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,false,false)) && (strchr(dmodes,*i)))
1273 if ((ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)) || (*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o'))
1275 charlcat(outpars,*i,MAXMODES);
1276 charremove(dmodes,*i);
1284 dest->modebits &= ~UM_INVISIBLE;
1287 dest->modebits &= ~UM_SERVERNOTICE;
1290 dest->modebits &= ~UM_WALLOPS;
1307 for (char* i = outpars; *i;)
1310 if (((*i == '-') || (*i == '+')) && ((*(i+1) == '-') || (*(i+1) == '+')))
1312 // someones playing silly buggers and trying
1313 // to put a +- or -+ into the line...
1318 // Someone's trying to make the last character in
1319 // the line be a + or - symbol.
1320 if ((*i == '-') || (*i == '+'))
1328 if ((*b) && (!IS_SINGLE(b,'+')) && (!IS_SINGLE(b,'-')))
1330 WriteTo(user, dest, "MODE %s :%s", dest->nick, b);
1331 FOREACH_MOD(I_OnMode,OnMode(user, dest, TYPE_USER, b));
1334 log(DEBUG,"Stripped mode line");
1335 log(DEBUG,"Line dest is now %s",dmodes);
1336 strlcpy(dest->modes,dmodes,MAXMODES-1);
1344 chan = FindChan(parameters[0]);
1349 /* just /modes #channel */
1350 WriteServ(user->fd,"324 %s %s +%s",user->nick, chan->name, chanmodes(chan, chan->HasUser(user)));
1351 WriteServ(user->fd,"329 %s %s %d", user->nick, chan->name, chan->created);
1356 char* mode = parameters[1];
1363 FOREACH_RESULT(I_OnRawMode,OnRawMode(user, chan, *mode, "", false, 0));
1368 for (BanList::iterator i = chan->bans.begin(); i != chan->bans.end(); i++)
1370 WriteServ(user->fd,"367 %s %s %s %s %d",user->nick, chan->name, i->data, i->set_by, i->set_time);
1372 WriteServ(user->fd,"368 %s %s :End of channel ban list",user->nick, chan->name);
1376 if ((ModeDefined(*mode,MT_CHANNEL)) && (ModeIsListMode(*mode,MT_CHANNEL)))
1378 // list of items for an extmode
1379 log(DEBUG,"Calling OnSendList for all modules, list output for mode %c",*mode);
1380 FOREACH_MOD(I_OnSendList,OnSendList(user,chan,*mode));
1386 if ((IS_LOCAL(user)) && (!is_uline(user->server)) && (!chan->HasUser(user)))
1388 WriteServ(user->fd,"442 %s %s :You're not on that channel!",user->nick, chan->name);
1393 FOREACH_RESULT(I_OnAccessCheck,OnAccessCheck(user, NULL, chan, AC_GENERAL_MODE));
1395 if(MOD_RESULT == ACR_DENY)
1398 if(MOD_RESULT == ACR_DEFAULT)
1400 if ((IS_LOCAL(user)) && (cstatus(user,chan) < STATUS_HOP))
1402 WriteServ(user->fd,"482 %s %s :You must be at least a half-operator to change modes on this channel",user->nick, chan->name);
1407 ServerInstance->ModeGrok->ProcessModes(parameters,user,chan,cstatus(user,chan),pcnt,false,false,false);
1411 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);
1419 void ModeParser::ServerMode(char **parameters, int pcnt, userrec *user)
1422 userrec* dest = Find(parameters[0]);
1425 char outpars[MAXBUF];
1426 bool next_ok = true;
1428 if ((dest) && (pcnt > 1))
1430 std::string tidied = ServerInstance->ModeGrok->CompressModes(parameters[1],false);
1431 parameters[1] = (char*)tidied.c_str();
1433 char dmodes[MAXBUF];
1434 strlcpy(dmodes,dest->modes,MAXBUF);
1436 outpars[0] = *parameters[1];
1438 direction = (*parameters[1] == '+');
1440 if ((*parameters[1] != '+') && (*parameters[1] != '-'))
1443 for (char* i = parameters[1]; *i; i++)
1445 if ((i != parameters[1]) && (*i != '+') && (*i != '-'))
1454 if ((direction != 1) && (next_ok))
1457 charlcat(outpars,'+',MAXBUF);
1463 if ((direction != 0) && (next_ok))
1466 charlcat(outpars,'-',MAXBUF);
1472 log(DEBUG,"begin mode processing entry");
1478 log(DEBUG,"umode %c being added",*i);
1479 if ((!strchr(dmodes,*i)) && (ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,true,true)))
1481 log(DEBUG,"umode %c is an allowed umode",*i);
1482 if ((*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o') || (ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)))
1484 charlcat(dmodes,*i,MAXBUF);
1485 charlcat(outpars,*i,53);
1489 dest->modebits |= UM_INVISIBLE;
1492 dest->modebits |= UM_SERVERNOTICE;
1495 dest->modebits |= UM_WALLOPS;
1505 // can only remove a mode they already have
1506 log(DEBUG,"umode %c being removed",*i);
1507 if ((ServerInstance->ModeGrok->AllowedUmode(*i,user->modes,false,true)) && (strchr(dmodes,*i)))
1509 log(DEBUG,"umode %c is an allowed umode",*i);
1510 if ((*i == 'i') || (*i == 's') || (*i == 'w') || (*i == 'o') || (ServerInstance->ModeGrok->ProcessModuleUmode(*i, user, dest, direction)))
1512 charlcat(outpars,*i,MAXBUF);
1513 charremove(dmodes,*i);
1517 dest->modebits &= ~UM_INVISIBLE;
1520 dest->modebits &= ~UM_SERVERNOTICE;
1523 dest->modebits &= ~UM_WALLOPS;
1540 for (char* i = outpars; *i;)
1543 if (((*i == '-') || (*i == '+')) && ((*(i+1) == '-') || (*(i+1) == '+')))
1545 // someones playing silly buggers and trying
1546 // to put a +- or -+ into the line...
1551 // Someone's trying to make the last character in
1552 // the line be a + or - symbol.
1553 if ((*i == '-') || (*i == '+'))
1561 if ((*b) && (!IS_SINGLE(b,'+')) && (!IS_SINGLE(b,'-')))
1563 WriteTo(user, dest, "MODE %s :%s", dest->nick, b);
1564 FOREACH_MOD(I_OnMode,OnMode(user, dest, TYPE_USER, b));
1567 log(DEBUG,"Stripped mode line");
1568 log(DEBUG,"Line dest is now %s",dmodes);
1569 strlcpy(dest->modes,dmodes,MAXMODES-1);
1576 Ptr = FindChan(parameters[0]);
1579 ServerInstance->ModeGrok->ProcessModes(parameters,user,Ptr,STATUS_OP,pcnt,true,false,false);
1583 WriteServ(user->fd,"401 %s %s :No such nick/channel",user->nick, parameters[0]);