X-Git-Url: https://git.netwichtig.de/gitweb/?a=blobdiff_plain;f=src%2Fmodes%2Fcmode_k.cpp;h=980b3215a4e504fad6dc65577476a882c404686e;hb=6fe1f4e1136f2ab95a88e68af1894bf6002d03f4;hp=e56b26ff132b4975e8355eb38a46fef303f30e80;hpb=1031f333332cf1b09db4fd632f141143ee637c34;p=user%2Fhenk%2Fcode%2Finspircd.git diff --git a/src/modes/cmode_k.cpp b/src/modes/cmode_k.cpp index e56b26ff1..980b3215a 100644 --- a/src/modes/cmode_k.cpp +++ b/src/modes/cmode_k.cpp @@ -21,37 +21,54 @@ #include "inspircd.h" -#include "mode.h" -#include "channels.h" -#include "users.h" #include "builtinmodes.h" -ModeChannelKey::ModeChannelKey() : ModeHandler(NULL, "key", 'k', PARAM_ALWAYS, MODETYPE_CHANNEL) +ModeChannelKey::ModeChannelKey() + : ParamMode(NULL, "key", 'k', PARAM_ALWAYS) { } ModeAction ModeChannelKey::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding) { - bool exists = channel->IsModeSet(this); + const std::string* key = ext.get(channel); + bool exists = (key != NULL); if (IS_LOCAL(source)) { if (exists == adding) return MODEACTION_DENY; - if (exists && (parameter != channel->GetModeParameter(this))) + if (exists && (parameter != *key)) { /* Key is currently set and the correct key wasnt given */ return MODEACTION_DENY; } } else { - if (exists && adding && parameter == channel->GetModeParameter(this)) + if (exists && adding && parameter == *key) { /* no-op, don't show */ return MODEACTION_DENY; } } + channel->SetMode(this, adding); if (adding) - parameter = parameter.substr(0, 32); + { + if (parameter.length() > maxkeylen) + parameter.erase(maxkeylen); + ext.set(channel, parameter); + } + else + ext.unset(channel); return MODEACTION_ALLOW; } + +void ModeChannelKey::SerializeParam(Channel* chan, const std::string* key, std::string& out) +{ + out += *key; +} + +ModeAction ModeChannelKey::OnSet(User* source, Channel* chan, std::string& param) +{ + // Dummy function, never called + return MODEACTION_DENY; +}