From 0e758a2ac23dc4a001e8e126cec14588da9a9769 Mon Sep 17 00:00:00 2001 From: Adam Date: Thu, 28 Jul 2016 21:29:35 -0400 Subject: Allow serializable fields to use storage in the respective objects. Split service management code nito a proper servicemanager. Make service references managed instead of lazy lookup. Also made events and serializable use service manager instead of their respective systems for management --- modules/nickserv/access.cpp | 31 ++++++++------ modules/nickserv/ajoin.cpp | 28 +++++++----- modules/nickserv/alist.cpp | 2 +- modules/nickserv/cert.cpp | 33 +++++++------- modules/nickserv/drop.cpp | 10 ++--- modules/nickserv/group.cpp | 44 +++++++++---------- modules/nickserv/identify.cpp | 6 +-- modules/nickserv/info.cpp | 23 ++++------ modules/nickserv/list.cpp | 7 +-- modules/nickserv/logout.cpp | 3 +- modules/nickserv/main/account.cpp | 10 ++--- modules/nickserv/main/account.h | 4 ++ modules/nickserv/main/accounttype.cpp | 13 +++--- modules/nickserv/main/identifyrequest.cpp | 11 +++++ modules/nickserv/main/identifyrequest.h | 1 + modules/nickserv/main/mode.h | 5 +++ modules/nickserv/main/modetype.h | 6 +-- modules/nickserv/main/nick.cpp | 8 ++-- modules/nickserv/main/nick.h | 8 ++++ modules/nickserv/main/nickserv.cpp | 67 ++++++++++++++--------------- modules/nickserv/main/nicktype.cpp | 28 ++++++------ modules/nickserv/maxemail.cpp | 7 +-- modules/nickserv/recover.cpp | 8 +++- modules/nickserv/register.cpp | 45 +++++++++++--------- modules/nickserv/resetpass.cpp | 3 +- modules/nickserv/set.cpp | 71 +++++++++++++++++-------------- modules/nickserv/set_misc.cpp | 22 ++++++---- modules/nickserv/suspend.cpp | 57 +++++++++++++------------ modules/nickserv/update.cpp | 10 ++--- 29 files changed, 309 insertions(+), 262 deletions(-) (limited to 'modules/nickserv') diff --git a/modules/nickserv/access.cpp b/modules/nickserv/access.cpp index 0e405484c..f29b98904 100644 --- a/modules/nickserv/access.cpp +++ b/modules/nickserv/access.cpp @@ -15,6 +15,11 @@ class NickAccessImpl : public NickAccess { + friend class NickAccessType; + + NickServ::Account *account = nullptr; + Anope::string mask; + public: NickAccessImpl(Serialize::TypeBase *type) : NickAccess(type) { } NickAccessImpl(Serialize::TypeBase *type, Serialize::ID id) : NickAccess(type, id) { } @@ -32,9 +37,9 @@ class NickAccessType : public Serialize::Type Serialize::ObjectField account; Serialize::Field mask; - NickAccessType(Module *creator) : Serialize::Type(creator, "NSAccess") - , account(this, "account", true) - , mask(this, "mask") + NickAccessType(Module *creator) : Serialize::Type(creator) + , account(this, "account", &NickAccessImpl::account, true) + , mask(this, "mask", &NickAccessImpl::mask) { } }; @@ -76,11 +81,11 @@ class CommandNSAccess : public Command return; } - std::vector access = nc->GetRefs(nsaccess); + std::vector access = nc->GetRefs(); - if (access.size() >= Config->GetModule(this->owner)->Get("accessmax", "32")) + if (access.size() >= Config->GetModule(this->GetOwner())->Get("accessmax", "32")) { - source.Reply(_("Sorry, the maximum of \002{0}\002 access entries has been reached."), Config->GetModule(this->owner)->Get("accessmax")); + source.Reply(_("Sorry, the maximum of \002{0}\002 access entries has been reached."), Config->GetModule(this->GetOwner())->Get("accessmax")); return; } @@ -91,7 +96,7 @@ class CommandNSAccess : public Command return; } - NickAccess *a = nsaccess.Create(); + NickAccess *a = Serialize::New(); a->SetAccount(nc); a->SetMask(mask); @@ -113,7 +118,7 @@ class CommandNSAccess : public Command return; } - for (NickAccess *a : nc->GetRefs(nsaccess)) + for (NickAccess *a : nc->GetRefs()) if (a->GetMask().equals_ci(mask)) { a->Delete(); @@ -128,7 +133,7 @@ class CommandNSAccess : public Command void DoList(CommandSource &source, NickServ::Account *nc, const Anope::string &mask) { - std::vector access = nc->GetRefs(nsaccess); + std::vector access = nc->GetRefs(); if (access.empty()) { source.Reply(_("The access list of \002{0}\002 is empty."), nc->GetDisplay()); @@ -236,6 +241,7 @@ class NSAccess : public Module public: NSAccess(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook(this) , commandnsaccess(this) , nick_type(this) { @@ -245,11 +251,12 @@ class NSAccess : public Module { if (u && Config->GetModule(this)->Get("addaccessonreg")) { - NickAccess *a = nsaccess.Create(); + NickAccess *a = Serialize::New(); a->SetAccount(na->GetAccount()); a->SetMask(u->Mask()); - //XXX? -// source.Reply(_("\002{0}\002 has been registered under your hostmask: \002{1}\002"), u_nick, na->GetAccount()->GetAccess(0)); + + u->SendMessage(Config->GetClient("NickServ"), + _("\002{0}\002 has been registered under your hostmask: \002{1}\002"), na->GetNick(), a->GetMask()); } } }; diff --git a/modules/nickserv/ajoin.cpp b/modules/nickserv/ajoin.cpp index 0b074a84a..fc5e9b198 100644 --- a/modules/nickserv/ajoin.cpp +++ b/modules/nickserv/ajoin.cpp @@ -14,6 +14,11 @@ class AutoJoinImpl : public AutoJoin { + friend class AutoJoinType; + + NickServ::Account *account = nullptr; + Anope::string channel, key; + public: AutoJoinImpl(Serialize::TypeBase *type) : AutoJoin(type) { } AutoJoinImpl(Serialize::TypeBase *type, Serialize::ID id) : AutoJoin(type, id) { } @@ -34,10 +39,10 @@ class AutoJoinType : public Serialize::Type Serialize::ObjectField owner; Serialize::Field channel, key; - AutoJoinType(Module *me) : Serialize::Type(me, "AutoJoin") - , owner(this, "owner", true) - , channel(this, "channel") - , key(this, "key") + AutoJoinType(Module *me) : Serialize::Type(me) + , owner(this, "owner", &AutoJoinImpl::account, true) + , channel(this, "channel", &AutoJoinImpl::channel) + , key(this, "key", &AutoJoinImpl::key) { } }; @@ -76,7 +81,7 @@ class CommandNSAJoin : public Command { void DoList(CommandSource &source, NickServ::Account *nc) { - std::vector channels = nc->GetRefs(autojoin); + std::vector channels = nc->GetRefs(); if (channels.empty()) { @@ -107,7 +112,7 @@ class CommandNSAJoin : public Command void DoAdd(CommandSource &source, NickServ::Account *nc, const Anope::string &chans, const Anope::string &keys) { - std::vector channels = nc->GetRefs(autojoin); + std::vector channels = nc->GetRefs(); Anope::string addedchans; Anope::string alreadyadded; @@ -123,9 +128,9 @@ class CommandNSAJoin : public Command if (channels[i]->GetChannel().equals_ci(chan)) break; - if (channels.size() >= Config->GetModule(this->owner)->Get("ajoinmax")) + if (channels.size() >= Config->GetModule(this->GetOwner())->Get("ajoinmax")) { - source.Reply(_("Sorry, the maximum of \002{0}\002 auto join entries has been reached."), Config->GetModule(this->owner)->Get("ajoinmax")); + source.Reply(_("Sorry, the maximum of \002{0}\002 auto join entries has been reached."), Config->GetModule(this->GetOwner())->Get("ajoinmax")); return; } @@ -143,7 +148,7 @@ class CommandNSAJoin : public Command continue; } - AutoJoin *entry = autojoin.Create(); + AutoJoin *entry = Serialize::New(); entry->SetOwner(nc); entry->SetChannel(chan); entry->SetKey(key); @@ -174,7 +179,7 @@ class CommandNSAJoin : public Command void DoDel(CommandSource &source, NickServ::Account *nc, const Anope::string &chans) { - std::vector channels = nc->GetRefs(autojoin); + std::vector channels = nc->GetRefs(); Anope::string delchans; Anope::string notfoundchans; commasepstream sep(chans); @@ -282,6 +287,7 @@ class NSAJoin : public Module public: NSAJoin(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook(this) , commandnsajoin(this) , ajtype(this) { @@ -297,7 +303,7 @@ class NSAJoin : public Module if (!NickServ) return; - std::vector channels = u->Account()->GetRefs(autojoin); + std::vector channels = u->Account()->GetRefs(); if (channels.empty()) return; diff --git a/modules/nickserv/alist.cpp b/modules/nickserv/alist.cpp index e4aaff38b..f80af7cb1 100644 --- a/modules/nickserv/alist.cpp +++ b/modules/nickserv/alist.cpp @@ -47,7 +47,7 @@ class CommandNSAList : public Command list.AddColumn(_("Number")).AddColumn(_("Channel")).AddColumn(_("Access")).AddColumn(_("Description")); - std::vector chans = nc->GetRefs(ChanServ::channel); + std::vector chans = nc->GetRefs(); std::sort(chans.begin(), chans.end(), ChannelSort); for (ChanServ::Channel *ci : chans) { diff --git a/modules/nickserv/cert.cpp b/modules/nickserv/cert.cpp index 23487f305..6df85aacd 100644 --- a/modules/nickserv/cert.cpp +++ b/modules/nickserv/cert.cpp @@ -14,7 +14,6 @@ #include "modules/nickserv.h" static Anope::hash_map certmap; -static EventHandlers *events; class CertServiceImpl : public CertService { @@ -31,7 +30,7 @@ class CertServiceImpl : public CertService bool Matches(User *u, NickServ::Account *nc) override { - std::vector cl = nc->GetRefs(certentry); + std::vector cl = nc->GetRefs(); return !u->fingerprint.empty() && FindCert(cl, u->fingerprint); } @@ -46,6 +45,11 @@ class CertServiceImpl : public CertService class NSCertEntryImpl : public NSCertEntry { + friend class NSCertEntryType; + + NickServ::Account *account = nullptr; + Anope::string cert; + public: NSCertEntryImpl(Serialize::TypeBase *type) : NSCertEntry(type) { } NSCertEntryImpl(Serialize::TypeBase *type, Serialize::ID id) : NSCertEntry(type, id) { } @@ -95,9 +99,9 @@ class NSCertEntryType : public Serialize::Type } } mask; - NSCertEntryType(Module *me) : Serialize::Type(me, "NSCertEntry") - , nc(this, "nc", true) - , mask(this, "mask") + NSCertEntryType(Module *me) : Serialize::Type(me) + , nc(this, "nc", &NSCertEntryImpl::account, true) + , mask(this, "mask", &NSCertEntryImpl::cert) { } }; @@ -141,8 +145,8 @@ class CommandNSCert : public Command void DoAdd(CommandSource &source, NickServ::Account *nc, Anope::string certfp) { - std::vector cl = nc->GetRefs(certentry); - unsigned max = Config->GetModule(this->owner)->Get("max", "5"); + std::vector cl = nc->GetRefs(); + unsigned max = Config->GetModule(this->GetOwner())->Get("max", "5"); if (cl.size() >= max) { @@ -175,9 +179,11 @@ class CommandNSCert : public Command return; } - NSCertEntry *e = certentry.Create(); + NSCertEntry *e = Serialize::New(); e->SetAccount(nc); e->SetCert(certfp); + + // XXX fire events Log(nc == source.GetAccount() ? LOG_COMMAND : LOG_ADMIN, source, this) << "to ADD certificate fingerprint " << certfp << " to " << nc->GetDisplay(); source.Reply(_("\002{0}\002 added to the certificate list of \002{1}\002."), certfp, nc->GetDisplay()); @@ -185,7 +191,7 @@ class CommandNSCert : public Command void DoDel(CommandSource &source, NickServ::Account *nc, Anope::string certfp) { - std::vector cl = nc->GetRefs(certentry); + std::vector cl = nc->GetRefs(); if (certfp.empty()) { @@ -215,7 +221,7 @@ class CommandNSCert : public Command void DoList(CommandSource &source, NickServ::Account *nc) { - std::vector cl = nc->GetRefs(certentry); + std::vector cl = nc->GetRefs(); if (cl.empty()) { @@ -309,18 +315,15 @@ class NSCert : public Module CommandNSCert commandnscert; CertServiceImpl cs; - EventHandlers onnickservevents; - public: NSCert(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook(this) + , EventHook(this) , commandnscert(this) , cs(this) - , onnickservevents(this) { if (!IRCD || !IRCD->CanCertFP) throw ModuleException("Your IRCd does not support ssl client certificates"); - - events = &onnickservevents; } void OnFingerprint(User *u) override diff --git a/modules/nickserv/drop.cpp b/modules/nickserv/drop.cpp index e1eba9a3c..e45f1e2ea 100644 --- a/modules/nickserv/drop.cpp +++ b/modules/nickserv/drop.cpp @@ -14,10 +14,8 @@ class CommandNSDrop : public Command { - EventHandlers &onnickdrop; - public: - CommandNSDrop(Module *creator, EventHandlers &event) : Command(creator, "nickserv/drop", 1, 1), onnickdrop(event) + CommandNSDrop(Module *creator) : Command(creator, "nickserv/drop", 1, 1) { this->SetSyntax(_("\037nickname\037")); this->SetDesc(_("Cancel the registration of a nickname")); @@ -54,7 +52,7 @@ class CommandNSDrop : public Command return; } - this->onnickdrop(&Event::NickDrop::OnNickDrop, source, na); + EventManager::Get()->Dispatch(&Event::NickDrop::OnNickDrop, source, na); Log(!is_mine ? LOG_ADMIN : LOG_COMMAND, source, this) << "to drop nickname " << na->GetNick() << " (group: " << na->GetAccount()->GetDisplay() << ") (email: " << (!na->GetAccount()->GetEmail().empty() ? na->GetAccount()->GetEmail() : "none") << ")"; na->Delete(); @@ -77,12 +75,10 @@ class CommandNSDrop : public Command class NSDrop : public Module { CommandNSDrop commandnsdrop; - EventHandlers onnickdrop; public: NSDrop(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - , commandnsdrop(this, onnickdrop) - , onnickdrop(this) + , commandnsdrop(this) { } diff --git a/modules/nickserv/group.cpp b/modules/nickserv/group.cpp index 3a50d0306..5c9fb326f 100644 --- a/modules/nickserv/group.cpp +++ b/modules/nickserv/group.cpp @@ -15,14 +15,13 @@ class NSGroupRequestListener : public NickServ::IdentifyRequestListener { - EventHandlers &onnickgroup; CommandSource source; Command *cmd; Anope::string nick; Reference target; public: - NSGroupRequestListener(EventHandlers &event, CommandSource &src, Command *c, const Anope::string &n, NickServ::Nick *targ) : onnickgroup(event), source(src), cmd(c), nick(n), target(targ) { } + NSGroupRequestListener(CommandSource &src, Command *c, const Anope::string &n, NickServ::Nick *targ) : source(src), cmd(c), nick(n), target(targ) { } void OnSuccess(NickServ::IdentifyRequest *) override { @@ -34,11 +33,11 @@ class NSGroupRequestListener : public NickServ::IdentifyRequestListener /* If the nick is already registered, drop it. */ if (na) { - Event::OnChangeCoreDisplay(&Event::ChangeCoreDisplay::OnChangeCoreDisplay, na->GetAccount(), u->nick); + EventManager::Get()->Dispatch(&Event::ChangeCoreDisplay::OnChangeCoreDisplay, na->GetAccount(), u->nick); delete na; } - na = NickServ::nick.Create(); + na = Serialize::New(); na->SetNick(nick); na->SetAccount(target->GetAccount()); na->SetLastUsermask(u->GetIdent() + "@" + u->GetDisplayedHost()); @@ -47,7 +46,7 @@ class NSGroupRequestListener : public NickServ::IdentifyRequestListener na->SetTimeRegistered(Anope::CurTime); u->Login(target->GetAccount()); - this->onnickgroup(&Event::NickGroup::OnNickGroup, u, target); + EventManager::Get()->Dispatch(&Event::NickGroup::OnNickGroup, u, target); Log(LOG_COMMAND, source, cmd) << "to make " << nick << " join group of " << target->GetNick() << " (" << target->GetAccount()->GetDisplay() << ") (email: " << (!target->GetAccount()->GetEmail().empty() ? target->GetAccount()->GetEmail() : "none") << ")"; source.Reply(_("You are now in the group of \002{0}\002."), target->GetNick()); @@ -69,10 +68,10 @@ class NSGroupRequestListener : public NickServ::IdentifyRequestListener class CommandNSGroup : public Command { - EventHandlers &onnickgroup; - + ServiceReference certservice; + public: - CommandNSGroup(Module *creator, EventHandlers &event) : Command(creator, "nickserv/group", 0, 2), onnickgroup(event) + CommandNSGroup(Module *creator) : Command(creator, "nickserv/group", 0, 2) { this->SetDesc(_("Join a group")); this->SetSyntax(_("\037[target]\037 \037[password]\037")); @@ -115,7 +114,7 @@ class CommandNSGroup : public Command } if (Config->GetModule("nickserv")->Get("restrictopernicks")) - for (Oper *o : Serialize::GetObjects(operblock)) + for (Oper *o : Serialize::GetObjects()) { if (!u->HasMode("OPER") && u->nick.find_ci(o->GetName()) != Anope::string::npos) { @@ -127,7 +126,7 @@ class CommandNSGroup : public Command NickServ::Nick *target, *na = NickServ::FindNick(u->nick); const Anope::string &guestnick = Config->GetModule("nickserv")->Get("guestnickprefix", "Guest"); time_t reg_delay = Config->GetModule("nickserv")->Get("regdelay"); - unsigned maxaliases = Config->GetModule(this->owner)->Get("maxaliases"); + unsigned maxaliases = Config->GetModule(this->GetOwner())->Get("maxaliases"); if (!(target = NickServ::FindNick(nick))) { source.Reply(_("\002{0}\002 isn't registered."), nick); @@ -147,7 +146,7 @@ class CommandNSGroup : public Command return; } - if (na && Config->GetModule(this->owner)->Get("nogroupchange")) + if (na && Config->GetModule(this->GetOwner())->Get("nogroupchange")) { source.Reply(_("Your nick is already registered.")); return; @@ -165,13 +164,13 @@ class CommandNSGroup : public Command return; } - if (na && Config->GetModule(this->owner)->Get("nogroupchange")) + if (na && Config->GetModule(this->GetOwner())->Get("nogroupchange")) { source.Reply(_("You are already registered.")); return; } - if (maxaliases && target->GetAccount()->GetRefs(NickServ::nick).size() >= maxaliases && !target->GetAccount()->IsServicesOper()) + if (maxaliases && target->GetAccount()->GetRefs().size() >= maxaliases && !target->GetAccount()->IsServicesOper()) { source.Reply(_("There are too many nicknames in your group.")); return; @@ -194,13 +193,13 @@ class CommandNSGroup : public Command if (ok == false && !pass.empty()) { - NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSGroupRequestListener(onnickgroup, source, this, u->nick, target), owner, target->GetAccount()->GetDisplay(), pass); - Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, source.GetUser(), req); + NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSGroupRequestListener(source, this, u->nick, target), this->GetOwner(), target->GetAccount()->GetDisplay(), pass); + EventManager::Get()->Dispatch(&Event::CheckAuthentication::OnCheckAuthentication, source.GetUser(), req); req->Dispatch(); } else { - NSGroupRequestListener req(onnickgroup, source, this, u->nick, target); + NSGroupRequestListener req(source, this, u->nick, target); if (ok) req.OnSuccess(nullptr); @@ -238,7 +237,7 @@ class CommandNSUngroup : public Command Anope::string nick = !params.empty() ? params[0] : ""; NickServ::Nick *na = NickServ::FindNick(!nick.empty() ? nick : u->nick); - if (u->Account()->GetRefs(NickServ::nick).size() == 1) + if (u->Account()->GetRefs().size() == 1) { source.Reply(_("Your nickname is not grouped to anything, so you can't ungroup it.")); return; @@ -260,9 +259,9 @@ class CommandNSUngroup : public Command NickServ::Account *oldcore = na->GetAccount(); if (na->GetNick().equals_ci(oldcore->GetDisplay())) - oldcore->SetDisplay(oldcore->GetRef(NickServ::nick)); + oldcore->SetDisplay(oldcore->GetRef()); - NickServ::Account *nc = NickServ::account.Create(); + NickServ::Account *nc = Serialize::New(); nc->SetDisplay(na->GetNick()); na->SetAccount(nc); @@ -319,7 +318,7 @@ class CommandNSGList : public Command list.AddColumn(_("Nick")).AddColumn(_("Expires")); time_t nickserv_expire = Config->GetModule("nickserv")->Get("expire", "21d"), unconfirmed_expire = Config->GetModule("nickserv")->Get("unconfirmedexpire", "1d"); - for (NickServ::Nick *na2 : nc->GetRefs(NickServ::nick)) + for (NickServ::Nick *na2 : nc->GetRefs()) { Anope::string expires; if (na2->HasFieldS("NS_NO_EXPIRE")) @@ -368,14 +367,11 @@ class NSGroup : public Module CommandNSUngroup commandnsungroup; CommandNSGList commandnsglist; - EventHandlers onnickgroup; - public: NSGroup(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - , commandnsgroup(this, onnickgroup) + , commandnsgroup(this) , commandnsungroup(this) , commandnsglist(this) - , onnickgroup(this) { if (Config->GetModule("nickserv")->Get("nonicknameownership")) throw ModuleException(modname + " can not be used with options:nonicknameownership enabled"); diff --git a/modules/nickserv/identify.cpp b/modules/nickserv/identify.cpp index 122378d8a..a9b1f9284 100644 --- a/modules/nickserv/identify.cpp +++ b/modules/nickserv/identify.cpp @@ -89,15 +89,15 @@ class CommandNSIdentify : public Command return; } - unsigned int maxlogins = Config->GetModule(this->owner)->Get("maxlogins"); + unsigned int maxlogins = Config->GetModule(this->GetOwner())->Get("maxlogins"); if (na && maxlogins && na->GetAccount()->users.size() >= maxlogins) { source.Reply(_("Account \002{0}\002 has already reached the maximum number of simultaneous logins ({1})."), na->GetAccount()->GetDisplay(), maxlogins); return; } - NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSIdentifyRequestListener(source, this), owner, na ? na->GetAccount()->GetDisplay() : nick, pass); - Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, u, req); + NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSIdentifyRequestListener(source, this), this->GetOwner(), na ? na->GetAccount()->GetDisplay() : nick, pass); + EventManager::Get()->Dispatch(&Event::CheckAuthentication::OnCheckAuthentication, u, req); req->Dispatch(); } diff --git a/modules/nickserv/info.cpp b/modules/nickserv/info.cpp index 0bc712ac9..02be72f2b 100644 --- a/modules/nickserv/info.cpp +++ b/modules/nickserv/info.cpp @@ -15,10 +15,8 @@ class CommandNSInfo : public Command { - EventHandlers &onnickinfo; - public: - CommandNSInfo(Module *creator, EventHandlers &event) : Command(creator, "nickserv/info", 0, 2), onnickinfo(event) + CommandNSInfo(Module *creator) : Command(creator, "nickserv/info", 0, 2) { this->SetDesc(_("Displays information about a given nickname")); this->SetSyntax(_("[\037nickname\037]")); @@ -60,7 +58,7 @@ class CommandNSInfo : public Command source.Reply(_("\002{0}\002 has not confirmed their account."), na->GetNick()); if (na->GetAccount()->IsServicesOper() && (show_hidden || !na->GetAccount()->HasFieldS("HIDE_STATUS"))) - source.Reply(_("\002{0}\002 is a Services Operator of type \002{0}\002."), na->GetNick(), na->GetAccount()->o->GetType()->GetName()); + source.Reply(_("\002{0}\002 is a Services Operator of type \002{1}\002."), na->GetNick(), na->GetAccount()->o->GetType()->GetName()); InfoFormatter info(source.nc); @@ -112,7 +110,7 @@ class CommandNSInfo : public Command } } - this->onnickinfo(&Event::NickInfo::OnNickInfo, source, na, info, show_hidden); + EventManager::Get()->Dispatch(&Event::NickInfo::OnNickInfo, source, na, info, show_hidden); std::vector replies; info.Process(replies); @@ -161,7 +159,7 @@ class CommandNSSetHide : public Command } NickServ::Account *nc = na->GetAccount(); - EventReturn MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); + EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -259,20 +257,17 @@ class NSInfo : public Module CommandNSSetHide commandnssethide; CommandNSSASetHide commandnssasethide; - EventHandlers onnickinfo; - Serialize::Field hide_email, hide_usermask, hide_status, hide_quit; public: NSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - , commandnsinfo(this, onnickinfo) + , commandnsinfo(this) , commandnssethide(this) , commandnssasethide(this) - , onnickinfo(this) - , hide_email(this, NickServ::account, "HIDE_EMAIL") - , hide_usermask(this, NickServ::account, "HIDE_MASK") - , hide_status(this, NickServ::account, "HIDE_STATUS") - , hide_quit(this, NickServ::account, "HIDE_QUIT") + , hide_email(this, "HIDE_EMAIL") + , hide_usermask(this, "HIDE_MASK") + , hide_status(this, "HIDE_STATUS") + , hide_quit(this, "HIDE_QUIT") { } diff --git a/modules/nickserv/list.cpp b/modules/nickserv/list.cpp index 53a3a9394..c6758d583 100644 --- a/modules/nickserv/list.cpp +++ b/modules/nickserv/list.cpp @@ -31,7 +31,7 @@ class CommandNSList : public Command bool is_servadmin = source.HasCommand("nickserv/list"); int count = 0, from = 0, to = 0; bool suspended, nsnoexpire, unconfirmed; - unsigned listmax = Config->GetModule(this->owner)->Get("listmax", "50"); + unsigned listmax = Config->GetModule(this->GetOwner())->Get("listmax", "50"); suspended = nsnoexpire = unconfirmed = false; @@ -200,7 +200,7 @@ class CommandNSSetPrivate : public Command } NickServ::Account *nc = na->GetAccount(); - EventReturn MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); + EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -270,10 +270,11 @@ class NSList : public Module public: NSList(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook(this) , commandnslist(this) , commandnssetprivate(this) , commandnssasetprivate(this) - , priv(this, NickServ::account, "NS_PRIVATE") + , priv(this, "NS_PRIVATE") { } diff --git a/modules/nickserv/logout.cpp b/modules/nickserv/logout.cpp index 9bcb543fc..2afc65124 100644 --- a/modules/nickserv/logout.cpp +++ b/modules/nickserv/logout.cpp @@ -46,6 +46,7 @@ class CommandNSLogout : public Command return; } +#warning "revalidate" #if 0 if (!nick.empty() && !param.empty() && param.equals_ci("REVALIDATE") && NickServ::service) NickServ::service->Validate(u2); @@ -64,7 +65,7 @@ class CommandNSLogout : public Command u2->Logout(); /* Send out an event */ - Event::OnNickLogout(&Event::NickLogout::OnNickLogout, u2); + EventManager::Get()->Dispatch(&Event::NickLogout::OnNickLogout, u2); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/nickserv/main/account.cpp b/modules/nickserv/main/account.cpp index d74154d97..bfde7f15b 100644 --- a/modules/nickserv/main/account.cpp +++ b/modules/nickserv/main/account.cpp @@ -22,7 +22,7 @@ AccountImpl::~AccountImpl() void AccountImpl::Delete() { - Event::OnDelCore(&Event::DelCore::OnDelCore, this); + EventManager::Get()->Dispatch(&Event::DelCore::OnDelCore, this); for (unsigned i = users.size(); i > 0; --i) users[i - 1]->Logout(); @@ -72,7 +72,7 @@ void AccountImpl::SetLanguage(const Anope::string &lang) MemoServ::MemoInfo *AccountImpl::GetMemos() { - return GetRef(MemoServ::memoinfo); + return GetRef(); } void AccountImpl::SetDisplay(NickServ::Nick *na) @@ -80,7 +80,7 @@ void AccountImpl::SetDisplay(NickServ::Nick *na) if (na->GetAccount() != this || na->GetNick() == this->GetDisplay()) return; - Event::OnChangeCoreDisplay(&Event::ChangeCoreDisplay::OnChangeCoreDisplay, this, na->GetNick()); + EventManager::Get()->Dispatch(&Event::ChangeCoreDisplay::OnChangeCoreDisplay, this, na->GetNick()); NickServ::nickcore_map& map = NickServ::service->GetAccountMap(); @@ -109,7 +109,7 @@ bool AccountImpl::IsOnAccess(User *u) if (!u->GetCloakedHost().empty()) buf3 = u->GetIdent() + "@" + u->GetCloakedHost(); - for (NickAccess *access : GetRefs(nsaccess)) + for (NickAccess *access : GetRefs()) { Anope::string a = access->GetMask(); if (Anope::Match(buf, a) || (!buf2.empty() && Anope::Match(buf2, a)) || (!buf3.empty() && Anope::Match(buf3, a))) @@ -121,7 +121,7 @@ bool AccountImpl::IsOnAccess(User *u) unsigned int AccountImpl::GetChannelCount() { unsigned int i = 0; - for (ChanServ::Channel *c : GetRefs(ChanServ::channel)) + for (ChanServ::Channel *c : GetRefs()) if (c->GetFounder() == this) ++i; return i; diff --git a/modules/nickserv/main/account.h b/modules/nickserv/main/account.h index 584548563..69edce0db 100644 --- a/modules/nickserv/main/account.h +++ b/modules/nickserv/main/account.h @@ -2,6 +2,10 @@ class AccountImpl : public NickServ::Account { + friend class AccountType; + + Anope::string display, password, email, language; + public: AccountImpl(Serialize::TypeBase *type) : NickServ::Account(type) { } AccountImpl(Serialize::TypeBase *type, Serialize::ID id) : NickServ::Account(type, id) { } diff --git a/modules/nickserv/main/accounttype.cpp b/modules/nickserv/main/accounttype.cpp index 3dad436b4..4f2c59d80 100644 --- a/modules/nickserv/main/accounttype.cpp +++ b/modules/nickserv/main/accounttype.cpp @@ -1,12 +1,11 @@ #include "module.h" #include "accounttype.h" -//#include "account.h" -AccountType::AccountType(Module *me) : Serialize::Type(me, "NickCore") - , display(this, "display") - , pass(this, "pass") - , email(this, "email") - , language(this, "language") +AccountType::AccountType(Module *me) : Serialize::Type(me) + , display(this, "display", &AccountImpl::display) + , pass(this, "pass", &AccountImpl::password) + , email(this, "email", &AccountImpl::email) + , language(this, "language", &AccountImpl::language) { } @@ -29,7 +28,7 @@ void AccountType::Display::SetField(AccountImpl *acc, const Anope::string &disp) NickServ::Account *AccountType::FindAccount(const Anope::string &acc) { Serialize::ID id; - EventReturn result = Event::OnSerialize(&Event::SerializeEvents::OnSerializeFind, this, &this->display, acc, id); + EventReturn result = EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializeFind, this, &this->display, acc, id); if (result == EVENT_ALLOW) return RequireID(id); diff --git a/modules/nickserv/main/identifyrequest.cpp b/modules/nickserv/main/identifyrequest.cpp index 4fc2f9989..3d014965b 100644 --- a/modules/nickserv/main/identifyrequest.cpp +++ b/modules/nickserv/main/identifyrequest.cpp @@ -49,3 +49,14 @@ void IdentifyRequestImpl::Dispatch() else dispatched = true; } + +void IdentifyRequestImpl::Unload(Module *m) +{ + if (this->GetOwner() != m) + return; + + if (!success) + l->OnFail(this); + delete this; +} + diff --git a/modules/nickserv/main/identifyrequest.h b/modules/nickserv/main/identifyrequest.h index e74d3129e..03857da96 100644 --- a/modules/nickserv/main/identifyrequest.h +++ b/modules/nickserv/main/identifyrequest.h @@ -10,4 +10,5 @@ class IdentifyRequestImpl : public NickServ::IdentifyRequest void Release(Module *m) override; void Success(Module *m) override; void Dispatch() override; + void Unload(Module *); }; diff --git a/modules/nickserv/main/mode.h b/modules/nickserv/main/mode.h index 9fc4c331e..df72e1823 100644 --- a/modules/nickserv/main/mode.h +++ b/modules/nickserv/main/mode.h @@ -1,6 +1,11 @@ class ModeImpl : public NickServ::Mode { + friend class NSModeType; + + NickServ::Account *account = nullptr; + Anope::string mode; + public: ModeImpl(Serialize::TypeBase *type) : NickServ::Mode(type) { } ModeImpl(Serialize::TypeBase *type, Serialize::ID id) : NickServ::Mode(type, id) { } diff --git a/modules/nickserv/main/modetype.h b/modules/nickserv/main/modetype.h index 0c4aefecc..5796614d4 100644 --- a/modules/nickserv/main/modetype.h +++ b/modules/nickserv/main/modetype.h @@ -6,9 +6,9 @@ class NSModeType : public Serialize::Type Serialize::ObjectField account; Serialize::Field mode; - NSModeType(Module *creator) : Serialize::Type(creator, "NSKeepMode") - , account(this, "account", true) - , mode(this, "mode") + NSModeType(Module *creator) : Serialize::Type(creator) + , account(this, "account", &ModeImpl::account, true) + , mode(this, "mode", &ModeImpl::mode) { } }; diff --git a/modules/nickserv/main/nick.cpp b/modules/nickserv/main/nick.cpp index 0ac55ff93..95cef63da 100644 --- a/modules/nickserv/main/nick.cpp +++ b/modules/nickserv/main/nick.cpp @@ -1,12 +1,10 @@ /* * - * (C) 2003-2014 Anope Team + * (C) 2003-2016 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. * */ @@ -22,12 +20,12 @@ NickImpl::~NickImpl() void NickImpl::Delete() { - Event::OnDelNick(&Event::DelNick::OnDelNick, this); + EventManager::Get()->Dispatch(&Event::DelNick::OnDelNick, this); if (this->GetAccount()) { /* Next: see if our core is still useful. */ - std::vector aliases = this->GetAccount()->GetRefs(NickServ::nick); + std::vector aliases = this->GetAccount()->GetRefs(); auto it = std::find(aliases.begin(), aliases.end(), this); if (it != aliases.end()) diff --git a/modules/nickserv/main/nick.h b/modules/nickserv/main/nick.h index 043d7c052..fa8e7bcc5 100644 --- a/modules/nickserv/main/nick.h +++ b/modules/nickserv/main/nick.h @@ -1,6 +1,14 @@ class NickImpl : public NickServ::Nick { + friend class NickType; + + NickServ::Account *account = nullptr; + Anope::string nick, last_quit, last_realname, last_usermask, last_realhost; + time_t time_registered = 0, last_seen = 0; + Anope::string vhost_ident, vhost_host, vhost_creator; + time_t vhost_created = 0; + public: NickImpl(Serialize::TypeBase *type) : NickServ::Nick(type) { } NickImpl(Serialize::TypeBase *type, Serialize::ID id) : NickServ::Nick(type, id) { } diff --git a/modules/nickserv/main/nickserv.cpp b/modules/nickserv/main/nickserv.cpp index 85ac34b12..434e4324c 100644 --- a/modules/nickserv/main/nickserv.cpp +++ b/modules/nickserv/main/nickserv.cpp @@ -138,16 +138,12 @@ class NickServCore : public Module, public NickServ::NickServService , 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; std::set identifyrequests; NickServ::nickalias_map NickList; NickServ::nickcore_map AccountList; @@ -173,21 +169,41 @@ class NickServCore : public Module, public NickServ::NickServService public: NickServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) , NickServ::NickServService(this) + + , EventHook(this) + , EventHook(this) + , EventHook(this) + , EventHook(this) + , EventHook(this) + , EventHook(this) + , EventHook(this) + , EventHook(this) + , EventHook(this) + , EventHook(this) + , EventHook(this) + , EventHook(this) + , EventHook(this) + , EventHook(this) + , EventHook(this) + , EventHook(this) + , EventHook(this) + , EventHook(this) + , EventHook(this) + , EventHook(this) + , held(this, "HELD") , collided(this, "COLLIDED") - , onprenickexpire(this) - , onnickexpire(this) - , onnickregister(this) - , onnickvalidate(this) , nick_type(this) , account_type(this) , mode_type(this) { + NickServ::service = this; } ~NickServCore() { OnShutdown(); + NickServ::service = nullptr; } void OnShutdown() override @@ -210,7 +226,7 @@ class NickServCore : public Module, public NickServ::NickServService if (!na) return; - EventReturn MOD_RESULT = this->onnickvalidate(&NickServ::Event::NickValidate::OnNickValidate, u, na); + EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&NickServ::Event::NickValidate::OnNickValidate, u, na); if (MOD_RESULT == EVENT_STOP) { this->Collide(u, na); @@ -412,7 +428,7 @@ class NickServCore : public Module, public NickServ::NickServService IRCD->SendLogout(user); user->RemoveMode(NickServ, "REGISTERED"); user->Logout(); - Event::OnNickLogout(&Event::NickLogout::OnNickLogout, user); + EventManager::Get()->Dispatch(&Event::NickLogout::OnNickLogout, user); } } @@ -588,11 +604,11 @@ class NickServCore : public Module, public NickServ::NickServService "nickname(s)."), NickServ->nick.c_str()); } - void OnNickCoreCreate(NickServ::Account *nc) override + void OnNickRegister(User *, NickServ::Nick *na, const Anope::string &) override { /* Set default flags */ for (unsigned i = 0; i < defaults.size(); ++i) - nc->SetS(defaults[i].upper(), true); + na->GetAccount()->SetS(defaults[i].upper(), true); } void OnUserQuit(User *u, const Anope::string &msg) override @@ -627,12 +643,12 @@ class NickServCore : public Module, public NickServ::NickServService if (nickserv_expire && Anope::CurTime - na->GetLastSeen() >= nickserv_expire) expire = true; - this->onprenickexpire(&NickServ::Event::PreNickExpire::OnPreNickExpire, na, expire); + EventManager::Get()->Dispatch(&NickServ::Event::PreNickExpire::OnPreNickExpire, na, expire); if (expire) { Log(LOG_NORMAL, "nickserv/expire", NickServ) << "Expiring nickname " << na->GetNick() << " (group: " << na->GetAccount()->GetDisplay() << ") (e-mail: " << (na->GetAccount()->GetEmail().empty() ? "none" : na->GetAccount()->GetEmail()) << ")"; - this->onnickexpire(&NickServ::Event::NickExpire::OnNickExpire, na); + EventManager::Get()->Dispatch(&NickServ::Event::NickExpire::OnNickExpire, na); delete na; } } @@ -657,27 +673,10 @@ class NickServCore : public Module, public NickServ::NickServService { for (std::set::iterator it = identifyrequests.begin(), it_end = identifyrequests.end(); it != it_end;) { - NickServ::IdentifyRequest *ir = *it; + IdentifyRequestImpl *ir = anope_dynamic_static_cast(*it); ++it; - ir->Release(m); -#if 0 - ir->holds.erase(m); - if (ir->holds.empty() && ir->dispatched) - { - if (!ir->success) - ir->OnFail(); - delete ir; - continue; - } - - if (ir->GetOwner() == m) - { - if (!ir->success) - ir->OnFail(); - delete ir; - } -#endif + ir->Unload(m); } } }; diff --git a/modules/nickserv/main/nicktype.cpp b/modules/nickserv/main/nicktype.cpp index 9607aaa2f..7d9b34ac1 100644 --- a/modules/nickserv/main/nicktype.cpp +++ b/modules/nickserv/main/nicktype.cpp @@ -1,19 +1,19 @@ #include "module.h" #include "nicktype.h" -NickType::NickType(Module *me) : Serialize::Type(me, "NickAlias") - , nick(this, "nick") - , last_quit(this, "last_quit") - , last_realname(this, "last_realname") - , last_usermask(this, "last_usermask") - , last_realhost(this, "last_realhost") - , time_registered(this, "time_registered") - , last_seen(this, "last_seen") - , vhost_ident(this, "vhost_ident") - , vhost_host(this, "vhost_host") - , vhost_creator(this, "vhost_creator") - , vhost_created(this, "vhost_created") - , nc(this, "nc") +NickType::NickType(Module *me) : Serialize::Type(me) + , nick(this, "nick", &NickImpl::nick) + , last_quit(this, "last_quit", &NickImpl::last_quit) + , last_realname(this, "last_realname", &NickImpl::last_realname) + , last_usermask(this, "last_usermask", &NickImpl::last_usermask) + , last_realhost(this, "last_realhost", &NickImpl::last_realhost) + , time_registered(this, "time_registered", &NickImpl::time_registered) + , last_seen(this, "last_seen", &NickImpl::last_seen) + , vhost_ident(this, "vhost_ident", &NickImpl::vhost_ident) + , vhost_host(this, "vhost_host", &NickImpl::vhost_host) + , vhost_creator(this, "vhost_creator", &NickImpl::vhost_creator) + , vhost_created(this, "vhost_created", &NickImpl::vhost_created) + , nc(this, "nc", &NickImpl::account) { } @@ -32,7 +32,7 @@ void NickType::Nick::SetField(NickImpl *na, const Anope::string &value) NickServ::Nick *NickType::FindNick(const Anope::string &n) { Serialize::ID id; - EventReturn result = Event::OnSerialize(&Event::SerializeEvents::OnSerializeFind, this, &this->nick, n, id); + EventReturn result = EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializeFind, this, &this->nick, n, id); if (result == EVENT_ALLOW) return RequireID(id); diff --git a/modules/nickserv/maxemail.cpp b/modules/nickserv/maxemail.cpp index 38054f819..34f83741d 100644 --- a/modules/nickserv/maxemail.cpp +++ b/modules/nickserv/maxemail.cpp @@ -49,6 +49,7 @@ class NSMaxEmail : public Module public: NSMaxEmail(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook(this) { } @@ -57,17 +58,17 @@ class NSMaxEmail : public Module if (source.IsOper()) return EVENT_CONTINUE; - if (command->name == "nickserv/register") + if (command->GetName() == "nickserv/register") { if (this->CheckLimitReached(source, params.size() > 1 ? params[1] : "")) return EVENT_STOP; } - else if (command->name == "nickserv/set/email") + else if (command->GetName() == "nickserv/set/email") { if (this->CheckLimitReached(source, params.size() > 0 ? params[0] : "")) return EVENT_STOP; } - else if (command->name == "nickserv/ungroup" && source.GetAccount()) + else if (command->GetName() == "nickserv/ungroup" && source.GetAccount()) { if (this->CheckLimitReached(source, source.GetAccount()->GetEmail())) return EVENT_STOP; diff --git a/modules/nickserv/recover.cpp b/modules/nickserv/recover.cpp index c95d3f135..9a6ddd64e 100644 --- a/modules/nickserv/recover.cpp +++ b/modules/nickserv/recover.cpp @@ -124,6 +124,8 @@ class NSRecoverRequestListener : public NickServ::IdentifyRequestListener class CommandNSRecover : public Command { + ServiceReference certservice; + public: CommandNSRecover(Module *creator) : Command(creator, "nickserv/recover", 1, 2) { @@ -170,8 +172,8 @@ class CommandNSRecover : public Command if (ok == false && !pass.empty()) { - NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSRecoverRequestListener(source, this, na->GetNick(), pass), owner, na->GetNick(), pass); - Event::OnCheckAuthentication(&Event::CheckAuthentication::OnCheckAuthentication, source.GetUser(), req); + NickServ::IdentifyRequest *req = NickServ::service->CreateIdentifyRequest(new NSRecoverRequestListener(source, this, na->GetNick(), pass), GetOwner(), na->GetNick(), pass); + EventManager::Get()->Dispatch(&Event::CheckAuthentication::OnCheckAuthentication, source.GetUser(), req); req->Dispatch(); } else @@ -204,6 +206,8 @@ class NSRecover : public Module public: NSRecover(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook(this) + , EventHook(this) , commandnsrecover(this) , recover(this, "recover") { diff --git a/modules/nickserv/register.cpp b/modules/nickserv/register.cpp index c7e6e5af2..e8255ca1a 100644 --- a/modules/nickserv/register.cpp +++ b/modules/nickserv/register.cpp @@ -44,8 +44,7 @@ class CommandNSConfirm : public Command } na->GetAccount()->UnsetS("UNCONFIRMED"); - if (NickServ::Event::OnNickConfirm) - NickServ::Event::OnNickConfirm(&NickServ::Event::NickConfirm::OnNickConfirm, source.GetUser(), na->GetAccount()); + EventManager::Get()->Dispatch(&NickServ::Event::NickConfirm::OnNickConfirm, source.GetUser(), na->GetAccount()); Log(LOG_ADMIN, source, this) << "to confirm nick " << na->GetNick() << " (" << na->GetAccount()->GetDisplay() << ")"; source.Reply(_("\002{0}\002 has been confirmed."), na->GetNick()); } @@ -59,12 +58,12 @@ class CommandNSConfirm : public Command } NickServ::Account *nc = source.nc; - nc->ShrinkOK("passcode"); + nc->Shrink("passcode"); Log(LOG_COMMAND, source, this) << "to confirm their email"; source.Reply(_("Your email address of \002{0}\002 has been confirmed."), source.nc->GetEmail()); nc->UnsetS("UNCONFIRMED"); - if (NickServ::Event::OnNickConfirm) - NickServ::Event::OnNickConfirm(&NickServ::Event::NickConfirm::OnNickConfirm, source.GetUser(), nc); + + EventManager::Get()->Dispatch(&NickServ::Event::NickConfirm::OnNickConfirm, source.GetUser(), nc); if (source.GetUser()) { @@ -115,7 +114,7 @@ class CommandNSRegister : public Command size_t nicklen = u_nick.length(); Anope::string pass = params[0]; Anope::string email = params.size() > 1 ? params[1] : ""; - const Anope::string &nsregister = Config->GetModule(this->owner)->Get("registration"); + const Anope::string &nsregister = Config->GetModule(this->GetOwner())->Get("registration"); if (Anope::ReadOnly) { @@ -129,7 +128,7 @@ class CommandNSRegister : public Command return; } - time_t nickregdelay = Config->GetModule(this->owner)->Get("nickregdelay"); + time_t nickregdelay = Config->GetModule(this->GetOwner())->Get("nickregdelay"); time_t reg_delay = Config->GetModule("nickserv")->Get("regdelay"); if (u && !u->HasMode("OPER") && nickregdelay && Anope::CurTime - u->timestamp < nickregdelay) { @@ -162,11 +161,11 @@ class CommandNSRegister : public Command } if (Config->GetModule("nickserv")->Get("restrictopernicks")) - for (Oper *o : Serialize::GetObjects(operblock)) + for (Oper *o : Serialize::GetObjects()) { if (!source.IsOper() && u_nick.find_ci(o->GetName()) != Anope::string::npos) { - source.Reply(_("\002{0}\002 may not be registered."), u_nick); + source.Reply(_("\002{0}\002 may not be registered because it is too similar to an operator nick."), u_nick); return; } } @@ -210,12 +209,15 @@ class CommandNSRegister : public Command return; } - NickServ::Account *nc = NickServ::account.Create(); + NickServ::Account *nc = Serialize::New(); nc->SetDisplay(u_nick); - NickServ::Nick *na = NickServ::nick.Create(); + NickServ::Nick *na = Serialize::New(); na->SetNick(u_nick); na->SetAccount(nc); + na->SetTimeRegistered(Anope::CurTime); + na->SetLastSeen(Anope::CurTime); + Anope::string epass; Anope::Encrypt(pass, epass); nc->SetPassword(epass); @@ -252,8 +254,7 @@ class CommandNSRegister : public Command } } - if (NickServ::Event::OnNickRegister) - NickServ::Event::OnNickRegister(&NickServ::Event::NickRegister::OnNickRegister, source.GetUser(), na, pass); + EventManager::Get()->Dispatch(&NickServ::Event::NickRegister::OnNickRegister, source.GetUser(), na, pass); if (u) { @@ -296,7 +297,7 @@ class CommandNSResend : public Command void Execute(CommandSource &source, const std::vector ¶ms) override { - if (!Config->GetModule(this->owner)->Get("registration").equals_ci("mail")) + if (!Config->GetModule(this->GetOwner())->Get("registration").equals_ci("mail")) { source.Reply(_("Access denied.")); return; @@ -316,7 +317,7 @@ class CommandNSResend : public Command return; } - if (Anope::CurTime < source.nc->lastmail + Config->GetModule(this->owner)->Get("resenddelay")) + if (Anope::CurTime < source.nc->lastmail + Config->GetModule(this->GetOwner())->Get("resenddelay")) { source.Reply(_("Cannot send mail now; please retry a little later.")); return; @@ -324,7 +325,7 @@ class CommandNSResend : public Command if (!SendRegmail(source.GetUser(), na, source.service)) { - Log(this->owner) << "Unable to resend registration verification code for " << source.GetNick(); + Log(this->GetOwner()) << "Unable to resend registration verification code for " << source.GetNick(); return; } @@ -335,7 +336,7 @@ class CommandNSResend : public Command bool OnHelp(CommandSource &source, const Anope::string &subcommand) override { - if (!Config->GetModule(this->owner)->Get("registration").equals_ci("mail")) + if (!Config->GetModule(this->GetOwner())->Get("registration").equals_ci("mail")) return false; source.Reply(_("This command will resend you the registration confirmation email.")); @@ -344,7 +345,7 @@ class CommandNSResend : public Command void OnServHelp(CommandSource &source) override { - if (Config->GetModule(this->owner)->Get("registration").equals_ci("mail")) + if (Config->GetModule(this->GetOwner())->Get("registration").equals_ci("mail")) Command::OnServHelp(source); } }; @@ -362,14 +363,16 @@ class NSRegister : public Module public: NSRegister(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook(this) + , EventHook(this) , commandnsregister(this) , commandnsconfirm(this) , commandnsrsend(this) - , unconfirmed(this, NickServ::account, "UNCONFIRMED") - , passcode(this, NickServ::account, "passcode") + , unconfirmed(this, "UNCONFIRMED") + , passcode(this, "passcode") { if (Config->GetModule(this)->Get("registration").equals_ci("disable")) - throw ModuleException("Module " + this->name + " will not load with registration disabled."); + throw ModuleException("Module " + Module::name + " will not load with registration disabled."); } void OnNickIdentify(User *u) override diff --git a/modules/nickserv/resetpass.cpp b/modules/nickserv/resetpass.cpp index 3be5a4c06..4f8fa5136 100644 --- a/modules/nickserv/resetpass.cpp +++ b/modules/nickserv/resetpass.cpp @@ -67,6 +67,7 @@ class NSResetPass : public Module public: NSResetPass(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook(this) , commandnsresetpass(this), reset(this, "reset") { if (!Config->GetBlock("mail")->Get("usemail")) @@ -75,7 +76,7 @@ class NSResetPass : public Module EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector ¶ms) override { - if (command->name == "nickserv/confirm" && params.size() > 1) + if (command->GetName() == "nickserv/confirm" && params.size() > 1) { if (Anope::ReadOnly) { diff --git a/modules/nickserv/set.cpp b/modules/nickserv/set.cpp index 337bdab9d..93d2dcc57 100644 --- a/modules/nickserv/set.cpp +++ b/modules/nickserv/set.cpp @@ -1,12 +1,10 @@ /* NickServ core functions * - * (C) 2003-2014 Anope Team + * (C) 2003-2016 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. * - * Based on the original code of Epona by Lara. - * Based on the original code of Services by Andy Church. */ #include "module.h" @@ -44,7 +42,7 @@ class CommandNSSet : public Command if (c_name.find_ci(this_name + " ") == 0) { - ServiceReference c("Command", info.name); + ServiceReference c(info.name); // XXX dup if (!c) continue; @@ -96,7 +94,7 @@ class CommandNSSASet : public Command if (c_name.find_ci(this_name + " ") == 0) { - ServiceReference command("Command", info.name); + ServiceReference command(info.name); if (command) { source.command = c_name; @@ -254,7 +252,7 @@ class CommandNSSetAutoOp : public Command NickServ::Account *nc = na->GetAccount(); EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -347,7 +345,7 @@ class CommandNSSetDisplay : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, user_na->GetAccount(), param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, user_na->GetAccount(), param); if (MOD_RESULT == EVENT_STOP) return; @@ -468,7 +466,7 @@ class CommandNSSetEmail : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -550,7 +548,7 @@ class CommandNSSetKeepModes : public Command NickServ::Account *nc = na->GetAccount(); EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -635,7 +633,7 @@ class CommandNSSetKill : public Command NickServ::Account *nc = na->GetAccount(); EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -657,7 +655,7 @@ class CommandNSSetKill : public Command } else if (param.equals_ci("IMMED")) { - if (Config->GetModule(this->owner)->Get("allowkillimmed")) + if (Config->GetModule(this->GetOwner())->Get("allowkillimmed")) { nc->SetS("KILLPROTECT",true); nc->UnsetS("KILL_QUICK"); @@ -749,7 +747,7 @@ class CommandNSSetLanguage : public Command NickServ::Account *nc = na->GetAccount(); EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -854,7 +852,7 @@ class CommandNSSetMessage : public Command } EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -949,7 +947,7 @@ class CommandNSSetSecure : public Command NickServ::Account *nc = na->GetAccount(); EventReturn MOD_RESULT; - MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); + MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; @@ -1105,10 +1103,16 @@ class NSSet : public Module /* email, passcode */ ExtensibleItem > ns_set_email; - EventHandlers onsetnickoption; - public: NSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook(this) + , EventHook(this) + , EventHook(this) + , EventHook(this) + , EventHook(this) + , EventHook(this) + , EventHook(this) + , commandnsset(this) , commandnssaset(this) , commandnssetautoop(this) @@ -1131,18 +1135,16 @@ class NSSet : public Module , commandnssasetsecure(this) , commandnssasetnoexpire(this) - , autoop(this, NickServ::account, "AUTOOP") - , keep_modes(this, NickServ::account, "NS_KEEP_MODES") - , killprotect(this, NickServ::account, "KILLPROTECT") - , kill_quick(this, NickServ::account, "KILL_QUICK") - , kill_immed(this, NickServ::account, "KILL_IMMED") - , message(this, NickServ::account, "MSG") - , secure(this, NickServ::account, "NS_SECURE") - , noexpire(this, NickServ::nick, "NS_NO_EXPIRE") + , autoop(this, "AUTOOP") + , keep_modes(this, "NS_KEEP_MODES") + , killprotect(this, "KILLPROTECT") + , kill_quick(this, "KILL_QUICK") + , kill_immed(this, "KILL_IMMED") + , message(this, "MSG") + , secure(this, "NS_SECURE") + , noexpire(this, "NS_NO_EXPIRE") , ns_set_email(this, "ns_set_email") - - , onsetnickoption(this) { } @@ -1151,7 +1153,7 @@ class NSSet : public Module { NickServ::Account *uac = source.nc; - if (command->name == "nickserv/confirm" && !params.empty() && uac) + if (command->GetName() == "nickserv/confirm" && !params.empty() && uac) { std::pair *n = ns_set_email.Get(uac); if (n) @@ -1210,11 +1212,14 @@ class NSSet : public Module void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) override { - if (u->Account() && setter.GetUser() == u && NickServ::mode) + if (u->Account() && setter.GetUser() == u) { - NickServ::Mode *m = NickServ::mode.Create(); - m->SetAccount(u->Account()); - m->SetMode(mname); + NickServ::Mode *m = Serialize::New(); + if (m != nullptr) + { + m->SetAccount(u->Account()); + m->SetMode(mname); + } } } @@ -1222,7 +1227,7 @@ class NSSet : public Module { if (u->Account() && setter.GetUser() == u) { - for (NickServ::Mode *m : u->Account()->GetRefs(NickServ::mode)) + for (NickServ::Mode *m : u->Account()->GetRefs()) if (m->GetMode() == mname) m->Delete(); } @@ -1231,7 +1236,7 @@ class NSSet : public Module void OnUserLogin(User *u) override { if (keep_modes.HasExt(u->Account())) - for (NickServ::Mode *mode : u->Account()->GetRefs(NickServ::mode)) + for (NickServ::Mode *mode : u->Account()->GetRefs()) { UserMode *um = ModeManager::FindUserModeByName(mode->GetMode()); /* if the null user can set the mode, then it's probably safe */ diff --git a/modules/nickserv/set_misc.cpp b/modules/nickserv/set_misc.cpp index 347ae034c..2c6ea317c 100644 --- a/modules/nickserv/set_misc.cpp +++ b/modules/nickserv/set_misc.cpp @@ -18,6 +18,11 @@ static Anope::map descriptions; class NSMiscDataImpl : public NSMiscData { + friend class NSMiscDataType; + + NickServ::Account *account = nullptr; + Anope::string name, data; + public: NSMiscDataImpl(Serialize::TypeBase *type) : NSMiscData(type) { } NSMiscDataImpl(Serialize::TypeBase *type, Serialize::ID id) : NSMiscData(type, id) { } @@ -38,10 +43,10 @@ class NSMiscDataType : public Serialize::Type Serialize::ObjectField owner; Serialize::Field name, data; - NSMiscDataType(Module *me) : Serialize::Type(me, "NSMiscData") - , owner(this, "nc", true) - , name(this, "name") - , data(this, "data") + NSMiscDataType(Module *me) : Serialize::Type(me) + , owner(this, "nc", &NSMiscDataImpl::account, true) + , name(this, "name", &NSMiscDataImpl::name) + , data(this, "data", &NSMiscDataImpl::data) { } }; @@ -108,14 +113,14 @@ class CommandNSSetMisc : public Command } NickServ::Account *nc = na->GetAccount(); - EventReturn MOD_RESULT = Event::OnSetNickOption(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); + EventReturn MOD_RESULT = EventManager::Get()->Dispatch(&Event::SetNickOption::OnSetNickOption, source, this, nc, param); if (MOD_RESULT == EVENT_STOP) return; Anope::string scommand = GetAttribute(source.command); /* remove existing */ - for (NSMiscData *data : nc->GetRefs(nsmiscdata)) + for (NSMiscData *data : nc->GetRefs()) if (data->GetName() == scommand) { data->Delete(); @@ -124,7 +129,7 @@ class CommandNSSetMisc : public Command if (!param.empty()) { - NSMiscData *data = nsmiscdata.Create(); + NSMiscData *data = Serialize::New(); data->SetAccount(nc); data->SetName(scommand); data->SetData(param); @@ -186,6 +191,7 @@ class NSSetMisc : public Module public: NSSetMisc(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) + , EventHook(this) , commandnssetmisc(this) , commandnssasetmisc(this) , type(this) @@ -217,7 +223,7 @@ class NSSetMisc : public Module void OnNickInfo(CommandSource &source, NickServ::Nick *na, InfoFormatter &info, bool) override { - for (NSMiscData *data : na->GetAccount()->GetRefs(nsmiscdata)) + for (NSMiscData *data : na->GetAccount()->GetRefs()) info[data->GetName()] = data->GetData(); } }; diff --git a/modules/nickserv/suspend.cpp b/modules/nickserv/suspend.cpp index b56e68f97..c33556e76 100644 --- a/modules/nickserv/suspend.cpp +++ b/modules/nickserv/suspend.cpp @@ -16,6 +16,12 @@ class NSSuspendInfoImpl : public NSSuspendInfo { + friend class NSSuspendType; + + NickServ::Account *account = nullptr; + Anope::string by, reason; + time_t when = 0, expires =0; + public: NSSuspendInfoImpl(Serialize::TypeBase *type) : NSSuspendInfo(type) { } NSSuspendInfoImpl(Serialize::TypeBase *type, Serialize::ID id) : NSSuspendInfo(type, id) { } @@ -43,12 +49,12 @@ class NSSuspendType : public Serialize::Type Serialize::Field by, reason; Serialize::Field when, expires; - NSSuspendType(Module *me) : Serialize::Type(me, "NSSuspendInfo") - , account(this, "nick", true) - , by(this, "by") - , reason(this, "reason") - , when(this, "time") - , expires(this, "expires") + NSSuspendType(Module *me) : Serialize::Type(me) + , account(this, "nick", &NSSuspendInfoImpl::account, true) + , by(this, "by", &NSSuspendInfoImpl::by) + , reason(this, "reason", &NSSuspendInfoImpl::reason) + , when(this, "when", &NSSuspendInfoImpl::when) + , expires(this, "expires", &NSSuspendInfoImpl::expires) { } }; @@ -105,10 +111,8 @@ void NSSuspendInfoImpl::SetExpires(const time_t &e) class CommandNSSuspend : public Command { - EventHandlers &onnicksuspend; - public: - CommandNSSuspend(Module *creator, EventHandlers &event) : Command(creator, "nickserv/suspend", 2, 3), onnicksuspend(event) + CommandNSSuspend(Module *creator) : Command(creator, "nickserv/suspend", 2, 3) { this->SetDesc(_("Suspend a given nick")); this->SetSyntax(_("\037account\037 [+\037expiry\037] [\037reason\037]")); @@ -120,7 +124,7 @@ class CommandNSSuspend : public Command const Anope::string &nick = params[0]; Anope::string expiry = params[1]; Anope::string reason = params.size() > 2 ? params[2] : ""; - time_t expiry_secs = Config->GetModule(this->owner)->Get("suspendexpire"); + time_t expiry_secs = Config->GetModule(this->GetOwner())->Get("suspendexpire"); if (Anope::ReadOnly) source.Reply(_("Services are in read-only mode. Any changes made may not persist.")); @@ -154,7 +158,7 @@ class CommandNSSuspend : public Command return; } - NSSuspendInfo *si = na->GetAccount()->GetRef(nssuspendinfo); + NSSuspendInfo *si = na->GetAccount()->GetRef(); if (!si) { source.Reply(_("\002%s\002 is already suspended."), na->GetAccount()->GetDisplay().c_str()); @@ -163,14 +167,14 @@ class CommandNSSuspend : public Command NickServ::Account *nc = na->GetAccount(); - si = nssuspendinfo.Create(); + si = Serialize::New(); si->SetAccount(nc); si->SetBy(source.GetNick()); si->SetReason(reason); si->SetWhen(Anope::CurTime); si->SetExpires(expiry_secs ? expiry_secs + Anope::CurTime : 0); - for (NickServ::Nick *na2 : nc->GetRefs(NickServ::nick)) + for (NickServ::Nick *na2 : nc->GetRefs()) { na2->SetLastQuit(reason); @@ -186,7 +190,7 @@ class CommandNSSuspend : public Command Log(LOG_ADMIN, source, this) << "for " << nick << " (" << (!reason.empty() ? reason : "No reason") << "), expires on " << (expiry_secs ? Anope::strftime(Anope::CurTime + expiry_secs) : "never"); source.Reply(_("\002{0}\002 is now suspended."), na->GetNick()); - this->onnicksuspend(&Event::NickSuspend::OnNickSuspend, na); + EventManager::Get()->Dispatch(&Event::NickSuspend::OnNickSuspend, na); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override @@ -199,10 +203,8 @@ class CommandNSSuspend : public Command class CommandNSUnSuspend : public Command { - EventHandlers &onnickunsuspend; - public: - CommandNSUnSuspend(Module *creator, EventHandlers &event) : Command(creator, "nickserv/unsuspend", 1, 1), onnickunsuspend(event) + CommandNSUnSuspend(Module *creator) : Command(creator, "nickserv/unsuspend", 1, 1) { this->SetDesc(_("Unsuspend a given nick")); this->SetSyntax(_("\037account\037")); @@ -222,7 +224,7 @@ class CommandNSUnSuspend : public Command return; } - NSSuspendInfo *si = na->GetAccount()->GetRef(nssuspendinfo); + NSSuspendInfo *si = na->GetAccount()->GetRef(); if (!si) { source.Reply(_("\002{0}\002 is not suspended."), na->GetNick()); @@ -235,7 +237,7 @@ class CommandNSUnSuspend : public Command source.Reply(_("\002{0}\002 is now released."), na->GetNick()); - this->onnickunsuspend(&Event::NickUnsuspend::OnNickUnsuspend, na); + EventManager::Get()->Dispatch(&Event::NickUnsuspend::OnNickUnsuspend, na); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override @@ -252,8 +254,6 @@ class NSSuspend : public Module { CommandNSSuspend commandnssuspend; CommandNSUnSuspend commandnsunsuspend; - EventHandlers onnicksuspend; - EventHandlers onnickunsuspend; std::vector show; NSSuspendType nst; @@ -272,10 +272,11 @@ class NSSuspend : public Module public: NSSuspend(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - , commandnssuspend(this, onnicksuspend) - , commandnsunsuspend(this, onnickunsuspend) - , onnicksuspend(this) - , onnickunsuspend(this) + , EventHook(this) + , EventHook(this) + , EventHook(this) + , commandnssuspend(this) + , commandnsunsuspend(this) , nst(this) { } @@ -289,7 +290,7 @@ class NSSuspend : public Module void OnNickInfo(CommandSource &source, NickServ::Nick *na, InfoFormatter &info, bool show_hidden) override { - NSSuspendInfo *s = na->GetAccount()->GetRef(nssuspendinfo); + NSSuspendInfo *s = na->GetAccount()->GetRef(); if (!s) return; @@ -307,7 +308,7 @@ class NSSuspend : public Module void OnPreNickExpire(NickServ::Nick *na, bool &expire) override { - NSSuspendInfo *s = na->GetAccount()->GetRef(nssuspendinfo); + NSSuspendInfo *s = na->GetAccount()->GetRef(); if (!s) return; @@ -327,7 +328,7 @@ class NSSuspend : public Module EventReturn OnNickValidate(User *u, NickServ::Nick *na) override { - NSSuspendInfo *s = na->GetAccount()->GetRef(nssuspendinfo); + NSSuspendInfo *s = na->GetAccount()->GetRef(); if (!s) return EVENT_CONTINUE; diff --git a/modules/nickserv/update.cpp b/modules/nickserv/update.cpp index 6781585d3..d4815b4cb 100644 --- a/modules/nickserv/update.cpp +++ b/modules/nickserv/update.cpp @@ -14,10 +14,8 @@ class CommandNSUpdate : public Command { - EventHandlers &onnickupdate; - public: - CommandNSUpdate(Module *creator, EventHandlers &event) : Command(creator, "nickserv/update", 0, 0), onnickupdate(event) + CommandNSUpdate(Module *creator) : Command(creator, "nickserv/update", 0, 0) { this->SetDesc(_("Updates your current status, i.e. it checks for new memos")); this->RequireUser(true); @@ -34,7 +32,7 @@ class CommandNSUpdate : public Command na->SetLastSeen(Anope::CurTime); } - this->onnickupdate(&Event::NickUpdate::OnNickUpdate, u); + EventManager::Get()->Dispatch(&Event::NickUpdate::OnNickUpdate, u); source.Reply(_("Status updated (memos, vhost, chmodes, flags).")); } @@ -53,12 +51,10 @@ class CommandNSUpdate : public Command class NSUpdate : public Module { CommandNSUpdate commandnsupdate; - EventHandlers onnickupdate; public: NSUpdate(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) - , commandnsupdate(this, onnickupdate) - , onnickupdate(this) + , commandnsupdate(this) { } -- cgit