diff options
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 }; } |
