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;
}
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;
}
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.
bool ModeParser::DelMode(ModeHandler* mh)
{
- if ((mh->GetModeChar() < 'A') || (mh->GetModeChar() > 'z'))
+ if (!ModeParser::IsModeChar(mh->GetModeChar()))
return false;
ModeHandlerMap& mhmap = modehandlersbyname[mh->GetModeType()];
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];
static_modes.b.DoRehash();
}
+bool ModeParser::IsModeChar(char chr)
+{
+ return ((chr >= 'A' && chr <= 'Z') || (chr >= 'a' && chr <= 'z'));
+}
+
ModeParser::ModeParser()
{
/* Clear mode handler list */