*/
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
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
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);
{
}
-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)
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
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;
}
}
/* 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)
}
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);
// 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))
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);
}
/* 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)))
else
{
/* ... and one parameter when removing */
- if (mh->GetNumParams(false))
+ if (mh->NeedsParam(false))
{
/* But not a list mode */
if (!pm)
{
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
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>");
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++]);
}
curr.param.clear();
- if (mh->GetNumParams(curr.adding))
+ if (mh->NeedsParam(curr.adding))
{
if (value.empty())
{