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 /include/modules | |
| 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 'include/modules')
48 files changed, 414 insertions, 431 deletions
diff --git a/include/modules/botserv.h b/include/modules/botserv.h index 09183b53a..d19dea2ac 100644 --- a/include/modules/botserv.h +++ b/include/modules/botserv.h @@ -18,5 +18,4 @@ namespace BotServ } }; - static ServiceReference<BotServService> service("BotServService", "BotServ"); } diff --git a/include/modules/botserv/badwords.h b/include/modules/botserv/badwords.h index 87986ee62..6f2205a97 100644 --- a/include/modules/botserv/badwords.h +++ b/include/modules/botserv/badwords.h @@ -31,6 +31,8 @@ class BadWord : public Serialize::Object protected: using Serialize::Object::Object; public: + static constexpr const char *NAME = "badword"; + virtual ~BadWord() = default; virtual ChanServ::Channel *GetChannel() anope_abstract; @@ -43,11 +45,12 @@ class BadWord : public Serialize::Object virtual void SetType(const BadWordType &) anope_abstract; }; -static Serialize::TypeReference<BadWord> badword("BadWord"); - -struct BadWords : public Service +class BadWords : public Service { - BadWords(Module *me) : Service(me, "BadWords", "badwords") { } + public: + static constexpr const char *NAME = "badwords"; + + BadWords(Module *me) : Service(me, NAME) { } /** Add a badword to the badword list * @param word The badword @@ -79,12 +82,14 @@ struct BadWords : public Service virtual void ClearBadWords(ChanServ::Channel *) anope_abstract; }; -static ServiceReference<BadWords> badwords("BadWords", "badwords"); - namespace Event { struct CoreExport BadWordEvents : Events { + static constexpr const char *NAME = "badwords"; + + using Events::Events; + /** Called before a badword is added to the badword list * @param ci The channel * @param bw The badword @@ -99,4 +104,3 @@ namespace Event }; } -template<> struct EventName<Event::BadWordEvents> { static constexpr const char *const name = "Badwords"; }; diff --git a/include/modules/botserv/bot.h b/include/modules/botserv/bot.h index fe6534309..e07b75f9a 100644 --- a/include/modules/botserv/bot.h +++ b/include/modules/botserv/bot.h @@ -10,6 +10,10 @@ namespace Event { struct CoreExport BotCreate : Events { + static constexpr const char *NAME = "botcreate"; + + using Events::Events; + /** Called when a new bot is made * @param bi The bot */ @@ -18,6 +22,10 @@ namespace Event struct CoreExport BotChange : Events { + static constexpr const char *NAME = "botchange"; + + using Events::Events; + /** Called when a bot is changed * @param bi The bot */ @@ -26,6 +34,10 @@ namespace Event struct CoreExport BotDelete : Events { + static constexpr const char *NAME = "botdelete"; + + using Events::Events; + /** Called when a bot is deleted * @param bi The bot */ @@ -33,6 +45,3 @@ namespace Event }; } -template<> struct EventName<Event::BotCreate> { static constexpr const char *const name = "OnBotCreate"; }; -template<> struct EventName<Event::BotChange> { static constexpr const char *const name = "OnBotChange"; }; -template<> struct EventName<Event::BotDelete> { static constexpr const char *const name = "OnBotDelete"; }; diff --git a/include/modules/botserv/info.h b/include/modules/botserv/info.h index 1ebd58c89..92bac8892 100644 --- a/include/modules/botserv/info.h +++ b/include/modules/botserv/info.h @@ -11,11 +11,13 @@ namespace Event { struct CoreExport ServiceBotEvent : Events { + static constexpr const char *NAME = "servicebotevent"; + + using Events::Events; + /** Called when a user uses botserv/info on a bot or channel. */ virtual void OnServiceBot(CommandSource &source, ServiceBot *bi, ChanServ::Channel *ci, InfoFormatter &info) anope_abstract; }; - extern CoreExport EventHandlers<ServiceBotEvent> OnServiceBot; } -template<> struct EventName<Event::ServiceBotEvent> { static constexpr const char *const name = "OnServiceBot"; }; diff --git a/include/modules/botserv/kick.h b/include/modules/botserv/kick.h index 1346d7427..4d0461739 100644 --- a/include/modules/botserv/kick.h +++ b/include/modules/botserv/kick.h @@ -1,14 +1,10 @@ /* BotServ 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. - * - * */ class KickerData : public Serialize::Object @@ -17,6 +13,8 @@ class KickerData : public Serialize::Object using Serialize::Object::Object; public: + static constexpr const char *const NAME = "kickerdata"; + virtual ChanServ::Channel *GetChannel() anope_abstract; virtual void SetChannel(ChanServ::Channel *) anope_abstract; @@ -102,15 +100,16 @@ class KickerData : public Serialize::Object virtual void SetDontKickVoices(const bool &) anope_abstract; }; -static Serialize::TypeReference<KickerData> kickerdata("KickerData"); - inline KickerData *GetKickerData(ChanServ::Channel *ci) { - KickerData *kd = ci->GetRef<KickerData *>(kickerdata); - if (!kd && kickerdata) + KickerData *kd = ci->GetRef<KickerData *>(); + if (!kd) { - kd = kickerdata.Create(); - kd->SetChannel(ci); + kd = Serialize::New<KickerData *>(); + if (kd != nullptr) + { + kd->SetChannel(ci); + } } return kd; } @@ -119,6 +118,10 @@ namespace Event { struct CoreExport BotBan : Events { + static constexpr const char *NAME = "botban"; + + using Events::Events; + /** Called when a bot places a ban * @param u User being banned * @param ci Channel the ban is placed on @@ -127,6 +130,3 @@ namespace Event virtual void OnBotBan(User *u, ChanServ::Channel *ci, const Anope::string &mask) anope_abstract; }; } - -template<> struct EventName<Event::BotBan> { static constexpr const char *const name = "OnBotBan"; }; - diff --git a/include/modules/chanserv.h b/include/modules/chanserv.h index 35fc3c332..88a8ac3b9 100644 --- a/include/modules/chanserv.h +++ b/include/modules/chanserv.h @@ -90,6 +90,8 @@ namespace ChanServ class Level : public Serialize::Object { public: + static constexpr const char *const NAME = "level"; + using Serialize::Object::Object; virtual Channel *GetChannel() anope_abstract; @@ -102,11 +104,11 @@ namespace ChanServ virtual void SetLevel(const int &) anope_abstract; }; - static Serialize::TypeReference<Level> level("Level"); - class Mode : public Serialize::Object { public: + static constexpr const char *const NAME = "mlockmode"; + using Serialize::Object::Object; virtual Channel *GetChannel() anope_abstract; @@ -119,12 +121,12 @@ namespace ChanServ virtual void SetParam(const Anope::string &) anope_abstract; }; - static Serialize::TypeReference<Mode> mode("CSKeepMode"); - class ChanServService : public Service { public: - ChanServService(Module *m) : Service(m, "ChanServService", "ChanServ") + static constexpr const char *NAME = "chanserv"; + + ChanServService(Module *m) : Service(m, NAME) { } @@ -142,7 +144,8 @@ namespace ChanServ virtual std::vector<Privilege> &GetPrivileges() anope_abstract; virtual void ClearPrivileges() anope_abstract; }; - static ServiceReference<ChanServService> service("ChanServService", "ChanServ"); + + extern ChanServService *service; inline Channel *Find(const Anope::string name) { @@ -153,22 +156,28 @@ namespace ChanServ { struct CoreExport PreChanExpire : Events { + static constexpr const char *NAME = "prechanexpire"; + + using Events::Events; + /** Called before a channel expires * @param ci The channel * @param expire Set to true to allow the chan to expire */ virtual void OnPreChanExpire(Channel *ci, bool &expire) anope_abstract; }; - static EventHandlersReference<PreChanExpire> OnPreChanExpire; struct CoreExport ChanExpire : Events { + static constexpr const char *NAME = "chanexpire"; + + using Events::Events; + /** Called before a channel expires * @param ci The channel */ virtual void OnChanExpire(Channel *ci) anope_abstract; }; - static EventHandlersReference<ChanExpire> OnChanExpire; } /* It matters that Base is here before Extensible (it is inherited by Serializable) @@ -182,6 +191,8 @@ namespace ChanServ using Serialize::Object::Object; public: + static constexpr const char *const NAME = "channel"; + virtual Anope::string GetName() anope_abstract; virtual void SetName(const Anope::string &) anope_abstract; @@ -247,6 +258,7 @@ namespace ChanServ if (ChanServ) return ChanServ; +#warning "if(this)" //XXX // if (!BotListByNick->empty()) // return BotListByNick->begin()->second; @@ -274,11 +286,6 @@ namespace ChanServ */ virtual unsigned GetAccessCount() /*const*/ anope_abstract; - /** Get the number of access entries for this channel, - * including those that are on other channels. - */ - virtual unsigned GetDeepAccessCount() const anope_abstract; - /** Clear the entire channel access list * * Clears the entire access list by deleting every item and then clearing the vector. @@ -350,8 +357,6 @@ namespace ChanServ virtual MemoServ::MemoInfo *GetMemos() anope_abstract; }; - static Serialize::TypeReference<Channel> channel("ChannelInfo"); - enum { ACCESS_INVALID = -10000, @@ -362,15 +367,14 @@ namespace ChanServ class CoreExport ChanAccess : public Serialize::Object { public: - typedef std::multimap<ChanAccess *, ChanAccess *> Set; - /* shows the 'path' taken to determine if an access entry matches a user - * .first are access entries checked - * .second are access entries which match - */ - typedef std::pair<Set, Set> Path; + static constexpr const char *const NAME = "access"; - ChanAccess(Serialize::TypeBase *type) : Serialize::Object(type) { } - ChanAccess(Serialize::TypeBase *type, Serialize::ID id) : Serialize::Object(type, id) { } + Channel *channel = nullptr; + Serialize::Object *object = nullptr; + Anope::string creator, mask; + time_t last_seen = 0, created = 0; + + using Serialize::Object::Object; virtual Channel *GetChannel() anope_abstract; virtual void SetChannel(Channel *ci) anope_abstract; @@ -396,9 +400,8 @@ namespace ChanServ /** Check if this access entry matches the given user or account * @param u The user * @param acc The account - * @param p The path to the access object which matches will be put here */ - virtual bool Matches(const User *u, NickServ::Account *acc, Path &p) anope_abstract; + virtual bool Matches(const User *u, NickServ::Account *acc) anope_abstract; /** Check if this access entry has the given privilege. * @param name The privilege name @@ -417,7 +420,7 @@ namespace ChanServ virtual void AccessUnserialize(const Anope::string &data) anope_abstract; /* Comparison operators to other Access entries */ - bool operator>(ChanAccess &other) + virtual bool operator>(ChanAccess &other) { const std::vector<Privilege> &privs = service->GetPrivileges(); for (unsigned i = privs.size(); i > 0; --i) @@ -434,7 +437,7 @@ namespace ChanServ return false; } - bool operator<(ChanAccess &other) + virtual bool operator<(ChanAccess &other) { const std::vector<Privilege> &privs = service->GetPrivileges(); for (unsigned i = privs.size(); i > 0; --i) @@ -461,174 +464,5 @@ namespace ChanServ return !(*this > other); } }; - - static Serialize::TypeReference<ChanAccess> chanaccess("ChanAccess"); - - /* A group of access entries. This is used commonly, for example with ChanServ::Channel::AccessFor, - * to show what access a user has on a channel because users can match multiple access entries. - */ - class CoreExport AccessGroup : public std::vector<ChanAccess *> - { - public: - /* Channel these access entries are on */ - ChanServ::Channel *ci; - /* Path from these entries to other entries that they depend on */ - ChanAccess::Path path; - /* Account these entries affect, if any */ - const NickServ::Account *nc; - /* super_admin always gets all privs. founder is a special case where ci->founder == nc */ - bool super_admin, founder; - - AccessGroup() - { - this->ci = NULL; - this->nc = NULL; - this->super_admin = this->founder = false; - } - - private: - bool HasPriv(ChanAccess *access, const Anope::string &name) - { - EventReturn MOD_RESULT = ::Event::OnCheckPriv(&::Event::CheckPriv::OnCheckPriv, access, name); - if (MOD_RESULT == EVENT_ALLOW || access->HasPriv(name)) - { - typedef std::multimap<ChanAccess *, ChanAccess *> P; - std::pair<P::const_iterator, P::const_iterator> it = this->path.second.equal_range(access); - if (it.first != it.second) - /* check all of the paths for this entry */ - for (; it.first != it.second; ++it.first) - { - ChanAccess *a = it.first->second; - /* if only one path fully matches then we are ok */ - if (HasPriv(a, name)) - return true; - } - else - /* entry is the end of a chain, all entries match, ok */ - return true; - } - - /* entry does not match or none of the chains fully match */ - return false; - } - - public: - /** Check if this access group has a certain privilege. Eg, it - * will check every ChanAccess entry of this group for any that - * has the given privilege. - * @param priv The privilege - * @return true if any entry has the given privilege - */ - bool HasPriv(const Anope::string &priv) - { - if (this->super_admin) - return true; - else if (!ci || ci->GetLevel(priv) == ACCESS_INVALID) - return false; - - /* Privileges prefixed with auto are understood to be given - * automatically. Sometimes founders want to not automatically - * obtain privileges, so we will let them */ - bool auto_mode = !priv.find("AUTO"); - - /* Only grant founder privilege if this isn't an auto mode or if they don't match any entries in this group */ - if ((!auto_mode || this->empty()) && this->founder) - return true; - - EventReturn MOD_RESULT; - MOD_RESULT = ::Event::OnGroupCheckPriv(&::Event::GroupCheckPriv::OnGroupCheckPriv, this, priv); - if (MOD_RESULT != EVENT_CONTINUE) - return MOD_RESULT == EVENT_ALLOW; - - for (unsigned i = this->size(); i > 0; --i) - { - ChanAccess *access = this->at(i - 1); - - if (HasPriv(access, priv)) - return true; - } - - return false; - } - - /** Get the "highest" access entry from this group of entries. - * The highest entry is determined by the entry that has the privilege - * with the highest rank (see Privilege::rank). - * @return The "highest" entry - */ - ChanAccess *Highest() - { - ChanAccess *highest = NULL; - for (unsigned i = 0; i < this->size(); ++i) - if (highest == NULL || *this->at(i) > *highest) - highest = this->at(i); - return highest; - } - - /* Comparison operators to other AccessGroups */ - bool operator>(AccessGroup &other) - { - if (other.super_admin) - return false; - else if (this->super_admin) - return true; - else if (other.founder) - return false; - else if (this->founder) - return true; - - const std::vector<Privilege> &privs = service->GetPrivileges(); - for (unsigned i = privs.size(); i > 0; --i) - { - bool this_p = this->HasPriv(privs[i - 1].name), - other_p = other.HasPriv(privs[i - 1].name); - - if (!this_p && !other_p) - continue; - - return this_p && !other_p; - } - - return false; - } - - bool operator<(AccessGroup &other) - { - if (this->super_admin) - return false; - else if (other.super_admin) - return true; - else if (this->founder) - return false; - else if (other.founder) - return true; - - const std::vector<Privilege> &privs = service->GetPrivileges(); - for (unsigned i = privs.size(); i > 0; --i) - { - bool this_p = this->HasPriv(privs[i - 1].name), - other_p = other.HasPriv(privs[i - 1].name); - - if (!this_p && !other_p) - continue; - - return !this_p && other_p; - } - - return false; - } - - bool operator>=(AccessGroup &other) - { - return !(*this < other); - } - - bool operator<=(AccessGroup &other) - { - return !(*this > other); - } - }; } -template<> struct EventName<ChanServ::Event::PreChanExpire> { static constexpr const char *const name = "OnPreChanExpire"; }; -template<> struct EventName<ChanServ::Event::ChanExpire> { static constexpr const char *const name = "OnChanExpire"; }; diff --git a/include/modules/chanserv/access.h b/include/modules/chanserv/access.h index 54eb3f353..35fad81d3 100644 --- a/include/modules/chanserv/access.h +++ b/include/modules/chanserv/access.h @@ -7,14 +7,16 @@ * */ -static Serialize::TypeReference<ChanServ::ChanAccess> accesschanaccess("AccessChanAccess"); -static Serialize::TypeReference<ChanServ::ChanAccess> flagschanaccess("FlagsChanAccess"); -static Serialize::TypeReference<ChanServ::ChanAccess> xopchanaccess("XOPChanAccess"); +#include "main/chanaccess.h" namespace Event { struct CoreExport LevelChange : Events { + static constexpr const char *NAME = "levelchange"; + + using Events::Events; + /** Called when a level for a channel is changed * @param source The source of the command * @param ci The channel the level was changed on @@ -25,4 +27,36 @@ namespace Event }; } -template<> struct EventName<Event::LevelChange> { static constexpr const char *const name = "OnLevelChange"; }; +class AccessChanAccess : public ChanAccessImpl +{ + public: + static constexpr const char *NAME = "accesschanaccess"; + + using ChanAccessImpl::ChanAccessImpl; + + virtual int GetLevel() anope_abstract; + virtual void SetLevel(const int &) anope_abstract; +}; + +class XOPChanAccess : public ChanAccessImpl +{ + public: + static constexpr const char *NAME = "xopchanaccess"; + + using ChanAccessImpl::ChanAccessImpl; + + virtual const Anope::string &GetType() anope_abstract; + virtual void SetType(const Anope::string &) anope_abstract; +}; + +class FlagsChanAccess : public ChanAccessImpl +{ + public: + static constexpr const char *NAME = "flagschanaccess"; + + using ChanAccessImpl::ChanAccessImpl; + + virtual const Anope::string &GetFlags() anope_abstract; + virtual void SetFlags(const Anope::string &) anope_abstract; +}; + diff --git a/include/modules/chanserv/akick.h b/include/modules/chanserv/akick.h index 966dac15b..cc7f0aaec 100644 --- a/include/modules/chanserv/akick.h +++ b/include/modules/chanserv/akick.h @@ -1,6 +1,6 @@ /* * - * (C) 2014 Anope Team + * (C) 2014-2016 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. @@ -15,6 +15,8 @@ class CoreExport AutoKick : public Serialize::Object protected: using Serialize::Object::Object; public: + static constexpr const char *const NAME = "akick"; + virtual ~AutoKick() = default; virtual ChanServ::Channel *GetChannel() anope_abstract; @@ -39,12 +41,14 @@ class CoreExport AutoKick : public Serialize::Object virtual void SetLastUsed(const time_t &) anope_abstract; }; -static Serialize::TypeReference<AutoKick> autokick("AutoKick"); - namespace Event { struct CoreExport Akick : Events { + static constexpr const char *NAME = "akick"; + + using Events::Events; + /** Called after adding an akick to a channel * @param source The source of the command * @param ci The channel @@ -61,4 +65,3 @@ namespace Event }; } -template<> struct EventName<Event::Akick> { static constexpr const char *const name = "Akick"; }; diff --git a/include/modules/chanserv/drop.h b/include/modules/chanserv/drop.h index db231059b..50f2627c2 100644 --- a/include/modules/chanserv/drop.h +++ b/include/modules/chanserv/drop.h @@ -11,6 +11,10 @@ namespace Event { struct CoreExport ChanDrop : Events { + static constexpr const char *NAME = "chandrop"; + + using Events::Events; + /** Called right before a channel is dropped * @param source The user dropping the channel * @param ci The channel @@ -19,4 +23,3 @@ namespace Event }; } -template<> struct EventName<Event::ChanDrop> { static constexpr const char *const name = "OnChanDrop"; }; diff --git a/include/modules/chanserv/entrymsg.h b/include/modules/chanserv/entrymsg.h index b5804068f..452057509 100644 --- a/include/modules/chanserv/entrymsg.h +++ b/include/modules/chanserv/entrymsg.h @@ -1,5 +1,5 @@ /* - * (C) 2003-2014 Anope Team + * (C) 2003-2016 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. @@ -12,6 +12,8 @@ class EntryMsg : public Serialize::Object using Serialize::Object::Object; public: + static constexpr const char *const NAME = "entrymsg"; + virtual ChanServ::Channel *GetChannel() anope_abstract; virtual void SetChannel(ChanServ::Channel *) anope_abstract; @@ -25,5 +27,4 @@ class EntryMsg : public Serialize::Object virtual void SetWhen(const time_t &) anope_abstract; }; -static Serialize::TypeReference<EntryMsg> entrymsg("EntryMsg"); diff --git a/include/modules/chanserv/info.h b/include/modules/chanserv/info.h index f80e3daf2..d487e3075 100644 --- a/include/modules/chanserv/info.h +++ b/include/modules/chanserv/info.h @@ -11,6 +11,10 @@ namespace Event { struct CoreExport ChanInfo : Events { + static constexpr const char *NAME = "chaninfo"; + + using Events::Events; + /** Called when a user requests info for a channel * @param source The user requesting info * @param ci The channel the user is requesting info for @@ -21,4 +25,3 @@ namespace Event }; } -template<> struct EventName<Event::ChanInfo> { static constexpr const char *const name = "OnChanInfo"; }; diff --git a/include/modules/chanserv/log.h b/include/modules/chanserv/log.h index d940f5e87..b579a05ed 100644 --- a/include/modules/chanserv/log.h +++ b/include/modules/chanserv/log.h @@ -1,12 +1,10 @@ /* ChanServ 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. + * */ class LogSetting : public Serialize::Object @@ -15,6 +13,8 @@ class LogSetting : public Serialize::Object using Serialize::Object::Object; public: + static constexpr const char *const NAME = "logsetting"; + virtual ChanServ::Channel *GetChannel() anope_abstract; virtual void SetChannel(ChanServ::Channel *) anope_abstract; @@ -39,6 +39,3 @@ class LogSetting : public Serialize::Object virtual time_t GetCreated() anope_abstract; virtual void SetCreated(const time_t &) anope_abstract; }; - -static Serialize::TypeReference<LogSetting> logsetting("LogSetting"); - diff --git a/include/modules/chanserv/main/chanaccess.h b/include/modules/chanserv/main/chanaccess.h new file mode 100644 index 000000000..7a297c405 --- /dev/null +++ b/include/modules/chanserv/main/chanaccess.h @@ -0,0 +1,31 @@ +#pragma once + +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) override; +}; diff --git a/include/modules/chanserv/mode.h b/include/modules/chanserv/mode.h index 4c7965e2a..78b7d861f 100644 --- a/include/modules/chanserv/mode.h +++ b/include/modules/chanserv/mode.h @@ -1,12 +1,10 @@ /* ChanServ 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. + * */ class ModeLock : public Serialize::Object @@ -15,6 +13,8 @@ class ModeLock : public Serialize::Object using Serialize::Object::Object; public: + static constexpr const char *const NAME = "modelock"; + virtual ChanServ::Channel *GetChannel() anope_abstract; virtual void SetChannel(ChanServ::Channel *) anope_abstract; @@ -34,12 +34,12 @@ class ModeLock : public Serialize::Object virtual void SetCreated(const time_t &) anope_abstract; }; -static Serialize::TypeReference<ModeLock> modelock("ModeLock"); - class ModeLocks : public Service { public: - ModeLocks(Module *me) : Service(me, "ModeLocks", "mlocks") { } + static constexpr const char *NAME = "mlocks"; + + ModeLocks(Module *me) : Service(me, NAME) { } typedef std::vector<ModeLock *> ModeList; @@ -98,12 +98,14 @@ class ModeLocks : public Service virtual Anope::string GetMLockAsString(ChanServ::Channel *, bool complete) const anope_abstract; }; -static ServiceReference<ModeLocks> mlocks("ModeLocks", "mlocks"); - namespace Event { struct CoreExport MLockEvents : Events { + static constexpr const char *NAME = "mlockevents"; + + using Events::Events; + /** Called when a mode is about to be mlocked * @param ci The channel the mode is being locked on * @param lock The mode lock @@ -119,5 +121,3 @@ namespace Event virtual EventReturn OnUnMLock(ChanServ::Channel *ci, ModeLock *lock) anope_abstract; }; } - -template<> struct EventName<Event::MLockEvents> { static constexpr const char *const name = "MLock"; }; diff --git a/include/modules/chanserv/set.h b/include/modules/chanserv/set.h index a0e81c888..1c5de3227 100644 --- a/include/modules/chanserv/set.h +++ b/include/modules/chanserv/set.h @@ -11,6 +11,10 @@ namespace Event { struct CoreExport SetChannelOption : Events { + static constexpr const char *NAME = "setchanneloption"; + + using Events::Events; + /** Called when a chanserv/set command is used * @param source The source of the command * @param cmd The command @@ -20,7 +24,5 @@ namespace Event */ virtual EventReturn OnSetChannelOption(CommandSource &source, Command *cmd, ChanServ::Channel *ci, const Anope::string &setting) anope_abstract; }; - static EventHandlersReference<SetChannelOption> OnSetChannelOption; } -template<> struct EventName<Event::SetChannelOption> { static constexpr const char *const name = "OnSetChannelOption"; }; diff --git a/include/modules/chanserv/set_misc.h b/include/modules/chanserv/set_misc.h index 65b92cc89..bdde80213 100644 --- a/include/modules/chanserv/set_misc.h +++ b/include/modules/chanserv/set_misc.h @@ -1,5 +1,5 @@ /* - * (C) 2014 Anope Team + * (C) 2014-2016 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. @@ -11,6 +11,8 @@ class CSMiscData : public Serialize::Object using Serialize::Object::Object; public: + static constexpr const char *const NAME = "csmiscdata"; + virtual ChanServ::Channel *GetChannel() anope_abstract; virtual void SetChannel(ChanServ::Channel *) anope_abstract; @@ -20,6 +22,3 @@ class CSMiscData : public Serialize::Object virtual Anope::string GetData() anope_abstract; virtual void SetData(const Anope::string &) anope_abstract; }; - -static Serialize::TypeReference<CSMiscData> csmiscdata("CSMiscData"); - diff --git a/include/modules/chanserv/suspend.h b/include/modules/chanserv/suspend.h index 27187ea09..93702c107 100644 --- a/include/modules/chanserv/suspend.h +++ b/include/modules/chanserv/suspend.h @@ -1,5 +1,5 @@ /* - * (C) 2014 Anope Team + * (C) 2014-2016 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. @@ -12,6 +12,8 @@ class CSSuspendInfo : public Serialize::Object using Serialize::Object::Object; public: + static constexpr const char *const NAME = "cssuspendinfo"; + virtual ChanServ::Channel *GetChannel() anope_abstract; virtual void SetChannel(ChanServ::Channel *) anope_abstract; @@ -28,12 +30,14 @@ class CSSuspendInfo : public Serialize::Object virtual void SetExpires(const time_t &) anope_abstract; }; -static Serialize::TypeReference<CSSuspendInfo> cssuspendinfo("CSSuspendInfo"); - namespace Event { struct CoreExport ChanSuspend : Events { + static constexpr const char *NAME = "chansuspend"; + + using Events::Events; + /** Called when a channel is suspended * @param ci The channel */ @@ -41,13 +45,14 @@ namespace Event }; struct CoreExport ChanUnsuspend : Events { + static constexpr const char *NAME = "chanunsuspend"; + + using Events::Events; + /** Called when a channel is unsuspended * @param ci The channel */ virtual void OnChanUnsuspend(ChanServ::Channel *ci) anope_abstract; }; - extern CoreExport EventHandlers<ChanUnsuspend> OnChanUnsuspend; } -template<> struct EventName<Event::ChanSuspend> { static constexpr const char *const name = "OnChanSuspend"; }; -template<> struct EventName<Event::ChanUnsuspend> { static constexpr const char *const name = "OnChanUnsuspend"; }; diff --git a/include/modules/dns.h b/include/modules/dns.h index f1ee94f87..e39f1ada8 100644 --- a/include/modules/dns.h +++ b/include/modules/dns.h @@ -118,7 +118,9 @@ namespace DNS class Manager : public Service { public: - Manager(Module *creator) : Service(creator, "DNS::Manager", "dns/manager") { } + static constexpr const char *NAME = "dns/manager"; + + Manager(Module *creator) : Service(creator, NAME) { } virtual ~Manager() { } virtual void Process(Request *req) anope_abstract; @@ -131,8 +133,6 @@ namespace DNS virtual uint32_t GetSerial() const anope_abstract; }; - static ServiceReference<DNS::Manager> manager("DNS::Manager", "dns/manager"); - /** A DNS query. */ class Request : public Timer, public Question @@ -182,17 +182,18 @@ namespace Event { struct CoreExport DnsRequest : Events { + static constexpr const char *NAME = "dnsrequest"; + + using Events::Events; + /** Called when a DNS request (question) is recieved. * @param req The dns request * @param reply The reply that will be sent */ virtual void OnDnsRequest(DNS::Query &req, DNS::Query *reply) anope_abstract; }; - static EventHandlersReference<DnsRequest> OnDnsRequest; } -template<> struct EventName<Event::DnsRequest> { static constexpr const char *const name = "OnDnsRequest"; }; - #endif // DNS_H diff --git a/include/modules/encryption.h b/include/modules/encryption.h index 3fe06cc2b..eb9ab8d62 100644 --- a/include/modules/encryption.h +++ b/include/modules/encryption.h @@ -27,7 +27,9 @@ namespace Encryption class Provider : public Service { public: - Provider(Module *creator, const Anope::string &sname) : Service(creator, "Encryption::Provider", sname) { } + static constexpr const char *NAME = "hash"; + + Provider(Module *creator, const Anope::string &sname) : Service(creator, NAME, sname) { } virtual ~Provider() { } virtual Context *CreateContext(IV * = NULL) anope_abstract; diff --git a/include/modules/fantasy.h b/include/modules/fantasy.h index 1bdd8afdc..7c41a4065 100644 --- a/include/modules/fantasy.h +++ b/include/modules/fantasy.h @@ -11,6 +11,10 @@ namespace Event { struct BotFantasy : Events { + static constexpr const char *NAME = "botfantasy"; + + using Events::Events; + /** Called on fantasy command * @param source The source of the command * @param c The command @@ -23,6 +27,10 @@ namespace Event struct CoreExport BotNoFantasyAccess : Events { + static constexpr const char *NAME = "botnofantasyaccess"; + + using Events::Events; + /** Called on fantasy command without access * @param source The source of the command * @param c The command @@ -34,5 +42,3 @@ namespace Event }; } -template<> struct EventName<Event::BotFantasy> { static constexpr const char *const name = "OnBotFantasy"; }; -template<> struct EventName<Event::BotNoFantasyAccess> { static constexpr const char *const name = "OnBotNoFantasyAccess"; }; diff --git a/include/modules/global.h b/include/modules/global.h index adac905cc..03e3cccc6 100644 --- a/include/modules/global.h +++ b/include/modules/global.h @@ -12,7 +12,9 @@ namespace Global class GlobalService : public Service { public: - GlobalService(Module *m) : Service(m, "GlobalService", "Global") + static constexpr const char *NAME = "global"; + + GlobalService(Module *m) : Service(m, NAME) { } @@ -23,7 +25,6 @@ namespace Global */ virtual void SendGlobal(ServiceBot *sender, const Anope::string &source, const Anope::string &message) anope_abstract; }; - static ServiceReference<GlobalService> service("GlobalService", "Global"); } diff --git a/include/modules/help.h b/include/modules/help.h index df81aecbf..2b9c84983 100644 --- a/include/modules/help.h +++ b/include/modules/help.h @@ -11,6 +11,10 @@ namespace Event { struct CoreExport Help : Events { + static constexpr const char *NAME = "help"; + + using Events::Events; + /** Called when someone uses the generic/help command * @param source Command source * @param params Params @@ -26,4 +30,3 @@ namespace Event }; } -template<> struct EventName<Event::Help> { static constexpr const char *const name = "Help"; }; diff --git a/include/modules/hostserv/del.h b/include/modules/hostserv/del.h index 9b2ea39ef..23b8537e8 100644 --- a/include/modules/hostserv/del.h +++ b/include/modules/hostserv/del.h @@ -10,6 +10,10 @@ namespace Event { struct CoreExport DeleteVhost : Events { + static constexpr const char *NAME = "deletevhost"; + + using Events::Events; + /** Called when a vhost is deleted * @param na The nickalias of the vhost */ @@ -17,4 +21,3 @@ namespace Event }; } -template<> struct EventName<Event::DeleteVhost> { static constexpr const char *const name = "OnDeleteVhost"; }; diff --git a/include/modules/httpd.h b/include/modules/httpd.h index 33e21a0b7..aea00826d 100644 --- a/include/modules/httpd.h +++ b/include/modules/httpd.h @@ -132,11 +132,16 @@ class HTTPProvider : public ListenSocket, public Service Anope::string ip; unsigned short port; bool ssl; + public: + static constexpr const char *NAME = "http"; + Anope::string ext_ip; std::vector<Anope::string> ext_headers; - HTTPProvider(Module *c, const Anope::string &n, const Anope::string &i, const unsigned short p, bool s) : ListenSocket(i, p, i.find(':') != Anope::string::npos), Service(c, "HTTPProvider", n), ip(i), port(p), ssl(s) { } + HTTPProvider(Module *c, const Anope::string &n, const Anope::string &i, const unsigned short p, bool s) + : ListenSocket(i, p, i.find(':') != Anope::string::npos) + , Service(c, NAME, n), ip(i), port(p), ssl(s) { } const Anope::string &GetIP() const { diff --git a/include/modules/memoserv.h b/include/modules/memoserv.h index b7d49ad3a..e84276039 100644 --- a/include/modules/memoserv.h +++ b/include/modules/memoserv.h @@ -17,6 +17,8 @@ namespace MemoServ class MemoServService : public Service { public: + static constexpr const char *NAME = "memoserv"; + enum MemoResult { MEMO_SUCCESS, @@ -25,7 +27,7 @@ namespace MemoServ MEMO_TARGET_FULL }; - MemoServService(Module *m) : Service(m, "MemoServService", "MemoServ") + MemoServService(Module *m) : Service(m, "MemoServService", NAME) { } @@ -42,17 +44,19 @@ namespace MemoServ */ virtual void Check(User *u) anope_abstract; - virtual Memo *CreateMemo() anope_abstract; virtual MemoInfo *GetMemoInfo(const Anope::string &targ, bool &is_registered, bool &is_chan, bool create) anope_abstract; - - virtual Ignore *CreateIgnore() anope_abstract; }; - static ServiceReference<MemoServService> service("MemoServService", "MemoServ"); + + extern MemoServService *service; namespace Event { struct CoreExport MemoSend : Events { + static constexpr const char *NAME = "memosend"; + + using Events::Events; + /** Called when a memo is sent * @param source The source of the memo * @param target The target of the memo @@ -61,10 +65,13 @@ namespace MemoServ */ virtual void OnMemoSend(const Anope::string &source, const Anope::string &target, MemoInfo *mi, Memo *m) anope_abstract; }; - static EventHandlersReference<MemoSend> OnMemoSend; struct CoreExport MemoDel : Events { + static constexpr const char *NAME = "memodel"; + + using Events::Events; + /** Called when a memo is deleted * @param target The target the memo is being deleted from (nick or channel) * @param mi The memo info @@ -72,7 +79,6 @@ namespace MemoServ */ virtual void OnMemoDel(const Anope::string &target, MemoInfo *mi, const Memo *m) anope_abstract; }; - static EventHandlersReference<MemoDel> OnMemoDel; } class Memo : public Serialize::Object @@ -81,6 +87,8 @@ namespace MemoServ using Serialize::Object::Object; public: + static constexpr const char *const NAME = "memo"; + virtual MemoInfo *GetMemoInfo() anope_abstract; virtual void SetMemoInfo(MemoInfo *) anope_abstract; @@ -100,8 +108,6 @@ namespace MemoServ virtual void SetReceipt(const bool &) anope_abstract; }; - static Serialize::TypeReference<Memo> memo("Memo"); - /* Memo info structures. Since both nicknames and channels can have memos, * we encapsulate memo data in a MemoInfo to make it easier to handle. */ @@ -111,6 +117,7 @@ namespace MemoServ using Serialize::Object::Object; public: + static constexpr const char *const NAME = "memoinfo"; virtual Memo *GetMemo(unsigned index) anope_abstract; @@ -130,23 +137,18 @@ namespace MemoServ virtual std::vector<Ignore *> GetIgnores() anope_abstract; }; - static Serialize::TypeReference<MemoInfo> memoinfo("MemoInfo"); - class Ignore : public Serialize::Object { protected: using Serialize::Object::Object; public: + static constexpr const char *const NAME = "memoignore"; + virtual MemoInfo *GetMemoInfo() anope_abstract; virtual void SetMemoInfo(MemoInfo *) anope_abstract; virtual Anope::string GetMask() anope_abstract; virtual void SetMask(const Anope::string &mask) anope_abstract; }; - - static Serialize::TypeReference<Ignore> ignore("MemoIgnore"); } - -template<> struct EventName<MemoServ::Event::MemoSend> { static constexpr const char *const name = "OnMemoSend"; }; -template<> struct EventName<MemoServ::Event::MemoDel> { static constexpr const char *const name = "OnMemoDel"; }; diff --git a/include/modules/nickserv.h b/include/modules/nickserv.h index 5c9cfb341..ef291ec95 100644 --- a/include/modules/nickserv.h +++ b/include/modules/nickserv.h @@ -45,7 +45,8 @@ namespace NickServ virtual Nick *FindNick(const Anope::string &nick) anope_abstract; virtual Account *FindAccount(const Anope::string &acc) anope_abstract; }; - static ServiceReference<NickServService> service("NickServService", "NickServ"); + + extern NickServService *service; inline Nick *FindNick(const Anope::string &nick) { @@ -61,25 +62,35 @@ namespace NickServ { struct CoreExport PreNickExpire : Events { + static constexpr const char *NAME = "prenickexpire"; + + using Events::Events; + /** Called before a nick expires * @param na The nick * @param expire Set to true to allow the nick to expire */ virtual void OnPreNickExpire(Nick *na, bool &expire) anope_abstract; }; - static EventHandlersReference<PreNickExpire> OnPreNickExpire; struct CoreExport NickExpire : Events { + static constexpr const char *NAME = "nickexpire"; + + using Events::Events; + /** Called when a nick drops * @param na The nick */ virtual void OnNickExpire(Nick *na) anope_abstract; }; - static EventHandlersReference<NickExpire> OnNickExpire; struct CoreExport NickRegister : Events { + static constexpr const char *NAME = "nickregister"; + + using Events::Events; + /** Called when a nick is registered * @param user The user registering the nick, of any * @param The nick @@ -87,16 +98,22 @@ namespace NickServ */ virtual void OnNickRegister(User *user, Nick *na, const Anope::string &password) anope_abstract; }; - static EventHandlersReference<NickRegister> OnNickRegister; struct CoreExport NickConfirm : Events { + static constexpr const char *NAME = "nickconfirm"; + + using Events::Events; + virtual void OnNickConfirm(User *, Account *) anope_abstract; }; - static EventHandlersReference<NickConfirm> OnNickConfirm; struct CoreExport NickValidate : Events { + static constexpr const char *NAME = "nickvalidate"; + + using Events::Events; + /** Called when a nick is validated. That is, to determine if a user is permissted * to be on the given nick. * @param u The user @@ -105,7 +122,6 @@ namespace NickServ */ virtual EventReturn OnNickValidate(User *u, Nick *na) anope_abstract; }; - static EventHandlersReference<NickValidate> OnNickValidate; } /* A registered nickname. @@ -117,6 +133,8 @@ namespace NickServ using Serialize::Object::Object; public: + static constexpr const char *const NAME = "nick"; + virtual Anope::string GetNick() anope_abstract; virtual void SetNick(const Anope::string &) anope_abstract; @@ -164,8 +182,6 @@ namespace NickServ virtual void SetVhostCreated(const time_t &) anope_abstract; }; - static Serialize::TypeReference<Nick> nick("NickAlias"); - /* A registered account. Each account must have a Nick with the same nick as the * account's display. * It matters that Base is here before Extensible (it is inherited by Serializable) @@ -173,6 +189,8 @@ namespace NickServ class CoreExport Account : public Serialize::Object { public: + static constexpr const char *const NAME = "account"; + /* Set if this user is a services operattor. o->ot must exist. */ Serialize::Reference<Oper> o; @@ -222,8 +240,6 @@ namespace NickServ virtual unsigned int GetChannelCount() anope_abstract; }; - static Serialize::TypeReference<Account> account("NickCore"); - /* A request to check if an account/password is valid. These can exist for * extended periods due to the time some authentication modules take. */ @@ -287,6 +303,8 @@ namespace NickServ class Mode : public Serialize::Object { public: + static constexpr const char *const NAME = "mode"; + using Serialize::Object::Object; virtual Account *GetAccount() anope_abstract; @@ -296,12 +314,4 @@ namespace NickServ virtual void SetMode(const Anope::string &) anope_abstract; }; - static Serialize::TypeReference<Mode> mode("NSKeepMode"); - } - -template<> struct EventName<NickServ::Event::PreNickExpire> { static constexpr const char *const name = "OnPreNickExpire"; }; -template<> struct EventName<NickServ::Event::NickExpire> { static constexpr const char *const name = "OnNickExpire"; }; -template<> struct EventName<NickServ::Event::NickRegister> { static constexpr const char *const name = "OnNickRegister"; }; -template<> struct EventName<NickServ::Event::NickConfirm> { static constexpr const char *const name = "OnNickConfirm"; }; -template<> struct EventName<NickServ::Event::NickValidate> { static constexpr const char *const name = "OnNickValidate"; }; diff --git a/include/modules/nickserv/access.h b/include/modules/nickserv/access.h index 73a625f3d..716b22927 100644 --- a/include/modules/nickserv/access.h +++ b/include/modules/nickserv/access.h @@ -1,6 +1,6 @@ /* * - * (C) 2003-2014 Anope Team + * (C) 2003-2016 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. @@ -9,6 +9,8 @@ class NickAccess : public Serialize::Object { public: + static constexpr const char *const NAME = "nsaccess"; + using Serialize::Object::Object; virtual NickServ::Account *GetAccount() anope_abstract; @@ -18,5 +20,4 @@ class NickAccess : public Serialize::Object virtual void SetMask(const Anope::string &) anope_abstract; }; -static Serialize::TypeReference<NickAccess> nsaccess("NSAccess"); diff --git a/include/modules/nickserv/ajoin.h b/include/modules/nickserv/ajoin.h index 7b4cc20e5..342be9e4f 100644 --- a/include/modules/nickserv/ajoin.h +++ b/include/modules/nickserv/ajoin.h @@ -1,9 +1,10 @@ /* * - * (C) 2013-2014 Anope Team + * (C) 2013-2016 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. + * */ class AutoJoin : public Serialize::Object @@ -12,6 +13,8 @@ class AutoJoin : public Serialize::Object using Serialize::Object::Object; public: + static constexpr const char *const NAME = "autojoin"; + virtual NickServ::Account *GetOwner() anope_abstract; virtual void SetOwner(NickServ::Account *acc) anope_abstract; @@ -22,4 +25,3 @@ class AutoJoin : public Serialize::Object virtual void SetKey(const Anope::string &k) anope_abstract; }; -static Serialize::TypeReference<AutoJoin> autojoin("AutoJoin"); diff --git a/include/modules/nickserv/cert.h b/include/modules/nickserv/cert.h index be75fb9bf..9bb21a565 100644 --- a/include/modules/nickserv/cert.h +++ b/include/modules/nickserv/cert.h @@ -14,7 +14,9 @@ class NSCertEntry; class CertService : public Service { public: - CertService(Module *c) : Service(c, "CertService", "certs") { } + static constexpr const char *NAME = "certs"; + + CertService(Module *c) : Service(c, NAME) { } virtual NickServ::Account* FindAccountFromCert(const Anope::string &cert) anope_abstract; @@ -23,11 +25,11 @@ class CertService : public Service virtual NSCertEntry *FindCert(const std::vector<NSCertEntry *> &cl, const Anope::string &certfp) anope_abstract; }; -static ServiceReference<CertService> certservice("CertService", "certs"); - class NSCertEntry : public Serialize::Object { public: + static constexpr const char *NAME = "nscert"; + using Serialize::Object::Object; virtual NickServ::Account *GetAccount() anope_abstract; @@ -37,12 +39,14 @@ class NSCertEntry : public Serialize::Object virtual void SetCert(const Anope::string &) anope_abstract; }; -static Serialize::TypeReference<NSCertEntry> certentry("NSCertEntry"); - namespace Event { struct CoreExport NickCertEvents : Events { + static constexpr const char *NAME = "nickcertevents"; + + using Events::Events; + /** Called when a user adds an entry to their cert list * @param nc The nick * @param entry The entry @@ -62,5 +66,3 @@ namespace Event }; } - -template<> struct EventName<Event::NickCertEvents> { static constexpr const char *const name = "OnNickCert"; }; diff --git a/include/modules/nickserv/drop.h b/include/modules/nickserv/drop.h index bae9d77b6..096458510 100644 --- a/include/modules/nickserv/drop.h +++ b/include/modules/nickserv/drop.h @@ -10,13 +10,15 @@ namespace Event { struct CoreExport NickDrop : Events { + static constexpr const char *NAME = "nickdrop"; + + using Events::Events; + /** Called when a nick is dropped * @param source The source of the command * @param na The nick */ virtual void OnNickDrop(CommandSource &source, NickServ::Nick *na) anope_abstract; }; - extern CoreExport EventHandlers<NickDrop> OnNickDrop; } -template<> struct EventName<Event::NickDrop> { static constexpr const char *const name = "OnNickDrop"; }; diff --git a/include/modules/nickserv/group.h b/include/modules/nickserv/group.h index caa568a9e..b4648498f 100644 --- a/include/modules/nickserv/group.h +++ b/include/modules/nickserv/group.h @@ -11,6 +11,10 @@ namespace Event { struct CoreExport NickGroup : Events { + static constexpr const char *NAME = "nickgroup"; + + using Events::Events; + /** Called when a user groups their nick * @param u The user grouping * @param target The target they're grouping to @@ -19,4 +23,3 @@ namespace Event }; } -template<> struct EventName<Event::NickGroup> { static constexpr const char *const name = "OnNickGroup"; }; diff --git a/include/modules/nickserv/info.h b/include/modules/nickserv/info.h index e816cc356..c9177c1c7 100644 --- a/include/modules/nickserv/info.h +++ b/include/modules/nickserv/info.h @@ -11,6 +11,10 @@ namespace Event { struct CoreExport NickInfo : Events { + static constexpr const char *NAME = "nickinfo"; + + using Events::Events; + /** Called when a user requests info for a nick * @param source The user requesting info * @param na The nick the user is requesting info from @@ -21,4 +25,3 @@ namespace Event }; } -template<> struct EventName<Event::NickInfo> { static constexpr const char *const name = "OnNickInfo"; }; diff --git a/include/modules/nickserv/set.h b/include/modules/nickserv/set.h index c6b86032b..c8438be3a 100644 --- a/include/modules/nickserv/set.h +++ b/include/modules/nickserv/set.h @@ -11,6 +11,10 @@ namespace Event { struct CoreExport SetNickOption : Events { + static constexpr const char *NAME = "setnickoption"; + + using Events::Events; + /** Called when a nickserv/set command is used. * @param source The source of the command * @param cmd The command @@ -20,7 +24,5 @@ namespace Event */ virtual EventReturn OnSetNickOption(CommandSource &source, Command *cmd, NickServ::Account *nc, const Anope::string &setting) anope_abstract; }; - static EventHandlersReference<SetNickOption> OnSetNickOption; } -template<> struct EventName<Event::SetNickOption> { static constexpr const char *const name = "OnSetNickOption"; }; diff --git a/include/modules/nickserv/set_misc.h b/include/modules/nickserv/set_misc.h index 18d49dd0f..9bf593c7f 100644 --- a/include/modules/nickserv/set_misc.h +++ b/include/modules/nickserv/set_misc.h @@ -1,5 +1,5 @@ /* - * (C) 2014 Anope Team + * (C) 2014-2016 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. @@ -11,6 +11,8 @@ class NSMiscData : public Serialize::Object using Serialize::Object::Object; public: + static constexpr const char *const NAME = "nsmiscdata"; + virtual NickServ::Account *GetAccount() anope_abstract; virtual void SetAccount(NickServ::Account *) anope_abstract; @@ -21,5 +23,3 @@ class NSMiscData : public Serialize::Object virtual void SetData(const Anope::string &) anope_abstract; }; -static Serialize::TypeReference<NSMiscData> nsmiscdata("NSMiscData"); - diff --git a/include/modules/nickserv/suspend.h b/include/modules/nickserv/suspend.h index fcfc0265d..2cd8faab6 100644 --- a/include/modules/nickserv/suspend.h +++ b/include/modules/nickserv/suspend.h @@ -12,6 +12,8 @@ class NSSuspendInfo : public Serialize::Object using Serialize::Object::Object; public: + static constexpr const char *const NAME = "nssuspendinfo"; + virtual NickServ::Account *GetAccount() anope_abstract; virtual void SetAccount(NickServ::Account *) anope_abstract; @@ -28,12 +30,14 @@ class NSSuspendInfo : public Serialize::Object virtual void SetExpires(const time_t &) anope_abstract; }; -static Serialize::TypeReference<NSSuspendInfo> nssuspendinfo("NSSuspendInfo"); - namespace Event { struct CoreExport NickSuspend : Events { + static constexpr const char *NAME = "nicksuspend"; + + using Events::Events; + /** Called when a nick is suspended * @param na The nick alias */ @@ -42,12 +46,13 @@ namespace Event struct CoreExport NickUnsuspend : Events { + static constexpr const char *NAME = "nickunsuspend"; + + using Events::Events; + /** Called when a nick is unsuspneded * @param na The nick alias */ virtual void OnNickUnsuspend(NickServ::Nick *na) anope_abstract; }; } - -template<> struct EventName<Event::NickSuspend> { static constexpr const char *const name = "OnNickSuspend"; }; -template<> struct EventName<Event::NickUnsuspend> { static constexpr const char *const name = "OnNickUnsuspend"; }; diff --git a/include/modules/nickserv/update.h b/include/modules/nickserv/update.h index ce75c33ac..531c1d237 100644 --- a/include/modules/nickserv/update.h +++ b/include/modules/nickserv/update.h @@ -11,6 +11,10 @@ namespace Event { struct CoreExport NickUpdate : Events { + static constexpr const char *NAME = "nickupdate"; + + using Events::Events; + /** Called when a user does /ns update * @param u The user */ @@ -18,4 +22,3 @@ namespace Event }; } -template<> struct EventName<Event::NickUpdate> { static constexpr const char *const name = "OnNickUpdate"; }; diff --git a/include/modules/operserv/defcon.h b/include/modules/operserv/defcon.h index f980d5008..f46609db3 100644 --- a/include/modules/operserv/defcon.h +++ b/include/modules/operserv/defcon.h @@ -11,6 +11,10 @@ namespace Event { struct CoreExport DefconLevel : Events { + static constexpr const char *NAME = "defconlevel"; + + using Events::Events; + /** Called when defcon level changes * @param level The level */ @@ -18,4 +22,3 @@ namespace Event }; } -template<> struct EventName<Event::DefconLevel> { static constexpr const char *const name = "OnDefconLevel"; }; diff --git a/include/modules/operserv/dns.h b/include/modules/operserv/dns.h index d76cd3d62..a6f4e33b2 100644 --- a/include/modules/operserv/dns.h +++ b/include/modules/operserv/dns.h @@ -13,18 +13,20 @@ class DNSZone : public Serialize::Object using Serialize::Object::Object; public: + static constexpr const char *const NAME = "dnszone"; + virtual Anope::string GetName() anope_abstract; virtual void SetName(const Anope::string &) anope_abstract; }; -static Serialize::TypeReference<DNSZone> dnszone("DNSZone"); - class DNSServer : public Serialize::Object { protected: using Serialize::Object::Object; public: + static constexpr const char *const NAME = "dnsserver"; + virtual DNSZone *GetZone() anope_abstract; virtual void SetZone(DNSZone *) anope_abstract; @@ -38,14 +40,14 @@ class DNSServer : public Serialize::Object virtual void SetPool(const bool &) anope_abstract; }; -static Serialize::TypeReference<DNSServer> dnsserver("DNSServer"); - class DNSZoneMembership : public Serialize::Object { protected: using Serialize::Object::Object; public: + static constexpr const char *const NAME = "dnszonemembership"; + virtual DNSServer *GetServer() anope_abstract; virtual void SetServer(DNSServer *) anope_abstract; @@ -53,14 +55,14 @@ class DNSZoneMembership : public Serialize::Object virtual void SetZone(DNSZone *) anope_abstract; }; -static Serialize::TypeReference<DNSZoneMembership> dnszonemembership("DNSZoneMembership"); - class DNSIP : public Serialize::Object { protected: using Serialize::Object::Object; public: + static constexpr const char *const NAME = "dnsip"; + virtual DNSServer *GetServer() anope_abstract; virtual void SetServer(DNSServer *) anope_abstract; @@ -68,5 +70,4 @@ class DNSIP : public Serialize::Object virtual void SetIP(const Anope::string &) anope_abstract; }; -static Serialize::TypeReference<DNSIP> dnsip("DNSIP"); diff --git a/include/modules/operserv/forbid.h b/include/modules/operserv/forbid.h index 9b21defec..9fb1cd692 100644 --- a/include/modules/operserv/forbid.h +++ b/include/modules/operserv/forbid.h @@ -1,9 +1,10 @@ /* * - * (C) 2013-2014 Anope Team + * (C) 2013-2016 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. + * */ enum ForbidType @@ -21,6 +22,8 @@ class ForbidData : public Serialize::Object using Serialize::Object::Object; public: + static constexpr const char *NAME = "forbid"; + virtual Anope::string GetMask() anope_abstract; virtual void SetMask(const Anope::string &) anope_abstract; @@ -43,14 +46,13 @@ class ForbidData : public Serialize::Object class ForbidService : public Service { public: - ForbidService(Module *m) : Service(m, "ForbidService", "forbid") { } + static constexpr const char *NAME = "forbid"; + + ForbidService(Module *m) : Service(m, NAME) { } virtual ForbidData *FindForbid(const Anope::string &mask, ForbidType type) anope_abstract; virtual std::vector<ForbidData *> GetForbids() anope_abstract; }; -static ServiceReference<ForbidService> forbid_service("ForbidService", "forbid"); - -static Serialize::TypeReference<ForbidData> forbiddata("ForbidData"); diff --git a/include/modules/operserv/ignore.h b/include/modules/operserv/ignore.h index 2326b5575..ab793c533 100644 --- a/include/modules/operserv/ignore.h +++ b/include/modules/operserv/ignore.h @@ -13,6 +13,8 @@ class Ignore : public Serialize::Object { public: + static constexpr const char *NAME = "ignore"; + using Serialize::Object::Object; virtual Anope::string GetMask() anope_abstract; @@ -28,16 +30,13 @@ class Ignore : public Serialize::Object virtual void SetTime(const time_t &) anope_abstract; }; -static Serialize::TypeReference<Ignore> ignoretype("IgnoreData"); - class IgnoreService : public Service { - protected: - IgnoreService(Module *c) : Service(c, "IgnoreService", "ignore") { } - public: + static constexpr const char *NAME = "ignore"; + + IgnoreService(Module *c) : Service(c, NAME) { } + virtual Ignore *Find(const Anope::string &mask) anope_abstract; }; -static ServiceReference<IgnoreService> ignore_service("IgnoreService", "ignore"); - diff --git a/include/modules/operserv/info.h b/include/modules/operserv/info.h index 6e819158d..6b3674bc1 100644 --- a/include/modules/operserv/info.h +++ b/include/modules/operserv/info.h @@ -1,9 +1,10 @@ /* * - * (C) 2014 Anope Team + * (C) 2014-2016 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. + * */ class OperInfo : public Serialize::Object @@ -12,6 +13,8 @@ class OperInfo : public Serialize::Object using Serialize::Object::Object; public: + static constexpr const char *const NAME = "operinfo"; + virtual Serialize::Object *GetTarget() anope_abstract; virtual void SetTarget(Serialize::Object *) anope_abstract; @@ -24,6 +27,3 @@ class OperInfo : public Serialize::Object virtual time_t GetCreated() anope_abstract; virtual void SetCreated(const time_t &) anope_abstract; }; - -static Serialize::TypeReference<OperInfo> operinfo("OperInfo"); - diff --git a/include/modules/operserv/news.h b/include/modules/operserv/news.h index 07627b1bc..43f7a1aaf 100644 --- a/include/modules/operserv/news.h +++ b/include/modules/operserv/news.h @@ -1,5 +1,13 @@ -#ifndef OS_NEWS -#define OS_NEWS +/* + * + * (C) 2016 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +#pragma once enum NewsType { @@ -11,6 +19,8 @@ enum NewsType class NewsItem : public Serialize::Object { public: + static constexpr const char *const NAME = "newsitem"; + using Serialize::Object::Object; virtual NewsType GetNewsType() anope_abstract; @@ -25,8 +35,3 @@ class NewsItem : public Serialize::Object virtual time_t GetTime() anope_abstract; virtual void SetTime(const time_t &) anope_abstract; }; - -static Serialize::TypeReference<NewsItem> newsitem("NewsItem"); - -#endif // OS_NEWS - diff --git a/include/modules/operserv/session.h b/include/modules/operserv/session.h index b9afd196e..1afa9e48a 100644 --- a/include/modules/operserv/session.h +++ b/include/modules/operserv/session.h @@ -16,6 +16,7 @@ class Exception : public Serialize::Object using Serialize::Object::Object; public: + static constexpr const char *NAME = "exception"; virtual Anope::string GetMask() anope_abstract; virtual void SetMask(const Anope::string &) anope_abstract; @@ -36,14 +37,14 @@ class Exception : public Serialize::Object virtual void SetExpires(const time_t &) anope_abstract; }; -static Serialize::TypeReference<Exception> exception("Exception"); - class SessionService : public Service { public: + static constexpr const char *NAME = "session"; + typedef std::unordered_map<cidr, Session *, cidr::hash> SessionMap; - SessionService(Module *m) : Service(m, "SessionService", "session") { } + SessionService(Module *m) : Service(m, NAME) { } virtual Exception *FindException(User *u) anope_abstract; @@ -54,12 +55,14 @@ class SessionService : public Service virtual SessionMap &GetSessions() anope_abstract; }; -static ServiceReference<SessionService> session_service("SessionService", "session"); - namespace Event { struct CoreExport Exception : Events { + static constexpr const char *NAME = "exception"; + + using Events::Events; + /** Called after an exception has been added * @param ex The exception * @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it @@ -74,4 +77,3 @@ namespace Event }; } -template<> struct EventName<Event::Exception> { static constexpr const char *const name = "Exception"; }; diff --git a/include/modules/redis.h b/include/modules/redis.h index 3ee13346c..a1181782a 100644 --- a/include/modules/redis.h +++ b/include/modules/redis.h @@ -68,7 +68,9 @@ namespace Redis class Provider : public Service { public: - Provider(Module *c, const Anope::string &n) : Service(c, "Redis::Provider", n) { } + static constexpr const char *NAME = "redis"; + + Provider(Module *c, const Anope::string &n) : Service(c, NAME, n) { } virtual void SendCommand(Interface *i, const std::vector<Anope::string> &cmds) anope_abstract; virtual void SendCommand(Interface *i, const Anope::string &str) anope_abstract; diff --git a/include/modules/sasl.h b/include/modules/sasl.h index 85e512310..4d0f6be44 100644 --- a/include/modules/sasl.h +++ b/include/modules/sasl.h @@ -1,6 +1,6 @@ /* * - * (C) 2014 Anope Team + * (C) 2014-2016 Anope Team * Contact us at team@anope.org * * Please read COPYING and README for further details. @@ -23,7 +23,9 @@ namespace SASL class Service : public ::Service { public: - Service(Module *o) : ::Service(o, "SASL::Service", "sasl") { } + static constexpr const char *NAME = "sasl"; + + Service(Module *o) : ::Service(o, NAME) { } virtual void ProcessMessage(const Message &) anope_abstract; @@ -40,84 +42,55 @@ namespace SASL virtual void RemoveSession(Session *) anope_abstract; }; - static ServiceReference<SASL::Service> sasl("SASL::Service", "sasl"); - - struct Session + class Session { + SASL::Service *service; + + public: time_t created; Anope::string uid; Reference<Mechanism> mech; - Session(Mechanism *m, const Anope::string &u) : created(Anope::CurTime), uid(u), mech(m) { } + Session(SASL::Service *s, Mechanism *m, const Anope::string &u) : service(s), created(Anope::CurTime), uid(u), mech(m) { } + virtual ~Session() { - if (sasl) - sasl->RemoveSession(this); + service->RemoveSession(this); } }; /* PLAIN, EXTERNAL, etc */ class Mechanism : public ::Service { + SASL::Service *service; + public: - Mechanism(Module *o, const Anope::string &sname) : Service(o, "SASL::Mechanism", sname) { } + static constexpr const char *NAME = "sasl/mechanism"; + + Mechanism(SASL::Service *s, Module *o, const Anope::string &sname) : Service(o, NAME, sname), service(s) { } + + SASL::Service *GetService() const { return service; } - virtual Session* CreateSession(const Anope::string &uid) { return new Session(this, uid); } + virtual Session* CreateSession(const Anope::string &uid) { return new Session(service, this, uid); } virtual void ProcessMessage(Session *session, const Message &) anope_abstract; virtual ~Mechanism() { - if (sasl) - sasl->DeleteSessions(this, true); + service->DeleteSessions(this, true); } }; class IdentifyRequestListener : public NickServ::IdentifyRequestListener { + SASL::Service *service = nullptr; Anope::string uid; public: - IdentifyRequestListener(const Anope::string &id) : uid(id) { } + IdentifyRequestListener(SASL::Service *s, const Anope::string &id) : service(s), uid(id) { } - void OnSuccess(NickServ::IdentifyRequest *req) override - { - if (!sasl) - return; - - NickServ::Nick *na = NickServ::FindNick(req->GetAccount()); - if (!na || na->GetAccount()->HasFieldS("NS_SUSPENDED")) - return OnFail(req); - - Session *s = sasl->GetSession(uid); - if (s) - { - Log(Config->GetClient("NickServ")) << "A user identified to account " << req->GetAccount() << " using SASL"; - sasl->Succeed(s, na->GetAccount()); - delete s; - } - } + void OnSuccess(NickServ::IdentifyRequest *req) override; - void OnFail(NickServ::IdentifyRequest *req) override - { - if (!sasl) - return; - - Session *s = sasl->GetSession(uid); - if (s) - { - sasl->Fail(s); - delete s; - } - - Anope::string accountstatus; - NickServ::Nick *na = NickServ::FindNick(req->GetAccount()); - if (!na) - accountstatus = "nonexistent "; - else if (na->GetAccount()->HasFieldS("NS_SUSPENDED")) - accountstatus = "suspended "; - - Log(Config->GetClient("NickServ")) << "A user failed to identify for " << accountstatus << "account " << req->GetAccount() << " using SASL"; - } + void OnFail(NickServ::IdentifyRequest *req) override; }; } diff --git a/include/modules/sql.h b/include/modules/sql.h index 49c92ccd0..cc747566d 100644 --- a/include/modules/sql.h +++ b/include/modules/sql.h @@ -71,6 +71,14 @@ namespace SQL qd.escape = false; qd.null = true; } + + Anope::string Unsafe() const + { + Anope::string q = query; + for (auto it = parameters.begin(); it != parameters.end(); ++it) + q = q.replace_all_cs("@" + it->first + "@", it->second.data); + return q; + } }; /** A result from a SQL query @@ -172,7 +180,9 @@ namespace SQL class Provider : public Service { public: - Provider(Module *c, const Anope::string &n) : Service(c, "SQL::Provider", n) { } + static constexpr const char *NAME = "sql"; + + Provider(Module *c, const Anope::string &n) : Service(c, NAME, n) { } virtual void Run(Interface *i, const Query &query) anope_abstract; diff --git a/include/modules/ssl.h b/include/modules/ssl.h index c0fcb02a7..ea38d1c3f 100644 --- a/include/modules/ssl.h +++ b/include/modules/ssl.h @@ -2,7 +2,9 @@ class SSLService : public Service { public: - SSLService(Module *o, const Anope::string &n) : Service(o, "SSLService", n) { } + static constexpr const char *NAME = "ssl"; + + SSLService(Module *o, const Anope::string &n) : Service(o, NAME, n) { } virtual void Init(Socket *s) anope_abstract; }; diff --git a/include/modules/xmlrpc.h b/include/modules/xmlrpc.h index 14ec7e997..41c9e832c 100644 --- a/include/modules/xmlrpc.h +++ b/include/modules/xmlrpc.h @@ -27,7 +27,9 @@ class XMLRPCEvent class XMLRPCServiceInterface : public Service { public: - XMLRPCServiceInterface(Module *creator, const Anope::string &sname) : Service(creator, "XMLRPCServiceInterface", sname) { } + static constexpr const char *NAME = "XMLRPCServiceInterface"; + + XMLRPCServiceInterface(Module *creator, const Anope::string &sname) : Service(creator, NAME) { } virtual void Register(XMLRPCEvent *event) anope_abstract; |
