aboutsummaryrefslogtreecommitdiffstats
path: root/src/coremods
diff options
context:
space:
mode:
authorGravatar Sadie Powell2021-07-03 15:26:47 +0100
committerGravatar Sadie Powell2021-07-03 15:26:47 +0100
commitc78d21d00bb6070d514b7a9a7be7e52dd59da411 (patch)
tree9fc45172c847cfe6de51472afaaf80b6001a4fad /src/coremods
parentWe 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/coremods')
-rw-r--r--src/coremods/core_mode.cpp61
1 files changed, 59 insertions, 2 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);
}
};