X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodules%2Fm_operchans.cpp;h=8f600392302803f6be6ee046014bd03376177425;hb=5a2af6ded883d71c6c4c9f1497cca1721f8b0742;hp=074c644e13d0130a631b861bd7c25204aa8a9567;hpb=fcacc8e0306382bc3f938073092c3729d77e2b41;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modules/m_operchans.cpp b/src/modules/m_operchans.cpp index 074c644e1..8f6003923 100644 --- a/src/modules/m_operchans.cpp +++ b/src/modules/m_operchans.cpp @@ -22,82 +22,79 @@ #include "inspircd.h" -/* $ModDesc: Provides support for oper-only chans via the +O channel mode */ +enum +{ + // From UnrealIRCd. + ERR_CANTJOINOPERSONLY = 520 +}; -class OperChans : public ModeHandler +class OperChans : public SimpleChannelModeHandler { public: /* This is an oper-only mode */ - OperChans(Module* Creator) : ModeHandler(Creator, "operonly", 'O', PARAM_NONE, MODETYPE_CHANNEL) { oper = true; } - - ModeAction OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding) + OperChans(Module* Creator) : SimpleChannelModeHandler(Creator, "operonly", 'O') { - if (adding) - { - if (!channel->IsModeSet('O')) - { - channel->SetMode('O',true); - return MODEACTION_ALLOW; - } - } - else - { - if (channel->IsModeSet('O')) - { - channel->SetMode('O',false); - return MODEACTION_ALLOW; - } - } - - return MODEACTION_DENY; + oper = true; } }; class ModuleOperChans : public Module { + private: OperChans oc; + std::string space; + std::string underscore; + public: - ModuleOperChans() : oc(this) + ModuleOperChans() + : oc(this) + , space(" ") + , underscore("_") { - if (!ServerInstance->Modes->AddMode(&oc)) - throw ModuleException("Could not add new modes!"); - Implementation eventlist[] = { I_OnCheckBan, I_On005Numeric, I_OnUserPreJoin }; - ServerInstance->Modules->Attach(eventlist, this, 3); } - ModResult OnUserPreJoin(User* user, Channel* chan, const char* cname, std::string &privs, const std::string &keygiven) + ModResult OnUserPreJoin(LocalUser* user, Channel* chan, const std::string& cname, std::string& privs, const std::string& keygiven) CXX11_OVERRIDE { - if (chan && chan->IsModeSet('O') && !IS_OPER(user)) + if (chan && chan->IsModeSet(oc) && !user->IsOper()) { - user->WriteNumeric(ERR_CANTJOINOPERSONLY, "%s %s :Only IRC operators may join %s (+O is set)", - user->nick.c_str(), chan->name.c_str(), chan->name.c_str()); + user->WriteNumeric(ERR_CANTJOINOPERSONLY, chan->name, InspIRCd::Format("Only server operators may join %s (+O is set)", chan->name.c_str())); return MOD_RES_DENY; } return MOD_RES_PASSTHRU; } - ModResult OnCheckBan(User *user, Channel *c, const std::string& mask) + ModResult OnCheckBan(User* user, Channel* chan, const std::string& mask) CXX11_OVERRIDE { - if (mask[0] == 'O' && mask[1] == ':') - { - if (IS_OPER(user) && InspIRCd::Match(user->oper->name, mask.substr(2))) - return MOD_RES_DENY; - } - return MOD_RES_PASSTHRU; - } + // Check whether the entry is an extban. + if (mask.length() <= 2 || mask[0] != 'O' || mask[1] != ':') + return MOD_RES_PASSTHRU; - void On005Numeric(std::string &output) - { - ServerInstance->AddExtBanChar('O'); + // If the user is not an oper they can't match this. + if (!user->IsOper()) + return MOD_RES_PASSTHRU; + + // Check whether the oper's type matches the ban. + const std::string submask = mask.substr(2); + if (InspIRCd::Match(user->oper->name, submask)) + return MOD_RES_DENY; + + // If the oper's type contains spaces recheck with underscores. + std::string opername(user->oper->name); + stdalgo::string::replace_all(opername, space, underscore); + if (InspIRCd::Match(opername, submask)) + return MOD_RES_DENY; + + return MOD_RES_PASSTHRU; } - ~ModuleOperChans() + void On005Numeric(std::map& tokens) CXX11_OVERRIDE { + tokens["EXTBAN"].push_back('O'); } - Version GetVersion() + Version GetVersion() CXX11_OVERRIDE { - return Version("Provides support for oper-only chans via the +O channel mode and 'O' extban", VF_VENDOR); + return Version("Provides support for oper-only channels via channel mode +O and extban 'O'", VF_VENDOR); } };