]> git.netwichtig.de Git - user/henk/code/inspircd.git/blob - src/mode.cpp
b3886eefe402324205700c97592abeba603b79e8
[user/henk/code/inspircd.git] / src / mode.cpp
1 /*       +------------------------------------+
2  *       | Inspire Internet Relay Chat Daemon |
3  *       +------------------------------------+
4  *
5  *  InspIRCd is copyright (C) 2002-2006 ChatSpike-Dev.
6  *                       E-mail:
7  *              <brain@chatspike.net>
8  *                <Craig@chatspike.net>
9  *     
10  * Written by Craig Edwards, Craig McLure, and others.
11  * This program is free but copyrighted software; see
12  *          the file COPYING for details.
13  *
14  * ---------------------------------------------------
15  */
16
17 using namespace std;
18
19 #include "inspircd_config.h"
20 #include "inspircd.h"
21 #include "configreader.h"
22 #include <unistd.h>
23 #include "hash_map.h"
24 #include "connection.h"
25 #include "users.h"
26 #include "modules.h"
27 #include "inspstring.h"
28 #include "helperfuncs.h"
29 #include "commands.h"
30 #include "mode.h"
31
32 /* +s (secret) */
33 #include "modes/cmode_s.h"
34 /* +p (private) */
35 #include "modes/cmode_p.h"
36 /* +b (bans) */
37 #include "modes/cmode_b.h"
38 /* +m (moderated) */
39 #include "modes/cmode_m.h"
40 /* +t (only (half) ops can change topic) */
41 #include "modes/cmode_t.h"
42 /* +n (no external messages) */
43 #include "modes/cmode_n.h"
44 /* +i (invite only) */
45 #include "modes/cmode_i.h"
46 /* +k (keyed channel) */
47 #include "modes/cmode_k.h"
48 /* +l (channel user limit) */
49 #include "modes/cmode_l.h"
50 /* +o (channel op) */
51 #include "modes/cmode_o.h"
52 /* +h (channel halfop) */
53 #include "modes/cmode_h.h"
54 /* +v (channel voice) */
55 #include "modes/cmode_v.h"
56
57 /* +s (server notices) */
58 #include "modes/umode_s.h"
59 /* +w (see wallops) */
60 #include "modes/umode_w.h"
61 /* +i (invisible) */
62 #include "modes/umode_i.h"
63 /* +o (operator) */
64 #include "modes/umode_o.h"
65 /* +n (notice mask - our implementation of snomasks) */
66 #include "modes/umode_n.h"
67
68 ModeHandler::ModeHandler(InspIRCd* Instance, char modeletter, int parameters_on, int parameters_off, bool listmode, ModeType type, bool operonly)
69         : ServerInstance(Instance), mode(modeletter), n_params_on(parameters_on), n_params_off(parameters_off), list(listmode), m_type(type), oper(operonly)
70 {
71 }
72
73 ModeHandler::~ModeHandler()
74 {
75 }
76
77 bool ModeHandler::IsListMode()
78 {
79         return list;
80 }
81
82 ModeType ModeHandler::GetModeType()
83 {
84         return m_type;
85 }
86
87 bool ModeHandler::NeedsOper()
88 {
89         return oper;
90 }
91
92 int ModeHandler::GetNumParams(bool adding)
93 {
94         return adding ? n_params_on : n_params_off;
95 }
96
97 char ModeHandler::GetModeChar()
98 {
99         return mode;
100 }
101
102 ModeAction ModeHandler::OnModeChange(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding)
103 {
104         return MODEACTION_DENY;
105 }
106
107 ModePair ModeHandler::ModeSet(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter)
108 {
109         if (dest)
110         {
111                 return std::make_pair(dest->IsModeSet(this->mode), "");
112         }
113         else
114         {
115                 return std::make_pair(channel->IsModeSet(this->mode), "");
116         }
117 }
118
119 void ModeHandler::DisplayList(userrec* user, chanrec* channel)
120 {
121 }
122
123 bool ModeHandler::CheckTimeStamp(time_t theirs, time_t ours, const std::string &their_param, const std::string &our_param, chanrec* channel)
124 {
125         return (ours < theirs);
126 }
127
128 ModeWatcher::ModeWatcher(InspIRCd* Instance, char modeletter, ModeType type) : ServerInstance(Instance), mode(modeletter), m_type(type)
129 {
130 }
131
132 ModeWatcher::~ModeWatcher()
133 {
134 }
135
136 char ModeWatcher::GetModeChar()
137 {
138         return mode;
139 }
140
141 ModeType ModeWatcher::GetModeType()
142 {
143         return m_type;
144 }
145
146 bool ModeWatcher::BeforeMode(userrec* source, userrec* dest, chanrec* channel, std::string &parameter, bool adding, ModeType type)
147 {
148         return true;
149 }
150
151 void ModeWatcher::AfterMode(userrec* source, userrec* dest, chanrec* channel, const std::string &parameter, bool adding, ModeType type)
152 {
153 }
154
155 userrec* ModeParser::SanityChecks(userrec *user,const char *dest,chanrec *chan,int status)
156 {
157         userrec *d;
158         if ((!user) || (!dest) || (!chan) || (!*dest))
159         {
160                 return NULL;
161         }
162         d = ServerInstance->FindNick(dest);
163         if (!d)
164         {
165                 user->WriteServ("401 %s %s :No such nick/channel",user->nick, dest);
166                 return NULL;
167         }
168         return d;
169 }
170
171 const char* ModeParser::Grant(userrec *d,chanrec *chan,int MASK)
172 {
173         if (!chan)
174                 return "";
175
176         for (std::vector<ucrec*>::const_iterator i = d->chans.begin(); i != d->chans.end(); i++)
177         {
178                 ucrec* n = (ucrec*)(*i);
179                 if (n->channel == chan)
180                 {
181                         if (n->uc_modes & MASK)
182                         {
183                                 return "";
184                         }
185                         n->uc_modes = n->uc_modes | MASK;
186                         switch (MASK)
187                         {
188                                 case UCMODE_OP:
189                                         n->channel->AddOppedUser(d);
190                                 break;
191                                 case UCMODE_HOP:
192                                         n->channel->AddHalfoppedUser(d);
193                                 break;
194                                 case UCMODE_VOICE:
195                                         n->channel->AddVoicedUser(d);
196                                 break;
197                         }
198                         ServerInstance->Log(DEBUG,"grant: %s %s",n->channel->name,d->nick);
199                         return d->nick;
200                 }
201         }
202         return "";
203 }
204
205 const char* ModeParser::Revoke(userrec *d,chanrec *chan,int MASK)
206 {
207         if (!chan)
208                 return "";
209
210         for (std::vector<ucrec*>::const_iterator i = d->chans.begin(); i != d->chans.end(); i++)
211         {
212                 ucrec* n = (ucrec*)(*i);
213                 if (n->channel == chan)
214                 {
215                         if ((n->uc_modes & MASK) == 0)
216                         {
217                                 return "";
218                         }
219                         n->uc_modes ^= MASK;
220                         switch (MASK)
221                         {
222                                 case UCMODE_OP:
223                                         n->channel->DelOppedUser(d);
224                                 break;
225                                 case UCMODE_HOP:
226                                         n->channel->DelHalfoppedUser(d);
227                                 break;
228                                 case UCMODE_VOICE:
229                                         n->channel->DelVoicedUser(d);
230                                 break;
231                         }
232                         ServerInstance->Log(DEBUG,"revoke: %s %s",n->channel->name,d->nick);
233                         return d->nick;
234                 }
235         }
236         return "";
237 }
238
239 void ModeParser::DisplayCurrentModes(userrec *user, userrec* targetuser, chanrec* targetchannel, const char* text)
240 {
241         if (targetchannel)
242         {
243                 /* Display channel's current mode string */
244                 user->WriteServ("324 %s %s +%s",user->nick, targetchannel->name, targetchannel->ChanModes(targetchannel->HasUser(user)));
245                 user->WriteServ("329 %s %s %d", user->nick, targetchannel->name, targetchannel->created);
246                 return;
247         }
248         else if (targetuser)
249         {
250                 /* Display user's current mode string */
251                 user->WriteServ("221 %s :+%s",targetuser->nick,targetuser->FormatModes());
252                 user->WriteServ("008 %s :+%s", targetuser->nick, targetuser->FormatNoticeMasks());
253                 return;
254         }
255
256         /* No such nick/channel */
257         user->WriteServ("401 %s %s :No such nick/channel",user->nick, text);
258         return;
259 }
260
261 void ModeParser::Process(const char** parameters, int pcnt, userrec *user, bool servermode)
262 {
263         std::string target = parameters[0];
264         ModeType type = MODETYPE_USER;
265         unsigned char mask = 0;
266         chanrec* targetchannel = ServerInstance->FindChan(parameters[0]);
267         userrec* targetuser  = ServerInstance->FindNick(parameters[0]);
268
269         ServerInstance->Log(DEBUG,"ModeParser::Process start");
270
271         /* Special case for displaying the list for listmodes,
272          * e.g. MODE #chan b, or MODE #chan +b without a parameter
273          */
274         if ((targetchannel) && (pcnt == 2))
275         {
276                 const char* mode = parameters[1];
277                 if (*mode == '+')
278                 mode++;
279                 unsigned char handler_id = ((*mode) - 65) | MASK_CHANNEL;
280                 ModeHandler* mh = modehandlers[handler_id];
281                 if ((mh) && (mh->IsListMode()))
282                 {
283                         mh->DisplayList(user, targetchannel);
284                         return;
285                 }
286         }
287
288         if (pcnt == 1)
289         {
290                 this->DisplayCurrentModes(user, targetuser, targetchannel, parameters[0]);
291         }
292         else if (pcnt > 1)
293         {
294                 if (targetchannel)
295                 {
296                         type = MODETYPE_CHANNEL;
297                         mask = MASK_CHANNEL;
298
299                         /* Extra security checks on channel modes
300                          * (e.g. are they a (half)op?
301                          */
302
303                         if ((IS_LOCAL(user)) && (targetchannel->GetStatus(user) < STATUS_HOP))
304                         {
305                                 /* We don't have halfop */
306                                 ServerInstance->Log(DEBUG,"The user is not a halfop or above, checking other reasons for being able to set the modes");
307
308                                 /* Are we a uline or is it a servermode? */
309                                 if ((!ServerInstance->ULine(user->server)) && (!servermode))
310                                 {
311                                         /* Not enough permission:
312                                          * NOT a uline and NOT a servermode,
313                                          * OR, NOT halfop or above.
314                                          */
315                                         user->WriteServ("482 %s %s :You're not a channel (half)operator",user->nick, targetchannel->name);
316                                         return;
317                                 }
318                         }
319                 }
320                 else if (targetuser)
321                 {
322                         type = MODETYPE_USER;
323                         mask = MASK_USER;
324                 }
325                 else
326                 {
327                         /* No such nick/channel */
328                         user->WriteServ("401 %s %s :No such nick/channel",user->nick, parameters[0]);
329                         return;
330                 }
331
332                 std::string mode_sequence = parameters[1];
333                 std::string parameter = "";
334                 std::ostringstream parameter_list;
335                 std::string output_sequence = "";
336                 bool adding = true, state_change = false;
337                 unsigned char handler_id = 0;
338                 int parameter_counter = 2; /* Index of first parameter */
339
340                 for (std::string::const_iterator letter = mode_sequence.begin(); letter != mode_sequence.end(); letter++)
341                 {
342                         unsigned char modechar = *letter;
343
344                         switch (modechar)
345                         {
346                                 /* NB:
347                                  * For + and - mode characters, we don't just stick the character into the output sequence.
348                                  * This is because the user may do something dumb, like: +-+ooo or +oo-+. To prevent this
349                                  * appearing in the output sequence, we store a flag which says there was a state change,
350                                  * which is set on any + or -, however, the + or - that we finish on is only appended to
351                                  * the output stream in the event it is followed by a non "+ or -" character, such as o or v.
352                                  */
353                                 case '+':
354                                         /* The following expression prevents: +o+o nick nick, compressing it to +oo nick nick,
355                                          * however, will allow the + if it is the first item in the sequence, regardless.
356                                          */
357                                         if ((!adding) || (!output_sequence.length()))
358                                                 state_change = true;
359                                         adding = true;
360                                         continue;
361                                 break;
362                                 case '-':
363                                         if ((adding) || (!output_sequence.length()))
364                                                 state_change = true;
365                                         adding = false;
366                                         continue;
367                                 break;
368                                 default:
369
370                                         /**
371                                          * Watch carefully for the sleight of hand trick.
372                                          * 65 is the ascii value of 'A'. We take this from
373                                          * the char we're looking at to get a number between
374                                          * 1 and 127. We then logic-or it to get the hashed
375                                          * position, dependent on wether its a channel or
376                                          * a user mode. This is a little stranger, but a lot
377                                          * faster, than using a map of pairs.
378                                          */
379                                         handler_id = (modechar - 65) | mask;
380
381                                         if (modehandlers[handler_id])
382                                         {
383                                                 bool abort = false;
384
385                                                 for (ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++)
386                                                 {
387                                                         if ((*watchers)->BeforeMode(user, targetuser, targetchannel, parameter, adding, type) == MODEACTION_DENY)
388                                                                 abort = true;
389                                                 }
390                                                 if ((modehandlers[handler_id]->GetModeType() == type) && (!abort))
391                                                 {
392                                                         if (modehandlers[handler_id]->GetNumParams(adding))
393                                                         {
394                                                                 /* This mode expects a parameter, do we have any parameters left in our list to use? */
395                                                                 if (parameter_counter < pcnt)
396                                                                 {
397                                                                         parameter = parameters[parameter_counter++];
398                                                                 }
399                                                                 else
400                                                                 {
401                                                                         /* No parameter, continue to the next mode */
402                                                                         continue;
403                                                                 }
404                                                         }
405
406                                                         /* It's an oper only mode, check if theyre an oper. If they arent,
407                                                          * eat any parameter that  came with the mode, and continue to next
408                                                          */
409                                                         if ((IS_LOCAL(user)) && (modehandlers[handler_id]->NeedsOper()) && (!*user->oper))
410                                                                 continue;
411
412                                                         /* Call the handler for the mode */
413                                                         ModeAction ma = modehandlers[handler_id]->OnModeChange(user, targetuser, targetchannel, parameter, adding);
414
415                                                         if ((modehandlers[handler_id]->GetNumParams(adding)) && (parameter == ""))
416                                                         {
417                                                                 /* The handler nuked the parameter and they are supposed to have one.
418                                                                  * We CANT continue now, even if they actually returned MODEACTION_ALLOW,
419                                                                  * so we bail to the next mode character.
420                                                                  */
421                                                                 continue;
422                                                         }
423
424                                                         if (ma == MODEACTION_ALLOW)
425                                                         {
426                                                                 /* We're about to output a valid mode letter - was there previously a pending state-change? */
427                                                                 if (state_change)
428                                                                         output_sequence.append(adding ? "+" : "-");
429                                                                 
430                                                                 /* Add the mode letter */
431                                                                 output_sequence.push_back(modechar);
432
433                                                                 /* Is there a valid parameter for this mode? If so add it to the parameter list */
434                                                                 if ((modehandlers[handler_id]->GetNumParams(adding)) && (parameter != ""))
435                                                                         parameter_list << " " << parameter;
436
437                                                                 /* Call all the AfterMode events in the mode watchers for this mode */
438                                                                 for (ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++)
439                                                                         (*watchers)->AfterMode(user, targetuser, targetchannel, parameter, adding, type);
440
441                                                                 /* Reset the state change flag */
442                                                                 state_change = false;
443                                                         }
444                                                 }
445                                         }
446                                         else
447                                         {
448                                                 /* No mode handler? Unknown mode character then. */
449                                                 user->WriteServ("472 %s %c :is unknown mode char to me",user->nick, modechar);
450                                         }
451                                 break;
452                         }
453                 }
454                 /* Was there at least one valid mode in the sequence? */
455                 if (output_sequence != "")
456                 {
457                         if (servermode)
458                         {
459                                 if (type == MODETYPE_CHANNEL)
460                                 {
461                                         targetchannel->WriteChannelWithServ(ServerInstance->Config->ServerName, "MODE %s %s%s", targetchannel->name, output_sequence.c_str(), parameter_list.str().c_str());
462                                 }
463                                 else
464                                 {
465                                         targetuser->WriteServ("MODE %s %s",targetuser->nick,output_sequence.c_str());
466                                 }
467                         }
468                         else
469                         {
470                                 if (type == MODETYPE_CHANNEL)
471                                 {
472                                         ServerInstance->Log(DEBUG,"Write output sequence and parameters to channel: %s %s%s",targetchannel->name,output_sequence.c_str(),parameter_list.str().c_str());
473                                         targetchannel->WriteChannel(user,"MODE %s %s%s",targetchannel->name,output_sequence.c_str(),parameter_list.str().c_str());
474                                         FOREACH_MOD(I_OnMode,OnMode(user, targetchannel, TYPE_CHANNEL, output_sequence + parameter_list.str()));
475                                 }
476                                 else
477                                 {
478                                         user->WriteTo(targetuser,"MODE %s %s",targetuser->nick,output_sequence.c_str());
479                                         FOREACH_MOD(I_OnMode,OnMode(user, targetuser, TYPE_USER, output_sequence));
480                                 }
481                         }
482                 }
483         }
484 }
485
486
487 void cmd_mode::Handle (const char** parameters, int pcnt, userrec *user)
488 {
489         if (!user)
490                 return;
491
492         ServerInstance->Modes->Process(parameters, pcnt, user, false);
493
494         return;
495 }
496
497 void ModeParser::CleanMask(std::string &mask)
498 {
499         std::string::size_type pos_of_pling = mask.find_first_of('!');
500         std::string::size_type pos_of_at = mask.find_first_of('@');
501         std::string::size_type pos_of_dot = mask.find_first_of('.');
502         std::string::size_type pos_of_colon = mask.find_first_of(':'); /* Because ipv6 addresses are colon delimited */
503
504         if ((pos_of_pling == std::string::npos) && (pos_of_at == std::string::npos))
505         {
506                 /* Just a nick, or just a host */
507                 if ((pos_of_dot == std::string::npos) && (pos_of_colon == std::string::npos))
508                 {
509                         /* It has no '.' in it, it must be a nick. */
510                         mask.append("!*@*");
511                 }
512                 else
513                 {
514                         /* Got a dot in it? Has to be a host */
515                         mask = "*!*@" + mask;
516                 }
517         }
518         else if ((pos_of_pling == std::string::npos) && (pos_of_at != std::string::npos))
519         {
520                 /* Has an @ but no !, its a user@host */
521                  mask = "*!" + mask;
522         }
523         else if ((pos_of_pling != std::string::npos) && (pos_of_at == std::string::npos))
524         {
525                 /* Has a ! but no @, it must be a nick!ident */
526                 mask.append("@*");
527         }
528 }
529
530 bool ModeParser::AddMode(ModeHandler* mh, unsigned const char modeletter)
531 {
532         unsigned char mask = 0;
533         unsigned char pos = 0;
534
535         /* Yes, i know, this might let people declare modes like '_' or '^'.
536          * If they do that, thats their problem, and if i ever EVER see an
537          * official InspIRCd developer do that, i'll beat them with a paddle!
538          */
539         if ((mh->GetModeChar() < 'A') || (mh->GetModeChar() > 'z'))
540                 return false;
541
542         mh->GetModeType() == MODETYPE_USER ? mask = MASK_USER : mask = MASK_CHANNEL;
543         pos = (mh->GetModeChar()-65) | mask;
544
545         if (modehandlers[pos])
546                 return false;
547
548         modehandlers[pos] = mh;
549         ServerInstance->Log(DEBUG,"ModeParser::AddMode: added mode %c",mh->GetModeChar());
550         return true;
551 }
552
553 ModeHandler* ModeParser::FindMode(unsigned const char modeletter, ModeType mt)
554 {
555         unsigned char mask = 0;
556         unsigned char pos = 0;
557
558         if ((modeletter < 'A') || (modeletter > 'z'))
559                 return NULL;
560
561         mt == MODETYPE_USER ? mask = MASK_USER : mask = MASK_CHANNEL;
562         pos = (modeletter-65) | mask;
563
564         return modehandlers[pos];
565 }
566
567 std::string ModeParser::UserModeList()
568 {
569         char modestr[256];
570         int pointer = 0;
571
572         for (unsigned char mode = 'A'; mode <= 'z'; mode++)
573         {
574                 unsigned char pos = (mode-65) | MASK_USER;
575
576                 if (modehandlers[pos])
577                         modestr[pointer++] = mode;
578         }
579         modestr[pointer++] = 0;
580         return modestr;
581 }
582
583 std::string ModeParser::ChannelModeList()
584 {
585         char modestr[256];
586         int pointer = 0;
587
588         for (unsigned char mode = 'A'; mode <= 'z'; mode++)
589         {
590                 unsigned char pos = (mode-65) | MASK_CHANNEL;
591
592                 if (modehandlers[pos])
593                         modestr[pointer++] = mode;
594         }
595         modestr[pointer++] = 0;
596         return modestr;
597 }
598
599 std::string ModeParser::ParaModeList()
600 {
601         char modestr[256];
602         int pointer = 0;
603
604         for (unsigned char mode = 'A'; mode <= 'z'; mode++)
605         {
606                 unsigned char pos = (mode-65) | MASK_CHANNEL;
607
608                 if ((modehandlers[pos]) && (modehandlers[pos]->GetNumParams(true)))
609                         modestr[pointer++] = mode;
610         }
611         modestr[pointer++] = 0;
612         return modestr;
613 }
614
615 bool ModeParser::AddModeWatcher(ModeWatcher* mw)
616 {
617         unsigned char mask = 0;
618         unsigned char pos = 0;
619
620         if (!mw)
621                 return false;
622
623         if ((mw->GetModeChar() < 'A') || (mw->GetModeChar() > 'z'))
624                 return false;
625
626         mw->GetModeType() == MODETYPE_USER ? mask = MASK_USER : mask = MASK_CHANNEL;
627         pos = (mw->GetModeChar()-65) | mask;
628
629         modewatchers[pos].push_back(mw);
630         ServerInstance->Log(DEBUG,"ModeParser::AddModeWatcher: watching mode %c",mw->GetModeChar());
631
632         return true;
633 }
634
635 bool ModeParser::DelModeWatcher(ModeWatcher* mw)
636 {
637         unsigned char mask = 0;
638         unsigned char pos = 0;
639
640         if (!mw)
641                 return false;
642
643         if ((mw->GetModeType() < 'A') || (mw->GetModeType() > 'z'))
644                 return false;
645
646         mw->GetModeType() == MODETYPE_USER ? mask = MASK_USER : mask = MASK_CHANNEL;
647         pos = (mw->GetModeChar()-65) | mask;
648
649         ModeWatchIter a = find(modewatchers[pos].begin(),modewatchers[pos].end(),mw);
650
651         if (a == modewatchers[pos].end())
652                 return false;
653
654         modewatchers[pos].erase(a);
655         ServerInstance->Log(DEBUG,"ModeParser::DelModeWatcher: stopped watching mode %c",mw->GetModeChar());
656
657         return true;
658 }
659
660 ModeParser::ModeParser(InspIRCd* Instance) : ServerInstance(Instance)
661 {
662         /* Clear mode list */
663         memset(modehandlers, 0, sizeof(modehandlers));
664         memset(modewatchers, 0, sizeof(modewatchers));
665
666         /* Initialise the RFC mode letters */
667
668         /* Start with channel simple modes, no params */
669         this->AddMode(new ModeChannelSecret(Instance), 's');
670         this->AddMode(new ModeChannelPrivate(Instance), 'p');
671         this->AddMode(new ModeChannelModerated(Instance), 'm');
672         this->AddMode(new ModeChannelTopicOps(Instance), 't');
673         this->AddMode(new ModeChannelNoExternal(Instance), 'n');
674         this->AddMode(new ModeChannelInviteOnly(Instance), 'i');
675
676         /* Cannel modes with params */
677         this->AddMode(new ModeChannelKey(Instance), 'k');
678         this->AddMode(new ModeChannelLimit(Instance), 'l');
679
680         /* Channel listmodes */
681         this->AddMode(new ModeChannelBan(Instance), 'b');
682         this->AddMode(new ModeChannelOp(Instance), 'o');
683         this->AddMode(new ModeChannelHalfOp(Instance), 'h');
684         this->AddMode(new ModeChannelVoice(Instance), 'v');
685
686         /* Now for usermodes */
687         this->AddMode(new ModeUserServerNotice(Instance), 's');
688         this->AddMode(new ModeUserWallops(Instance), 'w');
689         this->AddMode(new ModeUserInvisible(Instance), 'i');
690         this->AddMode(new ModeUserOperator(Instance), 'o');
691         this->AddMode(new ModeUserServerNoticeMask(Instance), 'n');
692 }
693
694 bool ModeParser::InsertMode(std::string &output, const char* mode, unsigned short section)
695 {
696         unsigned short currsection = 1;
697         unsigned int pos = output.find("CHANMODES=", 0) + 10; // +10 for the length of "CHANMODES="
698
699         if(section > 4 || section == 0)
700         {
701                 ServerInstance->Log(DEBUG, "InsertMode: CHANMODES doesn't have a section %dh :/", section);
702                 return false;
703         }
704
705         for(; pos < output.size(); pos++)
706         {
707                 if(section == currsection)
708                         break;
709
710                 if(output[pos] == ',')
711                         currsection++;
712         }
713
714         output.insert(pos, mode);
715         return true;
716 }
717