diff options
| author | 2014-02-15 14:38:24 +0100 | |
|---|---|---|
| committer | 2014-02-15 14:38:24 +0100 | |
| commit | 0556720b559d7ec5d8badacf0ac9b11e9c864847 (patch) | |
| tree | 0435a0e5b8e722fe35afb3f820f804bec8c0c7b2 /src/mode.cpp | |
| parent | Add ModeHandler::IsParameterMode() and MC_PARAM (diff) | |
| download | inspircd++-0556720b559d7ec5d8badacf0ac9b11e9c864847.tar.gz inspircd++-0556720b559d7ec5d8badacf0ac9b11e9c864847.tar.bz2 inspircd++-0556720b559d7ec5d8badacf0ac9b11e9c864847.zip | |
Add ParamModeBase and ParamMode, change all parameter modes to inherit from ParamMode
- Type of the extension used to store data is a template parameter
- The extension is automatically unset when the mode is unset
- Handlers inheriting from ParamMode have to provide OnSet() and SerializeParam(); may optionally provide OnUnset()
- Transparently handle the case when OnSet() modifies the mode parameter
- Remove Channel::custom_mode_params map; ask the mode handlers to serialize their parameters instead
Diffstat (limited to 'src/mode.cpp')
| -rw-r--r-- | src/mode.cpp | 44 |
1 files changed, 26 insertions, 18 deletions
diff --git a/src/mode.cpp b/src/mode.cpp index ad46e602d..eeab0de3a 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -127,21 +127,6 @@ ModeAction SimpleChannelModeHandler::OnModeChange(User* source, User* dest, Chan return MODEACTION_ALLOW; } -ModeAction ParamChannelModeHandler::OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding) -{ - if (adding && !ParamValidate(parameter)) - return MODEACTION_DENY; - std::string now = channel->GetModeParameter(this); - if (parameter == now) - return MODEACTION_DENY; - return MODEACTION_ALLOW; -} - -bool ParamChannelModeHandler::ParamValidate(std::string& parameter) -{ - return true; -} - ModeWatcher::ModeWatcher(Module* Creator, const std::string& modename, ModeType type) : mode(modename), m_type(type), creator(Creator) { @@ -227,6 +212,32 @@ ModeAction PrefixMode::OnModeChange(User* source, User*, Channel* chan, std::str return (memb->SetPrefix(this, adding) ? MODEACTION_ALLOW : MODEACTION_DENY); } +ModeAction ParamModeBase::OnModeChange(User* source, User*, Channel* chan, std::string& parameter, bool adding) +{ + if (adding) + { + if (chan->GetModeParameter(this) == parameter) + return MODEACTION_DENY; + + if (OnSet(source, chan, parameter) != MODEACTION_ALLOW) + return MODEACTION_DENY; + + chan->SetMode(this, true); + + // Handler might have changed the parameter internally + parameter.clear(); + this->GetParameter(chan, parameter); + } + else + { + if (!chan->IsModeSet(this)) + return MODEACTION_DENY; + this->OnUnsetInternal(source, chan); + chan->SetMode(this, false); + } + return MODEACTION_ALLOW; +} + ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, bool adding, const unsigned char modechar, std::string ¶meter, bool SkipACL) { @@ -336,9 +347,6 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, bool if (ma != MODEACTION_ALLOW) return ma; - if ((!mh->IsListMode()) && (mh->GetNumParams(true)) && (chan)) - chan->SetModeParam(mh, (adding ? parameter : "")); - itpair = modewatchermap.equal_range(mh->name); for (ModeWatchIter i = itpair.first; i != itpair.second; ++i) { |
