diff options
author | Peter Powell <petpow@saberuk.com> | 2017-09-11 15:38:26 +0100 |
---|---|---|
committer | Peter Powell <petpow@saberuk.com> | 2017-09-18 14:09:01 +0100 |
commit | ca9a56b7ac0ec2139ade835144369455baa757bc (patch) | |
tree | 85c22f30061f313ccba6c179667075ab347cc34e | |
parent | 60d92db9a1b71bbfd4230c5eb9f04cd6a87a41d8 (diff) |
Convert Disabled[CU]Modes to use a bitset instead of a char array.
-rw-r--r-- | include/configreader.h | 4 | ||||
-rw-r--r-- | src/configreader.cpp | 8 | ||||
-rw-r--r-- | src/mode.cpp | 4 | ||||
-rw-r--r-- | src/modules/m_conn_umodes.cpp | 8 |
4 files changed, 11 insertions, 13 deletions
diff --git a/include/configreader.h b/include/configreader.h index 36bb3297e..a98736640 100644 --- a/include/configreader.h +++ b/include/configreader.h @@ -319,11 +319,11 @@ class CoreExport ServerConfig /** This variable identifies which usermodes have been diabled. */ - char DisabledUModes[64]; + std::bitset<64> DisabledUModes; /** This variable identifies which chanmodes have been disabled. */ - char DisabledCModes[64]; + std::bitset<64> DisabledCModes; /** If set to true, then all opers on this server are * shown with a generic 'is an IRC operator' line rather diff --git a/src/configreader.cpp b/src/configreader.cpp index 005730dca..faf75dfcc 100644 --- a/src/configreader.cpp +++ b/src/configreader.cpp @@ -483,23 +483,23 @@ void ServerConfig::Fill() ReadXLine(this, "badhost", "host", ServerInstance->XLines->GetFactory("K")); ReadXLine(this, "exception", "host", ServerInstance->XLines->GetFactory("E")); - memset(DisabledUModes, 0, sizeof(DisabledUModes)); + DisabledUModes.reset(); 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 valid mode character. if (!ModeParser::IsModeChar(*p)) throw CoreException("Invalid usermode " + std::string(1, *p) + " was found."); - DisabledUModes[*p - 'A'] = 1; + DisabledUModes.set(*p - 'A'); } - memset(DisabledCModes, 0, sizeof(DisabledCModes)); + DisabledCModes.reset(); modes = ConfValue("disabled")->getString("chanmodes"); for (std::string::const_iterator p = modes.begin(); p != modes.end(); ++p) { if (!ModeParser::IsModeChar(*p)) throw CoreException("Invalid chanmode " + std::string(1, *p) + " was found."); - DisabledCModes[*p - 'A'] = 1; + DisabledCModes.set(*p - 'A'); } std::string v = security->getString("announceinvites"); diff --git a/src/mode.cpp b/src/mode.cpp index cd825d7a2..c4969d467 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -286,8 +286,8 @@ ModeAction ModeParser::TryMode(User* user, User* targetuser, Channel* chan, Mode if (IS_LOCAL(user) && !user->IsOper()) { - char* disabled = (type == MODETYPE_CHANNEL) ? ServerInstance->Config->DisabledCModes : ServerInstance->Config->DisabledUModes; - if (disabled[modechar - 'A']) + const std::bitset<64>& disabled = (type == MODETYPE_CHANNEL) ? ServerInstance->Config->DisabledCModes : ServerInstance->Config->DisabledUModes; + if (disabled.test(modechar - 'A')) { user->WriteNumeric(ERR_NOPRIVILEGES, InspIRCd::Format("Permission Denied - %s mode %c has been locked by the administrator", type == MODETYPE_CHANNEL ? "channel" : "user", modechar)); diff --git a/src/modules/m_conn_umodes.cpp b/src/modules/m_conn_umodes.cpp index 0b708641e..acac7640a 100644 --- a/src/modules/m_conn_umodes.cpp +++ b/src/modules/m_conn_umodes.cpp @@ -39,10 +39,8 @@ class ModuleModesOnConnect : public Module void OnUserConnect(LocalUser* user) CXX11_OVERRIDE { // Backup and zero out the disabled usermodes, so that we can override them here. - char save[64]; - memcpy(save, ServerInstance->Config->DisabledUModes, - sizeof(ServerInstance->Config->DisabledUModes)); - memset(ServerInstance->Config->DisabledUModes, 0, 64); + const std::bitset<64> save = ServerInstance->Config->DisabledUModes; + ServerInstance->Config->DisabledUModes.reset(); ConfigTag* tag = user->MyClass->config; std::string ThisModes = tag->getString("modes"); @@ -61,7 +59,7 @@ class ModuleModesOnConnect : public Module ServerInstance->Parser.CallHandler("MODE", modes, user); } - memcpy(ServerInstance->Config->DisabledUModes, save, 64); + ServerInstance->Config->DisabledUModes = save; } }; |