summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mode.h8
-rw-r--r--src/mode.cpp9
2 files changed, 17 insertions, 0 deletions
diff --git a/include/mode.h b/include/mode.h
index 2e40badca..4b8aa0935 100644
--- a/include/mode.h
+++ b/include/mode.h
@@ -479,6 +479,10 @@ class CoreExport ModeParser
*/
static const unsigned int MODETYPE_LAST = 2;
+ /** Type of the container that maps mode names to ModeHandlers
+ */
+ typedef TR1NS::unordered_map<std::string, ModeHandler*, irc::insensitive, irc::StrHashComp> ModeHandlerMap;
+
/** Mode handlers for each mode, to access a handler subtract
* 65 from the ascii value of the mode letter.
* The upper bit of the value indicates if its a usermode
@@ -486,6 +490,10 @@ class CoreExport ModeParser
*/
ModeHandler* modehandlers[MODETYPE_LAST][128];
+ /** A map of mode handlers keyed by their name
+ */
+ ModeHandlerMap modehandlersbyname[MODETYPE_LAST];
+
/** Lists of mode handlers by type
*/
struct
diff --git a/src/mode.cpp b/src/mode.cpp
index a2a0790b8..e70df5479 100644
--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -635,6 +635,9 @@ bool ModeParser::AddMode(ModeHandler* mh)
if (slot)
return false;
+ if (!modehandlersbyname[mh->GetModeType()].insert(std::make_pair(mh->name, mh)).second)
+ return false;
+
// Everything is fine, add the mode
slot = mh;
if (pm)
@@ -651,6 +654,11 @@ bool ModeParser::DelMode(ModeHandler* mh)
if ((mh->GetModeChar() < 'A') || (mh->GetModeChar() > 'z'))
return false;
+ ModeHandlerMap& mhmap = modehandlersbyname[mh->GetModeType()];
+ ModeHandlerMap::iterator mhmapit = mhmap.find(mh->name);
+ if ((mhmapit == mhmap.end()) || (mhmapit->second != mh))
+ return false;
+
ModeHandler*& slot = modehandlers[mh->GetModeType()][mh->GetModeChar()-65];
if (slot != mh)
return false;
@@ -689,6 +697,7 @@ bool ModeParser::DelMode(ModeHandler* mh)
break;
}
+ mhmap.erase(mhmapit);
slot = NULL;
if (mh->IsPrefixMode())
mhlist.prefix.erase(std::find(mhlist.prefix.begin(), mhlist.prefix.end(), mh->IsPrefixMode()));