summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Powell <petpow@saberuk.com>2017-09-11 15:22:40 +0100
committerPeter Powell <petpow@saberuk.com>2017-09-18 14:09:01 +0100
commit60d92db9a1b71bbfd4230c5eb9f04cd6a87a41d8 (patch)
treef9f938d98e9e81920446b357f86a4a558bea4567 /src
parent21f2f56e98625fe640f8045737335d8ebdf879b7 (diff)
Add ModeParser::IsModeChar to standardise mode validation.
Diffstat (limited to 'src')
-rw-r--r--src/configreader.cpp6
-rw-r--r--src/mode.cpp15
2 files changed, 11 insertions, 10 deletions
diff --git a/src/configreader.cpp b/src/configreader.cpp
index cc478b9b6..005730dca 100644
--- a/src/configreader.cpp
+++ b/src/configreader.cpp
@@ -487,8 +487,8 @@ void ServerConfig::Fill()
std::string modes = ConfValue("disabled")->getString("usermodes");
for (std::string::const_iterator p = modes.begin(); p != modes.end(); ++p)
{
- // Complain when the character is not a-z or A-Z
- if ((*p < 'A') || (*p > 'z') || ((*p < 'a') && (*p > 'Z')))
+ // Complain when the character is not a valid mode character.
+ if (!ModeParser::IsModeChar(*p))
throw CoreException("Invalid usermode " + std::string(1, *p) + " was found.");
DisabledUModes[*p - 'A'] = 1;
}
@@ -497,7 +497,7 @@ void ServerConfig::Fill()
modes = ConfValue("disabled")->getString("chanmodes");
for (std::string::const_iterator p = modes.begin(); p != modes.end(); ++p)
{
- if ((*p < 'A') || (*p > 'z') || ((*p < 'a') && (*p > 'Z')))
+ if (!ModeParser::IsModeChar(*p))
throw CoreException("Invalid chanmode " + std::string(1, *p) + " was found.");
DisabledCModes[*p - 'A'] = 1;
}
diff --git a/src/mode.cpp b/src/mode.cpp
index 22173c189..cd825d7a2 100644
--- a/src/mode.cpp
+++ b/src/mode.cpp
@@ -570,11 +570,7 @@ ModeHandler::Id ModeParser::AllocateModeId(ModeType mt)
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'))
+ if (!ModeParser::IsModeChar(mh->GetModeChar()))
throw ModuleException("Invalid letter for mode " + mh->name);
/* A mode prefix of ',' is not acceptable, it would fuck up server to server.
@@ -624,7 +620,7 @@ void ModeParser::AddMode(ModeHandler* mh)
bool ModeParser::DelMode(ModeHandler* mh)
{
- if ((mh->GetModeChar() < 'A') || (mh->GetModeChar() > 'z'))
+ if (!ModeParser::IsModeChar(mh->GetModeChar()))
return false;
ModeHandlerMap& mhmap = modehandlersbyname[mh->GetModeType()];
@@ -694,7 +690,7 @@ ModeHandler* ModeParser::FindMode(const std::string& modename, ModeType mt)
ModeHandler* ModeParser::FindMode(unsigned const char modeletter, ModeType mt)
{
- if ((modeletter < 'A') || (modeletter > 'z'))
+ if (!ModeParser::IsModeChar(modeletter))
return NULL;
return modehandlers[mt][modeletter-65];
@@ -919,6 +915,11 @@ void ModeParser::InitBuiltinModes()
static_modes.b.DoRehash();
}
+bool ModeParser::IsModeChar(char chr)
+{
+ return ((chr >= 'A' && chr <= 'Z') || (chr >= 'a' && chr <= 'z'));
+}
+
ModeParser::ModeParser()
{
/* Clear mode handler list */