From 55edfba1236f92462a82feaf22fa7e1f33283e44 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sat, 3 Jul 2021 18:52:10 +0100 Subject: Move hostchange port parsing to a method in the HostRule class. --- src/modules/m_hostchange.cpp | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) (limited to 'src/modules/m_hostchange.cpp') diff --git a/src/modules/m_hostchange.cpp b/src/modules/m_hostchange.cpp index 365d0bcad..4a4317625 100644 --- a/src/modules/m_hostchange.cpp +++ b/src/modules/m_hostchange.cpp @@ -50,22 +50,34 @@ class HostRule std::string prefix; std::string suffix; + void ReadConfig(ConfigTag* tag) + { + // Parse . + const std::string portlist = tag->getString("ports"); + if (!portlist.empty()) + { + irc::portparser portrange(portlist, false); + while (int port = portrange.GetToken()) + ports.insert(port); + } + } + public: - HostRule(const std::string& Mask, const std::string& Host, const insp::flat_set& Ports) + HostRule(ConfigTag* tag, const std::string& Mask, const std::string& Host) : action(HCA_SET) , host(Host) , mask(Mask) - , ports(Ports) { + ReadConfig(tag); } - HostRule(HostChangeAction Action, const std::string& Mask, const insp::flat_set& Ports, const std::string& Prefix, const std::string& Suffix) + HostRule(ConfigTag* tag, HostChangeAction Action, const std::string& Mask, const std::string& Prefix, const std::string& Suffix) : action(Action) , mask(Mask) - , ports(Ports) , prefix(Prefix) , suffix(Suffix) { + ReadConfig(tag); } HostChangeAction GetAction() const @@ -138,26 +150,17 @@ private: if (mask.empty()) throw ModuleException(" is a mandatory field, at " + tag->getTagLocation()); - insp::flat_set ports; - const std::string portlist = tag->getString("ports"); - if (!portlist.empty()) - { - irc::portparser portrange(portlist, false); - while (int port = portrange.GetToken()) - ports.insert(port); - } - // Determine what type of host rule this is. const std::string action = tag->getString("action"); if (stdalgo::string::equalsci(action, "addaccount")) { // The hostname is in the format [prefix][suffix]. - rules.push_back(HostRule(HostRule::HCA_ADDACCOUNT, mask, ports, tag->getString("prefix"), tag->getString("suffix"))); + rules.push_back(HostRule(tag, HostRule::HCA_ADDACCOUNT, mask, tag->getString("prefix"), tag->getString("suffix"))); } else if (stdalgo::string::equalsci(action, "addnick")) { // The hostname is in the format [prefix][suffix]. - rules.push_back(HostRule(HostRule::HCA_ADDNICK, mask, ports, tag->getString("prefix"), tag->getString("suffix"))); + rules.push_back(HostRule(tag, HostRule::HCA_ADDNICK, mask, tag->getString("prefix"), tag->getString("suffix"))); } else if (stdalgo::string::equalsci(action, "set")) { @@ -167,7 +170,7 @@ private: throw ModuleException(" is a mandatory field when using the 'set' action, at " + tag->getTagLocation()); // The hostname is in the format . - rules.push_back(HostRule(mask, value, ports)); + rules.push_back(HostRule(tag, mask, value)); continue; } else -- cgit v1.3.1-10-gc9f91 From ea9a72c5a586517abc99412221bb1752f0b20b51 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sat, 3 Jul 2021 18:58:13 +0100 Subject: Allow hostchange to select users based on connect class. --- docs/conf/modules.conf.example | 2 +- src/modules/m_hostchange.cpp | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) (limited to 'src/modules/m_hostchange.cpp') diff --git a/docs/conf/modules.conf.example b/docs/conf/modules.conf.example index e6c8d11b6..041f32f03 100644 --- a/docs/conf/modules.conf.example +++ b/docs/conf/modules.conf.example @@ -1118,7 +1118,7 @@ # # # -# +# # hostcycle: If loaded, when a user gets a host or ident set, it will # cycle them in all their channels. If not loaded it will simply change diff --git a/src/modules/m_hostchange.cpp b/src/modules/m_hostchange.cpp index 4a4317625..b0b3275e9 100644 --- a/src/modules/m_hostchange.cpp +++ b/src/modules/m_hostchange.cpp @@ -45,6 +45,7 @@ class HostRule private: HostChangeAction action; std::string host; + std::string klass; std::string mask; insp::flat_set ports; std::string prefix; @@ -52,6 +53,9 @@ class HostRule void ReadConfig(ConfigTag* tag) { + // Parse . + klass = tag->getString("class"); + // Parse . const std::string portlist = tag->getString("ports"); if (!portlist.empty()) @@ -92,6 +96,9 @@ class HostRule bool Matches(LocalUser* user) const { + if (!klass.empty() && !stdalgo::string::equalsci(klass, user->MyClass->GetName())) + return false; + if (!ports.empty() && !ports.count(user->server_sa.port())) return false; -- cgit v1.3.1-10-gc9f91