]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Convert ModeHandler::GetNumParams() to NeedsParam() that returns a bool
authorAttila Molnar <attilamolnar@hush.com>
Mon, 29 Aug 2016 12:50:08 +0000 (14:50 +0200)
committerAttila Molnar <attilamolnar@hush.com>
Mon, 29 Aug 2016 12:50:08 +0000 (14:50 +0200)
include/mode.h
src/channels.cpp
src/mode.cpp
src/modules/m_namedmodes.cpp
src/modules/m_permchannels.cpp
src/modules/m_spanningtree/translate.cpp
src/modules/m_spanningtree/uid.cpp
src/users.cpp

index e7ac756ecdaa636faf524166a272776f3fcea400..64829845f805c503979f912901c241b9a6d242de 100644 (file)
@@ -205,12 +205,11 @@ class CoreExport ModeHandler : public ServiceProvider
         */
        inline bool NeedsOper() const { return oper; }
        /**
-        * Returns the number of parameters for the mode. Any non-zero
-        * value should be considered to be equivalent to one.
-        * @param adding If this is true, the number of parameters required to set the mode should be returned, otherwise the number of parameters required to unset the mode shall be returned.
-        * @return The number of parameters the mode expects
+        * Check if the mode needs a parameter for adding or removing
+        * @param adding True to check if the mode needs a parameter when setting, false to check if the mode needs a parameter when unsetting
+        * @return True if the mode needs a parameter for the specified action, false if it doesn't
         */
-       int GetNumParams(bool adding);
+       bool NeedsParam(bool adding) const;
        /**
         * Returns the mode character this handler handles.
         * @return The mode character
index 7f2485a49903ebcf4ebe34b77432bc4da7bf555f..a757cdc5a34d6e265ea23f3ca3f01104b28b03aa 100644 (file)
@@ -138,7 +138,7 @@ void Channel::SetDefaultModes()
                        if (mode->IsPrefixMode())
                                continue;
 
-                       if (mode->GetNumParams(true))
+                       if (mode->NeedsParam(true))
                        {
                                list.GetToken(parameter);
                                // If the parameter begins with a ':' then it's invalid
@@ -148,7 +148,7 @@ void Channel::SetDefaultModes()
                        else
                                parameter.clear();
 
-                       if ((mode->GetNumParams(true)) && (parameter.empty()))
+                       if ((mode->NeedsParam(true)) && (parameter.empty()))
                                continue;
 
                        mode->OnModeChange(ServerInstance->FakeClient, ServerInstance->FakeClient, this, parameter, true);
index 3762dc52e14d9a25b537114532d1c58c43402dfe..8d3d9ccfa95319a3f58243c95cd2f4973fd95b69 100644 (file)
@@ -44,18 +44,18 @@ ModeHandler::~ModeHandler()
 {
 }
 
-int ModeHandler::GetNumParams(bool adding)
+bool ModeHandler::NeedsParam(bool adding) const
 {
        switch (parameters_taken)
        {
                case PARAM_ALWAYS:
-                       return 1;
+                       return true;
                case PARAM_SETONLY:
-                       return adding ? 1 : 0;
+                       return adding;
                case PARAM_NONE:
                        break;
        }
-       return 0;
+       return false;
 }
 
 std::string ModeHandler::GetUserParameter(User* user)
@@ -219,7 +219,7 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, Mode
 
        ModeHandler* mh = mcitem.mh;
        bool adding = mcitem.adding;
-       int pcnt = mh->GetNumParams(adding);
+       const bool needs_param = mh->NeedsParam(adding);
 
        std::string& parameter = mcitem.param;
        // crop mode parameter size to 250 characters
@@ -283,7 +283,7 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, Mode
                                return MODEACTION_DENY;
 
                        // A module whacked the parameter completely, and there was one. Abort.
-                       if (pcnt && parameter.empty())
+                       if ((needs_param) && (parameter.empty()))
                                return MODEACTION_DENY;
                }
        }
@@ -318,7 +318,7 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, Mode
        /* Call the handler for the mode */
        ModeAction ma = mh->OnModeChange(user, targetuser, chan, parameter, adding);
 
-       if (pcnt && parameter.empty())
+       if ((needs_param) && (parameter.empty()))
                return MODEACTION_DENY;
 
        if (ma != MODEACTION_ALLOW)
@@ -363,7 +363,7 @@ void ModeParser::ModeParamsToChangeList(User* user, ModeType type, const std::ve
                }
 
                std::string parameter;
-               if (mh->GetNumParams(adding) && param_at < endindex)
+               if ((mh->NeedsParam(adding)) && (param_at < endindex))
                        parameter = parameters[param_at++];
 
                changelist.push(mh, adding, parameter);
