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/chanserv/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/chanserv/main')
| -rw-r--r-- | modules/chanserv/main/chanaccess.cpp | 58 | ||||
| -rw-r--r-- | modules/chanserv/main/chanaccess.h | 30 | ||||
| -rw-r--r-- | modules/chanserv/main/chanaccesstype.h | 19 | ||||
| -rw-r--r-- | modules/chanserv/main/channel.cpp | 68 | ||||
| -rw-r--r-- | modules/chanserv/main/channel.h | 17 | ||||
| -rw-r--r-- | modules/chanserv/main/channeltype.cpp | 32 | ||||
| -rw-r--r-- | modules/chanserv/main/channeltype.h | 28 | ||||
| -rw-r--r-- | modules/chanserv/main/chanserv.cpp | 70 | ||||
| -rw-r--r-- | modules/chanserv/main/level.h | 6 | ||||
| -rw-r--r-- | modules/chanserv/main/leveltype.h | 8 | ||||
| -rw-r--r-- | modules/chanserv/main/mode.h | 5 | ||||
| -rw-r--r-- | modules/chanserv/main/modetype.h | 8 |
12 files changed, 148 insertions, 201 deletions
diff --git a/modules/chanserv/main/chanaccess.cpp b/modules/chanserv/main/chanaccess.cpp index 1601260c2..4d70fb30b 100644 --- a/modules/chanserv/main/chanaccess.cpp +++ b/modules/chanserv/main/chanaccess.cpp @@ -1,65 +1,65 @@ #include "module.h" -#include "chanaccess.h" +#include "modules/chanserv/main/chanaccess.h" #include "chanaccesstype.h" ChanServ::Channel *ChanAccessImpl::GetChannel() { - return Get(&ChanAccessType::ci); + return Get(&ChanAccessType<ChanServ::ChanAccess>::ci); } void ChanAccessImpl::SetChannel(ChanServ::Channel *ci) { - Object::Set(&ChanAccessType::ci, ci); + Object::Set(&ChanAccessType<ChanServ::ChanAccess>::ci, ci); } Anope::string ChanAccessImpl::GetCreator() { - return Get(&ChanAccessType::creator); + return Get(&ChanAccessType<ChanServ::ChanAccess>::creator); } void ChanAccessImpl::SetCreator(const Anope::string &c) { - Object::Set(&ChanAccessType::creator, c); + Object::Set(&ChanAccessType<ChanServ::ChanAccess>::creator, c); } time_t ChanAccessImpl::GetLastSeen() { - return Get(&ChanAccessType::last_seen); + return Get(&ChanAccessType<ChanServ::ChanAccess>::last_seen); } void ChanAccessImpl::SetLastSeen(const time_t &t) { - Object::Set(&ChanAccessType::last_seen, t); + Object::Set(&ChanAccessType<ChanServ::ChanAccess>::last_seen, t); } time_t ChanAccessImpl::GetCreated() { - return Get(&ChanAccessType::created); + return Get(&ChanAccessType<ChanServ::ChanAccess>::created); } void ChanAccessImpl::SetCreated(const time_t &t) { - Object::Set(&ChanAccessType::created, t); + Object::Set(&ChanAccessType<ChanServ::ChanAccess>::created, t); } Anope::string ChanAccessImpl::GetMask() { - return Get(&ChanAccessType::mask); + return Get(&ChanAccessType<ChanServ::ChanAccess>::mask); } void ChanAccessImpl::SetMask(const Anope::string &n) { - Object::Set(&ChanAccessType::mask, n); + Object::Set(&ChanAccessType<ChanServ::ChanAccess>::mask, n); } Serialize::Object *ChanAccessImpl::GetObj() { - return Get(&ChanAccessType::obj); + return Get(&ChanAccessType<ChanServ::ChanAccess>::obj); } void ChanAccessImpl::SetObj(Serialize::Object *o) { - Object::Set(&ChanAccessType::obj, o); + Object::Set(&ChanAccessType<ChanServ::ChanAccess>::obj, o); } Anope::string ChanAccessImpl::Mask() @@ -72,13 +72,13 @@ Anope::string ChanAccessImpl::Mask() NickServ::Account *ChanAccessImpl::GetAccount() { - if (!GetObj() || GetObj()->GetSerializableType() != NickServ::account) + if (!GetObj() || GetObj()->GetSerializableType()->GetName() != NickServ::Account::NAME) return nullptr; return anope_dynamic_static_cast<NickServ::Account *>(GetObj()); } -bool ChanAccessImpl::Matches(const User *u, NickServ::Account *acc, Path &p) +bool ChanAccessImpl::Matches(const User *u, NickServ::Account *acc) { if (this->GetAccount()) return this->GetAccount() == acc; @@ -93,35 +93,9 @@ bool ChanAccessImpl::Matches(const User *u, NickServ::Account *acc, Path &p) } if (acc) - for (NickServ::Nick *na : acc->GetRefs<NickServ::Nick *>(NickServ::nick)) + for (NickServ::Nick *na : acc->GetRefs<NickServ::Nick *>()) if (Anope::Match(na->GetNick(), this->Mask())) return true; - if (IRCD->IsChannelValid(this->Mask())) - { - ChanServ::Channel *tci = ChanServ::Find(this->Mask()); - if (tci) - { - for (unsigned i = 0; i < tci->GetAccessCount(); ++i) - { - ChanServ::ChanAccess *a = tci->GetAccess(i); - std::pair<ChanServ::ChanAccess *, ChanServ::ChanAccess *> pair = std::make_pair(this, a); - - std::pair<Set::iterator, Set::iterator> range = p.first.equal_range(this); - for (; range.first != range.second; ++range.first) - if (range.first->first == pair.first && range.first->second == pair.second) - goto cont; - - p.first.insert(pair); - if (a->Matches(u, acc, p)) - p.second.insert(pair); - - cont:; - } - - return p.second.count(this) > 0; - } - } - return false; } diff --git a/modules/chanserv/main/chanaccess.h b/modules/chanserv/main/chanaccess.h deleted file mode 100644 index bb65f79c5..000000000 --- a/modules/chanserv/main/chanaccess.h +++ /dev/null @@ -1,30 +0,0 @@ - -class ChanAccessImpl : public ChanServ::ChanAccess -{ - public: - ChanAccessImpl(Serialize::TypeBase *type) : ChanServ::ChanAccess(type) { } - ChanAccessImpl(Serialize::TypeBase *type, Serialize::ID id) : ChanServ::ChanAccess(type, id) { } - - ChanServ::Channel *GetChannel() override; - void SetChannel(ChanServ::Channel *ci) override; - - Anope::string GetCreator() override; - void SetCreator(const Anope::string &c) override; - - time_t GetLastSeen() override; - void SetLastSeen(const time_t &t) override; - - time_t GetCreated() override; - void SetCreated(const time_t &t) override; - - Anope::string GetMask() override; - void SetMask(const Anope::string &) override; - - Serialize::Object *GetObj() override; - void SetObj(Serialize::Object *) override; - - Anope::string Mask() override; - NickServ::Account *GetAccount() override; - - bool Matches(const User *u, NickServ::Account *acc, Path &p) override; -}; diff --git a/modules/chanserv/main/chanaccesstype.h b/modules/chanserv/main/chanaccesstype.h index ca8dc1b79..f679669f1 100644 --- a/modules/chanserv/main/chanaccesstype.h +++ b/modules/chanserv/main/chanaccesstype.h @@ -1,6 +1,9 @@ -class ChanAccessType : public Serialize::AbstractType +template<typename T> +class ChanAccessType : public Serialize::Type<T> { + static_assert(std::is_base_of<ChanServ::ChanAccess, T>::value, ""); + public: Serialize::ObjectField<ChanServ::ChanAccess, ChanServ::Channel *> ci; Serialize::Field<ChanServ::ChanAccess, Anope::string> mask; @@ -9,13 +12,13 @@ class ChanAccessType : public Serialize::AbstractType Serialize::Field<ChanServ::ChanAccess, time_t> last_seen; Serialize::Field<ChanServ::ChanAccess, time_t> created; - ChanAccessType(Module *me, const Anope::string &name) : Serialize::AbstractType(me, name) - , ci(this, "ci", true) - , mask(this, "mask") - , obj(this, "obj", true) - , creator(this, "creator") - , last_seen(this, "last_seen") - , created(this, "created") + ChanAccessType(Module *me) : Serialize::Type<T>(me) + , ci(this, "ci", &ChanServ::ChanAccess::channel, true) + , mask(this, "mask", &ChanServ::ChanAccess::mask) + , obj(this, "obj", &ChanServ::ChanAccess::object, true) + , creator(this, "creator", &ChanServ::ChanAccess::creator) + , last_seen(this, "last_seen", &ChanServ::ChanAccess::last_seen) + , created(this, "created", &ChanServ::ChanAccess::created) { } }; diff --git a/modules/chanserv/main/channel.cpp b/modules/chanserv/main/channel.cpp index 7190b8bd9..490a0306f 100644 --- a/modules/chanserv/main/channel.cpp +++ b/modules/chanserv/main/channel.cpp @@ -14,13 +14,6 @@ #include "channeltype.h" #include "modules/chanserv/akick.h" -ChannelImpl::ChannelImpl(Serialize::TypeBase *type, const Anope::string &chname) : ChanServ::Channel(type) -{ - SetName(chname); - SetTimeRegistered(Anope::CurTime); - SetLastUsed(Anope::CurTime); -} - ChannelImpl::~ChannelImpl() { ChanServ::registered_channel_map& map = ChanServ::service->GetChannels(); @@ -29,7 +22,7 @@ ChannelImpl::~ChannelImpl() void ChannelImpl::Delete() { - Event::OnDelChan(&Event::DelChan::OnDelChan, this); + EventManager::Get()->Dispatch(&Event::DelChan::OnDelChan, this); Log(LOG_DEBUG) << "Deleting channel " << this->GetName(); @@ -165,7 +158,7 @@ void ChannelImpl::SetBot(ServiceBot *bi) MemoServ::MemoInfo *ChannelImpl::GetMemos() { - return GetRef<MemoServ::MemoInfo *>(MemoServ::memoinfo); + return GetRef<MemoServ::MemoInfo *>(); } void ChannelImpl::SetFounder(NickServ::Account *nc) @@ -190,7 +183,7 @@ NickServ::Account *ChannelImpl::GetSuccessor() ChanServ::ChanAccess *ChannelImpl::GetAccess(unsigned index) { - std::vector<ChanServ::ChanAccess *> a = GetRefs<ChanServ::ChanAccess *>(ChanServ::chanaccess); + std::vector<ChanServ::ChanAccess *> a = GetRefs<ChanServ::ChanAccess *>(); return a.size() > index ? a[index] : nullptr; } @@ -217,7 +210,7 @@ ChanServ::AccessGroup ChannelImpl::AccessFor(const User *u, bool updateLastUsed) for (unsigned i = 0, end = this->GetAccessCount(); i < end; ++i) { ChanServ::ChanAccess *a = this->GetAccess(i); - if (a->Matches(u, u->Account(), group.path)) + if (a->Matches(u, u->Account())) group.push_back(a); } @@ -244,7 +237,7 @@ ChanServ::AccessGroup ChannelImpl::AccessFor(NickServ::Account *nc, bool updateL for (unsigned i = 0, end = this->GetAccessCount(); i < end; ++i) { ChanServ::ChanAccess *a = this->GetAccess(i); - if (a->Matches(NULL, nc, group.path)) + if (a->Matches(NULL, nc)) group.push_back(a); } @@ -259,45 +252,18 @@ ChanServ::AccessGroup ChannelImpl::AccessFor(NickServ::Account *nc, bool updateL unsigned ChannelImpl::GetAccessCount() { - return GetRefs<ChanServ::ChanAccess *>(ChanServ::chanaccess).size(); -} - -unsigned ChannelImpl::GetDeepAccessCount() const -{ - return 0; -#if 0 - ChanServ::ChanAccess::Path path; - for (unsigned i = 0, end = this->GetAccessCount(); i < end; ++i) - { - ChanServ::ChanAccess *a = this->GetAccess(i); - a->Matches(NULL, NULL, path); - } - - unsigned count = this->GetAccessCount(); - std::set<const ChanServ::Channel *> channels; - channels.insert(this); - for (ChanServ::ChanAccess::Set::iterator it = path.first.begin(); it != path.first.end(); ++it) - { - const ChanServ::Channel *ci = it->first->GetChannel(); - if (!channels.count(ci)) - { - channels.count(ci); - count += ci->GetAccessCount(); - } - } - return count; -#endif + return GetRefs<ChanServ::ChanAccess *>().size(); } void ChannelImpl::ClearAccess() { - for (ChanServ::ChanAccess *a : GetRefs<ChanServ::ChanAccess *>(ChanServ::chanaccess)) + for (ChanServ::ChanAccess *a : GetRefs<ChanServ::ChanAccess *>()) a->Delete(); } AutoKick *ChannelImpl::AddAkick(const Anope::string &user, NickServ::Account *akicknc, const Anope::string &reason, time_t t, time_t lu) { - AutoKick *ak = ::autokick.Create(); + AutoKick *ak = Serialize::New<AutoKick *>(); ak->SetChannel(this); ak->SetAccount(akicknc); ak->SetReason(reason); @@ -310,7 +276,7 @@ AutoKick *ChannelImpl::AddAkick(const Anope::string &user, NickServ::Account *ak AutoKick *ChannelImpl::AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t, time_t lu) { - AutoKick *ak = ::autokick.Create(); + AutoKick *ak = Serialize::New<AutoKick *>(); ak->SetChannel(this); ak->SetMask(mask); ak->SetReason(reason); @@ -323,25 +289,25 @@ AutoKick *ChannelImpl::AddAkick(const Anope::string &user, const Anope::string & AutoKick *ChannelImpl::GetAkick(unsigned index) { - std::vector<AutoKick *> a = GetRefs<AutoKick *>(autokick); + std::vector<AutoKick *> a = GetRefs<AutoKick *>(); return a.size() > index ? a[index] : nullptr; } unsigned ChannelImpl::GetAkickCount() { - std::vector<AutoKick *> t = GetRefs<AutoKick *>(autokick); + std::vector<AutoKick *> t = GetRefs<AutoKick *>(); return t.size(); } void ChannelImpl::ClearAkick() { - for (AutoKick *ak : GetRefs<AutoKick *>(autokick)) + for (AutoKick *ak : GetRefs<AutoKick *>()) ak->Delete(); } int16_t ChannelImpl::GetLevel(const Anope::string &priv) { - for (ChanServ::Level *l : this->GetRefs<ChanServ::Level *>(ChanServ::level)) + for (ChanServ::Level *l : this->GetRefs<ChanServ::Level *>()) if (l->GetName() == priv) return l->GetLevel(); @@ -357,7 +323,7 @@ int16_t ChannelImpl::GetLevel(const Anope::string &priv) void ChannelImpl::SetLevel(const Anope::string &priv, int16_t level) { - for (ChanServ::Level *l : this->GetRefs<ChanServ::Level *>(ChanServ::level)) + for (ChanServ::Level *l : this->GetRefs<ChanServ::Level *>()) if (l->GetName() == priv) { l->SetLevel(level); @@ -371,7 +337,7 @@ void ChannelImpl::SetLevel(const Anope::string &priv, int16_t level) return; } - ChanServ::Level *l = ChanServ::level.Create(); + ChanServ::Level *l = Serialize::New<ChanServ::Level *>(); l->SetChannel(this); l->SetName(priv); l->SetLevel(level); @@ -379,7 +345,7 @@ void ChannelImpl::SetLevel(const Anope::string &priv, int16_t level) void ChannelImpl::RemoveLevel(const Anope::string &priv) { - for (ChanServ::Level *l : this->GetRefs<ChanServ::Level *>(ChanServ::level)) + for (ChanServ::Level *l : this->GetRefs<ChanServ::Level *>()) if (l->GetName() == priv) { l->Delete(); @@ -389,7 +355,7 @@ void ChannelImpl::RemoveLevel(const Anope::string &priv) void ChannelImpl::ClearLevels() { - for (ChanServ::Level *l : this->GetRefs<ChanServ::Level *>(ChanServ::level)) + for (ChanServ::Level *l : this->GetRefs<ChanServ::Level *>()) l->Delete(); } diff --git a/modules/chanserv/main/channel.h b/modules/chanserv/main/channel.h index 86e42a8f9..801891821 100644 --- a/modules/chanserv/main/channel.h +++ b/modules/chanserv/main/channel.h @@ -2,10 +2,20 @@ class ChannelImpl : public ChanServ::Channel { + friend class ChannelType; + + NickServ::Account *founder = nullptr, *successor = nullptr; + Anope::string name, desc; + time_t time_registered = 0, last_used = 0; + Anope::string last_topic, last_topic_setter; + time_t last_topic_time = 0; + int16_t bantype = 0; + time_t banexpire = 0; + BotInfo *bi = nullptr; + public: ChannelImpl(Serialize::TypeBase *type) : ChanServ::Channel(type) { } ChannelImpl(Serialize::TypeBase *type, Serialize::ID id) : ChanServ::Channel(type, id) { } - ChannelImpl(Serialize::TypeBase *type, const Anope::string &chname); ~ChannelImpl(); void Delete() override; @@ -44,16 +54,17 @@ class ChannelImpl : public ChanServ::Channel MemoServ::MemoInfo *GetMemos() override; - bool IsFounder(const User *user) override; void SetFounder(NickServ::Account *nc) override; NickServ::Account *GetFounder() override; + void SetSuccessor(NickServ::Account *nc) override; NickServ::Account *GetSuccessor() override; + + bool IsFounder(const User *user) override; ChanServ::ChanAccess *GetAccess(unsigned index) /*const*/ override; ChanServ::AccessGroup AccessFor(const User *u, bool = true) override; ChanServ::AccessGroup AccessFor(NickServ::Account *nc, bool = true) override; unsigned GetAccessCount()/* const*/ override; - unsigned GetDeepAccessCount() const override; void ClearAccess() override; AutoKick* AddAkick(const Anope::string &user, NickServ::Account *akicknc, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0) override; AutoKick* AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0) override; diff --git a/modules/chanserv/main/channeltype.cpp b/modules/chanserv/main/channeltype.cpp index 4143285a8..0c65b1bb1 100644 --- a/modules/chanserv/main/channeltype.cpp +++ b/modules/chanserv/main/channeltype.cpp @@ -1,29 +1,29 @@ #include "module.h" #include "channeltype.h" -ChannelType::ChannelType(Module *me) : Serialize::Type<ChannelImpl>(me, "ChannelInfo") - , name(this, "name") - , desc(this, "desc") - , time_registered(this, "time_registered") - , last_used(this, "last_used") - , last_topic(this, "last_topic") - , last_topic_setter(this, "last_topic_setter") - , last_topic_time(this, "last_topic_time") - , bantype(this, "bantype") - , banexpire(this, "banexpire") - , founder(this, "founder") - , successor(this, "successor") - , bi(this, "bi") +ChannelType::ChannelType(Module *me) : Serialize::Type<ChannelImpl>(me) + , name(this, "name", &ChannelImpl::name) + , desc(this, "desc", &ChannelImpl::desc) + , time_registered(this, "time_registered", &ChannelImpl::time_registered) + , last_used(this, "last_used", &ChannelImpl::last_used) + , last_topic(this, "last_topic", &ChannelImpl::last_topic) + , last_topic_setter(this, "last_topic_setter", &ChannelImpl::last_topic_setter) + , last_topic_time(this, "last_topic_time", &ChannelImpl::last_topic_time) + , bantype(this, "bantype", &ChannelImpl::bantype) + , banexpire(this, "banexpire", &ChannelImpl::banexpire) + , founder(this, "founder", &ChannelImpl::founder) + , successor(this, "successor", &ChannelImpl::successor) + , bi(this, "bi", &ChannelImpl::bi) { } -void ChannelType::Name::SetField(ChanServ::Channel *c, const Anope::string &value) +void ChannelType::Name::SetField(ChannelImpl *c, const Anope::string &value) { ChanServ::registered_channel_map& map = ChanServ::service->GetChannels(); map.erase(GetField(c)); - Serialize::Field<ChanServ::Channel, Anope::string>::SetField(c, value); + Serialize::Field<ChannelImpl, Anope::string>::SetField(c, value); map[value] = c; } @@ -31,7 +31,7 @@ void ChannelType::Name::SetField(ChanServ::Channel *c, const Anope::string &valu ChanServ::Channel *ChannelType::FindChannel(const Anope::string &chan) { Serialize::ID id; - EventReturn result = Event::OnSerialize(&Event::SerializeEvents::OnSerializeFind, this, &this->name, chan, id); + EventReturn result = EventManager::Get()->Dispatch(&Event::SerializeEvents::OnSerializeFind, this, &this->name, chan, id); if (result == EVENT_ALLOW) return RequireID(id); diff --git a/modules/chanserv/main/channeltype.h b/modules/chanserv/main/channeltype.h index 7bc22a8f6..06d6410f8 100644 --- a/modules/chanserv/main/channeltype.h +++ b/modules/chanserv/main/channeltype.h @@ -4,29 +4,29 @@ class ChannelType : public Serialize::Type<ChannelImpl> { public: /* Channel name */ - struct Name : Serialize::Field<ChanServ::Channel, Anope::string> + struct Name : Serialize::Field<ChannelImpl, Anope::string> { - using Serialize::Field<ChanServ::Channel, Anope::string>::Field; + using Serialize::Field<ChannelImpl, Anope::string>::Field; - void SetField(ChanServ::Channel *c, const Anope::string &value) override; + void SetField(ChannelImpl *c, const Anope::string &value) override; } name; - Serialize::Field<ChanServ::Channel, Anope::string> desc; - Serialize::Field<ChanServ::Channel, time_t> time_registered; - Serialize::Field<ChanServ::Channel, time_t> last_used; + Serialize::Field<ChannelImpl, Anope::string> desc; + Serialize::Field<ChannelImpl, time_t> time_registered; + Serialize::Field<ChannelImpl, time_t> last_used; - Serialize::Field<ChanServ::Channel, Anope::string> last_topic; - Serialize::Field<ChanServ::Channel, Anope::string> last_topic_setter; - Serialize::Field<ChanServ::Channel, time_t> last_topic_time; + Serialize::Field<ChannelImpl, Anope::string> last_topic; + Serialize::Field<ChannelImpl, Anope::string> last_topic_setter; + Serialize::Field<ChannelImpl, time_t> last_topic_time; - Serialize::Field<ChanServ::Channel, int16_t> bantype; - Serialize::Field<ChanServ::Channel, time_t> banexpire; + Serialize::Field<ChannelImpl, int16_t> bantype; + Serialize::Field<ChannelImpl, time_t> banexpire; /* Channel founder */ - Serialize::ObjectField<ChanServ::Channel, NickServ::Account *> founder; + Serialize::ObjectField<ChannelImpl, NickServ::Account *> founder; /* Who gets the channel if the founder nick is dropped or expires */ - Serialize::ObjectField<ChanServ::Channel, NickServ::Account *> successor; + Serialize::ObjectField<ChannelImpl, NickServ::Account *> successor; - Serialize::ObjectField<ChanServ::Channel, BotInfo *> bi; + Serialize::ObjectField<ChannelImpl, BotInfo *> bi; ChannelType(Module *); diff --git a/modules/chanserv/main/chanserv.cpp b/modules/chanserv/main/chanserv.cpp index 9336b7c53..f579ec0ae 100644 --- a/modules/chanserv/main/chanserv.cpp +++ b/modules/chanserv/main/chanserv.cpp @@ -20,7 +20,7 @@ #include "leveltype.h" #include "modetype.h" #include "chanaccesstype.h" -#include "chanaccess.h" +#include "modules/chanserv/main/chanaccess.h" class ChanServCore : public Module , public ChanServ::ChanServService @@ -31,7 +31,6 @@ class ChanServCore : public Module , public EventHook<Event::DelChan> , public EventHook<Event::Help> , public EventHook<Event::CheckModes> - , public EventHook<Event::CreateChan> , public EventHook<Event::CanSet> , public EventHook<Event::ChannelSync> , public EventHook<Event::Log> @@ -47,30 +46,48 @@ class ChanServCore : public Module Reference<ServiceBot> ChanServ; std::vector<Anope::string> defaults; ExtensibleItem<bool> inhabit; - ExtensibleRef<bool> persist;//XXX? bool always_lower; - EventHandlers<ChanServ::Event::PreChanExpire> OnPreChanExpire; - EventHandlers<ChanServ::Event::ChanExpire> OnChanExpire; std::vector<ChanServ::Privilege> Privileges; ChanServ::registered_channel_map registered_channels; ChannelType channel_type; - ChanAccessType chanaccess_type; +// ChanAccessType chanaccess_type; LevelType level_type; CSModeType mode_type; public: ChanServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR) , ChanServService(this) + , EventHook<Event::ChannelCreate>(this) + , EventHook<Event::BotDelete>(this) + , EventHook<Event::BotPrivmsg>(this) + , EventHook<Event::DelCore>(this) + , EventHook<Event::DelChan>(this) + , EventHook<Event::Help>(this) + , EventHook<Event::CheckModes>(this) + , EventHook<Event::CanSet>(this) + , EventHook<Event::ChannelSync>(this) + , EventHook<Event::Log>(this) + , EventHook<Event::ExpireTick>(this) + , EventHook<Event::CheckDelete>(this) + , EventHook<Event::PreUplinkSync>(this) + , EventHook<Event::ChanRegistered>(this) + , EventHook<Event::JoinChannel>(this) + , EventHook<Event::ChannelModeSet>(this) + , EventHook<Event::ChanInfo>(this) + , EventHook<Event::SetCorrectModes>(this) , inhabit(this, "inhabit") - , persist("PERSIST") , always_lower(false) - , OnPreChanExpire(this) - , OnChanExpire(this) , channel_type(this) - , chanaccess_type(this, "ChanAccess") +// , chanaccess_type(this) , level_type(this) , mode_type(this) { + ChanServ::service = this; + } + + ~ChanServCore() + { + ChanServ::service = nullptr; } ChanServ::Channel *Find(const Anope::string &name) override @@ -143,7 +160,7 @@ class ChanServCore : public Module if (inhabit.HasExt(c)) return; - new ChanServTimer(ChanServ, inhabit, this->owner, c); + new ChanServTimer(ChanServ, inhabit, this, c); } void AddPrivilege(ChanServ::Privilege p) override @@ -265,7 +282,7 @@ class ChanServCore : public Module void OnDelCore(NickServ::Account *nc) override { unsigned int max_reg = Config->GetModule(this)->Get<unsigned int>("maxregistered"); - for (ChanServ::Channel *ci : nc->GetRefs<ChanServ::Channel *>(ChanServ::channel)) + for (ChanServ::Channel *ci : nc->GetRefs<ChanServ::Channel *>()) { if (ci->GetFounder() == nc) { @@ -336,7 +353,7 @@ class ChanServCore : public Module { /* remove access entries that are this channel */ - for (ChanServ::Channel *c : ci->GetRefs<ChanServ::Channel *>(ChanServ::channel)) + for (ChanServ::Channel *c : ci->GetRefs<ChanServ::Channel *>()) { for (unsigned j = 0; j < c->GetAccessCount(); ++j) { @@ -412,13 +429,6 @@ class ChanServCore : public Module } } - void OnCreateChan(ChanServ::Channel *ci) override - { - /* Set default chan flags */ - for (unsigned i = 0; i < defaults.size(); ++i) - ci->SetS<bool>(defaults[i].upper(), true); - } - EventReturn OnCanSet(User *u, const ChannelMode *cm) override { if (Config->GetModule(this)->Get<Anope::string>("nomlock").find(cm->mchar) != Anope::string::npos @@ -429,7 +439,7 @@ class ChanServCore : public Module void OnChannelSync(Channel *c) override { - bool perm = c->HasMode("PERM") || (c->ci && persist && persist->HasExt(c->ci)); + bool perm = c->HasMode("PERM") || (c->ci && c->ci->HasFieldS("PERSIST")); if (!perm && !c->botchannel && (c->users.empty() || (c->users.size() == 1 && c->users.begin()->second->user->server == Me))) { this->Hold(c); @@ -466,12 +476,12 @@ class ChanServCore : public Module expire = true; } - this->OnPreChanExpire(&ChanServ::Event::PreChanExpire::OnPreChanExpire, ci, expire); + EventManager::Get()->Dispatch(&ChanServ::Event::PreChanExpire::OnPreChanExpire, ci, expire); if (expire) { ::Log(LOG_NORMAL, "chanserv/expire", ChanServ) << "Expiring channel " << ci->GetName() << " (founder: " << (ci->GetFounder() ? ci->GetFounder()->GetDisplay() : "(none)") << ")"; - this->OnChanExpire(&ChanServ::Event::ChanExpire::OnChanExpire, ci); + EventManager::Get()->Dispatch(&ChanServ::Event::ChanExpire::OnChanExpire, ci); delete ci; } } @@ -488,12 +498,10 @@ class ChanServCore : public Module void OnPreUplinkSync(Server *serv) override { - if (!persist) - return; /* Find all persistent channels and create them, as we are about to finish burst to our uplink */ for (ChanServ::Channel *ci : channel_type.List<ChanServ::Channel *>()) { - if (persist->HasExt(ci)) + if (ci->HasFieldS("PERSIST")) { bool c; ci->c = Channel::FindOrCreate(ci->GetName(), c, ci->GetTimeRegistered()); @@ -521,13 +529,17 @@ class ChanServCore : public Module void OnChanRegistered(ChanServ::Channel *ci) override { - if (!persist || !ci->c) + /* Set default chan flags */ + for (unsigned i = 0; i < defaults.size(); ++i) + ci->SetS<bool>(defaults[i].upper(), true); + + if (!ci->c) return; /* Mark the channel as persistent */ if (ci->c->HasMode("PERM")) - persist->Set(ci, true); + ci->SetS("PERSIST", true); /* Persist may be in def cflags, set it here */ - else if (persist->HasExt(ci)) + else if (ci->HasFieldS("PERSIST")) ci->c->SetMode(NULL, "PERM"); } diff --git a/modules/chanserv/main/level.h b/modules/chanserv/main/level.h index 4521fceef..6c6397270 100644 --- a/modules/chanserv/main/level.h +++ b/modules/chanserv/main/level.h @@ -1,6 +1,12 @@ class LevelImpl : public ChanServ::Level { + friend class LevelType; + + ChanServ::Channel *channel = nullptr; + Anope::string name; + int level = 0; + public: LevelImpl(Serialize::TypeBase *type) : ChanServ::Level(type) { } LevelImpl(Serialize::TypeBase *type, Serialize::ID id) : ChanServ::Level(type, id) { } diff --git a/modules/chanserv/main/leveltype.h b/modules/chanserv/main/leveltype.h index 12e4c132f..ad6962f42 100644 --- a/modules/chanserv/main/leveltype.h +++ b/modules/chanserv/main/leveltype.h @@ -7,10 +7,10 @@ class LevelType : public Serialize::Type<LevelImpl> Serialize::Field<LevelImpl, Anope::string> name; Serialize::Field<LevelImpl, int> level; - LevelType(Module *creator) : Serialize::Type<LevelImpl>(creator, "Level") - , channel(this, "channel", true) - , name(this, "name") - , level(this, "level") + LevelType(Module *creator) : Serialize::Type<LevelImpl>(creator) + , channel(this, "channel", &LevelImpl::channel, true) + , name(this, "name", &LevelImpl::name) + , level(this, "level", &LevelImpl::level) { } }; diff --git a/modules/chanserv/main/mode.h b/modules/chanserv/main/mode.h index cd94e5ad1..8923a18ae 100644 --- a/modules/chanserv/main/mode.h +++ b/modules/chanserv/main/mode.h @@ -1,6 +1,11 @@ class ModeImpl : public ChanServ::Mode { + friend class CSModeType; + + ChanServ::Channel *channel = nullptr; + Anope::string mode, param; + public: ModeImpl(Serialize::TypeBase *type) : ChanServ::Mode(type) { } ModeImpl(Serialize::TypeBase *type, Serialize::ID id) : ChanServ::Mode(type, id) { } diff --git a/modules/chanserv/main/modetype.h b/modules/chanserv/main/modetype.h index b30c0491f..b03764e32 100644 --- a/modules/chanserv/main/modetype.h +++ b/modules/chanserv/main/modetype.h @@ -6,10 +6,10 @@ class CSModeType : public Serialize::Type<ModeImpl> Serialize::ObjectField<ModeImpl, ChanServ::Channel *> channel; Serialize::Field<ModeImpl, Anope::string> mode, param; - CSModeType(Module *creator) : Serialize::Type<ModeImpl>(creator, "CSKeepMode") - , channel(this, "channel", true) - , mode(this, "mode") - , param(this, "param") + CSModeType(Module *creator) : Serialize::Type<ModeImpl>(creator) + , channel(this, "channel", &ModeImpl::channel, true) + , mode(this, "mode", &ModeImpl::mode) + , param(this, "param", &ModeImpl::param) { } }; |
