summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAttila Molnar <attilamolnar@hush.com>2012-07-13 08:32:54 -0700
committerAttila Molnar <attilamolnar@hush.com>2012-07-13 08:32:54 -0700
commit2ab2de1dda8f2043898b9df8004ba5b6c4df7349 (patch)
tree42bca883f1dd74882348a16ce0c01a9112216e3e
parent13ebac30b161bc2272b39dafd585c4c7fd7c37e4 (diff)
parent374a152a56029fa011367d8a8e3af2772565447d (diff)
Merge pull request #249 from Shawn-Smith/insp20+simplemode
[2.0] Simplified the SimpleModeHandlers
-rw-r--r--src/mode.cpp61
1 files changed, 27 insertions, 34 deletions
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 <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 &parameter, 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 &parameter, 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 &parameter, bool adding)