diff options
author | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-03-07 02:45:02 +0000 |
---|---|---|
committer | danieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7> | 2009-03-07 02:45:02 +0000 |
commit | 1c33356677595047eba381db676d6de499e44ad6 (patch) | |
tree | f46dbdda8f39a9a8b755f0f0095460a29bfe7135 | |
parent | 96a4a1d41e42dba806c2e9954e148ed838262511 (diff) |
Fix r11178 not allowing keys to be unset
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11182 e03df62e-2008-0410-955e-edbf42e46eb7
-rw-r--r-- | src/modes/cmode_k.cpp | 50 |
1 files changed, 22 insertions, 28 deletions
diff --git a/src/modes/cmode_k.cpp b/src/modes/cmode_k.cpp index 2ee839efa..092f69fca 100644 --- a/src/modes/cmode_k.cpp +++ b/src/modes/cmode_k.cpp @@ -66,43 +66,37 @@ bool ModeChannelKey::CheckTimeStamp(time_t, time_t, const std::string &their_par ModeAction ModeChannelKey::OnModeChange(User* source, User*, Channel* channel, std::string ¶meter, bool adding, bool servermode) { - if ((channel->IsModeSet('k') != adding) || (!IS_LOCAL(source))) + bool exists = channel->IsModeSet('k'); + if (IS_LOCAL(source)) { - if (((channel->IsModeSet('k')) && (parameter != channel->GetModeParameter('k'))) && (IS_LOCAL(source))) + if (exists == adding) + return MODEACTION_DENY; + if (exists && (parameter != channel->GetModeParameter('k'))) { /* Key is currently set and the correct key wasnt given */ return MODEACTION_DENY; } - else if (channel->IsModeSet('k') && parameter == channel->GetModeParameter('k')) + } else { + if (exists && adding && parameter == channel->GetModeParameter('k')) { - /* Key is currently set, setting to the same as it already is.. drop it */ + /* no-op, don't show */ return MODEACTION_DENY; } - else if ((!channel->IsModeSet('k')) || ((adding) && (!IS_LOCAL(source)))) - { - /* Key isnt currently set */ - if ((parameter.length()) && (parameter.rfind(' ') == std::string::npos)) - { - std::string ckey; - ckey.assign(parameter, 0, 32); - channel->SetModeParam('k', ckey.c_str(), adding); - channel->SetMode('k', adding); - parameter = ckey; - return MODEACTION_ALLOW; - } - else - return MODEACTION_DENY; - } - else if (((channel->IsModeSet('k')) && (parameter == channel->GetModeParameter('k'))) || ((!adding) && (!IS_LOCAL(source)))) - { - /* Key is currently set, and correct key was given */ - channel->SetMode('k', adding); - return MODEACTION_ALLOW; - } - return MODEACTION_DENY; } - else - { + + /* invalid keys */ + if (!parameter.length()) return MODEACTION_DENY; + + if (parameter.rfind(' ') != std::string::npos) + return MODEACTION_DENY; + + channel->SetMode('k', adding); + if (adding) { + std::string ckey; + ckey.assign(parameter, 0, 32); + channel->SetModeParam('k', ckey.c_str(), adding); + parameter = ckey; } + return MODEACTION_ALLOW; } |