diff options
author | attilamolnar <attilamolnar@hush.com> | 2013-06-18 18:30:10 +0200 |
---|---|---|
committer | attilamolnar <attilamolnar@hush.com> | 2013-07-19 19:40:03 +0200 |
commit | b954283ccc4253a6881513bbe7f743c39886d3b7 (patch) | |
tree | 56386d71e6132d06e8e4e786fba867a4945114b1 /src/modules | |
parent | 5288eb159451aea53168c1a812a72594801f6421 (diff) |
Replace hardcoded mode letters, part 2
This changes all remaining Channel::IsModeSet() and Channel::GetModeParameter() calls to use ModeReferences for modes that were created by other modules or the core
Diffstat (limited to 'src/modules')
-rw-r--r-- | src/modules/m_banredirect.cpp | 13 | ||||
-rw-r--r-- | src/modules/m_channames.cpp | 10 | ||||
-rw-r--r-- | src/modules/m_denychans.cpp | 9 | ||||
-rw-r--r-- | src/modules/m_knock.cpp | 27 | ||||
-rw-r--r-- | src/modules/m_override.cpp | 19 | ||||
-rw-r--r-- | src/modules/m_redirect.cpp | 6 | ||||
-rw-r--r-- | src/modules/m_remove.cpp | 30 |
7 files changed, 72 insertions, 42 deletions
diff --git a/src/modules/m_banredirect.cpp b/src/modules/m_banredirect.cpp index 496b0c2c9..ddc79bf20 100644 --- a/src/modules/m_banredirect.cpp +++ b/src/modules/m_banredirect.cpp @@ -217,15 +217,18 @@ class ModuleBanRedirect : public Module { BanRedirect re; bool nofollow; + ChanModeReference limitmode; + ChanModeReference redirectmode; public: ModuleBanRedirect() - : re(this) + : re(this) + , nofollow(false) + , limitmode(this, "limit") + , redirectmode(this, "redirect") { - nofollow = false; } - void init() CXX11_OVERRIDE { ServerInstance->Modes->AddModeWatcher(&re); @@ -311,9 +314,9 @@ class ModuleBanRedirect : public Module std::string destlimit; if (destchan) - destlimit = destchan->GetModeParameter('l'); + destlimit = destchan->GetModeParameter(limitmode); - if(destchan && ServerInstance->Modules->Find("m_redirect.so") && destchan->IsModeSet('L') && !destlimit.empty() && (destchan->GetUserCounter() >= atoi(destlimit.c_str()))) + if(destchan && destchan->IsModeSet(redirectmode) && !destlimit.empty() && (destchan->GetUserCounter() >= atoi(destlimit.c_str()))) { user->WriteNumeric(474, "%s %s :Cannot join channel (You are banned)", user->nick.c_str(), chan->name.c_str()); return MOD_RES_DENY; diff --git a/src/modules/m_channames.cpp b/src/modules/m_channames.cpp index 29cbdca91..aed3ec226 100644 --- a/src/modules/m_channames.cpp +++ b/src/modules/m_channames.cpp @@ -49,9 +49,13 @@ class ModuleChannelNames : public Module NewIsChannelHandler myhandler; caller1<bool, const std::string&> rememberer; bool badchan; + ChanModeReference permchannelmode; public: - ModuleChannelNames() : rememberer(ServerInstance->IsChannel), badchan(false) + ModuleChannelNames() + : rememberer(ServerInstance->IsChannel) + , badchan(false) + , permchannelmode(this, "permanent") { } @@ -76,11 +80,11 @@ class ModuleChannelNames : public Module while (c2 != chanvec.rend()) { Channel* c = *c2++; - if (c->IsModeSet('P') && c->GetUserCounter()) + if (c->IsModeSet(permchannelmode) && c->GetUserCounter()) { std::vector<std::string> modes; modes.push_back(c->name); - modes.push_back("-P"); + modes.push_back("-" + permchannelmode->GetModeChar()); ServerInstance->Modes->Process(modes, ServerInstance->FakeClient); } diff --git a/src/modules/m_denychans.cpp b/src/modules/m_denychans.cpp index 0b82d0750..60af0e391 100644 --- a/src/modules/m_denychans.cpp +++ b/src/modules/m_denychans.cpp @@ -24,7 +24,14 @@ class ModuleDenyChannels : public Module { + ChanModeReference redirectmode; + public: + ModuleDenyChannels() + : redirectmode(this, "redirect") + { + } + void init() CXX11_OVERRIDE { Implementation eventlist[] = { I_OnUserPreJoin, I_OnRehash }; @@ -110,7 +117,7 @@ class ModuleDenyChannels : public Module { /* simple way to avoid potential loops: don't redirect to +L channels */ Channel *newchan = ServerInstance->FindChan(redirect); - if ((!newchan) || (!(newchan->IsModeSet('L')))) + if ((!newchan) || (!newchan->IsModeSet(redirectmode))) { user->WriteNumeric(926, "%s %s :Channel %s is forbidden, redirecting to %s: %s",user->nick.c_str(),cname.c_str(),cname.c_str(),redirect.c_str(), reason.c_str()); Channel::JoinUser(user, redirect); diff --git a/src/modules/m_knock.cpp b/src/modules/m_knock.cpp index b440328bd..3aa49094e 100644 --- a/src/modules/m_knock.cpp +++ b/src/modules/m_knock.cpp @@ -25,10 +25,16 @@ */ class CommandKnock : public Command { + SimpleChannelModeHandler& noknockmode; + ChanModeReference inviteonlymode; + public: bool sendnotice; bool sendnumeric; - CommandKnock(Module* Creator) : Command(Creator,"KNOCK", 2, 2) + CommandKnock(Module* Creator, SimpleChannelModeHandler& Noknockmode) + : Command(Creator,"KNOCK", 2, 2) + , noknockmode(Noknockmode) + , inviteonlymode(Creator, "inviteonly") { syntax = "<channel> <reason>"; Penalty = 5; @@ -49,13 +55,13 @@ class CommandKnock : public Command return CMD_FAILURE; } - if (c->IsModeSet('K')) + if (c->IsModeSet(noknockmode)) { user->WriteNumeric(480, "%s :Can't KNOCK on %s, +K is set.",user->nick.c_str(), c->name.c_str()); return CMD_FAILURE; } - if (!c->IsModeSet('i')) + if (!c->IsModeSet(inviteonlymode)) { user->WriteNumeric(480, "%s :Can't KNOCK on %s, channel is not invite only so knocking is pointless!",user->nick.c_str(), c->name.c_str()); return CMD_FAILURE; @@ -77,20 +83,15 @@ class CommandKnock : public Command } }; -/** Handles channel mode +K - */ -class Knock : public SimpleChannelModeHandler -{ - public: - Knock(Module* Creator) : SimpleChannelModeHandler(Creator, "noknock", 'K') { } -}; - class ModuleKnock : public Module { + SimpleChannelModeHandler kn; CommandKnock cmd; - Knock kn; + public: - ModuleKnock() : cmd(this), kn(this) + ModuleKnock() + : kn(this, "noknock", 'K') + , cmd(this, kn) { } diff --git a/src/modules/m_override.cpp b/src/modules/m_override.cpp index 1bc05a4ef..b29c1c676 100644 --- a/src/modules/m_override.cpp +++ b/src/modules/m_override.cpp @@ -30,8 +30,19 @@ class ModuleOverride : public Module { bool RequireKey; bool NoisyOverride; + ChanModeReference topiclock; + ChanModeReference inviteonly; + ChanModeReference key; + ChanModeReference limit; public: + ModuleOverride() + : topiclock(this, "topiclock") + , inviteonly(this, "inviteonly") + , key(this, "key") + , limit(this, "limit") + { + } void init() CXX11_OVERRIDE { @@ -68,7 +79,7 @@ class ModuleOverride : public Module { if (IS_LOCAL(source) && source->IsOper() && CanOverride(source, "TOPIC")) { - if (!channel->HasUser(source) || (channel->IsModeSet('t') && channel->GetPrefixValue(source) < HALFOP_VALUE)) + if (!channel->HasUser(source) || (channel->IsModeSet(topiclock) && channel->GetPrefixValue(source) < HALFOP_VALUE)) { ServerInstance->SNO->WriteGlobalSno('v',source->nick+" used oper override to change a topic on "+channel->name); } @@ -120,7 +131,7 @@ class ModuleOverride : public Module { if (chan) { - if (chan->IsModeSet('i') && (CanOverride(user,"INVITE"))) + if (chan->IsModeSet(inviteonly) && (CanOverride(user,"INVITE"))) { if (!IS_LOCAL(user)->IsInvited(chan)) { @@ -138,7 +149,7 @@ class ModuleOverride : public Module return MOD_RES_ALLOW; } - if (chan->IsModeSet('k') && (CanOverride(user,"KEY")) && keygiven != chan->GetModeParameter('k')) + if (chan->IsModeSet(key) && (CanOverride(user,"KEY")) && keygiven != chan->GetModeParameter(key)) { if (RequireKey && keygiven != "override") { @@ -153,7 +164,7 @@ class ModuleOverride : public Module return MOD_RES_ALLOW; } - if (chan->IsModeSet('l') && (chan->GetUserCounter() >= ConvToInt(chan->GetModeParameter('l'))) && (CanOverride(user,"LIMIT"))) + if (chan->IsModeSet(limit) && (chan->GetUserCounter() >= ConvToInt(chan->GetModeParameter(limit))) && (CanOverride(user,"LIMIT"))) { if (RequireKey && keygiven != "override") { diff --git a/src/modules/m_redirect.cpp b/src/modules/m_redirect.cpp index cc0fe1976..7af4818c3 100644 --- a/src/modules/m_redirect.cpp +++ b/src/modules/m_redirect.cpp @@ -95,12 +95,14 @@ class ModuleRedirect : public Module { Redirect re; AntiRedirect re_u; + ChanModeReference limitmode; bool UseUsermode; public: ModuleRedirect() : re(this) , re_u(this) + , limitmode(this, "limit") { } @@ -130,9 +132,9 @@ class ModuleRedirect : public Module { if (chan) { - if (chan->IsModeSet(re) && chan->IsModeSet('l')) + if (chan->IsModeSet(re) && chan->IsModeSet(limitmode)) { - if (chan->GetUserCounter() >= ConvToInt(chan->GetModeParameter('l'))) + if (chan->GetUserCounter() >= ConvToInt(chan->GetModeParameter(limitmode))) { std::string channel = chan->GetModeParameter(&re); diff --git a/src/modules/m_remove.cpp b/src/modules/m_remove.cpp index 7f274f00c..19b774f04 100644 --- a/src/modules/m_remove.cpp +++ b/src/modules/m_remove.cpp @@ -35,10 +35,13 @@ class RemoveBase : public Command { bool& supportnokicks; + ChanModeReference& nokicksmode; public: - RemoveBase(Module* Creator, bool& snk, const char* cmdn) - : Command(Creator, cmdn, 2, 3), supportnokicks(snk) + RemoveBase(Module* Creator, bool& snk, ChanModeReference& nkm, const char* cmdn) + : Command(Creator, cmdn, 2, 3) + , supportnokicks(snk) + , nokicksmode(nkm) { } @@ -47,9 +50,6 @@ class RemoveBase : public Command User* target; Channel* channel; std::string reason; - std::string protectkey; - std::string founderkey; - bool hasnokicks; /* Set these to the parameters needed, the new version of this module switches it's parameters around * supplying a new command with the new order while keeping the old /remove with the older order. @@ -81,8 +81,6 @@ class RemoveBase : public Command int ulevel = channel->GetPrefixValue(user); int tlevel = channel->GetPrefixValue(target); - hasnokicks = (ServerInstance->Modules->Find("m_nokicks.so") && channel->IsModeSet('Q')); - if (ServerInstance->ULine(target->server)) { user->WriteNumeric(482, "%s %s :Only a u-line may remove a u-line from a channel.", user->nick.c_str(), channame.c_str()); @@ -90,7 +88,7 @@ class RemoveBase : public Command } /* We support the +Q channel mode via. the m_nokicks module, if the module is loaded and the mode is set then disallow the /remove */ - if ((!IS_LOCAL(user)) || (!supportnokicks || !hasnokicks)) + if ((!IS_LOCAL(user)) || (!supportnokicks) || (!channel->IsModeSet(nokicksmode))) { /* We'll let everyone remove their level and below, eg: * ops can remove ops, halfops, voices, and those with no mode (no moders actually are set to 1) @@ -128,7 +126,7 @@ class RemoveBase : public Command else { /* m_nokicks.so was loaded and +Q was set, block! */ - user->WriteServ( "484 %s %s :Can't remove user %s from channel (+Q set)", user->nick.c_str(), channel->name.c_str(), target->nick.c_str()); + user->WriteServ( "484 %s %s :Can't remove user %s from channel (nokicks mode is set)", user->nick.c_str(), channel->name.c_str(), target->nick.c_str()); return CMD_FAILURE; } @@ -142,8 +140,8 @@ class RemoveBase : public Command class CommandRemove : public RemoveBase { public: - CommandRemove(Module* Creator, bool& snk) - : RemoveBase(Creator, snk, "REMOVE") + CommandRemove(Module* Creator, bool& snk, ChanModeReference& nkm) + : RemoveBase(Creator, snk, nkm, "REMOVE") { syntax = "<nick> <channel> [<reason>]"; TRANSLATE3(TR_NICK, TR_TEXT, TR_TEXT); @@ -168,8 +166,8 @@ class CommandRemove : public RemoveBase class CommandFpart : public RemoveBase { public: - CommandFpart(Module* Creator, bool& snk) - : RemoveBase(Creator, snk, "FPART") + CommandFpart(Module* Creator, bool& snk, ChanModeReference& nkm) + : RemoveBase(Creator, snk, nkm, "FPART") { syntax = "<channel> <nick> [<reason>]"; TRANSLATE3(TR_TEXT, TR_NICK, TR_TEXT); @@ -191,12 +189,16 @@ class CommandFpart : public RemoveBase class ModuleRemove : public Module { + ChanModeReference nokicksmode; CommandRemove cmd1; CommandFpart cmd2; bool supportnokicks; public: - ModuleRemove() : cmd1(this, supportnokicks), cmd2(this, supportnokicks) + ModuleRemove() + : nokicksmode(this, "nokick") + , cmd1(this, supportnokicks, nokicksmode) + , cmd2(this, supportnokicks, nokicksmode) { } |