From 4350050a82df2c90db4a2ca4fe3ae75a8a343e08 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Sat, 3 Jul 2021 13:58:34 +0100 Subject: Fix some "targ" usages which were missed in the earlier commit. --- src/modules/m_callerid.cpp | 11 ++++----- src/modules/m_censor.cpp | 6 ++--- src/modules/m_check.cpp | 50 +++++++++++++++++++------------------- src/modules/m_services_account.cpp | 8 +++--- 4 files changed, 37 insertions(+), 38 deletions(-) (limited to 'src/modules') diff --git a/src/modules/m_callerid.cpp b/src/modules/m_callerid.cpp index 361e2bdda..459f51739 100644 --- a/src/modules/m_callerid.cpp +++ b/src/modules/m_callerid.cpp @@ -140,15 +140,14 @@ struct CallerIDExtInfo : public ExtensionItem // We need to walk the list of users on our accept list, and remove ourselves from their wholistsme. for (callerid_data::UserSet::iterator it = dat->accepting.begin(); it != dat->accepting.end(); ++it) { - callerid_data *targ = this->get(*it, false); - - if (!targ) + callerid_data* target = this->get(*it, false); + if (!target) { ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "ERROR: Inconsistency detected in callerid state, please report (1)"); continue; // shouldn't happen, but oh well. } - if (!stdalgo::vector::swaperase(targ->wholistsme, dat)) + if (!stdalgo::vector::swaperase(target->wholistsme, dat)) ServerInstance->Logs->Log(MODNAME, LOG_DEFAULT, "ERROR: Inconsistency detected in callerid state, please report (2)"); } delete dat; @@ -292,8 +291,8 @@ public: } // Now, look them up, and add me to their list - callerid_data *targ = extInfo.get(whotoadd, true); - targ->wholistsme.push_back(dat); + callerid_data* target = extInfo.get(whotoadd, true); + target->wholistsme.push_back(dat); user->WriteNotice(whotoadd->nick + " is now on your accept list"); return true; diff --git a/src/modules/m_censor.cpp b/src/modules/m_censor.cpp index e369f71a9..27ffbbd69 100644 --- a/src/modules/m_censor.cpp +++ b/src/modules/m_censor.cpp @@ -63,11 +63,11 @@ class ModuleCensor : public Module case MessageTarget::TYPE_CHANNEL: { - Channel* targchan = target.Get(); - if (!targchan->IsModeSet(cc)) + Channel* targetchan = target.Get(); + if (!targetchan->IsModeSet(cc)) return MOD_RES_PASSTHRU; - ModResult result = CheckExemption::Call(exemptionprov, user, targchan, "censor"); + ModResult result = CheckExemption::Call(exemptionprov, user, targetchan, "censor"); if (result == MOD_RES_ALLOW) return MOD_RES_PASSTHRU; break; diff --git a/src/modules/m_check.cpp b/src/modules/m_check.cpp index 87e601913..74159611c 100644 --- a/src/modules/m_check.cpp +++ b/src/modules/m_check.cpp @@ -170,10 +170,10 @@ class CommandCheck : public Command return CMD_SUCCESS; User *targetuser; - Channel *targchan; + Channel *targetchan; targetuser = ServerInstance->FindNick(parameters[0]); - targchan = ServerInstance->FindChan(parameters[0]); + targetchan = ServerInstance->FindChan(parameters[0]); /* * Syntax of a /check reply: @@ -187,7 +187,7 @@ class CommandCheck : public Command if (targetuser) { - LocalUser* loctarg = IS_LOCAL(targetuser); + LocalUser* localtarget = IS_LOCAL(targetuser); /* /check on a user */ context.Write("nuh", targetuser->GetFullHost()); context.Write("realnuh", targetuser->GetFullRealHost()); @@ -198,8 +198,8 @@ class CommandCheck : public Command context.Write("uid", targetuser->uuid); context.Write("signon", targetuser->signon); context.Write("nickts", targetuser->age); - if (loctarg) - context.Write("lastmsg", loctarg->idle_lastmsg); + if (localtarget) + context.Write("lastmsg", localtarget->idle_lastmsg); if (targetuser->IsAway()) { @@ -213,26 +213,26 @@ class CommandCheck : public Command OperInfo* oper = targetuser->oper; /* user is an oper of type ____ */ context.Write("opertype", oper->name); - if (loctarg) + if (localtarget) { - context.Write("chanmodeperms", GetAllowedOperOnlyModes(loctarg, MODETYPE_CHANNEL)); - context.Write("usermodeperms", GetAllowedOperOnlyModes(loctarg, MODETYPE_USER)); - context.Write("snomaskperms", GetAllowedOperOnlySnomasks(loctarg)); + context.Write("chanmodeperms", GetAllowedOperOnlyModes(localtarget, MODETYPE_CHANNEL)); + context.Write("usermodeperms", GetAllowedOperOnlyModes(localtarget, MODETYPE_USER)); + context.Write("snomaskperms", GetAllowedOperOnlySnomasks(localtarget)); context.Write("commandperms", oper->AllowedOperCommands.ToString()); context.Write("permissions", oper->AllowedPrivs.ToString()); } } - if (loctarg) + if (localtarget) { - context.Write("clientaddr", loctarg->client_sa.str()); - context.Write("serveraddr", loctarg->server_sa.str()); + context.Write("clientaddr", localtarget->client_sa.str()); + context.Write("serveraddr", localtarget->server_sa.str()); - std::string classname = loctarg->GetClass()->name; + std::string classname = localtarget->GetClass()->name; if (!classname.empty()) context.Write("connectclass", classname); - context.Write("exempt", loctarg->exempt ? "yes" : "no"); + context.Write("exempt", localtarget->exempt ? "yes" : "no"); } else context.Write("onip", targetuser->GetIPString()); @@ -248,25 +248,25 @@ class CommandCheck : public Command context.DumpExt(targetuser); } - else if (targchan) + else if (targetchan) { /* /check on a channel */ - context.Write("createdat", targchan->age); + context.Write("createdat", targetchan->age); - if (!targchan->topic.empty()) + if (!targetchan->topic.empty()) { /* there is a topic, assume topic related information exists */ - context.Write("topic", targchan->topic); - context.Write("topic_setby", targchan->setby); - context.Write("topic_setat", targchan->topicset); + context.Write("topic", targetchan->topic); + context.Write("topic_setby", targetchan->setby); + context.Write("topic_setat", targetchan->topicset); } - context.Write("modes", targchan->ChanModes(true)); - context.Write("membercount", ConvToStr(targchan->GetUserCounter())); + context.Write("modes", targetchan->ChanModes(true)); + context.Write("membercount", ConvToStr(targetchan->GetUserCounter())); /* now the ugly bit, spool current members of a channel. :| */ - const Channel::MemberMap& ulist = targchan->GetUsers(); + const Channel::MemberMap& ulist = targetchan->GetUsers(); /* note that unlike /names, we do NOT check +i vs in the channel */ for (Channel::MemberMap::const_iterator i = ulist.begin(); i != ulist.end(); ++i) @@ -282,9 +282,9 @@ class CommandCheck : public Command const ModeParser::ListModeList& listmodes = ServerInstance->Modes->GetListModes(); for (ModeParser::ListModeList::const_iterator i = listmodes.begin(); i != listmodes.end(); ++i) - context.DumpListMode(*i, targchan); + context.DumpListMode(*i, targetchan); - context.DumpExt(targchan); + context.DumpExt(targetchan); } else { diff --git a/src/modules/m_services_account.cpp b/src/modules/m_services_account.cpp index 0192e7e78..44e121cfd 100644 --- a/src/modules/m_services_account.cpp +++ b/src/modules/m_services_account.cpp @@ -215,16 +215,16 @@ class ModuleServicesAccount { case MessageTarget::TYPE_CHANNEL: { - Channel* targchan = target.Get(); + Channel* targetchan = target.Get(); - if (!targchan->IsModeSet(regmoderatedmode) || is_registered) + if (!targetchan->IsModeSet(regmoderatedmode) || is_registered) return MOD_RES_PASSTHRU; - if (CheckExemption::Call(exemptionprov, user, targchan, "regmoderated") == MOD_RES_ALLOW) + if (CheckExemption::Call(exemptionprov, user, targetchan, "regmoderated") == MOD_RES_ALLOW) return MOD_RES_PASSTHRU; // User is messaging a +M channel and is not registered or exempt. - user->WriteNumeric(ERR_NEEDREGGEDNICK, targchan->name, "You need to be identified to a registered account to message this channel"); + user->WriteNumeric(ERR_NEEDREGGEDNICK, targetchan->name, "You need to be identified to a registered account to message this channel"); return MOD_RES_DENY; break; } -- cgit v1.3.1-10-gc9f91 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') 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') 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