From 8c2135aad0b2bbd8afca21a6c0664a9e4182dc9b Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Wed, 11 Feb 2015 16:46:11 +0100 Subject: Convert the account login event to use the new cross-module event system --- src/modules/m_ircv3.cpp | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'src/modules/m_ircv3.cpp') diff --git a/src/modules/m_ircv3.cpp b/src/modules/m_ircv3.cpp index b1c04cdf5..b80c110f4 100644 --- a/src/modules/m_ircv3.cpp +++ b/src/modules/m_ircv3.cpp @@ -40,7 +40,7 @@ class WriteNeighboursWithExt : public User::ForEachNeighborHandler } }; -class ModuleIRCv3 : public Module +class ModuleIRCv3 : public Module, public AccountEventListener { GenericCap cap_accountnotify; GenericCap cap_awaynotify; @@ -52,7 +52,9 @@ class ModuleIRCv3 : public Module CUList last_excepts; public: - ModuleIRCv3() : cap_accountnotify(this, "account-notify"), + ModuleIRCv3() + : AccountEventListener(this) + , cap_accountnotify(this, "account-notify"), cap_awaynotify(this, "away-notify"), cap_extendedjoin(this, "extended-join") { @@ -74,25 +76,21 @@ class ModuleIRCv3 : public Module cap_extendedjoin.HandleEvent(ev); if (accountnotify) - { cap_accountnotify.HandleEvent(ev); + } - if (ev.id == "account_login") - { - AccountEvent* ae = static_cast(&ev); - - // :nick!user@host ACCOUNT account - // or - // :nick!user@host ACCOUNT * - std::string line = ":" + ae->user->GetFullHost() + " ACCOUNT "; - if (ae->account.empty()) - line += "*"; - else - line += std::string(ae->account); - - WriteNeighboursWithExt(ae->user, line, cap_accountnotify.ext); - } - } + void OnAccountChange(User* user, const std::string& newaccount) CXX11_OVERRIDE + { + // :nick!user@host ACCOUNT account + // or + // :nick!user@host ACCOUNT * + std::string line = ":" + user->GetFullHost() + " ACCOUNT "; + if (newaccount.empty()) + line += "*"; + else + line += newaccount; + + WriteNeighboursWithExt(user, line, cap_accountnotify.ext); } void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts) CXX11_OVERRIDE -- cgit v1.3.1-10-gc9f91 From 971788e42fbdce52a6dcf201e52afd690506c3a9 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Wed, 11 Feb 2015 16:52:39 +0100 Subject: Allow enabling/disabling caps via GenericCap::SetActive() --- include/modules/cap.h | 11 ++++++++++- src/modules/m_ircv3.cpp | 27 ++++++++++----------------- 2 files changed, 20 insertions(+), 18 deletions(-) (limited to 'src/modules/m_ircv3.cpp') diff --git a/include/modules/cap.h b/include/modules/cap.h index cc1cb8d8c..fae7fff15 100644 --- a/include/modules/cap.h +++ b/include/modules/cap.h @@ -40,11 +40,14 @@ class CapEvent : public Event class GenericCap { + bool active; + public: LocalIntExt ext; const std::string cap; GenericCap(Module* parent, const std::string& Cap) - : ext("cap_" + Cap, ExtensionItem::EXT_USER, parent) + : active(true) + , ext("cap_" + Cap, ExtensionItem::EXT_USER, parent) , cap(Cap) { } @@ -54,6 +57,9 @@ class GenericCap if (ev.id != "cap_request") return; + if (!active) + return; + CapEvent *data = static_cast(&ev); if (data->type == CapEvent::CAPEVENT_REQ) { @@ -87,4 +93,7 @@ class GenericCap ext.set(data->user, 0); } } + + void SetActive(bool newstate) { active = newstate; } + bool IsActive() const { return active; } }; diff --git a/src/modules/m_ircv3.cpp b/src/modules/m_ircv3.cpp index b80c110f4..861ccec14 100644 --- a/src/modules/m_ircv3.cpp +++ b/src/modules/m_ircv3.cpp @@ -45,9 +45,6 @@ class ModuleIRCv3 : public Module, public AccountEventListener GenericCap cap_accountnotify; GenericCap cap_awaynotify; GenericCap cap_extendedjoin; - bool accountnotify; - bool awaynotify; - bool extendedjoin; CUList last_excepts; @@ -63,20 +60,16 @@ class ModuleIRCv3 : public Module, public AccountEventListener void ReadConfig(ConfigStatus& status) CXX11_OVERRIDE { ConfigTag* conf = ServerInstance->Config->ConfValue("ircv3"); - accountnotify = conf->getBool("accountnotify", true); - awaynotify = conf->getBool("awaynotify", true); - extendedjoin = conf->getBool("extendedjoin", true); + cap_accountnotify.SetActive(conf->getBool("accountnotify", true)); + cap_awaynotify.SetActive(conf->getBool("awaynotify", true)); + cap_extendedjoin.SetActive(conf->getBool("extendedjoin", true)); } void OnEvent(Event& ev) CXX11_OVERRIDE { - if (awaynotify) - cap_awaynotify.HandleEvent(ev); - if (extendedjoin) - cap_extendedjoin.HandleEvent(ev); - - if (accountnotify) - cap_accountnotify.HandleEvent(ev); + cap_awaynotify.HandleEvent(ev); + cap_extendedjoin.HandleEvent(ev); + cap_accountnotify.HandleEvent(ev); } void OnAccountChange(User* user, const std::string& newaccount) CXX11_OVERRIDE @@ -96,10 +89,10 @@ class ModuleIRCv3 : public Module, public AccountEventListener void OnUserJoin(Membership* memb, bool sync, bool created, CUList& excepts) CXX11_OVERRIDE { // Remember who is not going to see the JOIN because of other modules - if ((awaynotify) && (memb->user->IsAway())) + if ((cap_awaynotify.IsActive()) && (memb->user->IsAway())) last_excepts = excepts; - if (!extendedjoin) + if (!cap_extendedjoin.IsActive()) return; /* @@ -168,7 +161,7 @@ class ModuleIRCv3 : public Module, public AccountEventListener ModResult OnSetAway(User* user, const std::string &awaymsg) CXX11_OVERRIDE { - if (awaynotify) + if (cap_awaynotify.IsActive()) { // Going away: n!u@h AWAY :reason // Back from away: n!u@h AWAY @@ -183,7 +176,7 @@ class ModuleIRCv3 : public Module, public AccountEventListener void OnPostJoin(Membership *memb) CXX11_OVERRIDE { - if ((!awaynotify) || (!memb->user->IsAway())) + if ((!cap_awaynotify.IsActive()) || (!memb->user->IsAway())) return; std::string line = ":" + memb->user->GetFullHost() + " AWAY :" + memb->user->awaymsg; -- cgit v1.3.1-10-gc9f91 From f3ef8a230cf3a0e3c3f75f7e37d2a1945e531754 Mon Sep 17 00:00:00 2001 From: Attila Molnar Date: Wed, 11 Feb 2015 17:01:00 +0100 Subject: Convert the CAP event to use the new cross-module event system --- include/modules/cap.h | 16 ++++++++-------- src/modules/m_cap.cpp | 9 ++++++--- src/modules/m_ircv3.cpp | 7 ------- src/modules/m_namesx.cpp | 5 ----- src/modules/m_sasl.cpp | 5 ----- src/modules/m_starttls.cpp | 5 ----- src/modules/m_uhnames.cpp | 5 ----- 7 files changed, 14 insertions(+), 38 deletions(-) (limited to 'src/modules/m_ircv3.cpp') diff --git a/include/modules/cap.h b/include/modules/cap.h index fae7fff15..7aa60cd21 100644 --- a/include/modules/cap.h +++ b/include/modules/cap.h @@ -20,7 +20,9 @@ #pragma once -class CapEvent : public Event +#include "event.h" + +class CapEvent { public: enum CapEventType @@ -35,10 +37,10 @@ class CapEvent : public Event std::vector wanted; std::vector ack; User* user; - CapEvent(Module* sender, User* u, CapEventType capevtype) : Event(sender, "cap_request"), type(capevtype), user(u) {} + CapEvent(Module* sender, User* u, CapEventType capevtype) : type(capevtype), user(u) {} }; -class GenericCap +class GenericCap : public Events::ModuleEventListener { bool active; @@ -46,17 +48,15 @@ class GenericCap LocalIntExt ext; const std::string cap; GenericCap(Module* parent, const std::string& Cap) - : active(true) + : Events::ModuleEventListener(parent, "event/cap") + , active(true) , ext("cap_" + Cap, ExtensionItem::EXT_USER, parent) , cap(Cap) { } - void HandleEvent(Event& ev) + void OnCapEvent(CapEvent& ev) CXX11_OVERRIDE { - if (ev.id != "cap_request") - return; - if (!active) return; diff --git a/src/modules/m_cap.cpp b/src/modules/m_cap.cpp index db5d85f0f..2c2178a18 100644 --- a/src/modules/m_cap.cpp +++ b/src/modules/m_cap.cpp @@ -39,9 +39,12 @@ CAP END */ class CommandCAP : public Command { + Events::ModuleEventProvider capevprov; + public: LocalIntExt reghold; CommandCAP (Module* mod) : Command(mod, "CAP", 1), + capevprov(mod, "event/cap"), reghold("CAP_REGHOLD", ExtensionItem::EXT_USER, mod) { works_before_reg = true; @@ -70,7 +73,7 @@ class CommandCAP : public Command } reghold.set(user, 1); - Data.Send(); + FOREACH_MOD_CUSTOM(capevprov, GenericCap, OnCapEvent, (Data)); if (Data.ack.size() > 0) { @@ -93,7 +96,7 @@ class CommandCAP : public Command CapEvent Data(creator, user, subcommand == "LS" ? CapEvent::CAPEVENT_LS : CapEvent::CAPEVENT_LIST); reghold.set(user, 1); - Data.Send(); + FOREACH_MOD_CUSTOM(capevprov, GenericCap, OnCapEvent, (Data)); std::string Result = irc::stringjoiner(Data.wanted); user->WriteCommand("CAP", subcommand + " :" + Result); @@ -103,7 +106,7 @@ class CommandCAP : public Command CapEvent Data(creator, user, CapEvent::CAPEVENT_CLEAR); reghold.set(user, 1); - Data.Send(); + FOREACH_MOD_CUSTOM(capevprov, GenericCap, OnCapEvent, (Data)); std::string Result = irc::stringjoiner(Data.ack); user->WriteCommand("CAP", "ACK :" + Result); diff --git a/src/modules/m_ircv3.cpp b/src/modules/m_ircv3.cpp index 861ccec14..caee0d329 100644 --- a/src/modules/m_ircv3.cpp +++ b/src/modules/m_ircv3.cpp @@ -65,13 +65,6 @@ class ModuleIRCv3 : public Module, public AccountEventListener cap_extendedjoin.SetActive(conf->getBool("extendedjoin", true)); } - void OnEvent(Event& ev) CXX11_OVERRIDE - { - cap_awaynotify.HandleEvent(ev); - cap_extendedjoin.HandleEvent(ev); - cap_accountnotify.HandleEvent(ev); - } - void OnAccountChange(User* user, const std::string& newaccount) CXX11_OVERRIDE { // :nick!user@host ACCOUNT account diff --git a/src/modules/m_namesx.cpp b/src/modules/m_namesx.cpp index f211b01d8..c701f16bf 100644 --- a/src/modules/m_namesx.cpp +++ b/src/modules/m_namesx.cpp @@ -94,11 +94,6 @@ class ModuleNamesX : public Module line.erase(pos, 1); line.insert(pos, prefixes); } - - void OnEvent(Event& ev) CXX11_OVERRIDE - { - cap.HandleEvent(ev); - } }; MODULE_INIT(ModuleNamesX) diff --git a/src/modules/m_sasl.cpp b/src/modules/m_sasl.cpp index 0a2c840bd..ade998b4e 100644 --- a/src/modules/m_sasl.cpp +++ b/src/modules/m_sasl.cpp @@ -283,11 +283,6 @@ class ModuleSASL : public Module { return Version("Provides support for IRC Authentication Layer (aka: atheme SASL) via AUTHENTICATE.",VF_VENDOR); } - - void OnEvent(Event &ev) CXX11_OVERRIDE - { - cap.HandleEvent(ev); - } }; MODULE_INIT(ModuleSASL) diff --git a/src/modules/m_starttls.cpp b/src/modules/m_starttls.cpp index d591eed55..b05302fa9 100644 --- a/src/modules/m_starttls.cpp +++ b/src/modules/m_starttls.cpp @@ -102,11 +102,6 @@ class ModuleStartTLS : public Module ssl.SetProvider("ssl/" + newprovider); } - void OnEvent(Event& ev) CXX11_OVERRIDE - { - tls.HandleEvent(ev); - } - void On005Numeric(std::map& tokens) CXX11_OVERRIDE { tokens["STARTTLS"]; diff --git a/src/modules/m_uhnames.cpp b/src/modules/m_uhnames.cpp index 0a171c4dc..90bac54f5 100644 --- a/src/modules/m_uhnames.cpp +++ b/src/modules/m_uhnames.cpp @@ -66,11 +66,6 @@ class ModuleUHNames : public Module return MOD_RES_PASSTHRU; } - - void OnEvent(Event& ev) CXX11_OVERRIDE - { - cap.HandleEvent(ev); - } }; MODULE_INIT(ModuleUHNames) -- cgit v1.3.1-10-gc9f91