diff options
Diffstat (limited to 'src/mode.cpp')
-rw-r--r-- | src/mode.cpp | 77 |
1 files changed, 33 insertions, 44 deletions
diff --git a/src/mode.cpp b/src/mode.cpp index 5efc98250..845b23fb0 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -1,6 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * + * Copyright (C) 2012 Shawn Smith <shawn@inspircd.org> * Copyright (C) 2009-2010 Daniel De Graaf <danieldg@inspircd.org> * Copyright (C) 2007, 2009 Dennis Friis <peavey@inspircd.org> * Copyright (C) 2006-2008 Robin Burchell <robin+git@viroteck.net> @@ -132,47 +133,39 @@ bool ModeHandler::ResolveModeConflict(std::string& theirs, const std::string& ou ModeAction SimpleUserModeHandler::OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding) { - if (adding) - { - if (!dest->IsModeSet(this->GetModeChar())) - { - dest->SetMode(this->GetModeChar(),true); - return MODEACTION_ALLOW; - } - } - else - { - if (dest->IsModeSet(this->GetModeChar())) - { - dest->SetMode(this->GetModeChar(),false); - return MODEACTION_ALLOW; - } - } + /* We're either trying to add a mode we already have or + remove a mode we don't have, deny. */ + if (dest->IsModeSet(this->GetModeChar()) == adding) + return MODEACTION_DENY; - return MODEACTION_DENY; + /* adding will be either true or false, depending on if we + are adding or removing the mode, since we already checked + to make sure we aren't adding a mode we have or that we + aren't removing a mode we don't have, we don't have to do any + other checks here to see if it's true or false, just add or + remove the mode */ + dest->SetMode(this->GetModeChar(), adding); + + return MODEACTION_ALLOW; } ModeAction SimpleChannelModeHandler::OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding) { - if (adding) - { - if (!channel->IsModeSet(this->GetModeChar())) - { - channel->SetMode(this->GetModeChar(),true); - return MODEACTION_ALLOW; - } - } - else - { - if (channel->IsModeSet(this->GetModeChar())) - { - channel->SetMode(this->GetModeChar(),false); - return MODEACTION_ALLOW; - } - } + /* We're either trying to add a mode we already have or + remove a mode we don't have, deny. */ + if (channel->IsModeSet(this->GetModeChar()) == adding) + return MODEACTION_DENY; - return MODEACTION_DENY; + /* adding will be either true or false, depending on if we + are adding or removing the mode, since we already checked + to make sure we aren't adding a mode we have or that we + aren't removing a mode we don't have, we don't have to do any + other checks here to see if it's true or false, just add or + remove the mode */ + channel->SetMode(this->GetModeChar(), adding); + + return MODEACTION_ALLOW; } ModeAction ParamChannelModeHandler::OnModeChange(User* source, User* dest, Channel* channel, std::string ¶meter, bool adding) @@ -906,9 +899,6 @@ bool ModeParser::DelModeWatcher(ModeWatcher* mw) */ void ModeHandler::RemoveMode(User* user, irc::modestacker* stack) { - char moderemove[MAXBUF]; - std::vector<std::string> parameters; - if (user->IsModeSet(this->GetModeChar())) { if (stack) @@ -917,9 +907,10 @@ void ModeHandler::RemoveMode(User* user, irc::modestacker* stack) } else { - sprintf(moderemove,"-%c",this->GetModeChar()); + std::vector<std::string> parameters; parameters.push_back(user->nick); - parameters.push_back(moderemove); + parameters.push_back("-"); + parameters[1].push_back(this->GetModeChar()); ServerInstance->Modes->Process(parameters, ServerInstance->FakeClient); } } @@ -930,9 +921,6 @@ void ModeHandler::RemoveMode(User* user, irc::modestacker* stack) */ void ModeHandler::RemoveMode(Channel* channel, irc::modestacker* stack) { - char moderemove[MAXBUF]; - std::vector<std::string> parameters; - if (channel->IsModeSet(this->GetModeChar())) { if (stack) @@ -941,9 +929,10 @@ void ModeHandler::RemoveMode(Channel* channel, irc::modestacker* stack) } else { - sprintf(moderemove,"-%c",this->GetModeChar()); + std::vector<std::string> parameters; parameters.push_back(channel->name); - parameters.push_back(moderemove); + parameters.push_back("-"); + parameters[1].push_back(this->GetModeChar()); ServerInstance->SendMode(parameters, ServerInstance->FakeClient); } } |