diff options
| author | 2021-07-03 15:26:47 +0100 | |
|---|---|---|
| committer | 2021-07-03 15:26:47 +0100 | |
| commit | c78d21d00bb6070d514b7a9a7be7e52dd59da411 (patch) | |
| tree | 9fc45172c847cfe6de51472afaaf80b6001a4fad /src | |
| parent | We haven't used Travis CI in a long time so this is unnecessary. (diff) | |
Move ModeParser::GiveModeList to core_mode.
Now we've dropped support for the 1202 protocol we don't need this
in the core.
Diffstat (limited to 'src')
| -rw-r--r-- | src/coremods/core_mode.cpp | 61 | ||||
| -rw-r--r-- | src/mode.cpp | 48 |
2 files changed, 59 insertions, 50 deletions
diff --git a/src/coremods/core_mode.cpp b/src/coremods/core_mode.cpp index 0947251cf..ca18dc9d4 100644 --- a/src/coremods/core_mode.cpp +++ b/src/coremods/core_mode.cpp @@ -271,6 +271,63 @@ class CoreModMode private: CommandMode cmdmode; + std::string GenerateModeList(ModeType mt) + { + // Type A: Modes that add or remove an address to or from a list. These + // modes MUST always have a parameter when sent from the server to a + // client. A client MAY issue the mode without an argument to obtain the + // current contents of the list. + std::string type1; + + // Type B: Modes that change a setting on a channel. These modes MUST + // always have a parameter. + std::string type2; + + // Type C: Modes that change a setting on a channel. These modes MUST + // have a parameter when being set, and MUST NOT have a parameter when + // being unset. + std::string type3; + + // Type D: Modes that change a setting on a channel. These modes MUST + // NOT have a parameter. + std::string type4; + + for (const auto& [_, mh] : ServerInstance->Modes.GetModes(mt)) + { + if (mh->NeedsParam(true)) + { + PrefixMode* pm = mh->IsPrefixMode(); + if (mh->IsListMode() && (!pm || !pm->GetPrefix())) + { + type1 += mh->GetModeChar(); + continue; + } + + if (mh->NeedsParam(false)) + { + if (!pm) + type2 += mh->GetModeChar(); + } + else + { + type3 += mh->GetModeChar(); + } + } + else + { + type4 += mh->GetModeChar(); + } + } + + // These don't need to be alphabetically ordered but it looks nicer. + std::sort(type1.begin(), type1.end()); + std::sort(type2.begin(), type2.end()); + std::sort(type3.begin(), type3.end()); + std::sort(type4.begin(), type4.end()); + + return InspIRCd::Format("%s,%s,%s,%s", type1.c_str(), type2.c_str(), type3.c_str(), type4.c_str()); + } + public: CoreModMode() : Module(VF_CORE | VF_VENDOR, "Provides the MODE command") @@ -281,8 +338,8 @@ class CoreModMode void OnBuildISupport(ISupport::TokenMap& tokens) override { - tokens["CHANMODES"] = ServerInstance->Modes.GiveModeList(MODETYPE_CHANNEL); - tokens["USERMODES"] = ServerInstance->Modes.GiveModeList(MODETYPE_USER); + tokens["CHANMODES"] = GenerateModeList(MODETYPE_CHANNEL); + tokens["USERMODES"] = GenerateModeList(MODETYPE_USER); } }; diff --git a/src/mode.cpp b/src/mode.cpp index 66c520d4a..089670869 100644 --- a/src/mode.cpp +++ b/src/mode.cpp @@ -724,54 +724,6 @@ PrefixMode* ModeParser::FindPrefix(unsigned const char pfxletter) return NULL; } -std::string ModeParser::GiveModeList(ModeType mt) -{ - std::string type1; /* Listmodes EXCEPT those with a prefix */ - std::string type2; /* Modes that take a param when adding or removing */ - std::string type3; /* Modes that only take a param when adding */ - std::string type4; /* Modes that dont take a param */ - - for (unsigned char mode = 'A'; mode <= 'z'; mode++) - { - ModeHandler* mh = modehandlers[mt][mode-65]; - if (mh) - { - /* One parameter when adding */ - if (mh->NeedsParam(true)) - { - PrefixMode* pm = mh->IsPrefixMode(); - if ((mh->IsListMode()) && ((!pm) || (pm->GetPrefix() == 0))) - { - type1 += mh->GetModeChar(); - } - else - { - /* ... and one parameter when removing */ - if (mh->NeedsParam(false)) - { - /* But not a list mode */ - if (!pm) - { - type2 += mh->GetModeChar(); - } - } - else - { - /* No parameters when removing */ - type3 += mh->GetModeChar(); - } - } - } - else - { - type4 += mh->GetModeChar(); - } - } - } - - return type1 + "," + type2 + "," + type3 + "," + type4; -} - struct PrefixModeSorter { bool operator()(PrefixMode* lhs, PrefixMode* rhs) |
