1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * InspIRCd: (C) 2002-2010 InspIRCd Development Team
6 * See: http://wiki.inspircd.org/Credits
8 * This program is free but copyrighted software; see
9 * the file COPYING for details.
11 * ---------------------------------------------------
15 #include "inspstring.h"
18 #include "modes/cmode_s.h"
20 #include "modes/cmode_p.h"
22 #include "modes/cmode_b.h"
24 #include "modes/cmode_m.h"
25 /* +t (only (half) ops can change topic) */
26 #include "modes/cmode_t.h"
27 /* +n (no external messages) */
28 #include "modes/cmode_n.h"
29 /* +i (invite only) */
30 #include "modes/cmode_i.h"
31 /* +k (keyed channel) */
32 #include "modes/cmode_k.h"
33 /* +l (channel user limit) */
34 #include "modes/cmode_l.h"
36 #include "modes/cmode_o.h"
37 /* +v (channel voice) */
38 #include "modes/cmode_v.h"
39 /* +w (see wallops) */
40 #include "modes/umode_w.h"
42 #include "modes/umode_i.h"
44 #include "modes/umode_o.h"
45 /* +s (server notice masks) */
46 #include "modes/umode_s.h"
48 ModeHandler::ModeHandler(Module* Creator, const std::string& Name, char modeletter, ParamSpec Params, ModeType type)
49 : ServiceProvider(Creator, Name, SERVICE_MODE), m_paramtype(TR_TEXT),
50 parameters_taken(Params), mode(modeletter), prefix(0), oper(false),
51 list(false), m_type(type), levelrequired(HALFOP_VALUE)
55 CullResult ModeHandler::cull()
57 if (ServerInstance->Modes)
58 ServerInstance->Modes->DelMode(this);
59 return classbase::cull();
62 ModeHandler::~ModeHandler()
64 if (ServerInstance && ServerInstance->Modes && ServerInstance->Modes->FindMode(mode, m_type) == this)
65 ServerInstance->Logs->Log("MODE", DEFAULT, "ERROR: Destructor for mode %c called while still registered", mode);
68 bool ModeHandler::IsListMode()
73 unsigned int ModeHandler::GetPrefixRank()
78 int ModeHandler::GetNumParams(bool adding)
80 switch (parameters_taken)
85 return adding ? 1 : 0;
92 std::string ModeHandler::GetUserParameter(User* user)
97 ModResult ModeHandler::AccessCheck(User*, Channel*, std::string &, bool)
99 return MOD_RES_PASSTHRU;
102 ModeAction ModeHandler::OnModeChange(User*, User*, Channel*, std::string&, bool)
104 return MODEACTION_DENY;
107 void ModeHandler::DisplayList(User*, Channel*)
111 void ModeHandler::DisplayEmptyList(User*, Channel*)
115 void ModeHandler::OnParameterMissing(User* user, User* dest, Channel* channel)
119 bool ModeHandler::ResolveModeConflict(std::string& theirs, const std::string& ours, Channel*)
121 return (theirs < ours);
124 ModeAction SimpleUserModeHandler::OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
128 if (!dest->IsModeSet(this->GetModeChar()))
130 dest->SetMode(this->GetModeChar(),true);
131 return MODEACTION_ALLOW;
136 if (dest->IsModeSet(this->GetModeChar()))
138 dest->SetMode(this->GetModeChar(),false);
139 return MODEACTION_ALLOW;
143 return MODEACTION_DENY;
147 ModeAction SimpleChannelModeHandler::OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
151 if (!channel->IsModeSet(this->GetModeChar()))
153 channel->SetMode(this->GetModeChar(),true);
154 return MODEACTION_ALLOW;
159 if (channel->IsModeSet(this->GetModeChar()))
161 channel->SetMode(this->GetModeChar(),false);
162 return MODEACTION_ALLOW;
166 return MODEACTION_DENY;
169 ModeAction ParamChannelModeHandler::OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding)
171 if (adding && !ParamValidate(parameter))
172 return MODEACTION_DENY;
173 std::string now = channel->GetModeParameter(this);
174 if (parameter == now)
175 return MODEACTION_DENY;
177 channel->SetModeParam(this, parameter);
179 channel->SetModeParam(this, "");
180 return MODEACTION_ALLOW;
183 bool ParamChannelModeHandler::ParamValidate(std::string& parameter)
188 ModeWatcher::ModeWatcher(Module* Creator, char modeletter, ModeType type)
189 : mode(modeletter), m_type(type), creator(Creator)
193 ModeWatcher::~ModeWatcher()
197 char ModeWatcher::GetModeChar()
202 ModeType ModeWatcher::GetModeType()
207 bool ModeWatcher::BeforeMode(User*, User*, Channel*, std::string&, bool, ModeType)
212 void ModeWatcher::AfterMode(User*, User*, Channel*, const std::string&, bool, ModeType)
216 User* ModeParser::SanityChecks(User *user, const char *dest, Channel *chan, int)
219 if ((!user) || (!dest) || (!chan) || (!*dest))
223 d = ServerInstance->FindNick(dest);
226 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(), dest);
232 void ModeParser::DisplayCurrentModes(User *user, User* targetuser, Channel* targetchannel, const char* text)
236 /* Display channel's current mode string */
237 user->WriteNumeric(RPL_CHANNELMODEIS, "%s %s +%s",user->nick.c_str(), targetchannel->name.c_str(), targetchannel->ChanModes(targetchannel->HasUser(user)));
238 user->WriteNumeric(RPL_CHANNELCREATED, "%s %s %lu", user->nick.c_str(), targetchannel->name.c_str(), (unsigned long)targetchannel->age);
243 if (targetuser == user || user->HasPrivPermission("users/auspex"))
245 /* Display user's current mode string */
246 user->WriteNumeric(RPL_UMODEIS, "%s :+%s",targetuser->nick.c_str(),targetuser->FormatModes());
247 if (IS_OPER(targetuser))
248 user->WriteNumeric(RPL_SNOMASKIS, "%s +%s :Server notice mask", targetuser->nick.c_str(), targetuser->FormatNoticeMasks());
253 user->WriteNumeric(ERR_USERSDONTMATCH, "%s :Can't view modes for other users", user->nick.c_str());
259 ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, bool adding, const unsigned char modechar,
260 std::string ¶meter, bool SkipACL)
262 ModeType type = chan ? MODETYPE_CHANNEL : MODETYPE_USER;
263 unsigned char mask = chan ? MASK_CHANNEL : MASK_USER;
265 ModeHandler *mh = FindMode(modechar, type);
266 int pcnt = mh->GetNumParams(adding);
268 // crop mode parameter size to 250 characters
269 if (parameter.length() > 250)
270 parameter = parameter.substr(0, 250);
272 ModResult MOD_RESULT;
273 FIRST_MOD_RESULT(OnRawMode, MOD_RESULT, (user, chan, modechar, parameter, adding, pcnt));
275 if (IS_LOCAL(user) && (MOD_RESULT == MOD_RES_DENY))
276 return MODEACTION_DENY;
278 if (chan && !SkipACL && (MOD_RESULT != MOD_RES_ALLOW))
280 MOD_RESULT = mh->AccessCheck(user, chan, parameter, adding);
282 if (MOD_RESULT == MOD_RES_DENY)
283 return MODEACTION_DENY;
284 if (MOD_RESULT == MOD_RES_PASSTHRU)
286 unsigned int neededrank = mh->GetLevelRequired();
287 /* Compare our rank on the channel against the rank of the required prefix,
288 * allow if >= ours. Because mIRC and xchat throw a tizz if the modes shown
289 * in NAMES(X) are not in rank order, we know the most powerful mode is listed
290 * first, so we don't need to iterate, we just look up the first instead.
292 unsigned int ourrank = chan->GetPrefixValue(user);
293 if (ourrank < neededrank)
295 ModeHandler* neededmh = NULL;
296 for(char c='A'; c <= 'z'; c++)
298 ModeHandler *privmh = FindMode(c, MODETYPE_CHANNEL);
299 if (privmh && privmh->GetPrefixRank() >= neededrank)
301 // this mode is sufficient to allow this action
302 if (!neededmh || privmh->GetPrefixRank() < neededmh->GetPrefixRank())
307 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You must have channel %s access or above to %sset channel mode %c",
308 user->nick.c_str(), chan->name.c_str(), neededmh->name.c_str(), adding ? "" : "un", modechar);
310 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You cannot %sset channel mode %c",
311 user->nick.c_str(), chan->name.c_str(), adding ? "" : "un", modechar);
312 return MODEACTION_DENY;
317 unsigned char handler_id = (modechar - 'A') | mask;
319 for (ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++)
321 if ((*watchers)->BeforeMode(user, targetuser, chan, parameter, adding, type) == false)
322 return MODEACTION_DENY;
323 /* A module whacked the parameter completely, and there was one. abort. */
324 if (pcnt && parameter.empty())
325 return MODEACTION_DENY;
328 if (IS_LOCAL(user) && !IS_OPER(user))
330 char* disabled = (type == MODETYPE_CHANNEL) ? ServerInstance->Config->DisabledCModes : ServerInstance->Config->DisabledUModes;
331 if (disabled[modechar - 'A'])
333 user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Permission Denied - %s mode %c has been locked by the administrator",
334 user->nick.c_str(), type == MODETYPE_CHANNEL ? "channel" : "user", modechar);
335 return MODEACTION_DENY;
339 if (adding && IS_LOCAL(user) && mh->NeedsOper() && !user->HasModePermission(modechar, type))
341 /* It's an oper only mode, and they don't have access to it. */
344 user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Permission Denied - Oper type %s does not have access to set %s mode %c",
345 user->nick.c_str(), user->oper->NameStr(), type == MODETYPE_CHANNEL ? "channel" : "user", modechar);
349 user->WriteNumeric(ERR_NOPRIVILEGES, "%s :Permission Denied - Only operators may set %s mode %c",
350 user->nick.c_str(), type == MODETYPE_CHANNEL ? "channel" : "user", modechar);
352 return MODEACTION_DENY;
355 if (mh->GetTranslateType() == TR_NICK && !ServerInstance->FindNick(parameter))
357 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel", user->nick.c_str(), parameter.c_str());
358 return MODEACTION_DENY;
361 if (mh->GetPrefixRank() && chan)
363 User* user_to_prefix = ServerInstance->FindNick(parameter);
365 return MODEACTION_DENY;
366 if (!chan->SetPrefix(user_to_prefix, modechar, adding))
367 return MODEACTION_DENY;
370 /* Call the handler for the mode */
371 ModeAction ma = mh->OnModeChange(user, targetuser, chan, parameter, adding);
373 if (pcnt && parameter.empty())
374 return MODEACTION_DENY;
376 if (ma != MODEACTION_ALLOW)
379 for (ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++)
380 (*watchers)->AfterMode(user, targetuser, chan, parameter, adding, type);
382 return MODEACTION_ALLOW;
385 void ModeParser::Process(const std::vector<std::string>& parameters, User *user, bool merge)
387 std::string target = parameters[0];
388 Channel* targetchannel = ServerInstance->FindChan(target);
389 User* targetuser = ServerInstance->FindNick(target);
390 ModeType type = targetchannel ? MODETYPE_CHANNEL : MODETYPE_USER;
393 LastParseParams.clear();
394 LastParseTranslate.clear();
396 if (!targetchannel && !targetuser)
398 user->WriteNumeric(ERR_NOSUCHNICK, "%s %s :No such nick/channel",user->nick.c_str(),target.c_str());
401 if (parameters.size() == 1)
403 this->DisplayCurrentModes(user, targetuser, targetchannel, target.c_str());
407 ModResult MOD_RESULT;
408 FIRST_MOD_RESULT(OnPreMode, MOD_RESULT, (user, targetuser, targetchannel, parameters));
410 bool SkipAccessChecks = false;
412 if (!IS_LOCAL(user) || ServerInstance->ULine(user->server) || MOD_RESULT == MOD_RES_ALLOW)
413 SkipAccessChecks = true;
414 else if (MOD_RESULT == MOD_RES_DENY)
417 if (targetuser && !SkipAccessChecks && user != targetuser)
419 user->WriteNumeric(ERR_USERSDONTMATCH, "%s :Can't change mode for other users", user->nick.c_str());
423 std::string mode_sequence = parameters[1];
425 std::string output_mode;
426 std::ostringstream output_parameters;
427 LastParseParams.push_back(output_mode);
428 LastParseTranslate.push_back(TR_TEXT);
431 char output_pm = '\0'; // current output state, '+' or '-'
432 unsigned int param_at = 2;
434 for (std::string::const_iterator letter = mode_sequence.begin(); letter != mode_sequence.end(); letter++)
436 unsigned char modechar = *letter;
437 if (modechar == '+' || modechar == '-')
439 adding = (modechar == '+');
443 ModeHandler *mh = this->FindMode(modechar, type);
446 /* No mode handler? Unknown mode character then. */
447 user->WriteServ("%d %s %c :is unknown mode char to me", type == MODETYPE_CHANNEL ? 472 : 501, user->nick.c_str(), modechar);
451 std::string parameter = "";
452 int pcnt = mh->GetNumParams(adding);
453 if (pcnt && param_at == parameters.size())
455 /* No parameter, continue to the next mode */
456 mh->OnParameterMissing(user, targetuser, targetchannel);
461 parameter = parameters[param_at++];
462 /* Make sure the user isn't trying to slip in an invalid parameter */
463 if ((parameter.find(':') == 0) || (parameter.rfind(' ') != std::string::npos))
465 if (merge && targetchannel && targetchannel->IsModeSet(modechar) && !mh->IsListMode())
467 std::string ours = targetchannel->GetModeParameter(modechar);
468 if (!mh->ResolveModeConflict(parameter, ours, targetchannel))
469 /* we won the mode merge, don't apply this mode */
474 ModeAction ma = TryMode(user, targetuser, targetchannel, adding, modechar, parameter, SkipAccessChecks);
476 if (ma != MODEACTION_ALLOW)
479 char needed_pm = adding ? '+' : '-';
480 if (needed_pm != output_pm)
482 output_pm = needed_pm;
483 output_mode.append(1, output_pm);
485 output_mode.append(1, modechar);
489 TranslateType tt = mh->GetTranslateType();
492 User* u = ServerInstance->FindNick(parameter);
496 output_parameters << " " << parameter;
497 LastParseParams.push_back(parameter);
498 LastParseTranslate.push_back(tt);
501 if ( (output_mode.length() + output_parameters.str().length() > 450)
502 || (output_mode.length() > 100)
503 || (LastParseParams.size() > ServerInstance->Config->Limits.MaxModes))
505 /* mode sequence is getting too long */
510 LastParseParams[0] = output_mode;
512 if (!output_mode.empty())
514 LastParse = targetchannel ? targetchannel->name : targetuser->nick;
515 LastParse.append(" ");
516 LastParse.append(output_mode);
517 LastParse.append(output_parameters.str());
521 targetchannel->WriteChannel(user, "MODE %s", LastParse.c_str());
522 FOREACH_MOD(I_OnMode,OnMode(user, targetchannel, TYPE_CHANNEL, LastParseParams, LastParseTranslate));
526 targetuser->WriteFrom(user, "MODE %s", LastParse.c_str());
527 FOREACH_MOD(I_OnMode,OnMode(user, targetuser, TYPE_USER, LastParseParams, LastParseTranslate));
530 else if (targetchannel && parameters.size() == 2)
532 /* Special case for displaying the list for listmodes,
533 * e.g. MODE #chan b, or MODE #chan +b without a parameter
535 this->DisplayListModes(user, targetchannel, mode_sequence);
539 void ModeParser::DisplayListModes(User* user, Channel* chan, std::string &mode_sequence)
543 for (std::string::const_iterator letter = mode_sequence.begin(); letter != mode_sequence.end(); letter++)
545 unsigned char mletter = *letter;
549 /* Ensure the user doesnt request the same mode twice,
550 * so they cant flood themselves off out of idiocy.
552 if (sent[mletter] == seq)
557 ModeHandler *mh = this->FindMode(mletter, MODETYPE_CHANNEL);
559 if (!mh || !mh->IsListMode())
562 ModResult MOD_RESULT;
563 FIRST_MOD_RESULT(OnRawMode, MOD_RESULT, (user, chan, mletter, "", true, 0));
564 if (MOD_RESULT == MOD_RES_DENY)
568 if (!user->HasPrivPermission("channels/auspex") && ServerInstance->Config->HideModeLists[mletter] && (chan->GetPrefixValue(user) < HALFOP_VALUE))
570 user->WriteNumeric(ERR_CHANOPRIVSNEEDED, "%s %s :You do not have access to view the +%c list",
571 user->nick.c_str(), chan->name.c_str(), mletter);
575 unsigned char handler_id = (mletter - 'A') | MASK_CHANNEL;
577 for(ModeWatchIter watchers = modewatchers[handler_id].begin(); watchers != modewatchers[handler_id].end(); watchers++)
579 std::string dummyparam;
581 if (!((*watchers)->BeforeMode(user, NULL, chan, dummyparam, true, MODETYPE_CHANNEL)))
585 mh->DisplayList(user, chan);
587 mh->DisplayEmptyList(user, chan);
591 const std::string& ModeParser::GetLastParse()
596 void ModeParser::CleanMask(std::string &mask)
598 std::string::size_type pos_of_pling = mask.find_first_of('!');
599 std::string::size_type pos_of_at = mask.find_first_of('@');
600 std::string::size_type pos_of_dot = mask.find_first_of('.');
601 std::string::size_type pos_of_colons = mask.find("::"); /* Because ipv6 addresses are colon delimited -- double so it treats extban as nick */
603 if (mask.length() >= 2 && mask[1] == ':')
604 return; // if it's an extban, don't even try guess how it needs to be formed.
606 if ((pos_of_pling == std::string::npos) && (pos_of_at == std::string::npos))
608 /* Just a nick, or just a host - or clearly ipv6 (starting with :) */
609 if ((pos_of_dot == std::string::npos) && (pos_of_colons == std::string::npos) && mask[0] != ':')
611 /* It has no '.' in it, it must be a nick. */
616 /* Got a dot in it? Has to be a host */
617 mask = "*!*@" + mask;
620 else if ((pos_of_pling == std::string::npos) && (pos_of_at != std::string::npos))
622 /* Has an @ but no !, its a user@host */
625 else if ((pos_of_pling != std::string::npos) && (pos_of_at == std::string::npos))
627 /* Has a ! but no @, it must be a nick!ident */
632 bool ModeParser::AddMode(ModeHandler* mh)
634 unsigned char mask = 0;
635 unsigned char pos = 0;
637 /* Yes, i know, this might let people declare modes like '_' or '^'.
638 * If they do that, thats their problem, and if i ever EVER see an
639 * official InspIRCd developer do that, i'll beat them with a paddle!
641 if ((mh->GetModeChar() < 'A') || (mh->GetModeChar() > 'z') || (mh->GetPrefix() > 126))
644 /* A mode prefix of ',' is not acceptable, it would fuck up server to server.
645 * A mode prefix of ':' will fuck up both server to server, and client to server.
646 * A mode prefix of '#' will mess up /whois and /privmsg
648 if ((mh->GetPrefix() == ',') || (mh->GetPrefix() == ':') || (mh->GetPrefix() == '#'))
651 if (mh->GetPrefix() && FindPrefix(mh->GetPrefix()))
654 mh->GetModeType() == MODETYPE_USER ? mask = MASK_USER : mask = MASK_CHANNEL;
655 pos = (mh->GetModeChar()-65) | mask;
657 if (modehandlers[pos])
660 modehandlers[pos] = mh;
664 bool ModeParser::DelMode(ModeHandler* mh)
666 unsigned char mask = 0;
667 unsigned char pos = 0;
669 if ((mh->GetModeChar() < 'A') || (mh->GetModeChar() > 'z'))
672 mh->GetModeType() == MODETYPE_USER ? mask = MASK_USER : mask = MASK_CHANNEL;
673 pos = (mh->GetModeChar()-65) | mask;
675 if (modehandlers[pos] != mh)
678 /* Note: We can't stack here, as we have modes potentially being removed across many different channels.
679 * To stack here we have to make the algorithm slower. Discuss.
681 switch (mh->GetModeType())
684 for (user_hash::iterator i = ServerInstance->Users->clientlist->begin(); i != ServerInstance->Users->clientlist->end(); i++)
686 mh->RemoveMode(i->second);
689 case MODETYPE_CHANNEL:
690 for (chan_hash::iterator i = ServerInstance->chanlist->begin(); i != ServerInstance->chanlist->end(); i++)
692 mh->RemoveMode(i->second);
697 modehandlers[pos] = NULL;
702 ModeHandler* ModeParser::FindMode(unsigned const char modeletter, ModeType mt)
704 unsigned char mask = 0;
705 unsigned char pos = 0;
707 if ((modeletter < 'A') || (modeletter > 'z'))
710 mt == MODETYPE_USER ? mask = MASK_USER : mask = MASK_CHANNEL;
711 pos = (modeletter-65) | mask;
713 return modehandlers[pos];
716 std::string ModeParser::UserModeList()
721 for (unsigned char mode = 'A'; mode <= 'z'; mode++)
723 unsigned char pos = (mode-65) | MASK_USER;
725 if (modehandlers[pos])
726 modestr[pointer++] = mode;
728 modestr[pointer++] = 0;
732 std::string ModeParser::ChannelModeList()
737 for (unsigned char mode = 'A'; mode <= 'z'; mode++)
739 unsigned char pos = (mode-65) | MASK_CHANNEL;
741 if (modehandlers[pos])
742 modestr[pointer++] = mode;
744 modestr[pointer++] = 0;
748 std::string ModeParser::ParaModeList()
753 for (unsigned char mode = 'A'; mode <= 'z'; mode++)
755 unsigned char pos = (mode-65) | MASK_CHANNEL;
757 if ((modehandlers[pos]) && (modehandlers[pos]->GetNumParams(true)))
758 modestr[pointer++] = mode;
760 modestr[pointer++] = 0;
764 ModeHandler* ModeParser::FindPrefix(unsigned const char pfxletter)
766 for (unsigned char mode = 'A'; mode <= 'z'; mode++)
768 unsigned char pos = (mode-65) | MASK_CHANNEL;
770 if ((modehandlers[pos]) && (modehandlers[pos]->GetPrefix() == pfxletter))
772 return modehandlers[pos];
778 std::string ModeParser::GiveModeList(ModeMasks m)
780 std::string type1; /* Listmodes EXCEPT those with a prefix */
781 std::string type2; /* Modes that take a param when adding or removing */
782 std::string type3; /* Modes that only take a param when adding */
783 std::string type4; /* Modes that dont take a param */
785 for (unsigned char mode = 'A'; mode <= 'z'; mode++)
787 unsigned char pos = (mode-65) | m;
788 /* One parameter when adding */
789 if (modehandlers[pos])
791 if (modehandlers[pos]->GetNumParams(true))
793 if ((modehandlers[pos]->IsListMode()) && (!modehandlers[pos]->GetPrefix()))
795 type1 += modehandlers[pos]->GetModeChar();
799 /* ... and one parameter when removing */
800 if (modehandlers[pos]->GetNumParams(false))
802 /* But not a list mode */
803 if (!modehandlers[pos]->GetPrefix())
805 type2 += modehandlers[pos]->GetModeChar();
810 /* No parameters when removing */
811 type3 += modehandlers[pos]->GetModeChar();
817 type4 += modehandlers[pos]->GetModeChar();
822 return type1 + "," + type2 + "," + type3 + "," + type4;
825 std::string ModeParser::BuildPrefixes(bool lettersAndModes)
827 std::string mletters;
828 std::string mprefixes;
829 std::map<int,std::pair<char,char> > prefixes;
831 for (unsigned char mode = 'A'; mode <= 'z'; mode++)
833 unsigned char pos = (mode-65) | MASK_CHANNEL;
835 if ((modehandlers[pos]) && (modehandlers[pos]->GetPrefix()))
837 prefixes[modehandlers[pos]->GetPrefixRank()] = std::make_pair(
838 modehandlers[pos]->GetPrefix(), modehandlers[pos]->GetModeChar());
842 for(std::map<int,std::pair<char,char> >::reverse_iterator n = prefixes.rbegin(); n != prefixes.rend(); n++)
844 mletters = mletters + n->second.first;
845 mprefixes = mprefixes + n->second.second;
848 return lettersAndModes ? "(" + mprefixes + ")" + mletters : mletters;
851 bool ModeParser::AddModeWatcher(ModeWatcher* mw)
853 unsigned char mask = 0;
854 unsigned char pos = 0;
859 if ((mw->GetModeChar() < 'A') || (mw->GetModeChar() > 'z'))
862 mw->GetModeType() == MODETYPE_USER ? mask = MASK_USER : mask = MASK_CHANNEL;
863 pos = (mw->GetModeChar()-65) | mask;
865 modewatchers[pos].push_back(mw);
870 bool ModeParser::DelModeWatcher(ModeWatcher* mw)
872 unsigned char mask = 0;
873 unsigned char pos = 0;
878 if ((mw->GetModeChar() < 'A') || (mw->GetModeChar() > 'z'))
881 mw->GetModeType() == MODETYPE_USER ? mask = MASK_USER : mask = MASK_CHANNEL;
882 pos = (mw->GetModeChar()-65) | mask;
884 ModeWatchIter a = find(modewatchers[pos].begin(),modewatchers[pos].end(),mw);
886 if (a == modewatchers[pos].end())
891 modewatchers[pos].erase(a);
896 /** This default implementation can remove simple user modes
898 void ModeHandler::RemoveMode(User* user, irc::modestacker* stack)
900 char moderemove[MAXBUF];
901 std::vector<std::string> parameters;
903 if (user->IsModeSet(this->GetModeChar()))
907 stack->Push(this->GetModeChar());
911 sprintf(moderemove,"-%c",this->GetModeChar());
912 parameters.push_back(user->nick);
913 parameters.push_back(moderemove);
914 ServerInstance->Modes->Process(parameters, ServerInstance->FakeClient);
919 /** This default implementation can remove simple channel modes
922 void ModeHandler::RemoveMode(Channel* channel, irc::modestacker* stack)
924 char moderemove[MAXBUF];
925 std::vector<std::string> parameters;
927 if (channel->IsModeSet(this->GetModeChar()))
931 stack->Push(this->GetModeChar());
935 sprintf(moderemove,"-%c",this->GetModeChar());
936 parameters.push_back(channel->name);
937 parameters.push_back(moderemove);
938 ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
946 ModeChannelPrivate p;
947 ModeChannelModerated m;
948 ModeChannelTopicOps t;
950 ModeChannelNoExternal n;
951 ModeChannelInviteOnly i;
960 ModeUserInvisible ui;
962 ModeUserServerNoticeMask us;
964 void init(ModeParser* modes)
984 static builtin_modes static_modes;
986 ModeParser::ModeParser()
988 /* Clear mode handler list */
989 memset(modehandlers, 0, sizeof(modehandlers));
991 /* Last parse string */
995 memset(&sent, 0, sizeof(sent));
997 static_modes.init(this);
1000 ModeParser::~ModeParser()