diff options
Diffstat (limited to 'src/modules/m_hostchange.cpp')
| -rw-r--r-- | src/modules/m_hostchange.cpp | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/src/modules/m_hostchange.cpp b/src/modules/m_hostchange.cpp index 86c00d592..57eb0ac92 100644 --- a/src/modules/m_hostchange.cpp +++ b/src/modules/m_hostchange.cpp @@ -45,27 +45,43 @@ class HostRule private: HostChangeAction action; std::string host; + std::string klass; std::string mask; insp::flat_set<long> ports; std::string prefix; std::string suffix; + void ReadConfig(std::shared_ptr<ConfigTag> tag) + { + // Parse <hostchange:class>. + klass = tag->getString("class"); + + // Parse <hostchange:port>. + 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<long>& Ports) + HostRule(std::shared_ptr<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<long>& Ports, const std::string& Prefix, const std::string& Suffix) + HostRule(std::shared_ptr<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 @@ -80,6 +96,9 @@ class HostRule bool Matches(LocalUser* user) const { + if (!klass.empty() && !stdalgo::string::equalsci(klass, user->GetClass()->GetName())) + return false; + if (!ports.empty() && !ports.count(user->server_sa.port())) return false; @@ -138,26 +157,17 @@ private: if (mask.empty()) throw ModuleException("<hostchange:mask> is a mandatory field, at " + tag->source.str()); - insp::flat_set<long> ports; - const std::string portlist = tag->getString("ports"); - if (!portlist.empty()) - { - irc::portparser portrange(portlist, false); - while (long 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]<account>[suffix]. - rules.emplace_back(HostRule::HCA_ADDACCOUNT, mask, ports, tag->getString("prefix"), tag->getString("suffix")); + rules.emplace_back(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]<nick>[suffix]. - rules.emplace_back(HostRule::HCA_ADDNICK, mask, ports, tag->getString("prefix"), tag->getString("suffix")); + rules.emplace_back(tag, HostRule::HCA_ADDNICK, mask, tag->getString("prefix"), tag->getString("suffix")); } else if (stdalgo::string::equalsci(action, "set")) { @@ -167,7 +177,7 @@ private: throw ModuleException("<hostchange:value> is a mandatory field when using the 'set' action, at " + tag->source.str()); // The hostname is in the format <value>. - rules.emplace_back(mask, value, ports); + rules.emplace_back(tag, mask, value); continue; } else |
