summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mode.h6
-rw-r--r--src/mode.cpp13
-rw-r--r--src/modules.cpp3
3 files changed, 11 insertions, 11 deletions
diff --git a/include/mode.h b/include/mode.h
index c257226c9..7c5682135 100644
--- a/include/mode.h
+++ b/include/mode.h
@@ -637,10 +637,12 @@ class CoreExport ModeParser
const std::string& GetLastParse() const { return LastParse; }
const std::vector<std::string>& GetLastParseParams() { return LastParseParams; }
const std::vector<TranslateType>& GetLastParseTranslate() { return LastParseTranslate; }
+
/** Add a mode to the mode parser.
- * @return True if the mode was successfully added.
+ * Throws a ModuleException if the mode cannot be added.
*/
- bool AddMode(ModeHandler* mh);
+ void AddMode(ModeHandler* mh);
+
/** Delete a mode from the mode parser.
* When a mode is deleted, the mode handler will be called
* for every user (if it is a user mode) or for every channel
diff --git a/src/mode.cpp b/src/mode.cpp
index ef18663b9..b56c26990 100644
--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -619,14 +619,14 @@ ModeHandler::Id ModeParser::AllocateModeId(ModeType mt)
throw ModuleException("Out of ModeIds");
}
-bool ModeParser::AddMode(ModeHandler* mh)
+void ModeParser::AddMode(ModeHandler* mh)
{
/* Yes, i know, this might let people declare modes like '_' or '^'.
* If they do that, thats their problem, and if i ever EVER see an
* official InspIRCd developer do that, i'll beat them with a paddle!
*/
if ((mh->GetModeChar() < 'A') || (mh->GetModeChar() > 'z'))
- return false;
+ throw ModuleException("Invalid letter for mode " + mh->name);
/* A mode prefix of ',' is not acceptable, it would fuck up server to server.
* A mode prefix of ':' will fuck up both server to server, and client to server.
@@ -636,15 +636,15 @@ bool ModeParser::AddMode(ModeHandler* mh)
if (pm)
{
if ((pm->GetPrefix() > 126) || (pm->GetPrefix() == ',') || (pm->GetPrefix() == ':') || (pm->GetPrefix() == '#'))
- return false;
+ throw ModuleException("Invalid prefix for mode " + mh->name);
if (FindPrefix(pm->GetPrefix()))
- return false;
+ throw ModuleException("Prefix already exists for mode " + mh->name);
}
ModeHandler*& slot = modehandlers[mh->GetModeType()][mh->GetModeChar()-65];
if (slot)
- return false;
+ throw ModuleException("Letter is already in use for mode " + mh->name);
// The mode needs an id if it is either a user mode, a simple mode (flag) or a parameter mode.
// Otherwise (for listmodes and prefix modes) the id remains MODEID_MAX, which is invalid.
@@ -653,7 +653,7 @@ bool ModeParser::AddMode(ModeHandler* mh)
modeid = AllocateModeId(mh->GetModeType());
if (!modehandlersbyname[mh->GetModeType()].insert(std::make_pair(mh->name, mh)).second)
- return false;
+ throw ModuleException("Mode name already in use: " + mh->name);
// Everything is fine, add the mode
@@ -671,7 +671,6 @@ bool ModeParser::AddMode(ModeHandler* mh)
mhlist.list.push_back(mh->IsListModeBase());
RecreateModeListFor004Numeric();
- return true;
}
bool ModeParser::DelMode(ModeHandler* mh)
diff --git a/src/modules.cpp b/src/modules.cpp
index 88d89a35b..3723b09c3 100644
--- a/src/modules.cpp
+++ b/src/modules.cpp
@@ -594,8 +594,7 @@ void ModuleManager::AddService(ServiceProvider& item)
case SERVICE_MODE:
{
ModeHandler* mh = static_cast<ModeHandler*>(&item);
- if (!ServerInstance->Modes->AddMode(mh))
- throw ModuleException("Mode "+std::string(item.name)+" already exists.");
+ ServerInstance->Modes->AddMode(mh);
DataProviders.insert(std::make_pair((mh->GetModeType() == MODETYPE_CHANNEL ? "mode/" : "umode/") + item.name, &item));
dynamic_reference_base::reset_all();
return;