- if ((channel->IsModeSet('k') != adding) || (!IS_LOCAL(source)))
- {
- if (((channel->IsModeSet('k')) && (parameter != channel->GetModeParameter('k'))) && (IS_LOCAL(source)))
- {
- /* Key is currently set and the correct key wasnt given */
- return MODEACTION_DENY;
- }
- else if (channel->IsModeSet('k') && parameter == channel->GetModeParameter('k'))
- {
- /* Key is currently set, setting to the same as it already is.. drop it */
- 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
- {
- return MODEACTION_DENY;
- }