aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/mode.h8
-rw-r--r--src/coremods/core_mode.cpp61
-rw-r--r--src/mode.cpp48
3 files changed, 59 insertions, 58 deletions
diff --git a/include/mode.h b/include/mode.h
index 91e47fd3e..5f58d0f41 100644
--- a/include/mode.h
+++ b/include/mode.h
@@ -782,14 +782,6 @@ class CoreExport ModeParser
*/
PrefixMode* FindPrefix(unsigned const char pfxletter);
- /** Generates a list of modes, comma separated by type:
- * 1; Listmodes EXCEPT those with a prefix
- * 2; Modes that take a param when adding or removing
- * 3; Modes that only take a param when adding
- * 4; Modes that dont take a param
- */
- std::string GiveModeList(ModeType mt);
-
/** This returns the PREFIX=(ohv)@%+ section of the 005 numeric, or
* just the "@%+" part if the parameter false
*/
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)