From 1c33356677595047eba381db676d6de499e44ad6 Mon Sep 17 00:00:00 2001 From: danieldg Date: Sat, 7 Mar 2009 02:45:02 +0000 Subject: Fix r11178 not allowing keys to be unset git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11182 e03df62e-2008-0410-955e-edbf42e46eb7 --- src/modes/cmode_k.cpp | 50 ++++++++++++++++++++++---------------------------- 1 file changed, 22 insertions(+), 28 deletions(-) (limited to 'src/modes') 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; } -- cgit v1.2.3