From 42238034490fb5479d787bd1695750387d508200 Mon Sep 17 00:00:00 2001 From: Adam Date: Mon, 24 Nov 2014 14:27:23 -0500 Subject: Rewrite serializable to have field level granularity Represent serializable objects in a digraph, and as a result made most object relationships implicitly defined, and use the graph to trace references between objects to determine relationships. Edges may also be marked as having a dependency of the object they point to, which allows for automatic cleanup and deletion of most objects when no longer needed. Additionally, this allows not having to require in-memory copies of everything when using external databases. db_sql has been rewritten for this and now always requires a database to function. db_sql with MySQL now requires InnoDB to make use of transactions and foreign key constraints. --- include/modules/bs_badwords.h | 44 +++-- include/modules/bs_bot.h | 6 +- include/modules/bs_info.h | 6 +- include/modules/bs_kick.h | 124 ++++++++++--- include/modules/chanserv.h | 403 ++++++++++++++++++++++++------------------ include/modules/cs_access.h | 4 + include/modules/cs_akick.h | 44 ++--- include/modules/cs_entrymsg.h | 34 ++-- include/modules/cs_log.h | 51 +++--- include/modules/cs_mode.h | 62 ++++--- include/modules/cs_set_misc.h | 25 +++ include/modules/cs_suspend.h | 51 ++++++ include/modules/dns.h | 2 + include/modules/global.h | 2 +- include/modules/memoserv.h | 78 ++++++-- include/modules/nickserv.h | 204 ++++++++------------- include/modules/ns_access.h | 22 +++ include/modules/ns_ajoin.h | 25 +++ include/modules/ns_cert.h | 66 ++----- include/modules/ns_set_misc.h | 25 +++ include/modules/ns_suspend.h | 51 ++++++ include/modules/os_dns.h | 72 ++++++++ include/modules/os_forbid.h | 48 +++-- include/modules/os_ignore.h | 36 ++-- include/modules/os_info.h | 29 +++ include/modules/os_news.h | 35 ++-- include/modules/os_session.h | 89 ++++------ include/modules/redis.h | 19 +- include/modules/sasl.h | 6 +- include/modules/set_misc.h | 17 -- include/modules/sql.h | 142 +++++++-------- include/modules/suspend.h | 52 ------ 32 files changed, 1089 insertions(+), 785 deletions(-) create mode 100644 include/modules/cs_set_misc.h create mode 100644 include/modules/cs_suspend.h create mode 100644 include/modules/ns_access.h create mode 100644 include/modules/ns_ajoin.h create mode 100644 include/modules/ns_set_misc.h create mode 100644 include/modules/ns_suspend.h create mode 100644 include/modules/os_dns.h create mode 100644 include/modules/os_info.h delete mode 100644 include/modules/set_misc.h delete mode 100644 include/modules/suspend.h (limited to 'include/modules') diff --git a/include/modules/bs_badwords.h b/include/modules/bs_badwords.h index 6d5f22f2b..df42af6ec 100644 --- a/include/modules/bs_badwords.h +++ b/include/modules/bs_badwords.h @@ -17,7 +17,7 @@ enum BadWordType { /* Always kicks if the word is said */ BW_ANY, - /* User must way the entire word */ + /* User must say the entire word */ BW_SINGLE, /* The word has to start with the badword */ BW_START, @@ -26,51 +26,61 @@ enum BadWordType }; /* Structure used to contain bad words. */ -struct BadWord +class BadWord : public Serialize::Object { - Anope::string chan; - Anope::string word; - BadWordType type; - - virtual ~BadWord() { } protected: - BadWord() { } + using Serialize::Object::Object; + public: + virtual ~BadWord() = default; + + virtual ChanServ::Channel *GetChannel() anope_abstract; + virtual void SetChannel(ChanServ::Channel *) anope_abstract; + + virtual Anope::string GetWord() anope_abstract; + virtual void SetWord(const Anope::string &) anope_abstract; + + virtual BadWordType GetType() anope_abstract; + virtual void SetType(const BadWordType &) anope_abstract; }; -struct BadWords +static Serialize::TypeReference badword("BadWord"); + +struct BadWords : public Service { - virtual ~BadWords() { } + BadWords(Module *me) : Service(me, "BadWords", "badwords") { } /** Add a badword to the badword list * @param word The badword * @param type The type (SINGLE START END) * @return The badword */ - virtual BadWord* AddBadWord(const Anope::string &word, BadWordType type) anope_abstract; + virtual BadWord* AddBadWord(ChanServ::Channel *, const Anope::string &word, BadWordType type) anope_abstract; + + virtual std::vector GetBadWords(ChanServ::Channel *ci) anope_abstract; /** Get a badword structure by index * @param index The index * @return The badword */ - virtual BadWord* GetBadWord(unsigned index) const anope_abstract; + virtual BadWord* GetBadWord(ChanServ::Channel *, unsigned index) anope_abstract; /** Get how many badwords are on this channel * @return The number of badwords in the vector */ - virtual unsigned GetBadWordCount() const anope_abstract; + virtual unsigned GetBadWordCount(ChanServ::Channel *) anope_abstract; /** Remove a badword * @param index The index of the badword */ - virtual void EraseBadWord(unsigned index) anope_abstract; + virtual void EraseBadWord(ChanServ::Channel *, unsigned index) anope_abstract; /** Clear all badwords from the channel */ - virtual void ClearBadWords() anope_abstract; - - virtual void Check() anope_abstract; + virtual void ClearBadWords(ChanServ::Channel *) anope_abstract; }; +static ServiceReference badwords("BadWords", "badwords"); + namespace Event { struct CoreExport BadWordEvents : Events diff --git a/include/modules/bs_bot.h b/include/modules/bs_bot.h index c6d670f35..f66d57031 100644 --- a/include/modules/bs_bot.h +++ b/include/modules/bs_bot.h @@ -13,7 +13,7 @@ namespace Event /** Called when a new bot is made * @param bi The bot */ - virtual void OnBotCreate(BotInfo *bi) anope_abstract; + virtual void OnBotCreate(ServiceBot *bi) anope_abstract; }; struct CoreExport BotChange : Events @@ -21,7 +21,7 @@ namespace Event /** Called when a bot is changed * @param bi The bot */ - virtual void OnBotChange(BotInfo *bi) anope_abstract; + virtual void OnBotChange(ServiceBot *bi) anope_abstract; }; struct CoreExport BotDelete : Events @@ -29,6 +29,6 @@ namespace Event /** Called when a bot is deleted * @param bi The bot */ - virtual void OnBotDelete(BotInfo *bi) anope_abstract; + virtual void OnBotDelete(ServiceBot *bi) anope_abstract; }; } diff --git a/include/modules/bs_info.h b/include/modules/bs_info.h index 72180e312..606888f4c 100644 --- a/include/modules/bs_info.h +++ b/include/modules/bs_info.h @@ -9,12 +9,12 @@ namespace Event { - struct CoreExport BotInfoEvent : Events + struct CoreExport ServiceBotEvent : Events { /** Called when a user uses botserv/info on a bot or channel. */ - virtual void OnBotInfo(CommandSource &source, BotInfo *bi, ChanServ::Channel *ci, InfoFormatter &info) anope_abstract; + virtual void OnServiceBot(CommandSource &source, ServiceBot *bi, ChanServ::Channel *ci, InfoFormatter &info) anope_abstract; }; - extern CoreExport EventHandlers OnBotInfo; + extern CoreExport EventHandlers OnServiceBot; } diff --git a/include/modules/bs_kick.h b/include/modules/bs_kick.h index e327886d6..4fe234dd0 100644 --- a/include/modules/bs_kick.h +++ b/include/modules/bs_kick.h @@ -11,40 +11,110 @@ * */ -/* Indices for TTB (Times To Ban) */ -enum +class KickerData : public Serialize::Object { - TTB_BOLDS, - TTB_COLORS, - TTB_REVERSES, - TTB_UNDERLINES, - TTB_BADWORDS, - TTB_CAPS, - TTB_FLOOD, - TTB_REPEAT, - TTB_ITALICS, - TTB_AMSGS, - TTB_SIZE -}; + protected: + using Serialize::Object::Object; -struct KickerData -{ - bool amsgs, badwords, bolds, caps, colors, flood, italics, repeat, reverses, underlines; - int16_t ttb[TTB_SIZE]; /* Times to ban for each kicker */ - int16_t capsmin, capspercent; /* For CAPS kicker */ - int16_t floodlines, floodsecs; /* For FLOOD kicker */ - int16_t repeattimes; /* For REPEAT kicker */ + public: + virtual ChanServ::Channel *GetChannel() anope_abstract; + virtual void SetChannel(ChanServ::Channel *) anope_abstract; - bool dontkickops, dontkickvoices; + virtual bool GetAmsgs() anope_abstract; + virtual void SetAmsgs(const bool &) anope_abstract; - protected: - KickerData() { } + virtual bool GetBadwords() anope_abstract; + virtual void SetBadwords(const bool &) anope_abstract; - public: - virtual ~KickerData() { } - virtual void Check(ChanServ::Channel *ci) anope_abstract; + virtual bool GetBolds() anope_abstract; + virtual void SetBolds(const bool &) anope_abstract; + + virtual bool GetCaps() anope_abstract; + virtual void SetCaps(const bool &) anope_abstract; + + virtual bool GetColors() anope_abstract; + virtual void SetColors(const bool &) anope_abstract; + + virtual bool GetFlood() anope_abstract; + virtual void SetFlood(const bool &) anope_abstract; + + virtual bool GetItalics() anope_abstract; + virtual void SetItalics(const bool &) anope_abstract; + + virtual bool GetRepeat() anope_abstract; + virtual void SetRepeat(const bool &) anope_abstract; + + virtual bool GetReverses() anope_abstract; + virtual void SetReverses(const bool &) anope_abstract; + + virtual bool GetUnderlines() anope_abstract; + virtual void SetUnderlines(const bool &) anope_abstract; + + virtual int16_t GetTTBBolds() anope_abstract; + virtual void SetTTBBolds(const int16_t &) anope_abstract; + + virtual int16_t GetTTBColors() anope_abstract; + virtual void SetTTBColors(const int16_t &) anope_abstract; + + virtual int16_t GetTTBReverses() anope_abstract; + virtual void SetTTBReverses(const int16_t &) anope_abstract; + + virtual int16_t GetTTBUnderlines() anope_abstract; + virtual void SetTTBUnderlines(const int16_t &) anope_abstract; + + virtual int16_t GetTTBBadwords() anope_abstract; + virtual void SetTTBBadwords(const int16_t &) anope_abstract; + + virtual int16_t GetTTBCaps() anope_abstract; + virtual void SetTTBCaps(const int16_t &) anope_abstract; + + virtual int16_t GetTTBFlood() anope_abstract; + virtual void SetTTBFlood(const int16_t &) anope_abstract; + + virtual int16_t GetTTBRepeat() anope_abstract; + virtual void SetTTBRepeat(const int16_t &) anope_abstract; + + virtual int16_t GetTTBItalics() anope_abstract; + virtual void SetTTBItalics(const int16_t &) anope_abstract; + + virtual int16_t GetTTBAmsgs() anope_abstract; + virtual void SetTTBAmsgs(const int16_t &) anope_abstract; + + virtual int16_t GetCapsMin() anope_abstract; + virtual void SetCapsMin(const int16_t &) anope_abstract; + + virtual int16_t GetCapsPercent() anope_abstract; + virtual void SetCapsPercent(const int16_t &) anope_abstract; + + virtual int16_t GetFloodLines() anope_abstract; + virtual void SetFloodLines(const int16_t &) anope_abstract; + + virtual int16_t GetFloodSecs() anope_abstract; + virtual void SetFloodSecs(const int16_t &) anope_abstract; + + virtual int16_t GetRepeatTimes() anope_abstract; + virtual void SetRepeatTimes(const int16_t &) anope_abstract; + + virtual bool GetDontKickOps() anope_abstract; + virtual void SetDontKickOps(const bool &) anope_abstract; + + virtual bool GetDontKickVoices() anope_abstract; + virtual void SetDontKickVoices(const bool &) anope_abstract; }; +static Serialize::TypeReference kickerdata("KickerData"); + +inline KickerData *GetKickerData(ChanServ::Channel *ci) +{ + KickerData *kd = ci->GetRef(kickerdata); + if (!kd && kickerdata) + { + kd = kickerdata.Create(); + kd->SetChannel(ci); + } + return kd; +} + namespace Event { struct CoreExport BotBan : Events diff --git a/include/modules/chanserv.h b/include/modules/chanserv.h index c5e677407..9985f25dc 100644 --- a/include/modules/chanserv.h +++ b/include/modules/chanserv.h @@ -60,9 +60,7 @@ namespace ChanServ }; /* A privilege, probably configured using a privilege{} block. Most - * commands require specific privileges to be executed. The AccessProvider - * backing each ChanAccess determines whether that ChanAccess has a given - * privilege. + * commands require specific privileges to be executed. */ struct CoreExport Privilege { @@ -70,8 +68,9 @@ namespace ChanServ Anope::string desc; /* Rank relative to other privileges */ int rank; + int level; - Privilege(const Anope::string &n, const Anope::string &d, int r) : name(n), desc(d), rank(r) + Privilege(const Anope::string &n, const Anope::string &d, int r, int l) : name(n), desc(d), rank(r), level(l) { if (this->desc.empty()) for (unsigned j = 0; j < sizeof(descriptions) / sizeof(*descriptions); ++j) @@ -88,7 +87,40 @@ namespace ChanServ class Channel; using registered_channel_map = Anope::hash_map; - class AccessProvider; + class Level : public Serialize::Object + { + public: + using Serialize::Object::Object; + + virtual Channel *GetChannel() anope_abstract; + virtual void SetChannel(Channel *) anope_abstract; + + virtual Anope::string GetName() anope_abstract; + virtual void SetName(const Anope::string &) anope_abstract; + + virtual int GetLevel() anope_abstract; + virtual void SetLevel(const int &) anope_abstract; + }; + + static Serialize::TypeReference level("Level"); + + class Mode : public Serialize::Object + { + public: + using Serialize::Object::Object; + + virtual Channel *GetChannel() anope_abstract; + virtual void SetChannel(Channel *) anope_abstract; + + virtual Anope::string GetMode() anope_abstract; + virtual void SetMode(const Anope::string &) anope_abstract; + + virtual Anope::string GetParam() anope_abstract; + virtual void SetParam(const Anope::string &) anope_abstract; + }; + + static Serialize::TypeReference mode("CSKeepMode"); + class ChanServService : public Service { public: @@ -96,8 +128,6 @@ namespace ChanServ { } - virtual Channel *Create(const Anope::string &name) anope_abstract; - virtual Channel *Create(const Channel &) anope_abstract; virtual Channel *Find(const Anope::string &name) anope_abstract; virtual registered_channel_map& GetChannels() anope_abstract; @@ -112,14 +142,10 @@ namespace ChanServ virtual std::vector &GetPrivileges() anope_abstract; virtual void ClearPrivileges() anope_abstract; - virtual std::vector& GetProviders() anope_abstract; - - virtual void Destruct(ChanAccess *) anope_abstract; - virtual void Serialize(const ChanAccess *, Serialize::Data &data) anope_abstract; //XXX - typedef std::multimap Set; + typedef std::multimap Set; typedef std::pair Path; - virtual bool Matches(const ChanAccess *, const User *u, const NickServ::Account *acc, Path &p) anope_abstract; + virtual bool Matches(ChanAccess *, const User *u, NickServ::Account *acc, Path &p) anope_abstract; }; static ServiceReference service("ChanServService", "ChanServ"); @@ -152,51 +178,55 @@ namespace ChanServ /* It matters that Base is here before Extensible (it is inherited by Serializable) */ - class CoreExport Channel : public Serializable, public Extensible + class CoreExport Channel : public Serialize::Object { public: - /* channels who reference this one */ - Anope::map references; - Serialize::Reference founder; /* Channel founder */ - Serialize::Reference successor; /* Who gets the channel if the founder nick is dropped or expires */ - Serialize::Checker > access; /* List of authorized users */ - Serialize::Checker > akick; /* List of users to kickban */ - Anope::map levels; - - Anope::string name; /* Channel name */ - Anope::string desc; + ::Channel *c = nullptr; /* Pointer to channel, if the channel exists */ + + protected: + using Serialize::Object::Object; - time_t time_registered; - time_t last_used; + public: + virtual Anope::string GetName() anope_abstract; + virtual void SetName(const Anope::string &) anope_abstract; - Anope::string last_topic; /* The last topic that was set on this channel */ - Anope::string last_topic_setter; /* Setter */ - time_t last_topic_time; /* Time */ + virtual Anope::string GetDesc() anope_abstract; + virtual void SetDesc(const Anope::string &) anope_abstract; - ::Channel::ModeList last_modes; /* The last modes set on this channel */ + virtual time_t GetTimeRegistered() anope_abstract; + virtual void SetTimeRegistered(const time_t &) anope_abstract; - int16_t bantype; + virtual time_t GetLastUsed() anope_abstract; + virtual void SetLastUsed(const time_t &) anope_abstract; - MemoServ::MemoInfo *memos = nullptr; + virtual Anope::string GetLastTopic() anope_abstract; + virtual void SetLastTopic(const Anope::string &) anope_abstract; - ::Channel *c; /* Pointer to channel, if the channel exists */ + virtual Anope::string GetLastTopicSetter() anope_abstract; + virtual void SetLastTopicSetter(const Anope::string &) anope_abstract; - /* For BotServ */ - Serialize::Reference bi; /* Bot used on this channel */ + virtual time_t GetLastTopicTime() anope_abstract; + virtual void SetLastTopicTime(const time_t &) anope_abstract; - time_t banexpire; /* Time bans expire in */ + virtual int16_t GetBanType() anope_abstract; + virtual void SetBanType(const int16_t &) anope_abstract; - protected: - Channel() : Serializable("ChannelInfo"), access("ChanAccess"), akick("AutoKick") { } + virtual time_t GetBanExpire() anope_abstract; + virtual void SetBanExpire(const time_t &) anope_abstract; + + virtual BotInfo *GetBI() anope_abstract; + virtual void SetBI(BotInfo *) anope_abstract; + + virtual ServiceBot *GetBot() anope_abstract; + virtual void SetBot(ServiceBot *) anope_abstract; - public: /** Is the user the real founder? * @param user The user * @return true or false */ virtual bool IsFounder(const User *user) anope_abstract; - /** Change the founder of the channek + /** Change the founder of the channel * @params nc The new founder */ virtual void SetFounder(NickServ::Account *nc) anope_abstract; @@ -204,20 +234,30 @@ namespace ChanServ /** Get the founder of the channel * @return The founder */ - virtual NickServ::Account *GetFounder() const anope_abstract; + virtual NickServ::Account *GetFounder() anope_abstract; virtual void SetSuccessor(NickServ::Account *nc) anope_abstract; - virtual NickServ::Account *GetSuccessor() const anope_abstract; + virtual NickServ::Account *GetSuccessor() anope_abstract; /** Find which bot should send mode/topic/etc changes for this channel * @return The bot */ - virtual BotInfo *WhoSends() const anope_abstract; + ServiceBot *WhoSends() + { + if (this) + if (ServiceBot *bi = GetBot()) + return bi; - /** Add an entry to the channel access list - * @param access The entry - */ - virtual void AddAccess(ChanAccess *access) anope_abstract; + ServiceBot *ChanServ = Config->GetClient("ChanServ"); + if (ChanServ) + return ChanServ; + + //XXX +// if (!BotListByNick->empty()) +// return BotListByNick->begin()->second; + + return NULL; + } /** Get an entry from the channel access list by index * @@ -226,32 +266,24 @@ namespace ChanServ * * Retrieves an entry from the access list that matches the given index. */ - virtual ChanAccess *GetAccess(unsigned index) const anope_abstract; + virtual ChanAccess *GetAccess(unsigned index) /*const*/ anope_abstract; /** Retrieve the access for a user or group in the form of a vector of access entries * (as multiple entries can affect a single user). */ virtual AccessGroup AccessFor(const User *u) anope_abstract; - virtual AccessGroup AccessFor(const NickServ::Account *nc) anope_abstract; + virtual AccessGroup AccessFor(NickServ::Account *nc) anope_abstract; /** Get the size of the accss vector for this channel * @return The access vector size */ - virtual unsigned GetAccessCount() const anope_abstract; + 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; - /** Erase an entry from the channel access list - * - * @param index The index in the access list vector - * - * @return The erased entry - */ - virtual ChanAccess *EraseAccess(unsigned index) anope_abstract; - /** Clear the entire channel access list * * Clears the entire access list by deleting every item and then clearing the vector. @@ -280,17 +312,12 @@ namespace ChanServ * @param index The index in the akick vector * @return The akick structure, or NULL if not found */ - virtual AutoKick* GetAkick(unsigned index) const anope_abstract; + virtual AutoKick* GetAkick(unsigned index) anope_abstract; /** Get the size of the akick vector for this channel * @return The akick vector size */ - virtual unsigned GetAkickCount() const anope_abstract; - - /** Erase an entry from the channel akick list - * @param index The index of the akick - */ - virtual void EraseAkick(unsigned index) anope_abstract; + virtual unsigned GetAkickCount() anope_abstract; /** Clear the whole akick list */ @@ -301,7 +328,7 @@ namespace ChanServ * @return the level * @throws CoreException if priv is not a valid privilege */ - virtual int16_t GetLevel(const Anope::string &priv) const anope_abstract; + virtual int16_t GetLevel(const Anope::string &priv) anope_abstract; /** Set the level for a privilege * @param priv The privilege priv @@ -323,127 +350,60 @@ namespace ChanServ * @param u The user * @return A ban mask that affects the user */ - virtual Anope::string GetIdealBan(User *u) const anope_abstract; + virtual Anope::string GetIdealBan(User *u) anope_abstract; - virtual void AddChannelReference(const Anope::string &what) anope_abstract; - virtual void RemoveChannelReference(const Anope::string &what) anope_abstract; - virtual void GetChannelReferences(std::deque &chans) anope_abstract; + virtual MemoServ::MemoInfo *GetMemos() anope_abstract; }; + static Serialize::TypeReference channel("ChannelInfo"); + enum { ACCESS_INVALID = -10000, ACCESS_FOUNDER = 10001 }; - /* A provider of access. Only used for creating ChanAccesses, as - * they contain pure virtual functions. - */ - class CoreExport AccessProvider : public Service - { - public: - AccessProvider(Module *o, const Anope::string &n) : Service(o, "AccessProvider", n) - { - std::vector& providers = service->GetProviders(); - providers.push_back(this); - } - - virtual ~AccessProvider() - { - std::vector& providers = service->GetProviders(); - std::vector::iterator it = std::find(providers.begin(), providers.end(), this); - if (it != providers.end()) - providers.erase(it); - } - - /** Creates a new ChanAccess entry using this provider. - * @return The new entry - */ - virtual ChanAccess *Create() anope_abstract; - }; - /* Represents one entry of an access list on a channel. */ - class CoreExport ChanAccess : public Serializable + class CoreExport ChanAccess : public Serialize::Object { - Anope::string mask; - /* account this access entry is for, if any */ - Serialize::Reference nc; - public: - typedef std::multimap Set; + typedef std::multimap 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 Path; - /* The provider that created this access entry */ - AccessProvider *provider; - /* Channel this access entry is on */ - Serialize::Reference ci; - Anope::string creator; - time_t last_seen; - time_t created; + ChanAccess(Serialize::TypeBase *type) : Serialize::Object(type) { } + ChanAccess(Serialize::TypeBase *type, Serialize::ID id) : Serialize::Object(type, id) { } - ChanAccess(AccessProvider *p) : Serializable("ChanAccess"), provider(p) { } + inline Channel *GetChannel(); + inline void SetChannel(Channel *ci); - virtual ~ChanAccess() - { - service->Destruct(this); - } + inline Anope::string GetCreator(); + inline void SetCreator(const Anope::string &c); - void SetMask(const Anope::string &mask, Channel *c) - { - if (nc != NULL) - nc->RemoveChannelReference(this->ci); - else if (!this->mask.empty()) - { - Channel *targc = ChanServ::Find(this->mask); - if (targc) - targc->RemoveChannelReference(this->ci->name); - } + inline time_t GetLastSeen(); + inline void SetLastSeen(const time_t &t); - ci = c; - this->mask.clear(); - nc = NULL; + inline time_t GetCreated(); + inline void SetCreated(const time_t &t); - const NickServ::Nick *na = NickServ::FindNick(mask); - if (na != NULL) - { - nc = na->nc; - nc->AddChannelReference(ci); - } - else - { - this->mask = mask; + inline Anope::string GetMask(); + inline void SetMask(const Anope::string &); - Channel *targci = ChanServ::Find(mask); - if (targci != NULL) - targci->AddChannelReference(ci->name); - } - } - - const Anope::string &Mask() const - { - if (nc) - return nc->display; - else - return mask; - } + inline Serialize::Object *GetObj(); + inline void SetObj(Serialize::Object *); - NickServ::Account *GetAccount() const { return nc; } - - void Serialize(Serialize::Data &data) const override - { - service->Serialize(this, data); - } + inline Anope::string Mask(); + inline NickServ::Account *GetAccount(); /** Check if this access entry matches the given user or account * @param u The user * @param nc The account * @param p The path to the access object which matches will be put here */ - virtual bool Matches(const User *u, const NickServ::Account *acc, Path &p) const + virtual bool Matches(const User *u, NickServ::Account *acc, Path &p) { return service->Matches(this, u, acc, p); } @@ -451,13 +411,13 @@ namespace ChanServ /** Check if this access entry has the given privilege. * @param name The privilege name */ - virtual bool HasPriv(const Anope::string &name) const anope_abstract; + virtual bool HasPriv(const Anope::string &name) anope_abstract; /** Serialize the access given by this access entry into a human * readable form. chanserv/access will return a number, chanserv/xop * will be AOP, SOP, etc. */ - virtual Anope::string AccessSerialize() const anope_abstract; + virtual Anope::string AccessSerialize() anope_abstract; /** Unserialize this access entry from the given data. This data * will be fetched from AccessSerialize. @@ -465,7 +425,7 @@ namespace ChanServ virtual void AccessUnserialize(const Anope::string &data) anope_abstract; /* Comparison operators to other Access entries */ - virtual bool operator>(const ChanAccess &other) const + virtual bool operator>(ChanAccess &other) { const std::vector &privs = service->GetPrivileges(); for (unsigned i = privs.size(); i > 0; --i) @@ -482,7 +442,7 @@ namespace ChanServ return false; } - virtual bool operator<(const ChanAccess &other) const + virtual bool operator<(ChanAccess &other) { const std::vector &privs = service->GetPrivileges(); for (unsigned i = privs.size(); i > 0; --i) @@ -499,17 +459,116 @@ namespace ChanServ return false; } - bool operator>=(const ChanAccess &other) const + bool operator>=(ChanAccess &other) { return !(*this < other); } - bool operator<=(const ChanAccess &other) const + bool operator<=(ChanAccess &other) { return !(*this > other); } }; + class ChanAccessType : public Serialize::AbstractType + { + public: + Serialize::ObjectField ci; + Serialize::Field mask; + Serialize::ObjectField obj; + Serialize::Field creator; + Serialize::Field last_seen; + Serialize::Field 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") + { + } + }; + + ChanServ::Channel *ChanAccess::GetChannel() + { + return Get(&ChanAccessType::ci); + } + + void ChanAccess::SetChannel(ChanServ::Channel *ci) + { + Object::Set(&ChanAccessType::ci, ci); + } + + Anope::string ChanAccess::GetCreator() + { + return Get(&ChanAccessType::creator); + } + + void ChanAccess::SetCreator(const Anope::string &c) + { + Object::Set(&ChanAccessType::creator, c); + } + + time_t ChanAccess::GetLastSeen() + { + return Get(&ChanAccessType::last_seen); + } + + void ChanAccess::SetLastSeen(const time_t &t) + { + Object::Set(&ChanAccessType::last_seen, t); + } + + time_t ChanAccess::GetCreated() + { + return Get(&ChanAccessType::created); + } + + void ChanAccess::SetCreated(const time_t &t) + { + Object::Set(&ChanAccessType::created, t); + } + + Anope::string ChanAccess::GetMask() + { + return Get(&ChanAccessType::mask); + } + + void ChanAccess::SetMask(const Anope::string &n) + { + Object::Set(&ChanAccessType::mask, n); + } + + Serialize::Object *ChanAccess::GetObj() + { + return Get(&ChanAccessType::obj); + } + + void ChanAccess::SetObj(Serialize::Object *o) + { + Object::Set(&ChanAccessType::obj, o); + } + + Anope::string ChanAccess::Mask() + { + if (NickServ::Account *acc = GetAccount()) + return acc->GetDisplay(); + + return GetMask(); + } + + NickServ::Account *ChanAccess::GetAccount() + { + if (!GetObj() || GetObj()->GetSerializableType() != NickServ::account) + return nullptr; + + return anope_dynamic_static_cast(GetObj()); + } + + static Serialize::TypeReference 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. */ @@ -517,7 +576,7 @@ namespace ChanServ { public: /* Channel these access entries are on */ - const ChanServ::Channel *ci; + ChanServ::Channel *ci; /* Path from these entries to other entries that they depend on */ ChanAccess::Path path; /* Account these entries affect, if any */ @@ -533,18 +592,18 @@ namespace ChanServ } private: - bool HasPriv(const ChanAccess *access, const Anope::string &name) const + 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 P; + typedef std::multimap P; std::pair 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) { - const ChanAccess *a = it.first->second; + ChanAccess *a = it.first->second; /* if only one path fully matches then we are ok */ if (HasPriv(a, name)) return true; @@ -565,7 +624,7 @@ namespace ChanServ * @param priv The privilege * @return true if any entry has the given privilege */ - bool HasPriv(const Anope::string &priv) const + bool HasPriv(const Anope::string &priv) { if (this->super_admin) return true; @@ -602,7 +661,7 @@ namespace ChanServ * with the highest rank (see Privilege::rank). * @return The "highest" entry */ - const ChanAccess *Highest() const + ChanAccess *Highest() { ChanAccess *highest = NULL; for (unsigned i = 0; i < this->size(); ++i) @@ -612,7 +671,7 @@ namespace ChanServ } /* Comparison operators to other AccessGroups */ - bool operator>(const AccessGroup &other) const + bool operator>(AccessGroup &other) { if (other.super_admin) return false; @@ -638,7 +697,7 @@ namespace ChanServ return false; } - bool operator<(const AccessGroup &other) const + bool operator<(AccessGroup &other) { if (this->super_admin) return false; @@ -664,12 +723,12 @@ namespace ChanServ return false; } - bool operator>=(const AccessGroup &other) const + bool operator>=(AccessGroup &other) { return !(*this < other); } - bool operator<=(const AccessGroup &other) const + bool operator<=(AccessGroup &other) { return !(*this > other); } diff --git a/include/modules/cs_access.h b/include/modules/cs_access.h index 877a98f02..b56996ede 100644 --- a/include/modules/cs_access.h +++ b/include/modules/cs_access.h @@ -7,6 +7,10 @@ * */ +static Serialize::TypeReference accesschanaccess("AccessChanAccess"); +static Serialize::TypeReference flagschanaccess("FlagsChanAccess"); +static Serialize::TypeReference xopchanaccess("XOPChanAccess"); + namespace Event { struct CoreExport LevelChange : Events diff --git a/include/modules/cs_akick.h b/include/modules/cs_akick.h index 08a72260f..a5c050e51 100644 --- a/include/modules/cs_akick.h +++ b/include/modules/cs_akick.h @@ -7,35 +7,39 @@ * */ +#include "modules/nickserv.h" + /* AutoKick data. */ -class CoreExport AutoKick : public Serializable +class CoreExport AutoKick : public Serialize::Object { + protected: + using Serialize::Object::Object; public: - /* Channel this autokick is on */ - Serialize::Reference ci; + virtual ~AutoKick() = default; - Anope::string mask; - Serialize::Reference nc; + virtual ChanServ::Channel *GetChannel() anope_abstract; + virtual void SetChannel(ChanServ::Channel *) anope_abstract; - Anope::string reason; - Anope::string creator; - time_t addtime; - time_t last_used; + virtual Anope::string GetMask() anope_abstract; + virtual void SetMask(const Anope::string &) anope_abstract; - protected: - AutoKick() : Serializable("AutoKick") { } - public: - virtual ~AutoKick() { } -}; + virtual NickServ::Account *GetAccount() anope_abstract; + virtual void SetAccount(NickServ::Account *) anope_abstract; -class AutoKickService : public Service -{ - public: - AutoKickService(Module *o) : Service(o, "AutoKickService", "AutoKickService") { } + virtual Anope::string GetReason() anope_abstract; + virtual void SetReason(const Anope::string &) anope_abstract; + + virtual Anope::string GetCreator() anope_abstract; + virtual void SetCreator(const Anope::string &) anope_abstract; - virtual AutoKick* Create() anope_abstract; + virtual time_t GetAddTime() anope_abstract; + virtual void SetAddTime(const time_t &) anope_abstract; + + virtual time_t GetLastUsed() anope_abstract; + virtual void SetLastUsed(const time_t &) anope_abstract; }; -static ServiceReference akick("AutoKickService", "AutoKickService"); + +static Serialize::TypeReference autokick("AutoKick"); namespace Event { diff --git a/include/modules/cs_entrymsg.h b/include/modules/cs_entrymsg.h index 1fd072db5..b5804068f 100644 --- a/include/modules/cs_entrymsg.h +++ b/include/modules/cs_entrymsg.h @@ -6,30 +6,24 @@ * */ -struct EntryMsg -{ - Anope::string chan; - Anope::string creator; - Anope::string message; - time_t when; - - virtual ~EntryMsg() { } - protected: - EntryMsg() { } -}; - -struct EntryMessageList : Serialize::Checker > +class EntryMsg : public Serialize::Object { protected: - EntryMessageList() : Serialize::Checker >("EntryMsg") { } + using Serialize::Object::Object; public: - virtual ~EntryMessageList() - { - for (unsigned i = (*this)->size(); i > 0; --i) - delete (*this)->at(i - 1); - } + virtual ChanServ::Channel *GetChannel() anope_abstract; + virtual void SetChannel(ChanServ::Channel *) anope_abstract; + + virtual Anope::string GetCreator() anope_abstract; + virtual void SetCreator(const Anope::string &) anope_abstract; - virtual EntryMsg* Create() anope_abstract; + virtual Anope::string GetMessage() anope_abstract; + virtual void SetMessage(const Anope::string &) anope_abstract; + + virtual time_t GetWhen() anope_abstract; + virtual void SetWhen(const time_t &) anope_abstract; }; +static Serialize::TypeReference entrymsg("EntryMsg"); + diff --git a/include/modules/cs_log.h b/include/modules/cs_log.h index 8b945deee..d940f5e87 100644 --- a/include/modules/cs_log.h +++ b/include/modules/cs_log.h @@ -9,35 +9,36 @@ * Based on the original code of Services by Andy Church. */ -struct LogSetting +class LogSetting : public Serialize::Object { - Anope::string chan; - /* Our service name of the command */ - Anope::string service_name; - /* The name of the client the command is on */ - Anope::string command_service; - /* Name of the command to the user, can have spaces */ - Anope::string command_name; - Anope::string method, extra; - Anope::string creator; - time_t created; - - virtual ~LogSetting() { } protected: - LogSetting() { } -}; + using Serialize::Object::Object; -struct LogSettings : Serialize::Checker > -{ - typedef std::vector::iterator iterator; + public: + virtual ChanServ::Channel *GetChannel() anope_abstract; + virtual void SetChannel(ChanServ::Channel *) anope_abstract; - protected: - LogSettings() : Serialize::Checker >("LogSetting") - { - } + virtual Anope::string GetServiceName() anope_abstract; + virtual void SetServiceName(const Anope::string &) anope_abstract; - public: - virtual ~LogSettings() { } - virtual LogSetting *Create() anope_abstract; + virtual Anope::string GetCommandService() anope_abstract; + virtual void SetCommandService(const Anope::string &) anope_abstract; + + virtual Anope::string GetCommandName() anope_abstract; + virtual void SetCommandName(const Anope::string &) anope_abstract; + + virtual Anope::string GetMethod() anope_abstract; + virtual void SetMethod(const Anope::string &) anope_abstract; + + virtual Anope::string GetExtra() anope_abstract; + virtual void SetExtra(const Anope::string &) anope_abstract; + + virtual Anope::string GetCreator() anope_abstract; + virtual void SetCreator(const Anope::string &) anope_abstract; + + virtual time_t GetCreated() anope_abstract; + virtual void SetCreated(const time_t &) anope_abstract; }; +static Serialize::TypeReference logsetting("LogSetting"); + diff --git a/include/modules/cs_mode.h b/include/modules/cs_mode.h index b44744b87..a27197533 100644 --- a/include/modules/cs_mode.h +++ b/include/modules/cs_mode.h @@ -9,25 +9,39 @@ * Based on the original code of Services by Andy Church. */ -struct ModeLock +class ModeLock : public Serialize::Object { - Anope::string ci; - bool set; - Anope::string name; - Anope::string param; - Anope::string setter; - time_t created; - - virtual ~ModeLock() { } protected: - ModeLock() { } + using Serialize::Object::Object; + + public: + virtual ChanServ::Channel *GetChannel() anope_abstract; + virtual void SetChannel(ChanServ::Channel *) anope_abstract; + + virtual bool GetSet() anope_abstract; + virtual void SetSet(const bool &) anope_abstract; + + virtual Anope::string GetName() anope_abstract; + virtual void SetName(const Anope::string &) anope_abstract; + + virtual Anope::string GetParam() anope_abstract; + virtual void SetParam(const Anope::string &) anope_abstract; + + virtual Anope::string GetSetter() anope_abstract; + virtual void SetSetter(const Anope::string &) anope_abstract; + + virtual time_t GetCreated() anope_abstract; + virtual void SetCreated(const time_t &) anope_abstract; }; -struct ModeLocks +static Serialize::TypeReference modelock("ModeLock"); + +class ModeLocks : public Service { - typedef std::vector ModeList; + public: + ModeLocks(Module *me) : Service(me, "ModeLocks", "mlocks") { } - virtual ~ModeLocks() { } + typedef std::vector ModeList; /** Check if a mode is mlocked * @param mode The mode @@ -35,7 +49,7 @@ struct ModeLocks * @param status True to check mlock on, false for mlock off * @return true on success, false on fail */ - virtual bool HasMLock(ChannelMode *mode, const Anope::string ¶m, bool status) const anope_abstract; + virtual bool HasMLock(ChanServ::Channel *, ChannelMode *mode, const Anope::string ¶m, bool status) const anope_abstract; /** Set a mlock * @param mode The mode @@ -45,7 +59,7 @@ struct ModeLocks * @param created When the mlock was created * @return true on success, false on failure (module blocking) */ - virtual bool SetMLock(ChannelMode *mode, bool status, const Anope::string ¶m = "", Anope::string setter = "", time_t created = Anope::CurTime) anope_abstract; + virtual bool SetMLock(ChanServ::Channel *, ChannelMode *mode, bool status, const Anope::string ¶m = "", Anope::string setter = "", time_t created = Anope::CurTime) anope_abstract; /** Remove a mlock * @param mode The mode @@ -53,41 +67,39 @@ struct ModeLocks * @param param The param of the mode, required if it is a list or status mode * @return true on success, false on failure */ - virtual bool RemoveMLock(ChannelMode *mode, bool status, const Anope::string ¶m = "") anope_abstract; - - virtual void RemoveMLock(ModeLock *mlock) anope_abstract; + virtual bool RemoveMLock(ChanServ::Channel *, ChannelMode *mode, bool status, const Anope::string ¶m = "") anope_abstract; /** Clear all mlocks on the channel */ - virtual void ClearMLock() anope_abstract; + virtual void ClearMLock(ChanServ::Channel *) anope_abstract; /** Get all of the mlocks for this channel * @return The mlocks */ - virtual const ModeList &GetMLock() const anope_abstract; + virtual ModeList GetMLock(ChanServ::Channel *) const anope_abstract; /** Get a list of mode locks on a channel * @param name The mode name to get a list of * @return a list of mlocks for the given mode */ - virtual std::list GetModeLockList(const Anope::string &name) anope_abstract; + virtual std::list GetModeLockList(ChanServ::Channel *, const Anope::string &name) anope_abstract; /** Get details for a specific mlock * @param mname The mode name * @param An optional param to match with * @return The MLock, if any */ - virtual const ModeLock *GetMLock(const Anope::string &mname, const Anope::string ¶m = "") anope_abstract; + virtual ModeLock *GetMLock(ChanServ::Channel *, const Anope::string &mname, const Anope::string ¶m = "") anope_abstract; /** Get the current mode locks as a string * @param complete True to show mlock parameters aswell * @return A string of mode locks, eg: +nrt */ - virtual Anope::string GetMLockAsString(bool complete) const anope_abstract; - - virtual void Check() anope_abstract; + virtual Anope::string GetMLockAsString(ChanServ::Channel *, bool complete) const anope_abstract; }; +static ServiceReference mlocks("ModeLocks", "mlocks"); + namespace Event { struct CoreExport MLockEvents : Events diff --git a/include/modules/cs_set_misc.h b/include/modules/cs_set_misc.h new file mode 100644 index 000000000..65b92cc89 --- /dev/null +++ b/include/modules/cs_set_misc.h @@ -0,0 +1,25 @@ +/* + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +class CSMiscData : public Serialize::Object +{ + protected: + using Serialize::Object::Object; + + public: + virtual ChanServ::Channel *GetChannel() anope_abstract; + virtual void SetChannel(ChanServ::Channel *) anope_abstract; + + virtual Anope::string GetName() anope_abstract; + virtual void SetName(const Anope::string &) anope_abstract; + + virtual Anope::string GetData() anope_abstract; + virtual void SetData(const Anope::string &) anope_abstract; +}; + +static Serialize::TypeReference csmiscdata("CSMiscData"); + diff --git a/include/modules/cs_suspend.h b/include/modules/cs_suspend.h new file mode 100644 index 000000000..6c561b637 --- /dev/null +++ b/include/modules/cs_suspend.h @@ -0,0 +1,51 @@ +/* + * (C) 2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + * + */ + +class CSSuspendInfo : public Serialize::Object +{ + protected: + using Serialize::Object::Object; + + public: + virtual ChanServ::Channel *GetChannel() anope_abstract; + virtual void SetChannel(ChanServ::Channel *) anope_abstract; + + virtual Anope::string GetBy() anope_abstract; + virtual void SetBy(const Anope::string &) anope_abstract; + + virtual Anope::string GetReason() anope_abstract; + virtual void SetReason(const Anope::string &) anope_abstract; + + virtual time_t GetWhen() anope_abstract; + virtual void SetWhen(const time_t &) anope_abstract; + + virtual time_t GetExpires() anope_abstract; + virtual void SetExpires(const time_t &) anope_abstract; +}; + +static Serialize::TypeReference cssuspendinfo("CSSuspendInfo"); + +namespace Event +{ + struct CoreExport ChanSuspend : Events + { + /** Called when a channel is suspended + * @param ci The channel + */ + virtual void OnChanSuspend(ChanServ::Channel *ci) anope_abstract; + }; + struct CoreExport ChanUnsuspend : Events + { + /** Called when a channel is unsuspended + * @param ci The channel + */ + virtual void OnChanUnsuspend(ChanServ::Channel *ci) anope_abstract; + }; + extern CoreExport EventHandlers OnChanUnsuspend; +} + diff --git a/include/modules/dns.h b/include/modules/dns.h index 0f7e288c3..7a0a587fa 100644 --- a/include/modules/dns.h +++ b/include/modules/dns.h @@ -131,6 +131,8 @@ namespace DNS virtual uint32_t GetSerial() const anope_abstract; }; + static ServiceReference manager("DNS::Manager", "dns/manager"); + /** A DNS query. */ class Request : public Timer, public Question diff --git a/include/modules/global.h b/include/modules/global.h index 7f1cf7f72..adac905cc 100644 --- a/include/modules/global.h +++ b/include/modules/global.h @@ -21,7 +21,7 @@ namespace Global * @param source The sender of the global * @param message The message */ - virtual void SendGlobal(BotInfo *sender, const Anope::string &source, const Anope::string &message) anope_abstract; + virtual void SendGlobal(ServiceBot *sender, const Anope::string &source, const Anope::string &message) anope_abstract; }; static ServiceReference service("GlobalService", "Global"); } diff --git a/include/modules/memoserv.h b/include/modules/memoserv.h index b2bfbf8cb..9a209e27f 100644 --- a/include/modules/memoserv.h +++ b/include/modules/memoserv.h @@ -12,6 +12,8 @@ namespace MemoServ { + class Ignore; + class MemoServService : public Service { public: @@ -42,6 +44,8 @@ namespace MemoServ 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 service("MemoServService", "MemoServ"); @@ -71,40 +75,76 @@ namespace MemoServ static EventHandlersReference OnMemoDel("OnMemoDel"); } - class Memo : public Serializable + class Memo : public Serialize::Object { - public: - bool unread; - bool receipt; protected: - Memo() : Serializable("Memo") { } + using Serialize::Object::Object; +// Memo() : Serialize::Object("Memo") { } public: + virtual MemoInfo *GetMemoInfo() anope_abstract; + virtual void SetMemoInfo(MemoInfo *) anope_abstract; + + virtual time_t GetTime() anope_abstract; + virtual void SetTime(const time_t &) anope_abstract; + + virtual Anope::string GetSender() anope_abstract; + virtual void SetSender(const Anope::string &) anope_abstract; + + virtual Anope::string GetText() anope_abstract; + virtual void SetText(const Anope::string &) anope_abstract; - Anope::string owner; - /* When it was sent */ - time_t time; - Anope::string sender; - Anope::string text; + virtual bool GetUnread() anope_abstract; + virtual void SetUnread(const bool &) anope_abstract; + + virtual bool GetReceipt() anope_abstract; + virtual void SetReceipt(const bool &) anope_abstract; }; + static Serialize::TypeReference 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. */ - struct CoreExport MemoInfo + class MemoInfo : public Serialize::Object { - int16_t memomax anope_abstract; - Serialize::Checker > memos; - std::vector ignores; - - MemoInfo() : memos("Memo") { } - virtual ~MemoInfo() { } + protected: + using Serialize::Object::Object; + //using MemoInfo::MemoInfo; + //MemoInfo() : Serialize::Object("MemoInfo") { } + public: - virtual Memo *GetMemo(unsigned index) const anope_abstract; + virtual Memo *GetMemo(unsigned index) anope_abstract; - virtual unsigned GetIndex(Memo *m) const anope_abstract; + virtual unsigned GetIndex(Memo *m) anope_abstract; virtual void Del(unsigned index) anope_abstract; virtual bool HasIgnore(User *u) anope_abstract; + + virtual Serialize::Object *GetOwner() anope_abstract; + virtual void SetOwner(Serialize::Object *) anope_abstract; + + virtual int16_t GetMemoMax() anope_abstract; + virtual void SetMemoMax(const int16_t &) anope_abstract; + + virtual std::vector GetMemos() anope_abstract; + virtual std::vector GetIgnores() anope_abstract; }; + + static Serialize::TypeReference memoinfo("MemoInfo"); + + class Ignore : public Serialize::Object + { + protected: + using Serialize::Object::Object; + + public: + 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("MemoIgnore"); } diff --git a/include/modules/nickserv.h b/include/modules/nickserv.h index 0430276fe..84ff39520 100644 --- a/include/modules/nickserv.h +++ b/include/modules/nickserv.h @@ -11,6 +11,7 @@ #include "event.h" #include "service.h" +#include "serialize.h" namespace NickServ { @@ -35,11 +36,11 @@ namespace NickServ virtual IdentifyRequest *CreateIdentifyRequest(IdentifyRequestListener *l, Module *owner, const Anope::string &acc, const Anope::string &pass) anope_abstract; virtual std::set& GetIdentifyRequests() anope_abstract; - virtual nickalias_map& GetNickList() anope_abstract; - virtual nickcore_map& GetAccountList() anope_abstract; + virtual std::vector GetNickList() anope_abstract; + virtual nickalias_map& GetNickMap() anope_abstract; - virtual Nick *CreateNick(const Anope::string &nick, Account *acc) anope_abstract; - virtual Account *CreateAccount(const Anope::string &acc) anope_abstract; + virtual std::vector GetAccountList() anope_abstract; + virtual nickcore_map& GetAccountMap() anope_abstract; virtual Nick *FindNick(const Anope::string &nick) anope_abstract; virtual Account *FindAccount(const Anope::string &acc) anope_abstract; @@ -104,30 +105,35 @@ namespace NickServ /* A registered nickname. * It matters that Base is here before Extensible (it is inherited by Serializable) */ - class CoreExport Nick : public Serializable, public Extensible + class CoreExport Nick : public Serialize::Object { protected: - Anope::string vhost_ident, vhost_host, vhost_creator; - time_t vhost_created; + using Serialize::Object::Object; public: - Anope::string nick; - Anope::string last_quit; - Anope::string last_realname; - /* Last usermask this nick was seen on, eg user@host */ - Anope::string last_usermask; - /* Last uncloaked usermask, requires nickserv/auspex to see */ - Anope::string last_realhost; - time_t time_registered; - time_t last_seen; - /* Account this nick is tied to. Multiple nicks can be tied to a single account. */ - Serialize::Reference nc; + virtual Anope::string GetNick() anope_abstract; + virtual void SetNick(const Anope::string &) anope_abstract; - protected: - Nick() : Serializable("NickAlias") { } + virtual Anope::string GetLastQuit() anope_abstract; + virtual void SetLastQuit(const Anope::string &) anope_abstract; - public: - virtual ~Nick() { } + virtual Anope::string GetLastRealname() anope_abstract; + virtual void SetLastRealname(const Anope::string &) anope_abstract; + + virtual Anope::string GetLastUsermask() anope_abstract; + virtual void SetLastUsermask(const Anope::string &) anope_abstract; + + virtual Anope::string GetLastRealhost() anope_abstract; + virtual void SetLastRealhost(const Anope::string &) anope_abstract; + + virtual time_t GetTimeRegistered() anope_abstract; + virtual void SetTimeRegistered(const time_t &) anope_abstract; + + virtual time_t GetLastSeen() anope_abstract; + virtual void SetLastSeen(const time_t &) anope_abstract; + + virtual Account *GetAccount() anope_abstract; + virtual void SetAccount(Account *acc) anope_abstract; /** Set a vhost for the user * @param ident The ident @@ -136,153 +142,82 @@ namespace NickServ * @param time When the vhost was craated */ virtual void SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created = Anope::CurTime) anope_abstract; - - /** Remove a users vhost - **/ virtual void RemoveVhost() anope_abstract; + virtual bool HasVhost() anope_abstract; - /** Check if the user has a vhost - * @return true or false - */ - virtual bool HasVhost() const anope_abstract; + virtual Anope::string GetVhostIdent() anope_abstract; + virtual void SetVhostIdent(const Anope::string &) anope_abstract; - /** Retrieve the vhost ident - * @return the ident - */ - virtual const Anope::string &GetVhostIdent() const anope_abstract; + virtual Anope::string GetVhostHost() anope_abstract; + virtual void SetVhostHost(const Anope::string &) anope_abstract; - /** Retrieve the vhost host - * @return the host - */ - virtual const Anope::string &GetVhostHost() const anope_abstract; + virtual Anope::string GetVhostCreator() anope_abstract; + virtual void SetVhostCreator(const Anope::string &) anope_abstract; - /** Retrieve the vhost creator - * @return the creator - */ - virtual const Anope::string &GetVhostCreator() const anope_abstract; - - /** Retrieve when the vhost was created - * @return the time it was created - */ - virtual time_t GetVhostCreated() const anope_abstract; + virtual time_t GetVhostCreated() anope_abstract; + virtual void SetVhostCreated(const time_t &) anope_abstract; }; + static Serialize::TypeReference 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) */ - class CoreExport Account : public Serializable, public Extensible + class CoreExport Account : public Serialize::Object { - protected: - /* Channels which reference this core in some way (this is on their access list, akick list, is founder, successor, etc) */ - Serialize::Checker > chanaccess; public: - /* Name of the account. Find(display)->nc == this. */ - Anope::string display; - /* User password in form of hashm:data */ - Anope::string pass; - Anope::string email; - /* Locale name of the language of the user. Empty means default language */ - Anope::string language; - /* Access list, contains user@host masks of users who get certain privileges based - * on if NI_SECURE is set and what (if any) kill protection is enabled. */ - std::vector access; - MemoServ::MemoInfo *memos = nullptr; - std::map last_modes; - - /* Nicknames registered that are grouped to this account. - * for n in aliases, n->nc == this. - */ - Serialize::Checker > aliases; - /* Set if this user is a services operattor. o->ot must exist. */ - Oper *o; + Serialize::Reference o; /* Unsaved data */ - /* Number of channels registered by this account */ - uint16_t channelcount; /* Last time an email was sent to this user */ - time_t lastmail; + time_t lastmail = 0; /* Users online now logged into this account */ - std::list users; + std::vector users; protected: - /** Constructor - * @param display The display nick - */ - Account() : Serializable("NickCore"), chanaccess("ChannelInfo"), aliases("NickAlias") { } + using Serialize::Object::Object; public: - virtual ~Account() { } + virtual Anope::string GetDisplay() anope_abstract; + virtual void SetDisplay(const Anope::string &) anope_abstract; + + virtual Anope::string GetPassword() anope_abstract; + virtual void SetPassword(const Anope::string &) anope_abstract; + + virtual Anope::string GetEmail() anope_abstract; + virtual void SetEmail(const Anope::string &) anope_abstract; + + virtual Anope::string GetLanguage() anope_abstract; + virtual void SetLanguage(const Anope::string &) anope_abstract; /** Changes the display for this account * @param na The new display, must be grouped to this account. */ - virtual void SetDisplay(const Nick *na) anope_abstract; + virtual void SetDisplay(Nick *na) anope_abstract; /** Checks whether this account is a services oper or not. * @return True if this account is a services oper, false otherwise. */ virtual bool IsServicesOper() const anope_abstract; - /** Add an entry to the nick's access list - * - * @param entry The nick!ident@host entry to add to the access list - * - * Adds a new entry into the access list. - */ - virtual void AddAccess(const Anope::string &entry) anope_abstract; - - /** Get an entry from the nick's access list by index - * - * @param entry Index in the access list vector to retrieve - * @return The access list entry of the given index if within bounds, an empty string if the vector is empty or the index is out of bounds - * - * Retrieves an entry from the access list corresponding to the given index. - */ - virtual Anope::string GetAccess(unsigned entry) const anope_abstract; - - /** Get the number of entries on the access list for this account. - */ - virtual unsigned GetAccessCount() const anope_abstract; - - /** Find an entry in the nick's access list - * - * @param entry The nick!ident@host entry to search for - * @return True if the entry is found in the access list, false otherwise - * - * Search for an entry within the access list. - */ - virtual bool FindAccess(const Anope::string &entry) anope_abstract; - - /** Erase an entry from the nick's access list - * - * @param entry The nick!ident@host entry to remove - * - * Removes the specified access list entry from the access list. - */ - virtual void EraseAccess(const Anope::string &entry) anope_abstract; - - /** Clears the entire nick's access list - * - * Deletes all the memory allocated in the access list vector and then clears the vector. - */ - virtual void ClearAccess() anope_abstract; - /** Is the given user on this accounts access list? * * @param u The user * * @return true if the user is on the access list */ - virtual bool IsOnAccess(const User *u) const anope_abstract; + virtual bool IsOnAccess(User *u) anope_abstract; + + virtual MemoServ::MemoInfo *GetMemos() anope_abstract; - virtual void AddChannelReference(ChanServ::Channel *ci) anope_abstract; - virtual void RemoveChannelReference(ChanServ::Channel *ci) anope_abstract; - virtual void GetChannelReferences(std::deque &queue) anope_abstract; + virtual unsigned int GetChannelCount() anope_abstract; }; + static Serialize::TypeReference 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. */ @@ -342,4 +277,19 @@ namespace NickServ virtual void OnSuccess(IdentifyRequest *) anope_abstract; virtual void OnFail(IdentifyRequest *) anope_abstract; }; + + class Mode : public Serialize::Object + { + public: + using Serialize::Object::Object; + + virtual Account *GetAccount() anope_abstract; + virtual void SetAccount(Account *) anope_abstract; + + virtual Anope::string GetMode() anope_abstract; + virtual void SetMode(const Anope::string &) anope_abstract; + }; + + static Serialize::TypeReference mode("NSKeepMode"); + } diff --git a/include/modules/ns_access.h b/include/modules/ns_access.h new file mode 100644 index 000000000..73a625f3d --- /dev/null +++ b/include/modules/ns_access.h @@ -0,0 +1,22 @@ +/* + * + * (C) 2003-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +class NickAccess : public Serialize::Object +{ + public: + using Serialize::Object::Object; + + virtual NickServ::Account *GetAccount() anope_abstract; + virtual void SetAccount(NickServ::Account *) anope_abstract; + + virtual Anope::string GetMask() anope_abstract; + virtual void SetMask(const Anope::string &) anope_abstract; +}; + +static Serialize::TypeReference nsaccess("NSAccess"); + diff --git a/include/modules/ns_ajoin.h b/include/modules/ns_ajoin.h new file mode 100644 index 000000000..7b4cc20e5 --- /dev/null +++ b/include/modules/ns_ajoin.h @@ -0,0 +1,25 @@ +/* + * + * (C) 2013-2014 Anope Team + * Contact us at team@anope.org + * + * Please read COPYING and README for further details. + */ + +class AutoJoin : public Serialize::Object +{ + protected: + using Serialize::Object::Object; + + public: + virtual NickServ::Account *GetOwner() anope_abstract; + virtual void SetOwner(NickServ::Account *acc) anope_abstract; + + virtual Anope::string GetChannel() anope_abstract; + virtual void SetChannel(const Anope::string &c) anope_abstract; + + virtual Anope::string GetKey() anope_abstract; + virtual void SetKey(const Anope::string &k) anope_abstract; +}; + +static Serialize::TypeReference autojoin("AutoJoin"); diff --git a/include/modules/ns_cert.h b/include/modules/ns_cert.h index eb02d7653..994f0378e 100644 --- a/include/modules/ns_cert.h +++ b/include/modules/ns_cert.h @@ -9,66 +9,36 @@ * Based on the original code of Services by Andy Church. */ -struct NSCertList +class NSCertEntry; + +class CertService : public Service { - protected: - NSCertList() { } public: - virtual ~NSCertList() { } - - /** Add an entry to the nick's certificate list - * - * @param entry The fingerprint to add to the cert list - * - * Adds a new entry into the cert list. - */ - virtual void AddCert(const Anope::string &entry) anope_abstract; - - /** Get an entry from the nick's cert list by index - * - * @param entry Index in the certificaate list vector to retrieve - * @return The fingerprint entry of the given index if within bounds, an empty string if the vector is empty or the index is out of bounds - * - * Retrieves an entry from the certificate list corresponding to the given index. - */ - virtual Anope::string GetCert(unsigned entry) const anope_abstract; - - virtual unsigned GetCertCount() const anope_abstract; - - /** Find an entry in the nick's cert list - * - * @param entry The fingerprint to search for - * @return True if the fingerprint is found in the cert list, false otherwise - * - * Search for an fingerprint within the cert list. - */ - virtual bool FindCert(const Anope::string &entry) const anope_abstract; + CertService(Module *c) : Service(c, "CertService", "certs") { } - /** Erase a fingerprint from the nick's certificate list - * - * @param entry The fingerprint to remove - * - * Removes the specified fingerprint from the cert list. - *