From 26ac315192e0d8a04d50e910697ab794eedf0cc1 Mon Sep 17 00:00:00 2001 From: Adam Date: Sun, 20 Apr 2014 14:35:14 -0400 Subject: New event system --- modules/pseudoclients/botserv.cpp | 24 +++++++++++-- modules/pseudoclients/chanserv.cpp | 70 ++++++++++++++++++++++++++++++++------ modules/pseudoclients/global.cpp | 23 ++++++++++--- modules/pseudoclients/hostserv.cpp | 18 ++++++++++ modules/pseudoclients/memoserv.cpp | 34 +++++++++++++++--- modules/pseudoclients/nickserv.cpp | 68 ++++++++++++++++++++++++++++++------ modules/pseudoclients/operserv.cpp | 54 +++++++++++++++++++++-------- 7 files changed, 244 insertions(+), 47 deletions(-) (limited to 'modules/pseudoclients') diff --git a/modules/pseudoclients/botserv.cpp b/modules/pseudoclients/botserv.cpp index cd09ed227..dbaf7b8d2 100644 --- a/modules/pseudoclients/botserv.cpp +++ b/modules/pseudoclients/botserv.cpp @@ -10,15 +10,35 @@ */ #include "module.h" +#include "modules/help.h" class BotServCore : public Module + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook { Reference BotServ; ExtensibleRef persist, inhabit; public: - BotServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR), - persist("PERSIST"), inhabit("inhabit") + BotServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) + , EventHook("OnSetCorrectModes") + , EventHook("OnBotAssign") + , EventHook("OnJoinChannel") + , EventHook("OnLeaveChannel") + , EventHook("Help") + , EventHook("OnChannelModeSet") + , EventHook("OnCreateChan") + , EventHook("OnUserKicked") + , EventHook("OnCreateBot") + , persist("PERSIST") + , inhabit("inhabit") { } diff --git a/modules/pseudoclients/chanserv.cpp b/modules/pseudoclients/chanserv.cpp index 1d6e1090c..7c607e251 100644 --- a/modules/pseudoclients/chanserv.cpp +++ b/modules/pseudoclients/chanserv.cpp @@ -11,18 +11,66 @@ #include "module.h" #include "modules/cs_mode.h" - -class ChanServCore : public Module, public ChanServService +#include "modules/help.h" +#include "modules/bs_bot.h" +#include "modules/chanserv.h" +#include "modules/cs_info.h" + +class ChanServCore : public Module + , public ChanServ::ChanServService + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook { Reference ChanServ; std::vector defaults; ExtensibleItem inhabit; ExtensibleRef persist; bool always_lower; + EventHandlers OnPreChanExpire; + EventHandlers OnChanExpire; public: - ChanServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR), - ChanServService(this), inhabit(this, "inhabit"), persist("PERSIST"), always_lower(false) + ChanServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) + , ChanServService(this) + , EventHook("OnBotDelete") + , EventHook("OnBotPrivmsg") + , EventHook("OnDelCore") + , EventHook("OnDelChan") + , EventHook("OnHelp") + , EventHook("OnCheckModes") + , EventHook("OnCreateChan") + , EventHook("OnCanSet") + , EventHook("OnChannelSync") + , EventHook("OnLog") + , EventHook("OnExpireTick") + , EventHook("OnCheckDelete") + , EventHook("OnPreUplinkSync") + , EventHook("OnChanRegistered") + , EventHook("OnJoinChannel") + , EventHook("OnChannelModeSet") + , EventHook("OnChanInfo") + , EventHook("OnSetCorrectModes") + , inhabit(this, "inhabit") + , persist("PERSIST") + , always_lower(false) + , OnPreChanExpire(this, "OnPreChanExpire") + , OnChanExpire(this, "OnChanExpire") { } @@ -167,13 +215,13 @@ class ChanServCore : public Module, public ChanServService if (newowner) { - Log(LOG_NORMAL, "chanserv/drop", ChanServ) << "Transferring foundership of " << ci->name << " from deleted nick " << nc->display << " to " << newowner->display; + ::Log(LOG_NORMAL, "chanserv/drop", ChanServ) << "Transferring foundership of " << ci->name << " from deleted nick " << nc->display << " to " << newowner->display; ci->SetFounder(newowner); ci->SetSuccessor(NULL); } else { - Log(LOG_NORMAL, "chanserv/drop", ChanServ) << "Deleting channel " << ci->name << " owned by deleted nick " << nc->display; + ::Log(LOG_NORMAL, "chanserv/drop", ChanServ) << "Deleting channel " << ci->name << " owned by deleted nick " << nc->display; delete ci; continue; @@ -318,7 +366,7 @@ class ChanServCore : public Module, public ChanServService } } - void OnLog(Log *l) override + void OnLog(::Log *l) override { if (l->type == LOG_CHANNEL) l->bi = ChanServ; @@ -351,12 +399,12 @@ class ChanServCore : public Module, public ChanServService expire = true; } - FOREACH_MOD(OnPreChanExpire, (ci, expire)); + this->OnPreChanExpire(&ChanServ::Event::PreChanExpire::OnPreChanExpire, ci, expire); if (expire) { - Log(LOG_NORMAL, "chanserv/expire", ChanServ) << "Expiring channel " << ci->name << " (founder: " << (ci->GetFounder() ? ci->GetFounder()->display : "(none)") << ")"; - FOREACH_MOD(OnChanExpire, (ci)); + ::Log(LOG_NORMAL, "chanserv/expire", ChanServ) << "Expiring channel " << ci->name << " (founder: " << (ci->GetFounder() ? ci->GetFounder()->display : "(none)") << ")"; + this->OnChanExpire(&ChanServ::Event::ChanExpire::OnChanExpire, ci); delete ci; } } @@ -425,7 +473,7 @@ class ChanServCore : public Module, public ChanServService { if (always_lower && c->ci && c->creation_time > c->ci->time_registered) { - Log(LOG_DEBUG) << "Changing TS of " << c->name << " from " << c->creation_time << " to " << c->ci->time_registered; + ::Log(LOG_DEBUG) << "Changing TS of " << c->name << " from " << c->creation_time << " to " << c->ci->time_registered; c->creation_time = c->ci->time_registered; IRCD->SendChannel(c); c->Reset(); diff --git a/modules/pseudoclients/global.cpp b/modules/pseudoclients/global.cpp index fe15a3ef9..e7577db47 100644 --- a/modules/pseudoclients/global.cpp +++ b/modules/pseudoclients/global.cpp @@ -10,8 +10,15 @@ */ #include "module.h" - -class GlobalCore : public Module, public GlobalService +#include "modules/help.h" +#include "modules/global.h" + +class GlobalCore : public Module + , public Global::GlobalService + , public EventHook + , public EventHook + , public EventHook + , public EventHook { Reference Global; @@ -24,8 +31,12 @@ class GlobalCore : public Module, public GlobalService } public: - GlobalCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR), - GlobalService(this) + GlobalCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) + , GlobalService(this) + , EventHook("OnRestart") + , EventHook("OnShutdown") + , EventHook("OnNewServer") + , EventHook("OnHelp") { } @@ -90,6 +101,10 @@ class GlobalCore : public Module, public GlobalService source.Reply(_("%s commands:"), Global->nick.c_str()); return EVENT_CONTINUE; } + + void OnPostHelp(CommandSource &source, const std::vector ¶ms) override + { + } }; MODULE_INIT(GlobalCore) diff --git a/modules/pseudoclients/hostserv.cpp b/modules/pseudoclients/hostserv.cpp index 9d9130fa6..373275e59 100644 --- a/modules/pseudoclients/hostserv.cpp +++ b/modules/pseudoclients/hostserv.cpp @@ -10,12 +10,26 @@ */ #include "module.h" +#include "modules/ns_update.h" +#include "modules/hs_del.h" +#include "modules/help.h" class HostServCore : public Module + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook { Reference HostServ; + public: HostServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) + , EventHook("OnUserLogin") + , EventHook("OnNickUpdate") + , EventHook("OnHelp") + , EventHook("OnSetVhost") + , EventHook("OnDeleteVhost") { if (!IRCD || !IRCD->CanSetVHost) throw ModuleException("Your IRCd does not support vhosts"); @@ -79,6 +93,10 @@ class HostServCore : public Module return EVENT_CONTINUE; } + void OnPostHelp(CommandSource &source, const std::vector ¶ms) override + { + } + void OnSetVhost(NickAlias *na) override { if (Config->GetModule(this)->Get("activate_on_set")) diff --git a/modules/pseudoclients/memoserv.cpp b/modules/pseudoclients/memoserv.cpp index 71f5e64d0..c9b11d294 100644 --- a/modules/pseudoclients/memoserv.cpp +++ b/modules/pseudoclients/memoserv.cpp @@ -10,10 +10,24 @@ */ #include "module.h" - -class MemoServCore : public Module, public MemoServService +#include "modules/ns_update.h" +#include "modules/help.h" +#include "modules/bs_bot.h" +#include "modules/memoserv.h" + +class MemoServCore : public Module, public MemoServ::MemoServService + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook { Reference MemoServ; + EventHandlers onmemosend; + EventHandlers onmemodel; bool SendMemoMail(NickCore *nc, MemoInfo *mi, Memo *m) { @@ -36,8 +50,18 @@ class MemoServCore : public Module, public MemoServService } public: - MemoServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR), - MemoServService(this) + MemoServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) + , MemoServ::MemoServService(this) + , EventHook("OnNickCoreCreate") + , EventHook("OnCreateChan") + , EventHook("OnBotDelete") + , EventHook("OnNickIdentify") + , EventHook("OnJoinChannel") + , EventHook("OnUserAway") + , EventHook("OnNickUpdate") + , EventHook("OnHelp") + , onmemosend(this, "OnMemoSend") + , onmemodel(this, "OnMemoDel") { } @@ -74,7 +98,7 @@ class MemoServCore : public Module, public MemoServService m->text = message; m->unread = true; - FOREACH_MOD(OnMemoSend, (source, target, mi, m)); + this->onmemosend(&MemoServ::Event::MemoSend::OnMemoSend, source, target, mi, m); if (ischan) { diff --git a/modules/pseudoclients/nickserv.cpp b/modules/pseudoclients/nickserv.cpp index d8b55a9d5..f29b1aa02 100644 --- a/modules/pseudoclients/nickserv.cpp +++ b/modules/pseudoclients/nickserv.cpp @@ -10,18 +10,23 @@ */ #include "module.h" +#include "modules/ns_info.h" +#include "modules/ns_group.h" +#include "modules/ns_update.h" +#include "modules/help.h" +#include "modules/nickserv.h" /** Timer for colliding nicks to force people off of nicknames */ class NickServCollide : public Timer { - NickServService *service; + NickServ::NickServService *service; Reference u; time_t ts; Reference na; public: - NickServCollide(NickServService *nss, User *user, NickAlias *nick, time_t delay) : Timer(delay), service(nss), u(user), ts(user->timestamp), na(nick) + NickServCollide(NickServ::NickServService *nss, User *user, NickAlias *nick, time_t delay) : Timer(delay), service(nss), u(user), ts(user->timestamp), na(nick) { } @@ -91,11 +96,32 @@ class NickServRelease : public User, public Timer void Tick(time_t t) override { } }; -class NickServCore : public Module, public NickServService +class NickServCore : public Module, public NickServ::NickServService + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook { Reference NickServ; std::vector defaults; ExtensibleItem held, collided; + EventHandlers onprenickexpire; + EventHandlers onnickexpire; + EventHandlers onnickregister; + EventHandlers onnickvalidate; void OnCancel(User *u, NickAlias *na) { @@ -113,8 +139,31 @@ class NickServCore : public Module, public NickServService } public: - NickServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR), - NickServService(this), held(this, "HELD"), collided(this, "COLLIDED") + NickServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) + , NickServ::NickServService(this) + , EventHook("OnShutdown") + , EventHook("OnRestart") + , EventHook("OnUserLogin") + , EventHook("OnDelNick") + , EventHook("OnDelCore") + , EventHook("OnChangeCoreDisplay") + , EventHook("OnNickIdentify") + , EventHook("OnNickGroup") + , EventHook("OnNickUpdate") + , EventHook("OnUserConnect") + , EventHook("OnPostUserLogoff") + , EventHook("OnServerSync") + , EventHook("OnUserNickChange") + , EventHook("OnUserModeSet") + , EventHook("OnHelp") + , EventHook("OnExpireTick") + , EventHook("OnNickInfo") + , held(this, "HELD") + , collided(this, "COLLIDED") + , onprenickexpire(this, "OnPreNickExpire") + , onnickexpire(this, "OnNickExpire") + , onnickregister(this, "OnNickRegister") + , onnickvalidate(this, "OnNickValidate") { } @@ -143,8 +192,7 @@ class NickServCore : public Module, public NickServService if (!na) return; - EventReturn MOD_RESULT; - FOREACH_RESULT(OnNickValidate, MOD_RESULT, (u, na)); + EventReturn MOD_RESULT = this->onnickvalidate(&NickServ::Event::NickValidate::OnNickValidate, u, na); if (MOD_RESULT == EVENT_STOP) { this->Collide(u, na); @@ -306,7 +354,7 @@ class NickServCore : public Module, public NickServService IRCD->SendLogout(user); user->RemoveMode(NickServ, "REGISTERED"); user->Logout(); - FOREACH_MOD(OnNickLogout, (user)); + Event::OnNickLogout(&Event::NickLogout::OnNickLogout, user); } nc->users.clear(); } @@ -515,12 +563,12 @@ class NickServCore : public Module, public NickServService if (nickserv_expire && Anope::CurTime - na->last_seen >= nickserv_expire) expire = true; - FOREACH_MOD(OnPreNickExpire, (na, expire)); + this->onprenickexpire(&NickServ::Event::PreNickExpire::OnPreNickExpire, na, expire); if (expire) { Log(LOG_NORMAL, "nickserv/expire", NickServ) << "Expiring nickname " << na->nick << " (group: " << na->nc->display << ") (e-mail: " << (na->nc->email.empty() ? "none" : na->nc->email) << ")"; - FOREACH_MOD(OnNickExpire, (na)); + this->onnickexpire(&NickServ::Event::NickExpire::OnNickExpire, na); delete na; } } diff --git a/modules/pseudoclients/operserv.cpp b/modules/pseudoclients/operserv.cpp index 7b43436f7..91d7f1add 100644 --- a/modules/pseudoclients/operserv.cpp +++ b/modules/pseudoclients/operserv.cpp @@ -10,6 +10,8 @@ */ #include "module.h" +#include "modules/help.h" +#include "modules/nickserv.h" class SGLineManager : public XLineManager { @@ -23,7 +25,7 @@ class SGLineManager : public XLineManager void OnExpire(const XLine *x) override { - Log(Config->GetClient("OperServ"), "expire/akill") << "AKILL on \002" << x->mask << "\002 has expired"; + ::Log(Config->GetClient("OperServ"), "expire/akill") << "AKILL on \002" << x->mask << "\002 has expired"; } void Send(User *u, XLine *x) override @@ -68,10 +70,8 @@ class SGLineManager : public XLineManager class SQLineManager : public XLineManager { - ServiceReference nickserv; - public: - SQLineManager(Module *creator) : XLineManager(creator, "xlinemanager/sqline", 'Q'), nickserv("NickServService", "NickServ") { } + SQLineManager(Module *creator) : XLineManager(creator, "xlinemanager/sqline", 'Q') { } void OnMatch(User *u, XLine *x) override { @@ -80,7 +80,7 @@ class SQLineManager : public XLineManager void OnExpire(const XLine *x) override { - Log(Config->GetClient("OperServ"), "expire/sqline") << "SQLINE on \002" << x->mask << "\002 has expired"; + ::Log(Config->GetClient("OperServ"), "expire/sqline") << "SQLINE on \002" << x->mask << "\002 has expired"; } void Send(User *u, XLine *x) override @@ -89,8 +89,8 @@ class SQLineManager : public XLineManager { if (!u) ; - else if (nickserv) - nickserv->Collide(u, NULL); + else if (NickServ::service) + NickServ::service->Collide(u, NULL); else u->Kill(Config->GetClient("OperServ"), "Q-Lined: " + x->reason); } @@ -144,7 +144,7 @@ class SNLineManager : public XLineManager void OnExpire(const XLine *x) override { - Log(Config->GetClient("OperServ"), "expire/snline") << "SNLINE on \002" << x->mask << "\002 has expired"; + ::Log(Config->GetClient("OperServ"), "expire/snline") << "SNLINE on \002" << x->mask << "\002 has expired"; } void Send(User *u, XLine *x) override @@ -171,6 +171,15 @@ class SNLineManager : public XLineManager }; class OperServCore : public Module + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook + , public EventHook { Reference OperServ; SGLineManager sglines; @@ -178,8 +187,19 @@ class OperServCore : public Module SNLineManager snlines; public: - OperServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR), - sglines(this), sqlines(this), snlines(this) + OperServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) + , EventHook("OnBotPrivmsg") + , EventHook("OnServerQuit") + , EventHook("OnUserModeSet") + , EventHook("OnUserModeUnset") + , EventHook("OnUserConnect") + , EventHook("OnUserNickChange") + , EventHook("OnCheckKick") + , EventHook("OnHelp") + , EventHook("OnLog") + , sglines(this) + , sqlines(this) + , snlines(this) { /* Yes, these are in this order for a reason. Most violent->least violent. */ @@ -218,7 +238,7 @@ class OperServCore : public Module if (bi == OperServ && !u->HasMode("OPER") && Config->GetModule(this)->Get("opersonly")) { u->SendMessage(bi, ACCESS_DENIED); - Log(bi, "bados") << "Denied access to " << bi->nick << " from " << u->GetMask() << " (non-oper)"; + ::Log(bi, "bados") << "Denied access to " << bi->nick << " from " << u->GetMask() << " (non-oper)"; return EVENT_STOP; } @@ -228,19 +248,19 @@ class OperServCore : public Module void OnServerQuit(Server *server) override { if (server->IsJuped()) - Log(server, "squit", OperServ) << "Received SQUIT for juped server " << server->GetName(); + ::Log(server, "squit", OperServ) << "Received SQUIT for juped server " << server->GetName(); } void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) override { if (mname == "OPER") - Log(u, "oper", OperServ) << "is now an IRC operator."; + ::Log(u, "oper", OperServ) << "is now an IRC operator."; } void OnUserModeUnset(const MessageSource &setter, User *u, const Anope::string &mname) override { if (mname == "OPER") - Log(u, "oper", OperServ) << "is no longer an IRC operator"; + ::Log(u, "oper", OperServ) << "is no longer an IRC operator"; } void OnUserConnect(User *u, bool &exempt) override @@ -276,7 +296,11 @@ class OperServCore : public Module return EVENT_CONTINUE; } - void OnLog(Log *l) override + void OnPostHelp(CommandSource &source, const std::vector ¶ms) override + { + } + + void OnLog(::Log *l) override { if (l->type == LOG_SERVER) l->bi = OperServ; -- cgit