diff options
| author | Adam <Adam@anope.org> | 2016-07-28 21:29:35 -0400 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2016-07-28 21:29:35 -0400 |
| commit | 0e758a2ac23dc4a001e8e126cec14588da9a9769 (patch) | |
| tree | 45df813323e023c5c89db7279426c4ad0943b4a9 /modules/nickserv/main | |
| parent | a3c8afae00c54d5b95c620248b51f90679d7d53f (diff) | |
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
Diffstat (limited to 'modules/nickserv/main')
| -rw-r--r-- | modules/nickserv/main/account.cpp | 10 | ||||
| -rw-r--r-- | modules/nickserv/main/account.h | 4 | ||||
| -rw-r--r-- | modules/nickserv/main/accounttype.cpp | 13 | ||||
| -rw-r--r-- | modules/nickserv/main/identifyrequest.cpp | 11 | ||||
| -rw-r--r-- | modules/nickserv/main/identifyrequest.h | 1 | ||||
| -rw-r--r-- | modules/nickserv/main/mode.h | 5 | ||||
| -rw-r--r-- | modules/nickserv/main/modetype.h | 6 | ||||
| -rw-r--r-- | modules/nickserv/main/nick.cpp | 8 | ||||
| -rw-r--r-- | modules/nickserv/main/nick.h | 8 | ||||
| -rw-r--r-- | modules/nickserv/main/nickserv.cpp | 67 | ||||
| -rw-r--r-- | modules/nickserv/main/nicktype.cpp | 28 |
11 files changed, 93 insertions, 68 deletions
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 *>(MemoServ::memoinfo); + return GetRef<MemoServ::MemoInfo *>(); } 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<NickAccess *>(nsaccess)) + for (NickAccess *access : GetRefs<NickAccess *>()) { 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 *>(ChanServ::channel)) + for (ChanServ::Channel *c : GetRefs<ChanServ::Channel *>()) 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<AccountImpl>(me, "NickCore") - , display(this, "display") - , pass(this, "pass") - , email(this, "email") - , language(this, "language") +AccountType::AccountType(Module *me) : Serialize::Type<AccountImpl>(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<ModeImpl> Serialize::ObjectField<ModeImpl, NickServ::Account *> account; Serialize::Field<ModeImpl, Anope::string> mode; - NSModeType(Module *creator) : Serialize::Type<ModeImpl>(creator, "NSKeepMode") - , account(this, "account", true) - , mode(this, "mode") + NSModeType(Module *creator) : Serialize::Type<ModeImpl>(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<NickServ::Nick *> aliases = this->GetAccount()->GetRefs<NickServ::Nick *>(NickServ::nick); + std::vector<NickServ::Nick *> aliases = this->GetAccount()->GetRefs<NickServ::Nick *>(); 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<Event::ExpireTick> , public EventHook<Event::NickInfo> , public EventHook<Event::ModuleUnload> - , public EventHook<Event::NickCoreCreate> + , public EventHook<NickServ::Event::NickRegister> , public EventHook<Event::UserQuit> { Reference<ServiceBot> NickServ; std::vector<Anope::string> defaults; ExtensibleItem<bool> held, collided; - EventHandlers<NickServ::Event::PreNickExpire> onprenickexpire; - EventHandlers<NickServ::Event::NickExpire> onnickexpire; - EventHandlers<NickServ::Event::NickRegister> onnickregister; - EventHandlers<NickServ::Event::NickValidate> onnickvalidate; std::set<NickServ::IdentifyRequest *> 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<Event::Shutdown>(this) + , EventHook<Event::Restart>(this) + , EventHook<Event::UserLogin>(this) + , EventHook<Event::DelNick>(this) + , EventHook<Event::DelCore>(this) + , EventHook<Event::ChangeCoreDisplay>(this) + , EventHook<Event::NickIdentify>(this) + , EventHook<Event::NickGroup>(this) + , EventHook<Event::NickUpdate>(this) + , EventHook<Event::UserConnect>(this) + , EventHook<Event::PostUserLogoff>(this) + , EventHook<Event::ServerSync>(this) + , EventHook<Event::UserNickChange>(this) + , EventHook<Event::UserModeSet>(this) + , EventHook<Event::Help>(this) + , EventHook<Event::ExpireTick>(this) + , EventHook<Event::NickInfo>(this) + , EventHook<Event::ModuleUnload>(this) + , EventHook<NickServ::Event::NickRegister>(this) + , EventHook<Event::UserQuit>(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<bool>(defaults[i].upper(), true); + na->GetAccount()->SetS<bool>(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<NickServ::IdentifyRequest *>::iterator it = identifyrequests.begin(), it_end = identifyrequests.end(); it != it_end;) { - NickServ::IdentifyRequest *ir = *it; + IdentifyRequestImpl *ir = anope_dynamic_static_cast<IdentifyRequestImpl *>(*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<NickImpl>(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<NickImpl>(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); |
