]> git.netwichtig.de Git - user/henk/code/inspircd.git/commitdiff
Fix +k for real
authordanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Sat, 7 Mar 2009 05:47:09 +0000 (05:47 +0000)
committerdanieldg <danieldg@e03df62e-2008-0410-955e-edbf42e46eb7>
Sat, 7 Mar 2009 05:47:09 +0000 (05:47 +0000)
git-svn-id: http://svn.inspircd.org/repository/trunk/inspircd@11185 e03df62e-2008-0410-955e-edbf42e46eb7

src/modes/cmode_k.cpp

index a09131354a6bdc8eb4f7b46b4568964eb2ae0917..de420cae2eb8a08db0bad66bfe326eb4274a2fbf 100644 (file)
@@ -40,15 +40,18 @@ void ModeChannelKey::RemoveMode(Channel* channel, irc::modestacker* stack)
         * so we have a special-case RemoveMode here for it
         */
 
-       if (channel->IsModeSet(this->GetModeChar()))
+       if (channel->IsModeSet('k'))
        {
                if (stack)
                {
-                       stack->Push(this->GetModeChar(), channel->GetModeParameter('k'));
+                       stack->Push('k', channel->GetModeParameter('k'));
                }
                else
                {
-                       std::vector<std::string> parameters; parameters.push_back(channel->name); parameters.push_back("-k"); parameters.push_back(channel->GetModeParameter('k'));
+                       std::vector<std::string> parameters;
+                       parameters.push_back(channel->name);
+                       parameters.push_back("-k");
+                       parameters.push_back(channel->GetModeParameter('k'));
                        ServerInstance->SendMode(parameters, ServerInstance->FakeClient);
                }
        }
@@ -91,11 +94,20 @@ ModeAction ModeChannelKey::OnModeChange(User* source, User*, Channel* channel, s
        if (parameter.rfind(' ') != std::string::npos)
                return MODEACTION_DENY;
 
-       std::string ckey;
-       ckey.assign(parameter, 0, 32);
-       parameter = ckey;
-       if (adding && exists)
+       /* must first unset if we are changing the key, otherwise it will be ignored */
+       if (exists && adding)
                channel->SetMode('k', false);
-       channel->SetModeParam('k', parameter.c_str(), adding);
+
+       /* must run setmode always, to process the change */
+       channel->SetMode('k', adding);
+
+       if (adding)
+       {
+               std::string ckey;
+               ckey.assign(parameter, 0, 32);
+               parameter = ckey;
+               /* running this does not run setmode, despite the third parameter */
+               channel->SetModeParam('k', parameter.c_str(), true);
+       }
        return MODEACTION_ALLOW;
 }