From 374a152a56029fa011367d8a8e3af2772565447d Mon Sep 17 00:00:00 2001 From: Shawn Smith Date: Fri, 6 Jul 2012 20:57:44 -0400 Subject: Improved the SimpleModeHandlers --- src/mode.cpp | 61 +++++++++++++++++++++++++++--------------------------------- 1 file changed, 27 insertions(+), 34 deletions(-) (limited to 'src') diff --git a/src/mode.cpp b/src/mode.cpp index 5efc98250..083445cef 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -1,6 +1,7 @@ /* * InspIRCd -- Internet Relay Chat Daemon * + * Copyright (C) 2012 Shawn Smith * Copyright (C) 2009-2010 Daniel De Graaf * Copyright (C) 2007, 2009 Dennis Friis * Copyright (C) 2006-2008 Robin Burchell @@ -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) -- cgit v1.2.3