summaryrefslogtreecommitdiff
path: root/include/modules
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2014-11-24 14:27:23 -0500
committerAdam <Adam@anope.org>2014-11-24 14:27:23 -0500
commit42238034490fb5479d787bd1695750387d508200 (patch)
treec93c62e0e1c936e656ae5b9ee1b62380ce2a194c /include/modules
parentd492923610d9c9146b2a2b63de38deab2cfd4ca7 (diff)
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.
Diffstat (limited to 'include/modules')
-rw-r--r--include/modules/bs_badwords.h44
-rw-r--r--include/modules/bs_bot.h6
-rw-r--r--include/modules/bs_info.h6
-rw-r--r--include/modules/bs_kick.h124
-rw-r--r--include/modules/chanserv.h403
-rw-r--r--include/modules/cs_access.h4
-rw-r--r--include/modules/cs_akick.h44
-rw-r--r--include/modules/cs_entrymsg.h34
-rw-r--r--include/modules/cs_log.h51
-rw-r--r--include/modules/cs_mode.h62
-rw-r--r--include/modules/cs_set_misc.h25
-rw-r--r--include/modules/cs_suspend.h51
-rw-r--r--include/modules/dns.h2
-rw-r--r--include/modules/global.h2
-rw-r--r--include/modules/memoserv.h78
-rw-r--r--include/modules/nickserv.h204
-rw-r--r--include/modules/ns_access.h22
-rw-r--r--include/modules/ns_ajoin.h25
-rw-r--r--include/modules/ns_cert.h66
-rw-r--r--include/modules/ns_set_misc.h25
-rw-r--r--include/modules/ns_suspend.h51
-rw-r--r--include/modules/os_dns.h72
-rw-r--r--include/modules/os_forbid.h48
-rw-r--r--include/modules/os_ignore.h36
-rw-r--r--include/modules/os_info.h29
-rw-r--r--include/modules/os_news.h35
-rw-r--r--include/modules/os_session.h89
-rw-r--r--include/modules/redis.h19
-rw-r--r--include/modules/sasl.h6
-rw-r--r--include/modules/set_misc.h17
-rw-r--r--include/modules/sql.h142
-rw-r--r--include/modules/suspend.h52
32 files changed, 1089 insertions, 785 deletions
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("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<BadWord *> 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", "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<BotInfoEvent> OnBotInfo;
+ extern CoreExport EventHandlers<ServiceBotEvent> 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("KickerData");
+
+inline KickerData *GetKickerData(ChanServ::Channel *ci)
+{
+ KickerData *kd = ci->GetRef<KickerData *>(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<Channel *>;
- 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("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> 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<Privilege> &GetPrivileges() anope_abstract;
virtual void ClearPrivileges() anope_abstract;
- virtual std::vector<AccessProvider *>& GetProviders() anope_abstract;
-
- virtual void Destruct(ChanAccess *) anope_abstract;
- virtual void Serialize(const ChanAccess *, Serialize::Data &data) anope_abstract;
//XXX
- typedef std::multimap<const ChanAccess *, const ChanAccess *> Set;
+ typedef std::multimap<ChanAccess *, ChanAccess *> Set;
typedef std::pair<Set, Set> 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<ChanServService> 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<int> references;
- Serialize::Reference<NickServ::Account> founder; /* Channel founder */
- Serialize::Reference<NickServ::Account> successor; /* Who gets the channel if the founder nick is dropped or expires */
- Serialize::Checker<std::vector<ChanAccess *> > access; /* List of authorized users */
- Serialize::Checker<std::vector<AutoKick *> > akick; /* List of users to kickban */
- Anope::map<int16_t> 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<BotInfo> 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<Anope::string> &chans) anope_abstract;
+ virtual MemoServ::MemoInfo *GetMemos() anope_abstract;
};
+ static Serialize::TypeReference<Channel> 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<AccessProvider *>& providers = service->GetProviders();
- providers.push_back(this);
- }
-
- virtual ~AccessProvider()
- {
- std::vector<AccessProvider *>& providers = service->GetProviders();
- std::vector<AccessProvider *>::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<NickServ::Account> nc;
-
public:
- typedef std::multimap<const ChanAccess *, const ChanAccess *> Set;
+ 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;
- /* The provider that created this access entry */
- AccessProvider *provider;
- /* Channel this access entry is on */
- Serialize::Reference<Channel> 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<Privilege> &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<Privilege> &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<ChanServ::ChanAccess, ChanServ::Channel *> ci;
+ Serialize::Field<ChanServ::ChanAccess, Anope::string> mask;
+ Serialize::ObjectField<ChanServ::ChanAccess, Serialize::Object *> obj;
+ Serialize::Field<ChanServ::ChanAccess, Anope::string> creator;
+ Serialize::Field<ChanServ::ChanAccess, time_t> last_seen;
+ Serialize::Field<ChanServ::ChanAccess, time_t> created;
+
+ ChanAccessType(Module *me, const Anope::string &name) : Serialize::AbstractType(me, name)
+ , ci(this, "ci", true)
+ , mask(this, "mask")
+ , obj(this, "obj", true)
+ , creator(this, "creator")
+ , last_seen(this, "last_seen")
+ , created(this, "created")