X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmode.cpp;h=c07c342a362d71211a0d7f0e351c27654e8c0244;hb=e336c3dfa9be7fd2f571b58f03745e23f4544513;hp=fd5e307074e2aea1e0ee0bf97f22f2fe3eefdf8b;hpb=a3e0768758ca68429a29d9c78ce672f2d938c6e7;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/mode.cpp b/src/mode.cpp index fd5e30707..c07c342a3 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -24,12 +24,18 @@ #include "inspircd.h" -#include "builtinmodes.h" ModeHandler::ModeHandler(Module* Creator, const std::string& Name, char modeletter, ParamSpec Params, ModeType type, Class mclass) - : ServiceProvider(Creator, Name, SERVICE_MODE), modeid(ModeParser::MODEID_MAX), - parameters_taken(Params), mode(modeletter), oper(false), - list(false), m_type(type), type_id(mclass), levelrequired(HALFOP_VALUE) + : ServiceProvider(Creator, Name, SERVICE_MODE) + , modeid(ModeParser::MODEID_MAX) + , parameters_taken(Params) + , mode(modeletter) + , oper(false) + , list(false) + , m_type(type) + , type_id(mclass) + , ranktoset(HALFOP_VALUE) + , ranktounset(HALFOP_VALUE) { } @@ -155,11 +161,20 @@ void ModeWatcher::AfterMode(User*, User*, Channel*, const std::string&, bool) PrefixMode::PrefixMode(Module* Creator, const std::string& Name, char ModeLetter, unsigned int Rank, char PrefixChar) : ModeHandler(Creator, Name, ModeLetter, PARAM_ALWAYS, MODETYPE_CHANNEL, MC_PREFIX) - , prefix(PrefixChar), prefixrank(Rank) + , prefix(PrefixChar) + , prefixrank(Rank) + , selfremove(true) { list = true; } +ModResult PrefixMode::AccessCheck(User* src, Channel*, std::string& value, bool adding) +{ + if (!adding && src->nick == value && selfremove) + return MOD_RES_ALLOW; + return MOD_RES_PASSTHRU; +} + ModeAction PrefixMode::OnModeChange(User* source, User*, Channel* chan, std::string& parameter, bool adding) { User* target; @@ -182,6 +197,14 @@ ModeAction PrefixMode::OnModeChange(User* source, User*, Channel* chan, std::str return (memb->SetPrefix(this, adding) ? MODEACTION_ALLOW : MODEACTION_DENY); } +void PrefixMode::Update(unsigned int rank, unsigned int setrank, unsigned int unsetrank, bool selfrm) +{ + prefixrank = rank; + ranktoset = setrank; + ranktounset = unsetrank; + selfremove = selfrm; +} + ModeAction ParamModeBase::OnModeChange(User* source, User*, Channel* chan, std::string& parameter, bool adding) { if (adding) @@ -237,7 +260,7 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, Mode return MODEACTION_DENY; if (MOD_RESULT == MOD_RES_PASSTHRU) { - unsigned int neededrank = mh->GetLevelRequired(); + unsigned int neededrank = mh->GetLevelRequired(adding); /* Compare our rank on the channel against the rank of the required prefix, * allow if >= ours. Because mIRC and xchat throw a tizz if the modes shown * in NAMES(X) are not in rank order, we know the most powerful mode is listed @@ -426,6 +449,12 @@ unsigned int ModeParser::ProcessSingle(User* user, Channel* targetchannel, User* Modes::Change& item = *i; ModeHandler* mh = item.mh; + // If a mode change has been given for a mode that does not exist then reject + // it. This can happen when core_reloadmodule attempts to restore a mode that + // no longer exists. + if (!mh) + continue; + // If the mode is supposed to have a parameter then we first take a look at item.param // and, if we were asked to, also handle mode merges now if (mh->NeedsParam(item.adding)) @@ -870,53 +899,6 @@ void PrefixMode::RemoveMode(Channel* chan, Modes::ChangeList& changelist) } } -struct builtin_modes -{ - SimpleChannelModeHandler s; - SimpleChannelModeHandler p; - SimpleChannelModeHandler m; - SimpleChannelModeHandler t; - - SimpleChannelModeHandler n; - SimpleChannelModeHandler i; - ModeChannelKey k; - ModeChannelLimit l; - - ModeChannelBan b; - ModeChannelOp o; - ModeChannelVoice v; - - SimpleUserModeHandler ui; - ModeUserOperator uo; - ModeUserServerNoticeMask us; - - builtin_modes() - : s(NULL, "secret", 's') - , p(NULL, "private", 'p') - , m(NULL, "moderated", 'm') - , t(NULL, "topiclock", 't') - , n(NULL, "noextmsg", 'n') - , i(NULL, "inviteonly", 'i') - , ui(NULL, "invisible", 'i') - { - } - - void init() - { - ServiceProvider* modes[] = { &s, &p, &m, &t, &n, &i, &k, &l, &b, &o, &v, - &ui, &uo, &us }; - ServerInstance->Modules->AddServices(modes, sizeof(modes)/sizeof(ServiceProvider*)); - } -}; - -static builtin_modes static_modes; - -void ModeParser::InitBuiltinModes() -{ - static_modes.init(); - static_modes.b.DoRehash(); -} - bool ModeParser::IsModeChar(char chr) { return ((chr >= 'A' && chr <= 'Z') || (chr >= 'a' && chr <= 'z'));