@@ -432,7 +432,7 @@ unsigned int ModeParser::ProcessSingle(User* user, Channel* targetchannel, User*
 
                // 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->GetNumParams(item.adding))
+               if (mh->NeedsParam(item.adding))
                {
                        // Skip the mode if the parameter does not pass basic validation
                        if (!IsModeParamValid(user, targetchannel, targetuser, item))
@@ -719,7 +719,7 @@ std::string ModeParser::CreateModeList(ModeType mt, bool needparam)
        for (unsigned char mode = 'A'; mode <= 'z'; mode++)
        {
                ModeHandler* mh = modehandlers[mt][mode-65];
-               if ((mh) && ((!needparam) || (mh->GetNumParams(true))))
+               if ((mh) && ((!needparam) || (mh->NeedsParam(true))))
                        modestr.push_back(mode);
        }
 
@@ -756,7 +756,7 @@ std::string ModeParser::GiveModeList(ModeType mt)
                 /* One parameter when adding */
                if (mh)
                {
-                       if (mh->GetNumParams(true))
+                       if (mh->NeedsParam(true))
                        {
                                PrefixMode* pm = mh->IsPrefixMode();
                                if ((mh->IsListMode()) && ((!pm) || (pm->GetPrefix() == 0)))
@@ -766,7 +766,7 @@ std::string ModeParser::GiveModeList(ModeType mt)
                                else
                                {
                                        /* ... and one parameter when removing */
-                                       if (mh->GetNumParams(false))
+                                       if (mh->NeedsParam(false))
                                        {
                                                /* But not a list mode */
                                                if (!pm)
@@ -858,7 +858,7 @@ void ModeHandler::RemoveMode(Channel* channel, Modes::ChangeList& changelist)
 {
        if (channel->IsModeSet(this))
        {
-               if (this->GetNumParams(false))
+               if (this->NeedsParam(false))
                        // Removing this mode requires a parameter
                        changelist.push_remove(this, channel->GetModeParameter(this));
                else
index d4263d899d46a741ee20482736043b904f18577c..7a86c9e3cffb4a44700592c19332ae83e261fd69 100644 (file)
@@ -31,7 +31,7 @@ static void DisplayList(LocalUser* user, Channel* channel)
                if (!channel->IsModeSet(mh))
                        continue;
                numeric.Add("+" + mh->name);
-               if (mh->GetNumParams(true))
+               if (mh->NeedsParam(true))
                {
                        if ((mh->name == "key") && (!channel->HasUser(user)) && (!user->HasPrivPermission("channels/auspex")))
                                numeric.Add("<key>");
@@ -80,7 +80,7 @@ class CommandProp : public SplitCommand
                        ModeHandler* mh = ServerInstance->Modes->FindMode(prop, MODETYPE_CHANNEL);
                        if (mh)
                        {
-                               if (mh->GetNumParams(plus))
+                               if (mh->NeedsParam(plus))
                                {
                                        if (i != parameters.size())
                                                modes.push(mh, plus, parameters[i++]);
@@ -161,7 +161,7 @@ class ModuleNamedModes : public Module
                                }
 
                                curr.param.clear();
-                               if (mh->GetNumParams(curr.adding))
+                               if (mh->NeedsParam(curr.adding))
                                {
                                        if (value.empty())
                                        {
index 9a5da5ce49e2313f85ee907beadb14d63957b5ab..9e77bd60e1cb6f5b420c2c17b90a57985885fa6d 100644 (file)
@@ -236,7 +236,7 @@ public:
                                        ModeHandler* mode = ServerInstance->Modes->FindMode(*n, MODETYPE_CHANNEL);
                                        if (mode)
                                        {
-                                               if (mode->GetNumParams(true))
+                                               if (mode->NeedsParam(true))
                                                        list.GetToken(par);
                                                else
                                                        par.clear();
index 48c0632e557d98d865b77b4f29fc381a326a1250..66e1bb35b4b6786ffaf0452dfbf6cd33b15affdb 100644 (file)
@@ -27,7 +27,7 @@ std::string Translate::ModeChangeListToParams(const Modes::ChangeList::List& mod
        {
                const Modes::Change& item = *i;
                ModeHandler* mh = item.mh;
-               if (!mh->GetNumParams(item.adding))
+               if (!mh->NeedsParam(item.adding))
                        continue;
 
                ret.push_back(' ');
index eff5371199110a59d14f4ebd398506b38c5b14b1..a41fe408d990a3525cd6d97863a878f2720a4c64 100644 (file)
@@ -98,7 +98,7 @@ CmdResult CommandUID::HandleServer(TreeServer* remoteserver, std::vector<std::st
                if (!mh)
                        throw ProtocolException("Unrecognised mode '" + std::string(1, *v) + "'");
 
-               if (mh->GetNumParams(true))
+               if (mh->NeedsParam(true))
                {
                        if (paramptr >= params.size() - 1)
                                throw ProtocolException("Out of parameters while processing modes");
index 24b2928ae052e55503013aa696782be294604bcd..c57b6fc14d3e2f6580ab536ee1d92d01512fe3c4 100644 (file)
@@ -51,7 +51,7 @@ const char* User::FormatModes(bool showparameters)
                if (mh && IsModeSet(mh))
                {
                        data.push_back(n + 65);
-                       if (showparameters && mh->GetNumParams(true))
+                       if (showparameters && mh->NeedsParam(true))
                        {
                                std::string p = mh->GetUserParameter(this);
                                if (p.length())