summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2012-04-23 05:08:26 -0400
committerAdam <Adam@anope.org>2012-04-23 05:08:26 -0400
commit573e49a7ead331219eb6f0d3ca9cf83e793a5c9c (patch)
treee145e04fa3d041cf92ce46da4ac790b63231059c
parent63c639e108a00d7dbb0d7ac9891684fc83a3b207 (diff)
Reworked live SQL support yet again
-rw-r--r--data/example.conf34
-rw-r--r--include/access.h18
-rw-r--r--include/account.h28
-rw-r--r--include/anope.h4
-rw-r--r--include/base.h50
-rw-r--r--include/bots.h14
-rw-r--r--include/channels.h24
-rw-r--r--include/defs.h1
-rw-r--r--include/extensible.h16
-rw-r--r--include/extern.h14
-rw-r--r--include/logger.h18
-rw-r--r--include/mail.h4
-rw-r--r--include/memo.h10
-rw-r--r--include/modes.h14
-rw-r--r--include/modules.h56
-rw-r--r--include/oper.h18
-rw-r--r--include/protocol.h2
-rw-r--r--include/regchannel.h92
-rw-r--r--include/serialize.h189
-rw-r--r--include/servers.h2
-rw-r--r--include/service.h4
-rw-r--r--include/users.h27
-rw-r--r--modules/commands/bs_badwords.cpp8
-rw-r--r--modules/commands/bs_bot.cpp13
-rw-r--r--modules/commands/bs_botlist.cpp2
-rw-r--r--modules/commands/bs_info.cpp10
-rw-r--r--modules/commands/bs_kick.cpp4
-rw-r--r--modules/commands/cs_access.cpp24
-rw-r--r--modules/commands/cs_akick.cpp17
-rw-r--r--modules/commands/cs_clone.cpp11
-rw-r--r--modules/commands/cs_drop.cpp2
-rw-r--r--modules/commands/cs_enforce.cpp14
-rw-r--r--modules/commands/cs_entrymsg.cpp25
-rw-r--r--modules/commands/cs_fantasy_stats.cpp5
-rw-r--r--modules/commands/cs_flags.cpp8
-rw-r--r--modules/commands/cs_info.cpp6
-rw-r--r--modules/commands/cs_list.cpp4
-rw-r--r--modules/commands/cs_log.cpp67
-rw-r--r--modules/commands/cs_mode.cpp16
-rw-r--r--modules/commands/cs_modes.cpp30
-rw-r--r--modules/commands/cs_register.cpp11
-rw-r--r--modules/commands/cs_saset.cpp4
-rw-r--r--modules/commands/cs_seen.cpp22
-rw-r--r--modules/commands/cs_set.cpp4
-rw-r--r--modules/commands/cs_set_founder.cpp5
-rw-r--r--modules/commands/cs_set_misc.cpp30
-rw-r--r--modules/commands/cs_set_successor.cpp2
-rw-r--r--modules/commands/cs_suspend.cpp34
-rw-r--r--modules/commands/cs_updown.cpp4
-rw-r--r--modules/commands/cs_xop.cpp20
-rw-r--r--modules/commands/help.cpp10
-rw-r--r--modules/commands/hs_del.cpp4
-rw-r--r--modules/commands/hs_group.cpp9
-rw-r--r--modules/commands/hs_list.cpp4
-rw-r--r--modules/commands/hs_off.cpp2
-rw-r--r--modules/commands/hs_on.cpp2
-rw-r--r--modules/commands/hs_request.cpp33
-rw-r--r--modules/commands/hs_set.cpp9
-rw-r--r--modules/commands/ms_cancel.cpp17
-rw-r--r--modules/commands/ms_check.cpp14
-rw-r--r--modules/commands/ms_del.cpp33
-rw-r--r--modules/commands/ms_info.cpp43
-rw-r--r--modules/commands/ms_list.cpp21
-rw-r--r--modules/commands/ms_read.cpp31
-rw-r--r--modules/commands/ms_rsend.cpp4
-rw-r--r--modules/commands/ms_sendall.cpp6
-rw-r--r--modules/commands/ms_set.cpp35
-rw-r--r--modules/commands/ms_staff.cpp4
-rw-r--r--modules/commands/ns_access.cpp3
-rw-r--r--modules/commands/ns_ajoin.cpp35
-rw-r--r--modules/commands/ns_alist.cpp4
-rw-r--r--modules/commands/ns_cert.cpp16
-rw-r--r--modules/commands/ns_drop.cpp2
-rw-r--r--modules/commands/ns_getemail.cpp4
-rw-r--r--modules/commands/ns_getpass.cpp2
-rw-r--r--modules/commands/ns_ghost.cpp2
-rw-r--r--modules/commands/ns_group.cpp82
-rw-r--r--modules/commands/ns_info.cpp2
-rw-r--r--modules/commands/ns_list.cpp4
-rw-r--r--modules/commands/ns_register.cpp39
-rw-r--r--modules/commands/ns_resetpass.cpp18
-rw-r--r--modules/commands/ns_saset.cpp6
-rw-r--r--modules/commands/ns_sendpass.cpp6
-rw-r--r--modules/commands/ns_set.cpp4
-rw-r--r--modules/commands/ns_set_autoop.cpp2
-rw-r--r--modules/commands/ns_set_display.cpp4
-rw-r--r--modules/commands/ns_set_email.cpp17
-rw-r--r--modules/commands/ns_set_greet.cpp2
-rw-r--r--modules/commands/ns_set_hide.cpp2
-rw-r--r--modules/commands/ns_set_kill.cpp2
-rw-r--r--modules/commands/ns_set_language.cpp2
-rw-r--r--modules/commands/ns_set_message.cpp2
-rw-r--r--modules/commands/ns_set_misc.cpp32
-rw-r--r--modules/commands/ns_set_private.cpp2
-rw-r--r--modules/commands/ns_set_secure.cpp2
-rw-r--r--modules/commands/ns_status.cpp2
-rw-r--r--modules/commands/ns_suspend.cpp45
-rw-r--r--modules/commands/os_akill.cpp8
-rw-r--r--modules/commands/os_forbid.cpp8
-rw-r--r--modules/commands/os_forbid.h24
-rw-r--r--modules/commands/os_ignore.cpp6
-rw-r--r--modules/commands/os_ignore.h28
-rw-r--r--modules/commands/os_modinfo.cpp4
-rw-r--r--modules/commands/os_news.cpp12
-rw-r--r--modules/commands/os_news.h24
-rw-r--r--modules/commands/os_oper.cpp34
-rw-r--r--modules/commands/os_session.cpp8
-rw-r--r--modules/commands/os_session.h24
-rw-r--r--modules/commands/os_stats.cpp9
-rw-r--r--modules/commands/os_sxline.cpp12
-rw-r--r--modules/database/db_flatfile.cpp12
-rw-r--r--modules/database/db_old.cpp4
-rw-r--r--modules/database/db_plain.cpp101
-rw-r--r--modules/database/db_sql.cpp50
-rw-r--r--modules/database/db_sql_live.cpp311
-rw-r--r--modules/database/db_sql_live_read.cpp179
-rw-r--r--modules/database/db_sql_live_write.cpp440
-rw-r--r--modules/encryption/enc_md5.cpp4
-rw-r--r--modules/encryption/enc_none.cpp4
-rw-r--r--modules/encryption/enc_old.cpp4
-rw-r--r--modules/encryption/enc_sha1.cpp4
-rw-r--r--modules/encryption/enc_sha256.cpp4
-rw-r--r--modules/extra/m_dnsbl.cpp4
-rw-r--r--modules/extra/m_ldap_authentication.cpp9
-rw-r--r--modules/extra/m_ldap_oper.cpp22
-rw-r--r--modules/extra/m_mysql.cpp81
-rw-r--r--modules/extra/m_proxyscan.cpp4
-rw-r--r--modules/extra/m_sqlite.cpp82
-rw-r--r--modules/extra/m_xmlrpc_main.cpp14
-rw-r--r--modules/extra/ns_maxemail.cpp4
-rw-r--r--modules/extra/sql.h7
-rw-r--r--modules/protocol/bahamut.cpp15
-rw-r--r--modules/protocol/inspircd-ts6.h16
-rw-r--r--modules/protocol/inspircd11.cpp18
-rw-r--r--modules/protocol/inspircd12.cpp6
-rw-r--r--modules/protocol/inspircd20.cpp6
-rw-r--r--modules/protocol/plexus.cpp25
-rw-r--r--modules/protocol/ratbox.cpp21
-rw-r--r--modules/protocol/unreal.cpp25
-rw-r--r--modules/pseudoclients/botserv.cpp6
-rw-r--r--modules/pseudoclients/chanserv.cpp24
-rw-r--r--modules/pseudoclients/global.cpp12
-rw-r--r--modules/pseudoclients/global.h2
-rw-r--r--modules/pseudoclients/hostserv.cpp6
-rw-r--r--modules/pseudoclients/memoserv.cpp46
-rw-r--r--modules/pseudoclients/nickserv.cpp37
-rw-r--r--modules/pseudoclients/operserv.cpp31
-rw-r--r--src/access.cpp35
-rw-r--r--src/actions.cpp2
-rw-r--r--src/bots.cpp55
-rw-r--r--src/botserv.cpp16
-rw-r--r--src/channels.cpp76
-rw-r--r--src/chanserv.cpp19
-rw-r--r--src/config.cpp31
-rw-r--r--src/init.cpp2
-rw-r--r--src/language.cpp2
-rw-r--r--src/logger.cpp39
-rw-r--r--src/mail.cpp2
-rw-r--r--src/main.cpp4
-rw-r--r--src/memoserv.cpp53
-rw-r--r--src/messages.cpp2
-rw-r--r--src/misc.cpp6
-rw-r--r--src/modes.cpp21
-rw-r--r--src/nickalias.cpp43
-rw-r--r--src/nickcore.cpp36
-rw-r--r--src/nickserv.cpp31
-rw-r--r--src/operserv.cpp108
-rw-r--r--src/protocol.cpp6
-rw-r--r--src/regchannel.cpp495
-rw-r--r--src/serialize.cpp95
-rw-r--r--src/servers.cpp6
-rw-r--r--src/users.cpp37
172 files changed, 2515 insertions, 2215 deletions
diff --git a/data/example.conf b/data/example.conf
index a17b51a36..e27067e9a 100644
--- a/data/example.conf
+++ b/data/example.conf
@@ -1091,40 +1091,34 @@ db_flatfile
* db_sql
*
* This module allows saving and loading databases using one of the SQL engines.
+ * This module does not use any real time reading or writing to SQL. Changes to
+ * the SQL tables not done by Anope will have no effect and will be overwritten.
*
* WARNING: This module will delete every table in the database it uses. Be sure
* to put Anope in its own separate database.
*/
#module { name = "db_sql" }
+
+/*
+ * db_sql_live
+ *
+ * This module allows saving and loading databases using one of the SQL engines.
+ * This module reads and writes to SQL in real time. Changes to the SQL tables
+ * will be immediately reflected into Anope. This module should not be loaded
+ * in conjunction with db_sql.
+ */
+#module { name = "db_sql_live" }
+
db_sql
{
/*
- * The SQL service db_sql should use, these are configured in modules.conf.
+ * The SQL service db_sql(_live) should use, these are configured in modules.conf.
* For MySQL, this should probably be mysql/main.
*/
engine = "sqlite/main"
}
/*
- * db_sql_live_read, db_sql_live_write
- *
- * Enables (live) SQL support.
- *
- * The db_sql_live modules are an extension to db_sql, and should only be used if
- * db_sql is being used.
- *
- * The db_sql_live_read module pulls data in real time from
- * SQL as it is needed by the core.
- * At this time this supports the three main tables: ChannelInfo, NickAlias, and NickCore.
- *
- * The db_sql_live_write module writes data to SQL in real time as it is modified by
- * the core.
- *
- */
-#module { name = "db_sql_live_read" }
-#module { name = "db_sql_live_write" }
-
-/*
* [REQUIRED] Encryption modules.
*
* The encryption modules are used when dealing with passwords. This determines how
diff --git a/include/access.h b/include/access.h
index e19c15a76..18499b602 100644
--- a/include/access.h
+++ b/include/access.h
@@ -59,7 +59,7 @@ class CoreExport ChanAccess : public Serializable
{
public:
AccessProvider *provider;
- ChannelInfo *ci;
+ serialize_obj<ChannelInfo> ci;
Anope::string mask;
Anope::string creator;
time_t last_seen;
@@ -68,13 +68,13 @@ class CoreExport ChanAccess : public Serializable
ChanAccess(AccessProvider *p);
virtual ~ChanAccess();
- Anope::string serialize_name() const;
- serialized_data serialize();
- static void unserialize(serialized_data &);
+ const Anope::string serialize_name() const anope_override;
+ Serialize::Data serialize() const anope_override;
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &);
- virtual bool Matches(User *u, NickCore *nc);
+ virtual bool Matches(const User *u, const NickCore *nc) const;
virtual bool HasPriv(const Anope::string &name) const = 0;
- virtual Anope::string Serialize() = 0;
+ virtual Anope::string Serialize() const = 0;
virtual void Unserialize(const Anope::string &data) = 0;
bool operator>(const ChanAccess &other) const;
@@ -86,12 +86,12 @@ class CoreExport ChanAccess : public Serializable
class CoreExport AccessGroup : public std::vector<ChanAccess *>
{
public:
- ChannelInfo *ci;
- NickCore *nc;
+ const ChannelInfo *ci;
+ const NickCore *nc;
bool SuperAdmin, Founder;
AccessGroup();
bool HasPriv(const Anope::string &priv) const;
- ChanAccess *Highest() const;
+ const ChanAccess *Highest() const;
bool operator>(const AccessGroup &other) const;
bool operator<(const AccessGroup &other) const;
bool operator>=(const AccessGroup &other) const;
diff --git a/include/account.h b/include/account.h
index 18bdcc876..756c97348 100644
--- a/include/account.h
+++ b/include/account.h
@@ -23,8 +23,8 @@
typedef Anope::insensitive_map<NickAlias *> nickalias_map;
typedef Anope::insensitive_map<NickCore *> nickcore_map;
-extern CoreExport nickalias_map NickAliasList;
-extern CoreExport nickcore_map NickCoreList;
+extern serialize_checker<nickalias_map> NickAliasList;
+extern serialize_checker<nickcore_map> NickCoreList;
/* NickServ nickname structures. */
@@ -109,7 +109,7 @@ const Anope::string NickCoreFlagStrings[] = {
"MEMO_MAIL", "HIDE_STATUS", "SUSPENDED", "AUTOOP", "FORBIDDEN", "UNCONFIRMED", "STATS", ""
};
-class CoreExport NickAlias : public Base, public Extensible, public Flags<NickNameFlag, NS_END>, public Serializable
+class CoreExport NickAlias : public Extensible, public Flags<NickNameFlag, NS_END>, public Serializable
{
Anope::string vhost_ident, vhost_host, vhost_creator;
time_t vhost_created;
@@ -117,7 +117,7 @@ class CoreExport NickAlias : public Base, public Extensible, public Flags<NickNa
public:
/** Default constructor
* @param nickname The nick
- * @param nickcore The nickcofe for this nick
+ * @param nickcore The nickcore for this nick
*/
NickAlias(const Anope::string &nickname, NickCore *nickcore);
@@ -132,11 +132,11 @@ class CoreExport NickAlias : public Base, public Extensible, public Flags<NickNa
Anope::string last_realhost; /* Last uncloaked usermask, requires nickserv/auspex to see */
time_t time_registered; /* When the nick was registered */
time_t last_seen; /* When it was seen online for the last time */
- NickCore *nc; /* I'm an alias of this */
+ serialize_obj<NickCore> nc; /* I'm an alias of this */
- Anope::string serialize_name() const anope_override;
- serialized_data serialize() anope_override;
- static void unserialize(serialized_data &);
+ const Anope::string serialize_name() const anope_override;
+ Serialize::Data serialize() const anope_override;
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &);
/** Release a nick
* See the comment in users.cpp
@@ -188,7 +188,7 @@ class CoreExport NickAlias : public Base, public Extensible, public Flags<NickNa
time_t GetVhostCreated() const;
};
-class CoreExport NickCore : public Base, public Extensible, public Flags<NickCoreFlag, NI_END>, public Serializable
+class CoreExport NickCore : public Extensible, public Flags<NickCoreFlag, NI_END>, public Serializable
{
public:
/** Default constructor
@@ -216,11 +216,11 @@ class CoreExport NickCore : public Base, public Extensible, public Flags<NickCor
/* Unsaved data */
uint16_t channelcount; /* Number of channels currently registered */
time_t lastmail; /* Last time this nick record got a mail */
- std::list<NickAlias *> aliases; /* List of aliases */
+ std::list<serialize_obj<NickAlias> > aliases; /* List of aliases */
- Anope::string serialize_name() const anope_override;
- serialized_data serialize() anope_override;
- static void unserialize(serialized_data &);
+ const Anope::string serialize_name() const anope_override;
+ Serialize::Data serialize() const anope_override;
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &);
/** Checks whether this account is a services oper or not.
* @return True if this account is a services oper, false otherwise.
@@ -291,7 +291,7 @@ class CoreExport NickCore : public Base, public Extensible, public Flags<NickCor
*
* Search for an fingerprint within the cert list.
*/
- bool FindCert(const Anope::string &entry);
+ bool FindCert(const Anope::string &entry) const;
/** Erase a fingerprint from the nick's certificate list
*
diff --git a/include/anope.h b/include/anope.h
index b286d0fb6..c67b1decb 100644
--- a/include/anope.h
+++ b/include/anope.h
@@ -670,7 +670,7 @@ template<typename T, size_t Size = 32> class Flags
Flag_Values.reset();
}
- Anope::string ToString()
+ Anope::string ToString() const
{
std::vector<Anope::string> v = ToVector();
Anope::string flag_buf;
@@ -692,7 +692,7 @@ template<typename T, size_t Size = 32> class Flags
FromVector(v);
}
- std::vector<Anope::string> ToVector()
+ std::vector<Anope::string> ToVector() const
{
std::vector<Anope::string> ret;
for (unsigned i = 0; this->Flag_Strings && !this->Flag_Strings[i].empty(); ++i)
diff --git a/include/base.h b/include/base.h
index 2a7cb5147..cc0e84bf9 100644
--- a/include/base.h
+++ b/include/base.h
@@ -30,6 +30,7 @@ class dynamic_reference_base
bool invalid;
public:
dynamic_reference_base() : invalid(false) { }
+ dynamic_reference_base(const dynamic_reference_base &other) : invalid(other.invalid) { }
virtual ~dynamic_reference_base() { }
inline void Invalidate() { this->invalid = true; }
};
@@ -40,66 +41,67 @@ class dynamic_reference : public dynamic_reference_base
protected:
T *ref;
public:
+ dynamic_reference() : ref(NULL)
+ {
+ }
+
dynamic_reference(T *obj) : ref(obj)
{
if (ref)
ref->AddReference(this);
}
- dynamic_reference(const dynamic_reference<T> &obj) : ref(obj.ref)
+ dynamic_reference(const dynamic_reference<T> &other) : dynamic_reference_base(other), ref(other.ref)
{
- if (ref)
+ if (*this)
ref->AddReference(this);
}
virtual ~dynamic_reference()
{
- if (this->invalid)
+ if (*this)
{
- this->invalid = false;
- this->ref = NULL;
- }
- else if (this->operator bool())
ref->DelReference(this);
+ }
}
virtual operator bool()
{
- if (this->invalid)
- {
- this->invalid = false;
- this->ref = NULL;
- }
- return this->ref != NULL;
+ if (!this->invalid)
+ return this->ref != NULL;
+ return false;
}
- virtual inline operator T*()
+ virtual inline operator T*() const
{
- if (this->operator bool())
+ if (!this->invalid)
return this->ref;
return NULL;
}
- virtual inline T *operator->()
+ virtual inline T* operator->()
{
- if (this->operator bool())
+ if (!this->invalid)
return this->ref;
return NULL;
}
virtual inline void operator=(T *newref)
{
- if (this->invalid)
- {
- this->invalid = false;
- this->ref = NULL;
- }
- else if (this->operator bool())
+ if (*this)
this->ref->DelReference(this);
this->ref = newref;
- if (this->operator bool())
+ this->invalid = false;
+ if (*this)
this->ref->AddReference(this);
}
+
+ virtual inline bool operator==(const dynamic_reference<T> &other) const
+ {
+ if (!this->invalid)
+ return this->ref == other;
+ return false;
+ }
};
#endif // BASE_H
diff --git a/include/bots.h b/include/bots.h
index 8d39cd0b3..749e4c92d 100644
--- a/include/bots.h
+++ b/include/bots.h
@@ -14,9 +14,11 @@
#include "commands.h"
-extern CoreExport Anope::insensitive_map<BotInfo *> BotListByNick;
-extern CoreExport Anope::map<BotInfo *> BotListByUID;
typedef Anope::insensitive_map<BotInfo *> botinfo_map;
+typedef Anope::map<BotInfo *> botinfouid_map;
+
+extern serialize_checker<botinfo_map> BotListByNick;
+extern serialize_checker<botinfouid_map> BotListByUID;
/** Flags settable on a bot
*/
@@ -60,9 +62,9 @@ class CoreExport BotInfo : public User, public Flags<BotFlag, BI_END>, public Se
*/
virtual ~BotInfo();
- Anope::string serialize_name() const;
- serialized_data serialize();
- static void unserialize(serialized_data &);
+ const Anope::string serialize_name() const;
+ Serialize::Data serialize() const;
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &);
void GenerateUID();
@@ -90,7 +92,7 @@ class CoreExport BotInfo : public User, public Flags<BotFlag, BI_END>, public Se
/** Get the number of channels this bot is assigned to
*/
- unsigned GetChannelCount();
+ unsigned GetChannelCount() const;
/** Join this bot to a channel
* @param c The channel
diff --git a/include/channels.h b/include/channels.h
index 43da37f51..a738f5b8b 100644
--- a/include/channels.h
+++ b/include/channels.h
@@ -12,7 +12,7 @@
#include "anope.h"
#include "extensible.h"
#include "modes.h"
-
+#include "serialize.h"
typedef Anope::insensitive_map<Channel *> channel_map;
extern CoreExport channel_map ChannelList;
@@ -40,7 +40,7 @@ enum ChannelFlag
const Anope::string ChannelFlagString[] = { "CH_INABIT", "CH_PERSIST", "CH_SYNCING", "" };
-class CoreExport Channel : public Base, public Extensible, public Flags<ChannelFlag, 3>
+class CoreExport Channel : public virtual Base, public Extensible, public Flags<ChannelFlag, 3>
{
public:
typedef std::multimap<ChannelModeName, Anope::string> ModeList;
@@ -61,7 +61,7 @@ class CoreExport Channel : public Base, public Extensible, public Flags<ChannelF
~Channel();
Anope::string name; /* Channel name */
- ChannelInfo *ci; /* Corresponding ChannelInfo */
+ serialize_obj<ChannelInfo> ci; /* Corresponding ChannelInfo */
time_t creation_time; /* When channel was created */
/* List of users in the channel */
@@ -104,14 +104,14 @@ class CoreExport Channel : public Base, public Extensible, public Flags<ChannelF
* @param u The user
* @return A user container if found, else NULL
*/
- UserContainer *FindUser(User *u);
+ UserContainer *FindUser(const User *u) const;
/** Check if a user has a status on a channel
* @param u The user
* @param cms The status mode, or NULL to represent no status
* @return true or false
*/
- bool HasUserStatus(User *u, ChannelModeStatus *cms) const;
+ bool HasUserStatus(const User *u, ChannelModeStatus *cms) const;
/** Check if a user has a status on a channel
* Use the overloaded function for ChannelModeStatus* to check for no status
@@ -119,7 +119,7 @@ class CoreExport Channel : public Base, public Extensible, public Flags<ChannelF
* @param Name The Mode name, eg CMODE_OP, CMODE_VOICE
* @return true or false
*/
- bool HasUserStatus(User *u, ChannelModeName Name) const;
+ bool HasUserStatus(const User *u, ChannelModeName Name) const;
/** See if a channel has a mode
* @param Name The mode name
@@ -156,7 +156,7 @@ class CoreExport Channel : public Base, public Extensible, public Flags<ChannelF
* @param param Optional param arg for the mode
* @param EnforceMLock true if mlocks should be enforced, false to override mlock
*/
- void SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string &param = "", bool EnforceMLock = true);
+ void SetMode(const BotInfo *bi, ChannelMode *cm, const Anope::string &param = "", bool EnforceMLock = true);
/**
* Set a mode on a channel
@@ -165,7 +165,7 @@ class CoreExport Channel : public Base, public Extensible, public Flags<ChannelF
* @param param Optional param arg for the mode
* @param EnforceMLock true if mlocks should be enforced, false to override mlock
*/
- void SetMode(BotInfo *bi, ChannelModeName Name, const Anope::string &param = "", bool EnforceMLock = true);
+ void SetMode(const BotInfo *bi, ChannelModeName Name, const Anope::string &param = "", bool EnforceMLock = true);
/** Remove a mode from a channel
* @param bi The client setting the modes
@@ -173,7 +173,7 @@ class CoreExport Channel : public Base, public Extensible, public Flags<ChannelF
* @param param Optional param arg for the mode
* @param EnforceMLock true if mlocks should be enforced, false to override mlock
*/
- void RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string &param = "", bool EnforceMLock = true);
+ void RemoveMode(const BotInfo *bi, ChannelMode *cm, const Anope::string &param = "", bool EnforceMLock = true);
/**
* Remove a mode from a channel
@@ -182,7 +182,7 @@ class CoreExport Channel : public Base, public Extensible, public Flags<ChannelF
* @param param Optional param arg for the mode
* @param EnforceMLock true if mlocks should be enforced, false to override mlock
*/
- void RemoveMode(BotInfo *bi, ChannelModeName Name, const Anope::string &param = "", bool EnforceMLock = true);
+ void RemoveMode(const BotInfo *bi, ChannelModeName Name, const Anope::string &param = "", bool EnforceMLock = true);
/** Get a param from the channel
* @param Name The mode
@@ -196,7 +196,7 @@ class CoreExport Channel : public Base, public Extensible, public Flags<ChannelF
* @param EnforceMLock Should mlock be enforced on this mode change
* @param cmodes The modes to set
*/
- void SetModes(BotInfo *bi, bool EnforceMLock, const char *cmodes, ...);
+ void SetModes(const BotInfo *bi, bool EnforceMLock, const char *cmodes, ...);
/** Set a string of modes internally on a channel
* @param setter the setter (if it is a user)
@@ -255,6 +255,6 @@ extern void do_join(const Anope::string &source, const Anope::string &channels,
extern void do_kick(const Anope::string &source, const Anope::string &channel, const Anope::string &users, const Anope::string &reason);
extern void do_part(const Anope::string &source, const Anope::string &channels, const Anope::string &reason);
-extern void chan_set_correct_modes(User *user, Channel *c, int give_modes);
+extern void chan_set_correct_modes(const User *user, Channel *c, int give_modes);
#endif // CHANNELS_H
diff --git a/include/defs.h b/include/defs.h
index 098f48edd..db3c801ed 100644
--- a/include/defs.h
+++ b/include/defs.h
@@ -36,6 +36,7 @@ class NickAlias;
class NickCore;
class OperType;
class Regex;
+class Serializable;
class Server;
class ServerConfig;
class Socket;
diff --git a/include/extensible.h b/include/extensible.h
index 1416e1983..e0281c197 100644
--- a/include/extensible.h
+++ b/include/extensible.h
@@ -17,12 +17,6 @@ class CoreExport ExtensibleItem
virtual void OnDelete();
};
-class ExtensibleString : public Anope::string, public ExtensibleItem
-{
- public:
- ExtensibleString(const Anope::string &s) : Anope::string(s), ExtensibleItem() { }
-};
-
class CoreExport Extensible
{
private:
@@ -92,9 +86,9 @@ class CoreExport Extensible
* @param key The key parameter is an arbitary string which identifies the extension data
* @return The item found
*/
- template<typename T> T GetExt(const Anope::string &key)
+ template<typename T> T GetExt(const Anope::string &key) const
{
- extensible_map::iterator it = this->extension_items.find(key);
+ extensible_map::const_iterator it = this->extension_items.find(key);
if (it != this->extension_items.end())
return debug_cast<T>(it->second);
@@ -106,7 +100,7 @@ class CoreExport Extensible
* @param key The key parameter is an arbitary string which identifies the extension data
* @return True if the item was found.
*/
- bool HasExt(const Anope::string &key)
+ bool HasExt(const Anope::string &key) const
{
return this->extension_items.count(key) > 0;
}
@@ -116,9 +110,9 @@ class CoreExport Extensible
* @return This function writes a list of all extension items stored
* in this object by name into the given deque and returns void.
*/
- void GetExtList(std::deque<Anope::string> &list)
+ void GetExtList(std::deque<Anope::string> &list) const
{
- for (extensible_map::iterator it = extension_items.begin(), it_end = extension_items.end(); it != it_end; ++it)
+ for (extensible_map::const_iterator it = extension_items.begin(), it_end = extension_items.end(); it != it_end; ++it)
list.push_back(it->first);
}
};
diff --git a/include/extern.h b/include/extern.h
index aff091913..09d8e69ee 100644
--- a/include/extern.h
+++ b/include/extern.h
@@ -21,7 +21,7 @@
/**** actions.c ****/
E bool bad_password(User *u);
-E void common_unban(ChannelInfo *ci, User *u, bool full = false);
+E void common_unban(const ChannelInfo *ci, User *u, bool full = false);
/**** channels.c ****/
@@ -34,7 +34,7 @@ E void do_join(const Anope::string &source, const Anope::string &channels, const
E void do_kick(const Anope::string &source, const Anope::string &channel, const Anope::string &users, const Anope::string &reason);
E void do_part(const Anope::string &source, const Anope::string &channels, const Anope::string &reason);
-E void chan_set_correct_modes(User *user, Channel *c, int give_modes);
+E void chan_set_correct_modes(const User *user, Channel *c, int give_modes);
/**** encrypt.c ****/
@@ -57,7 +57,7 @@ E std::vector<Anope::string> domains;
E void InitLanguages();
E const char *translate(const char *string);
E const char *translate(User *u, const char *string);
-E const char *translate(NickCore *nc, const char *string);
+E const char *translate(const NickCore *nc, const char *string);
E const char *anope_gettext(const char *lang, const char *string);
/**** main.c ****/
@@ -115,9 +115,9 @@ E bool OnError(const Anope::string &, const std::vector<Anope::string> &);
E bool IsFile(const Anope::string &filename);
E time_t dotime(const Anope::string &s);
-E Anope::string duration(const time_t &seconds, NickCore *nc = NULL);
-E Anope::string expire_left(NickCore *nc, time_t expires);
-E Anope::string do_strftime(const time_t &t, NickCore *nc = NULL, bool short_output = false);
+E Anope::string duration(const time_t &seconds, const NickCore *nc = NULL);
+E Anope::string expire_left(const NickCore *nc, time_t expires);
+E Anope::string do_strftime(const time_t &t, const NickCore *nc = NULL, bool short_output = false);
E bool IsValidIdent(const Anope::string &ident);
E bool IsValidHost(const Anope::string &host);
@@ -137,7 +137,7 @@ E Anope::string normalizeBuffer(const Anope::string &);
/* Number of generic modes we support */
E unsigned GenericChannelModes, GenericUserModes;
-E std::multimap<ChannelModeName, ModeLock> def_mode_locks;
+E std::multimap<ChannelModeName, ModeLock *> def_mode_locks;
E void SetDefaultMLock(ServerConfig *config);
/**** process.c ****/
diff --git a/include/logger.h b/include/logger.h
index a6e3ca113..8cb54a754 100644
--- a/include/logger.h
+++ b/include/logger.h
@@ -48,11 +48,11 @@ struct LogFile
class CoreExport Log
{
public:
- BotInfo *bi;
- User *u;
+ const BotInfo *bi;
+ const User *u;
Command *c;
Channel *chan;
- ChannelInfo *ci;
+ const ChannelInfo *ci;
Server *s;
LogType Type;
Anope::string Category;
@@ -60,21 +60,21 @@ class CoreExport Log
std::stringstream buf;
- Log(LogType type = LOG_NORMAL, const Anope::string &category = "", BotInfo *bi = NULL);
+ Log(LogType type = LOG_NORMAL, const Anope::string &category = "", const BotInfo *bi = NULL);
/* LOG_COMMAND/OVERRIDE/ADMIN */
- Log(LogType type, User *u, Command *c, ChannelInfo *ci = NULL);
+ Log(LogType type, const User *u, Command *c, const ChannelInfo *ci = NULL);
/* LOG_CHANNEL */
- Log(User *u, Channel *c, const Anope::string &category = "");
+ Log(const User *u, Channel *c, const Anope::string &category = "");
/* LOG_USER */
- explicit Log(User *u, const Anope::string &category = "", BotInfo *bi = NULL);
+ explicit Log(const User *u, const Anope::string &category = "", const BotInfo *bi = NULL);
/* LOG_SERVER */
- explicit Log(Server *s, const Anope::string &category = "", BotInfo *bi = NULL);
+ explicit Log(Server *s, const Anope::string &category = "", const BotInfo *bi = NULL);
- explicit Log(BotInfo *b, const Anope::string &category = "");
+ explicit Log(const BotInfo *b, const Anope::string &category = "");
~Log();
diff --git a/include/mail.h b/include/mail.h
index 06cfe4b39..baef45589 100644
--- a/include/mail.h
+++ b/include/mail.h
@@ -16,9 +16,9 @@
#include "anope.h"
#include "threadengine.h"
+#include "serialize.h"
-
-extern CoreExport bool Mail(User *u, NickCore *nc, BotInfo *service, const Anope::string &subject, const Anope::string &message);
+extern CoreExport bool Mail(User *u, NickCore *nc, const BotInfo *service, const Anope::string &subject, const Anope::string &message);
extern CoreExport bool Mail(NickCore *nc, const Anope::string &subject, const Anope::string &message);
extern CoreExport bool MailValidate(const Anope::string &email);
diff --git a/include/memo.h b/include/memo.h
index 420def504..8ece00d6a 100644
--- a/include/memo.h
+++ b/include/memo.h
@@ -38,9 +38,9 @@ class CoreExport Memo : public Flags<MemoFlag>, public Serializable
public:
Memo();
- Anope::string serialize_name() const anope_override;
- serialized_data serialize() anope_override;
- static void unserialize(serialized_data &);
+ const Anope::string serialize_name() const anope_override;
+ Serialize::Data serialize() const anope_override;
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &);
Anope::string owner;
time_t time; /* When it was sent */
@@ -51,9 +51,11 @@ class CoreExport Memo : public Flags<MemoFlag>, public Serializable
struct CoreExport MemoInfo
{
int16_t memomax;
- std::vector<Memo *> memos;
+ serialize_checker<std::vector<Memo *> > memos;
std::vector<Anope::string> ignores;
+ MemoInfo();
+ Memo *GetMemo(unsigned index) const;
unsigned GetIndex(Memo *m) const;
void Del(unsigned index);
void Del(Memo *m);
diff --git a/include/modes.h b/include/modes.h
index c8ef794bd..0fb822b7e 100644
--- a/include/modes.h
+++ b/include/modes.h
@@ -113,7 +113,7 @@ enum ModeClass
/** This class is the basis of all modes in Anope
*/
-class CoreExport Mode : public Base
+class CoreExport Mode : public virtual Base
{
public:
/* Class of mode this is */
@@ -231,7 +231,7 @@ class CoreExport ChannelModeList : public ChannelMode
* @param e The entry to match against
* @return true on match
*/
- virtual bool Matches(User *u, const Entry *e) { return false; }
+ virtual bool Matches(const User *u, const Entry *e) { return false; }
/** Called when a mask is added to a channel
* @param chan The channel
@@ -359,7 +359,7 @@ class StackerInfo
/* The type of object this stacker info is for */
StackerType Type;
/* Bot this is sent from */
- BotInfo *bi;
+ const BotInfo *bi;
/** Add a mode to this object
* @param mode The mode
@@ -401,7 +401,7 @@ class CoreExport ModeManager
* @param Param A param, if there is one
* @param Type The type this is, user or channel
*/
- static void StackerAddInternal(BotInfo *bi, Base *Object, Mode *mode, bool Set, const Anope::string &Param, StackerType Type);
+ static void StackerAddInternal(const BotInfo *bi, Base *Object, Mode *mode, bool Set, const Anope::string &Param, StackerType Type);
public:
/* List of all modes Anope knows about */
@@ -469,7 +469,7 @@ class CoreExport ModeManager
* @param Set true for setting, false for removing
* @param Param The param, if there is one
*/
- static void StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const Anope::string &Param = "");
+ static void StackerAdd(const BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const Anope::string &Param = "");
/** Add a mode to the stacker to be set on a user
* @param bi The client to set the modes from
@@ -478,7 +478,7 @@ class CoreExport ModeManager
* @param Set true for setting, false for removing
* @param param The param, if there is one
*/
- static void StackerAdd(BotInfo *bi, User *u, UserMode *um, bool Set, const Anope::string &Param = "");
+ static void StackerAdd(const BotInfo *bi, User *u, UserMode *um, bool Set, const Anope::string &Param = "");
/** Process all of the modes in the stacker and send them to the IRCd to be set on channels/users
*/
@@ -531,7 +531,7 @@ class CoreExport Entry : public Flags<EntryType>
* @param full True to match against a users real host and IP
* @return true on match
*/
- bool Matches(User *u, bool full = false) const;
+ bool Matches(const User *u, bool full = false) const;
};
#endif // MODES_H
diff --git a/include/modules.h b/include/modules.h
index 78ab24486..d44cbf8d9 100644
--- a/include/modules.h
+++ b/include/modules.h
@@ -9,14 +9,16 @@
* Based on the original code of Services by Andy Church.
*/
+#include "serialize.h"
+
#ifndef MODULES_H
#define MODULES_H
-#include "extensible.h"
#include "base.h"
#include "modes.h"
#include "timers.h"
#include "logger.h"
+#include "extensible.h"
/** This definition is used as shorthand for the various classes
* and functions needed to make a module loadable by the OS.
@@ -381,18 +383,13 @@ class CoreExport Module : public Extensible
* @param ci The channel
* @param bw The badword
*/
- virtual void OnBadWordAdd(ChannelInfo *ci, BadWord *bw) { }
+ virtual void OnBadWordAdd(ChannelInfo *ci, const BadWord *bw) { }
/** Called before a badword is deleted from a channel
* @param ci The channel
* @param bw The badword
*/
- virtual void OnBadWordDel(ChannelInfo *ci, BadWord *bw) { }
-
- /** Called in findbot()
- * @param nick The nick being looked up
- */
- virtual void OnFindBot(const Anope::string &nick) { }
+ virtual void OnBadWordDel(ChannelInfo *ci, const BadWord *bw) { }
/** Called before a bot kicks a user
* @param bi The bot sending the kick
@@ -513,14 +510,14 @@ class CoreExport Module : public Extensible
* @param xlm The xline manager it was added to
* @return EVENT_CONTINUE to let other modules decide, EVENT_STOP to halt the command and not process it
*/
- virtual EventReturn OnAddXLine(User *u, XLine *x, XLineManager *xlm) { return EVENT_CONTINUE; }
+ virtual EventReturn OnAddXLine(User *u, const XLine *x, XLineManager *xlm) { return EVENT_CONTINUE; }
/** Called before a XLine is deleted
* @param u The user deleting the XLine
* @param x The XLine
* @param xlm The xline manager it was deleted from
*/
- virtual void OnDelXLine(User *u, XLine *x, XLineManager *xlm) { }
+ virtual void OnDelXLine(User *u, const XLine *x, XLineManager *xlm) { }
/** Called when a user is checked for whether they are a services oper
* @param u The user
@@ -632,14 +629,14 @@ class CoreExport Module : public Extensible
* @param ci The channel
* @param ak The akick
*/
- virtual void OnAkickAdd(User *u, ChannelInfo *ci, AutoKick *ak) { }
+ virtual void OnAkickAdd(User *u, ChannelInfo *ci, const AutoKick *ak) { }
/** Called before removing an akick from a channel
* @param u The user removing the akick
* @param ci The channel
* @param ak The akick
*/
- virtual void OnAkickDel(User *u, ChannelInfo *ci, AutoKick *ak) { }
+ virtual void OnAkickDel(User *u, ChannelInfo *ci, const AutoKick *ak) { }
/** Called after a user join a channel when we decide whether to kick them or not
* @param u The user
@@ -657,11 +654,6 @@ class CoreExport Module : public Extensible
*/
virtual void OnChanInfo(CommandSource &source, ChannelInfo *ci, InfoFormatter &info, bool ShowHidden) { }
- /** Called on cs_findchan()
- * @param chname The name being looked up
- */
- virtual void OnFindChan(const Anope::string &chname) { }
-
/** Checks if access has the channel privilege 'priv'.
* @param access THe access struct
* @param priv The privilege being checked for
@@ -776,18 +768,6 @@ class CoreExport Module : public Extensible
*/
virtual void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool ShowHidden) { }
- /** Called in findnick()
- * Useful to modify the na returned by findnick()
- * @param nick The nick being looked up
- */
- virtual void OnFindNick(const Anope::string &nick) { }
-
- /** Called in findcore()
- * Useful to modify the nc returned by findcore()
- * @param nick The nick being looked up
- */
- virtual void OnFindCore(const Anope::string &nick) { }
-
/** Check whether a users password is correct.
* @param u The user
* @param command The command the user is doing
@@ -837,14 +817,14 @@ class CoreExport Module : public Extensible
* @param mi The memo info
* @param m The memo
*/
- virtual void OnMemoDel(const NickCore *nc, MemoInfo *mi, Memo *m) { }
+ virtual void OnMemoDel(NickCore *nc, MemoInfo *mi, const Memo *m) { }
/** Called when a memo is deleted
* @param ci The channel of the memo being deleted
* @param mi The memo info
* @param m The memo
*/
- virtual void OnMemoDel(ChannelInfo *ci, MemoInfo *mi, Memo *m) { }
+ virtual void OnMemoDel(ChannelInfo *ci, MemoInfo *mi, const Memo *m) { }
/** Called when a mode is set on a channel
* @param c The channel
@@ -948,6 +928,12 @@ class CoreExport Module : public Extensible
* @return EVENT_STOP to stop checking modes
*/
virtual EventReturn OnCheckModes(Channel *c) { return EVENT_CONTINUE; }
+
+ virtual void OnSerializeCheck(SerializeType *) { }
+ virtual void OnSerializableConstruct(Serializable *) { }
+ virtual void OnSerializableDestruct(Serializable *) { }
+ virtual void OnSerializePtrAssign(Serializable *) { }
+ virtual void OnSerializableUpdate(Serializable *) { }
};
/** Implementation-specific flags which may be set in ModuleManager::Attach()
@@ -961,18 +947,18 @@ enum Implementation
I_OnDelNick, I_OnDelCore, I_OnChangeCoreDisplay,
I_OnNickClearAccess, I_OnNickAddAccess, I_OnNickEraseAccess,
I_OnNickClearCert, I_OnNickAddCert, I_OnNickEraseCert,
- I_OnNickInfo, I_OnFindNick, I_OnFindCore, I_OnCheckAuthentication,
+ I_OnNickInfo, I_OnCheckAuthentication,
I_OnNickUpdate,
/* ChanServ */
I_OnChanSuspend, I_OnChanDrop, I_OnPreChanExpire, I_OnChanExpire, I_OnAccessAdd,
I_OnAccessDel, I_OnAccessClear, I_OnLevelChange, I_OnChanRegistered, I_OnChanUnsuspend, I_OnCreateChan, I_OnDelChan, I_OnChannelCreate,
I_OnChannelDelete, I_OnAkickAdd, I_OnAkickDel, I_OnCheckKick, I_OnCheckModes,
- I_OnChanInfo, I_OnFindChan, I_OnCheckPriv, I_OnGroupCheckPriv,
+ I_OnChanInfo, I_OnCheckPriv, I_OnGroupCheckPriv,
/* BotServ */
I_OnBotJoin, I_OnBotKick, I_OnBotCreate, I_OnBotChange, I_OnBotDelete, I_OnBotAssign, I_OnBotUnAssign,
- I_OnUserKicked, I_OnBotFantasy, I_OnBotNoFantasyAccess, I_OnBotBan, I_OnBadWordAdd, I_OnBadWordDel, I_OnFindBot,
+ I_OnUserKicked, I_OnBotFantasy, I_OnBotNoFantasyAccess, I_OnBotBan, I_OnBadWordAdd, I_OnBadWordDel,
/* HostServ */
I_OnSetVhost, I_OnDeleteVhost,
@@ -1001,6 +987,8 @@ enum Implementation
I_OnEncrypt, I_OnDecrypt,
I_OnChannelModeSet, I_OnChannelModeUnset, I_OnUserModeSet, I_OnUserModeUnset, I_OnChannelModeAdd, I_OnUserModeAdd,
I_OnMLock, I_OnUnMLock, I_OnServerSync, I_OnUplinkSync, I_OnBotPrivmsg, I_OnPrivmsg, I_OnLog,
+
+ I_OnSerializeCheck, I_OnSerializableConstruct, I_OnSerializableDestruct, I_OnSerializePtrAssign, I_OnSerializableUpdate,
I_END
};
diff --git a/include/oper.h b/include/oper.h
index b3034b7c5..d388c4339 100644
--- a/include/oper.h
+++ b/include/oper.h
@@ -40,18 +40,18 @@ class CoreExport XLine : public Serializable
bool HasNickOrReal() const;
bool IsRegex() const;
- Anope::string serialize_name() const;
- serialized_data serialize();
- static void unserialize(serialized_data &data);
+ const Anope::string serialize_name() const anope_override;
+ Serialize::Data serialize() const anope_override;
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &data);
};
class CoreExport XLineManager : public Service
{
char type;
/* List of XLines in this XLineManager */
- std::vector<XLine *> XLines;
+ serialize_checker<std::vector<XLine *> > XLines;
/* Akills can have the same IDs, sometimes */
- static std::multimap<Anope::string, XLine *, ci::less> XLinesByUID;
+ static serialize_checker<std::multimap<Anope::string, XLine *, ci::less> > XLinesByUID;
public:
/* List of XLine managers we check users against in XLineManager::CheckAll */
static std::list<XLineManager *> XLineManagers;
@@ -118,7 +118,7 @@ class CoreExport XLineManager : public Service
* @param index The index
* @return The XLine, or NULL if the index is out of bounds
*/
- XLine *GetEntry(unsigned index);
+ XLine* GetEntry(unsigned index);
/** Clear the XLine vector
* Note: This does not remove the XLines from the IRCd
@@ -138,7 +138,7 @@ class CoreExport XLineManager : public Service
* @param mask The mask
* @return The XLine the user matches, or NULL
*/
- XLine *HasEntry(const Anope::string &mask);
+ XLine* HasEntry(const Anope::string &mask);
/** Check a user against all of the xlines in this XLineManager
* @param u The user
@@ -150,7 +150,7 @@ class CoreExport XLineManager : public Service
* @param u The user
* @param x The xline
*/
- virtual bool Check(User *u, XLine *x) = 0;
+ virtual bool Check(User *u, const XLine *x) = 0;
/** Called when a user matches a xline in this XLineManager
* @param u The user
@@ -161,7 +161,7 @@ class CoreExport XLineManager : public Service
/** Called when an XLine expires
* @param x The xline
*/
- virtual void OnExpire(XLine *x);
+ virtual void OnExpire(const XLine *x);
/** Called to send an XLine to the IRCd
* @param u The user, if we know it
diff --git a/include/protocol.h b/include/protocol.h
index edfc5bd53..b471ce23f 100644
--- a/include/protocol.h
+++ b/include/protocol.h
@@ -84,7 +84,7 @@ class CoreExport IRCDProto
virtual void SendQuit(const User *u, const char *fmt, ...);
virtual void SendPing(const Anope::string &servname, const Anope::string &who);
virtual void SendPong(const Anope::string &servname, const Anope::string &who);
- virtual void SendJoin(User *, Channel *, const ChannelStatus *) = 0;
+ virtual void SendJoin(const User *, Channel *, const ChannelStatus *) = 0;
virtual void SendSQLineDel(const XLine *x) { }
virtual void SendInvite(const BotInfo *bi, const Channel *c, const User *u);
virtual void SendPart(const BotInfo *bi, const Channel *chan, const char *fmt, ...);
diff --git a/include/regchannel.h b/include/regchannel.h
index cc7246097..255bcc200 100644
--- a/include/regchannel.h
+++ b/include/regchannel.h
@@ -15,9 +15,11 @@
#include "extensible.h"
#include "logger.h"
#include "modules.h"
+#include "serialize.h"
typedef Anope::insensitive_map<ChannelInfo *> registered_channel_map;
-extern CoreExport registered_channel_map RegisteredChannelList;
+
+extern serialize_checker<registered_channel_map> RegisteredChannelList;
/** Flags used for the ChannelInfo class
*/
@@ -90,9 +92,9 @@ struct CoreExport BadWord : Serializable
Anope::string word;
BadWordType type;
- Anope::string serialize_name() const anope_override;
- serialized_data serialize() anope_override;
- static void unserialize(serialized_data &);
+ const Anope::string serialize_name() const anope_override;
+ Serialize::Data serialize() const anope_override;
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &);
};
/** Flags for auto kick
@@ -110,25 +112,25 @@ class CoreExport AutoKick : public Flags<AutoKickFlag>, public Serializable
{
public:
AutoKick();
- ChannelInfo *ci;
+ serialize_obj<ChannelInfo> ci;
/* Only one of these can be in use */
Anope::string mask;
- NickCore *nc;
+ serialize_obj<NickCore> nc;
Anope::string reason;
Anope::string creator;
time_t addtime;
time_t last_used;
- Anope::string serialize_name() const anope_override;
- serialized_data serialize() anope_override;
- static void unserialize(serialized_data &);
+ const Anope::string serialize_name() const anope_override;
+ Serialize::Data serialize() const anope_override;
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &);
};
struct CoreExport ModeLock : Serializable
{
public:
- ChannelInfo *ci;
+ serialize_obj<ChannelInfo> ci;
bool set;
ChannelModeName name;
Anope::string param;
@@ -137,14 +139,14 @@ struct CoreExport ModeLock : Serializable
ModeLock(ChannelInfo *ch, bool s, ChannelModeName n, const Anope::string &p, const Anope::string &se = "", time_t c = Anope::CurTime);
- Anope::string serialize_name() const anope_override;
- serialized_data serialize() anope_override;
- static void unserialize(serialized_data &);
+ const Anope::string serialize_name() const anope_override;
+ Serialize::Data serialize() const anope_override;
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &);
};
struct CoreExport LogSetting : Serializable
{
- ChannelInfo *ci;
+ serialize_obj<ChannelInfo> ci;
/* Our service name of the command */
Anope::string service_name;
/* The name of the client the command is on */
@@ -155,24 +157,24 @@ struct CoreExport LogSetting : Serializable
Anope::string creator;
time_t created;
- Anope::string serialize_name() const anope_override;
- serialized_data serialize() anope_override;
- static void unserialize(serialized_data &);
+ const Anope::string serialize_name() const anope_override;
+ Serialize::Data serialize() const anope_override;
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &);
};
class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag, CI_END>, public Serializable
{
private:
- NickCore *founder; /* Channel founder */
- std::vector<ChanAccess *> access; /* List of authorized users */
- std::vector<AutoKick *> akick; /* List of users to kickban */
- std::vector<BadWord *> badwords; /* List of badwords */
+ serialize_obj<NickCore> founder; /* Channel founder */
+ serialize_checker<std::vector<ChanAccess *> > access; /* List of authorized users */
+ serialize_checker<std::vector<AutoKick *> > akick; /* List of users to kickban */
+ serialize_checker<std::vector<BadWord *> > badwords; /* List of badwords */
std::map<Anope::string, int16_t> levels;
public:
- typedef std::multimap<ChannelModeName, ModeLock> ModeList;
- ModeList mode_locks;
- std::vector<LogSetting> log_settings;
+ typedef std::multimap<ChannelModeName, ModeLock *> ModeList;
+ serialize_checker<ModeList> mode_locks;
+ serialize_checker<std::vector<LogSetting *> > log_settings;
/** Default constructor
* @param chname The channel name
@@ -182,14 +184,14 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
/** Copy constructor
* @param ci The ChannelInfo to copy settings to
*/
- ChannelInfo(ChannelInfo &ci);
+ ChannelInfo(const ChannelInfo &ci);
/** Default destructor
*/
~ChannelInfo();
Anope::string name; /* Channel name */
- NickCore *successor; /* Who gets the channel if the founder nick is dropped or expires */
+ serialize_obj<NickCore> successor; /* Who gets the channel if the founder nick is dropped or expires */
Anope::string desc;
time_t time_registered;
@@ -206,7 +208,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
Channel *c; /* Pointer to channel record (if channel is currently in use) */
/* For BotServ */
- BotInfo *bi; /* Bot used on this channel */
+ serialize_obj<BotInfo> bi; /* Bot used on this channel */
Flags<BotServFlag> botflags;
int16_t ttb[TTB_SIZE]; /* Times to ban for each kicker */
@@ -214,9 +216,9 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
int16_t floodlines, floodsecs; /* For FLOOD kicker */
int16_t repeattimes; /* For REPEAT kicker */
- Anope::string serialize_name() const anope_override;
- serialized_data serialize() anope_override;
- static void unserialize(serialized_data &);
+ const Anope::string serialize_name() const anope_override;
+ Serialize::Data serialize() const anope_override;
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &);
/** Change the founder of the channek
* @params nc The new founder
@@ -231,7 +233,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
/** Find which bot should send mode/topic/etc changes for this channel
* @return The bot
*/
- BotInfo *WhoSends();
+ BotInfo *WhoSends() const;
/** Add an entry to the channel access list
* @param access The entry
@@ -245,13 +247,13 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
*
* Retrieves an entry from the access list that matches the given index.
*/
- ChanAccess *GetAccess(unsigned index);
+ ChanAccess *GetAccess(unsigned index) const;
/** 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).
*/
- AccessGroup AccessFor(User *u);
- AccessGroup AccessFor(NickCore *nc);
+ AccessGroup AccessFor(const User *u);
+ AccessGroup AccessFor(const NickCore *nc);
/** Get the size of the accss vector for this channel
* @return The access vector size
@@ -272,7 +274,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
*
* Clears the memory used by the given access entry and removes it from the vector.
*/
- void EraseAccess(ChanAccess *taccess);
+ void EraseAccess(const ChanAccess *taccess);
/** Clear the entire channel access list
*
@@ -287,7 +289,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
* @param t The time the akick was added, defaults to now
* @param lu The time the akick was last used, defaults to never
*/
- AutoKick *AddAkick(const Anope::string &user, NickCore *akicknc, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0);
+ AutoKick* AddAkick(const Anope::string &user, NickCore *akicknc, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0);
/** Add an akick entry to the channel by reason
* @param user The user who added the akick
@@ -296,13 +298,13 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
* @param t The time the akick was added, defaults to now
* @param lu The time the akick was last used, defaults to never
*/
- AutoKick *AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0);
+ AutoKick* AddAkick(const Anope::string &user, const Anope::string &mask, const Anope::string &reason, time_t t = Anope::CurTime, time_t lu = 0);
/** Get an entry from the channel akick list
* @param index The index in the akick vector
* @return The akick structure, or NULL if not found
*/
- AutoKick *GetAkick(unsigned index);
+ AutoKick* GetAkick(unsigned index) const;
/** Get the size of the akick vector for this channel
* @return The akick vector size
@@ -323,13 +325,13 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
* @param type The type (SINGLE START END)
* @return The badword
*/
- BadWord *AddBadWord(const Anope::string &word, BadWordType type);
+ BadWord* AddBadWord(const Anope::string &word, BadWordType type);
/** Get a badword structure by index
* @param index The index
* @return The badword
*/
- BadWord *GetBadWord(unsigned index);
+ BadWord* GetBadWord(unsigned index) const;
/** Get how many badwords are on this channel
* @return The number of badwords in the vector
@@ -378,7 +380,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
/** Get all of the mlocks for this channel
* @return The mlocks
*/
- const std::multimap<ChannelModeName, ModeLock> &GetMLock() const;
+ const ModeList &GetMLock() const;
/** Get a list of modes on a channel
* @param Name The mode name to get a list of
@@ -391,7 +393,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
* @param An optional param to match with
* @return The MLock, if any
*/
- ModeLock *GetMLock(ChannelModeName mname, const Anope::string &param = "");
+ const ModeLock *GetMLock(ChannelModeName mname, const Anope::string &param = "");
/** Get the current mode locks as a string
* @param complete True to show mlock parameters aswell
@@ -421,7 +423,7 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
* @return the level
* @throws CoreException if priv is not a valid privilege
*/
- int16_t GetLevel(const Anope::string &priv);
+ int16_t GetLevel(const Anope::string &priv) const;
/** Set the level for a privilege
* @param priv The privilege priv
@@ -440,8 +442,8 @@ class CoreExport ChannelInfo : public Extensible, public Flags<ChannelInfoFlag,
};
extern ChannelInfo *cs_findchan(const Anope::string &chan);
-extern bool IsFounder(User *user, ChannelInfo *ci);
+extern bool IsFounder(const User *user, const ChannelInfo *ci);
extern void update_cs_lastseen(User *user, ChannelInfo *ci);
-extern int get_idealban(ChannelInfo *ci, User *u, Anope::string &ret);
+extern int get_idealban(const ChannelInfo *ci, User *u, Anope::string &ret);
#endif // REGCHANNEL_H
diff --git a/include/serialize.h b/include/serialize.h
index 891af726f..82287d5ab 100644
--- a/include/serialize.h
+++ b/include/serialize.h
@@ -16,6 +16,7 @@
#include <sstream>
#include "anope.h"
+#include "base.h"
namespace Serialize
{
@@ -30,13 +31,13 @@ class stringstream : public std::stringstream
{
private:
Serialize::DataType type;
- bool key;
unsigned _max;
public:
stringstream();
stringstream(const stringstream &ss);
Anope::string astr() const;
+
template<typename T> std::istream &operator>>(T &val)
{
std::istringstream is(this->str());
@@ -44,23 +45,31 @@ class stringstream : public std::stringstream
return *this;
}
std::istream &operator>>(Anope::string &val);
+
+ bool operator==(const stringstream &other) const;
+ bool operator!=(const stringstream &other) const;
+
stringstream &setType(Serialize::DataType t);
Serialize::DataType getType() const;
- stringstream &setKey();
- bool getKey() const;
stringstream &setMax(unsigned m);
unsigned getMax() const;
};
+namespace Serialize
+{
+ typedef std::map<Anope::string, stringstream> Data;
+}
extern void RegisterTypes();
-class CoreExport Serializable
+class CoreExport Serializable : public virtual Base
{
private:
- static std::list<Serializable *> *serizliable_items;
+ static std::list<Serializable *> *serializable_items;
+ private:
std::list<Serializable *>::iterator s_iter;
+ Serialize::Data last_commit;
protected:
Serializable();
@@ -71,35 +80,195 @@ class CoreExport Serializable
Serializable &operator=(const Serializable &);
public:
- typedef std::map<Anope::string, stringstream> serialized_data;
+ unsigned int id;
+
+ void destroy();
+
+ void QueueUpdate();
- virtual Anope::string serialize_name() const = 0;
- virtual serialized_data serialize() = 0;
+ bool IsCached();
+ void UpdateCache();
+
+ virtual const Anope::string serialize_name() const = 0;
+ virtual Serialize::Data serialize() const = 0;
static const std::list<Serializable *> &GetItems();
};
class CoreExport SerializeType
{
- typedef void (*unserialize_func)(Serializable::serialized_data &);
+ typedef Serializable* (*unserialize_func)(Serializable *obj, Serialize::Data &);
static std::vector<Anope::string> type_order;
static Anope::map<SerializeType *> types;
Anope::string name;
unserialize_func unserialize;
+ time_t timestamp;
public:
+ std::map<unsigned int, Serializable *> objects;
+
SerializeType(const Anope::string &n, unserialize_func f);
~SerializeType();
const Anope::string &GetName();
- void Create(Serializable::serialized_data &data);
+ Serializable *Unserialize(Serializable *obj, Serialize::Data &data);
+
+ void Check();
+
+ time_t GetTimestamp() const;
+ void UpdateTimestamp();
static SerializeType *Find(const Anope::string &name);
static const std::vector<Anope::string> &GetTypeOrder();
};
+template<typename T>
+class serialize_checker
+{
+ Anope::string name;
+ T obj;
+
+ public:
+ serialize_checker(const Anope::string &n) : name(n) { }
+
+ inline const T* operator->() const
+ {
+ static SerializeType *type = SerializeType::Find(this->name);
+ if (type)
+ type->Check();
+ return &this->obj;
+ }
+ inline T* operator->()
+ {
+ static SerializeType *type = SerializeType::Find(this->name);
+ if (type)
+ type->Check();
+ return &this->obj;
+ }
+
+ inline const T& operator*() const
+ {
+ static SerializeType *type = SerializeType::Find(this->name);
+ if (type)
+ type->Check();
+ return this->obj;
+ }
+ inline T& operator*()
+ {
+ static SerializeType *type = SerializeType::Find(this->name);
+ if (type)
+ type->Check();
+ return this->obj;
+ }
+
+ inline operator const T&() const
+ {
+ static SerializeType *type = SerializeType::Find(this->name);
+ if (type)
+ type->Check();
+ return this->obj;
+ }
+ inline operator T&()
+ {
+ static SerializeType *type = SerializeType::Find(this->name);
+ if (type)
+ type->Check();
+ return this->obj;
+ }
+};
+
+#include "modules.h"
+
+template<typename T>
+class serialize_obj : public dynamic_reference_base
+{
+ protected:
+ T *ref;
+
+ public:
+ serialize_obj() : ref(NULL)
+ {
+ }
+
+ serialize_obj(T *obj) : ref(obj)
+ {
+ if (obj)
+ obj->AddReference(this);
+ }
+
+ serialize_obj(const serialize_obj<T> &other) : ref(other.ref)
+ {
+ if (*this)
+ this->ref->AddReference(this);
+ }
+
+ ~serialize_obj()
+ {
+ if (*this)
+ this->ref->DelReference(this);
+ }
+
+ virtual operator bool() const
+ {
+ if (!this->invalid)
+ return this->ref != NULL;
+ return NULL;
+ }
+
+ inline void operator=(T *newref)
+ {
+ if (*this)
+ this->ref->DelReference(this);
+
+ this->ref = newref;
+ this->invalid = false;
+
+ if (newref)
+ this->ref->AddReference(this);
+ }
+
+ virtual inline operator T*() const
+ {
+ if (!this->invalid)
+ {
+ if (this->ref)
+ {
+ FOREACH_MOD(I_OnSerializePtrAssign, OnSerializePtrAssign(this->ref));
+ }
+ return this->ref;
+ }
+ return NULL;
+ }
+
+ virtual inline T* operator*() const
+ {
+ if (!this->invalid)
+ {
+ if (this->ref)
+ {
+ FOREACH_MOD(I_OnSerializePtrAssign, OnSerializePtrAssign(this->ref));
+ }
+ return this->ref;
+ }
+ return NULL;
+ }
+
+ virtual inline T* operator->() const
+ {
+ if (!this->invalid)
+ {
+ if (this->ref)
+ {
+ FOREACH_MOD(I_OnSerializePtrAssign, OnSerializePtrAssign(this->ref));
+ }
+ return this->ref;
+ }
+ return NULL;
+ }
+};
+
#endif // SERIALIZE_H
diff --git a/include/servers.h b/include/servers.h
index c2e56dbde..7b85a182a 100644
--- a/include/servers.h
+++ b/include/servers.h
@@ -137,7 +137,7 @@ class CoreExport Server : public Flags<ServerFlag>
* @param source The source of the message
* @param message The message
*/
- void Notice(BotInfo *source, const Anope::string &message);
+ void Notice(const BotInfo *source, const Anope::string &message);
/** Find a server
* @param name The name or SID/numeric
diff --git a/include/service.h b/include/service.h
index f9e36ff40..949e7b1a1 100644
--- a/include/service.h
+++ b/include/service.h
@@ -15,7 +15,7 @@
#include "anope.h"
#include "modules.h"
-class CoreExport Service : public Base
+class CoreExport Service : public virtual Base
{
static Anope::map<Anope::map<Service *> > services;
public:
@@ -89,7 +89,7 @@ class service_reference : public dynamic_reference<T>
this->name = n;
}
- operator bool()
+ operator bool() anope_override
{
if (this->invalid)
{
diff --git a/include/users.h b/include/users.h
index a6510235f..e69c9d30b 100644
--- a/include/users.h
+++ b/include/users.h
@@ -11,6 +11,7 @@
#include "anope.h"
#include "modes.h"
#include "extensible.h"
+#include "serialize.h"
extern CoreExport Anope::insensitive_map<User *> UserListByNick;
extern CoreExport Anope::map<User *> UserListByUID;
@@ -36,7 +37,7 @@ typedef std::list<ChannelContainer *> UChannelList;
/* Online user and channel data. */
-class CoreExport User : public Base, public Extensible
+class CoreExport User : public virtual Base, public Extensible
{
protected:
Anope::string vident;
@@ -45,7 +46,7 @@ class CoreExport User : public Base, public Extensible
bool OnAccess; /* If the user is on the access list of the nick theyre on */
Flags<UserModeName, UMODE_END * 2> modes; /* Bitset of mode names the user has set on them */
std::map<UserModeName, Anope::string> Params; /* Map of user modes and the params this user has */
- NickCore *nc; /* NickCore account the user is currently loggged in as */
+ serialize_obj<NickCore> nc; /* NickCore account the user is currently loggged in as */
public: // XXX: exposing a tiny bit too much
Anope::string nick; /* User's current nick */
@@ -159,8 +160,8 @@ class CoreExport User : public Base, public Extensible
* @param fmt Format of the Message
* @param ... any number of parameters
*/
- void SendMessage(BotInfo *source, const char *fmt, ...);
- virtual void SendMessage(BotInfo *source, Anope::string msg);
+ void SendMessage(const BotInfo *source, const char *fmt, ...);
+ virtual void SendMessage(const BotInfo *source, Anope::string msg);
/** Collide a nick
* See the comment in users.cpp
@@ -187,19 +188,19 @@ class CoreExport User : public Base, public Extensible
/** Get the account the user is logged in using
* @return The account or NULL
*/
- virtual NickCore *Account();
+ virtual NickCore *Account() const;
/** Check if the user is identified for their nick
* @param CheckNick True to check if the user is identified to the nickname they are on too
* @return true or false
*/
- virtual bool IsIdentified(bool CheckNick = false);
+ virtual bool IsIdentified(bool CheckNick = false) const;
/** Check if the user is recognized for their nick (on the nicks access list)
* @param CheckSecure Only returns true if the user has secure off
* @return true or false
*/
- virtual bool IsRecognized(bool CheckSecure = true);
+ virtual bool IsRecognized(bool CheckSecure = true) const;
/** Check if the user is a services oper
* @return true if they are an oper
@@ -244,32 +245,32 @@ class CoreExport User : public Base, public Extensible
* @param um The user mode
* @param Param Optional param for the mode
*/
- void SetMode(BotInfo *bi, UserMode *um, const Anope::string &Param = "");
+ void SetMode(const BotInfo *bi, UserMode *um, const Anope::string &Param = "");
/** Set a mode on the user
* @param bi The client setting the mode
* @param Name The mode name
* @param Param Optional param for the mode
*/
- void SetMode(BotInfo *bi, UserModeName Name, const Anope::string &Param = "");
+ void SetMode(const BotInfo *bi, UserModeName Name, const Anope::string &Param = "");
/** Remove a mode on the user
* @param bi The client setting the mode
* @param um The user mode
*/
- void RemoveMode(BotInfo *bi, UserMode *um);
+ void RemoveMode(const BotInfo *bi, UserMode *um);
/** Remove a mode from the user
* @param bi The client setting the mode
* @param Name The mode name
*/
- void RemoveMode(BotInfo *bi, UserModeName Name);
+ void RemoveMode(const BotInfo *bi, UserModeName Name);
/** Set a string of modes on a user
* @param bi The client setting the modes
* @param umodes The modes
*/
- void SetModes(BotInfo *bi, const char *umodes, ...);
+ void SetModes(const BotInfo *bi, const char *umodes, ...);
/** Set a string of modes on a user internally
* @param umodes The modes
@@ -287,7 +288,7 @@ class CoreExport User : public Base, public Extensible
* @param c The channel
* @return The channel container, or NULL
*/
- ChannelContainer *FindChannel(const Channel *c);
+ ChannelContainer *FindChannel(const Channel *c) const;
/** Check if the user is protected from kicks and negative mode changes
* @return true or false
diff --git a/modules/commands/bs_badwords.cpp b/modules/commands/bs_badwords.cpp
index bb7a073f1..eaf00d347 100644
--- a/modules/commands/bs_badwords.cpp
+++ b/modules/commands/bs_badwords.cpp
@@ -81,7 +81,7 @@ class CommandBSBadwords : public Command
if (!Number || Number > ci->GetBadWordCount())
return;
- BadWord *bw = ci->GetBadWord(Number - 1);
+ const BadWord *bw = ci->GetBadWord(Number - 1);
ListFormatter::ListEntry entry;
entry["Number"] = stringify(Number);
entry["Word"] = bw->word;
@@ -96,7 +96,7 @@ class CommandBSBadwords : public Command
{
for (unsigned i = 0, end = ci->GetBadWordCount(); i < end; ++i)
{
- BadWord *bw = ci->GetBadWord(i);
+ const BadWord *bw = ci->GetBadWord(i);
if (!word.empty() && !Anope::Match(bw->word, word))
continue;
@@ -154,7 +154,7 @@ class CommandBSBadwords : public Command
for (unsigned i = 0, end = ci->GetBadWordCount(); i < end; ++i)
{
- BadWord *bw = ci->GetBadWord(i);
+ const BadWord *bw = ci->GetBadWord(i);
if (!bw->word.empty() && ((Config->BSCaseSensitive && realword.equals_cs(bw->word)) || (!Config->BSCaseSensitive && realword.equals_ci(bw->word))))
{
@@ -183,7 +183,7 @@ class CommandBSBadwords : public Command
else
{
unsigned i, end;
- BadWord *badword;
+ const BadWord *badword;
for (i = 0, end = ci->GetBadWordCount(); i < end; ++i)
{
diff --git a/modules/commands/bs_bot.cpp b/modules/commands/bs_bot.cpp
index 526cd922c..b1f22909f 100644
--- a/modules/commands/bs_bot.cpp
+++ b/modules/commands/bs_bot.cpp
@@ -22,7 +22,6 @@ class CommandBSBot : public Command
const Anope::string &user = params[2];
const Anope::string &host = params[3];
const Anope::string &real = params[4];
- BotInfo *bi;
if (findbot(nick))
{
@@ -93,7 +92,7 @@ class CommandBSBot : public Command
return;
}
- bi = new BotInfo(nick, user, host, real);
+ BotInfo *bi = new BotInfo(nick, user, host, real);
Log(LOG_ADMIN, source.u, this) << "ADD " << bi->GetMask() << " " << bi->realname;
@@ -110,7 +109,6 @@ class CommandBSBot : public Command
const Anope::string &user = params.size() > 3 ? params[3] : "";
const Anope::string &host = params.size() > 4 ? params[4] : "";
const Anope::string &real = params.size() > 5 ? params[5] : "";
- BotInfo *bi;
if (oldnick.empty() || nick.empty())
{
@@ -118,7 +116,8 @@ class CommandBSBot : public Command
return;
}
- if (!(bi = findbot(oldnick)))
+ BotInfo *bi = findbot(oldnick);
+ if (!bi)
{
source.Reply(BOT_DOES_NOT_EXIST, oldnick.c_str());
return;
@@ -263,7 +262,6 @@ class CommandBSBot : public Command
void DoDel(CommandSource &source, const std::vector<Anope::string> &params)
{
const Anope::string &nick = params[1];
- BotInfo *bi;
if (nick.empty())
{
@@ -271,7 +269,8 @@ class CommandBSBot : public Command
return;
}
- if (!(bi = findbot(nick)))
+ BotInfo *bi = findbot(nick);
+ if (!bi)
{
source.Reply(BOT_DOES_NOT_EXIST, nick.c_str());
return;
@@ -288,7 +287,7 @@ class CommandBSBot : public Command
Log(LOG_ADMIN, source.u, this) << "DEL " << bi->nick;
source.Reply(_("Bot \002%s\002 has been deleted."), nick.c_str());
- delete bi;
+ bi->destroy();
return;
}
public:
diff --git a/modules/commands/bs_botlist.cpp b/modules/commands/bs_botlist.cpp
index ed50371fc..68fb7bdfa 100644
--- a/modules/commands/bs_botlist.cpp
+++ b/modules/commands/bs_botlist.cpp
@@ -30,7 +30,7 @@ class CommandBSBotList : public Command
list.addColumn("Nick").addColumn("Mask");
- for (Anope::insensitive_map<BotInfo *>::const_iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it)
+ for (Anope::insensitive_map<BotInfo *>::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
{
BotInfo *bi = it->second;
diff --git a/modules/commands/bs_info.cpp b/modules/commands/bs_info.cpp
index ed36818b3..251bd84df 100644
--- a/modules/commands/bs_info.cpp
+++ b/modules/commands/bs_info.cpp
@@ -17,12 +17,12 @@
class CommandBSInfo : public Command
{
private:
- void send_bot_channels(std::vector<Anope::string> &buffers, BotInfo *bi)
+ void send_bot_channels(std::vector<Anope::string> &buffers, const BotInfo *bi)
{
Anope::string buf;
- for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it)
+ for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it)
{
- ChannelInfo *ci = it->second;
+ const ChannelInfo *ci = it->second;
if (ci->bi == bi)
{
@@ -38,7 +38,7 @@ class CommandBSInfo : public Command
buffers.push_back(buf);
}
- void CheckOptStr(Anope::string &buf, BotServFlag flag, const char *option, Flags<BotServFlag> &flags, NickCore *nc)
+ void CheckOptStr(Anope::string &buf, BotServFlag flag, const char *option, Flags<BotServFlag> &flags, const NickCore *nc)
{
if (flags.HasFlag(flag))
{
@@ -60,7 +60,7 @@ class CommandBSInfo : public Command
const Anope::string &query = params[0];
User *u = source.u;
- BotInfo *bi = findbot(query);
+ const BotInfo *bi = findbot(query);
ChannelInfo *ci;
InfoFormatter info(u);
diff --git a/modules/commands/bs_kick.cpp b/modules/commands/bs_kick.cpp
index 42b43e7a1..819c5af74 100644
--- a/modules/commands/bs_kick.cpp
+++ b/modules/commands/bs_kick.cpp
@@ -900,7 +900,7 @@ class BSKick : public Module
for (unsigned i = 0, end = ci->GetBadWordCount(); i < end; ++i)
{
- BadWord *bw = ci->GetBadWord(i);
+ const BadWord *bw = ci->GetBadWord(i);
if (bw->type == BW_ANY && ((Config->BSCaseSensitive && nbuf.find(bw->word) != Anope::string::npos) || (!Config->BSCaseSensitive && nbuf.find_ci(bw->word) != Anope::string::npos)))
mustkick = true;
@@ -1012,7 +1012,7 @@ class BSKick : public Module
Channel *chan = (*it)->chan;
++it;
- if (chan->ci != NULL && chan->ci->botflags.HasFlag(BS_KICK_AMSGS) && !chan->ci->AccessFor(u).HasPriv("NOKICK"))
+ if (chan->ci && chan->ci->botflags.HasFlag(BS_KICK_AMSGS) && !chan->ci->AccessFor(u).HasPriv("NOKICK"))
{
check_ban(chan->ci, u, TTB_AMSGS);
bot_kick(chan->ci, u, _("Don't use AMSGs!"));
diff --git a/modules/commands/cs_access.cpp b/modules/commands/cs_access.cpp
index aa32d29ef..a37446df2 100644
--- a/modules/commands/cs_access.cpp
+++ b/modules/commands/cs_access.cpp
@@ -15,7 +15,7 @@
static std::map<Anope::string, int16_t, ci::less> defaultLevels;
-static void reset_levels(ChannelInfo *ci)
+static inline void reset_levels(ChannelInfo *ci)
{
ci->ClearLevels();
for (std::map<Anope::string, int16_t, ci::less>::iterator it = defaultLevels.begin(), it_end = defaultLevels.end(); it != it_end; ++it)
@@ -36,7 +36,7 @@ class AccessChanAccess : public ChanAccess
return this->ci->GetLevel(name) != ACCESS_INVALID && this->level >= this->ci->GetLevel(name);
}
- Anope::string Serialize()
+ Anope::string Serialize() const
{
return stringify(this->level);
}
@@ -46,11 +46,11 @@ class AccessChanAccess : public ChanAccess
this->level = convertTo<int>(data);
}
- static int DetermineLevel(ChanAccess *access)
+ static int DetermineLevel(const ChanAccess *access)
{
if (access->provider->name == "access/access")
{
- AccessChanAccess *aaccess = debug_cast<AccessChanAccess *>(access);
+ const AccessChanAccess *aaccess = debug_cast<const AccessChanAccess *>(access);
return aaccess->level;
}
else
@@ -108,7 +108,7 @@ class CommandCSAccess : public Command
}
AccessGroup u_access = ci->AccessFor(u);
- ChanAccess *highest = u_access.Highest();
+ const ChanAccess *highest = u_access.Highest();
int u_level = (highest ? AccessChanAccess::DetermineLevel(highest) : 0);
if (level >= u_level && !u_access.Founder && !u->HasPriv("chanserv/access/modify"))
{
@@ -123,7 +123,7 @@ class CommandCSAccess : public Command
bool override = !ci->AccessFor(u).HasPriv("ACCESS_CHANGE") || (level >= u_level && !u_access.Founder);
- if (mask.find_first_of("!*@") == Anope::string::npos && findnick(mask) == NULL)
+ if (mask.find_first_of("!*@") == Anope::string::npos && !findnick(mask))
{
User *targ = finduser(mask);
if (targ != NULL)
@@ -137,7 +137,7 @@ class CommandCSAccess : public Command
for (unsigned i = ci->GetAccessCount(); i > 0; --i)
{
- ChanAccess *access = ci->GetAccess(i - 1);
+ const ChanAccess *access = ci->GetAccess(i - 1);
if (mask.equals_ci(access->mask))
{
/* Don't allow lowering from a level >= u_level */
@@ -230,7 +230,7 @@ class CommandCSAccess : public Command
ChanAccess *access = ci->GetAccess(Number - 1);
AccessGroup u_access = ci->AccessFor(user);
- ChanAccess *u_highest = u_access.Highest();
+ const ChanAccess *u_highest = u_access.Highest();
if ((u_highest ? AccessChanAccess::DetermineLevel(u_highest) : 0) <= AccessChanAccess::DetermineLevel(access) && !u_access.Founder && !this->override && !access->mask.equals_ci(user->Account()->display))
{
@@ -255,7 +255,7 @@ class CommandCSAccess : public Command
else
{
AccessGroup u_access = ci->AccessFor(u);
- ChanAccess *highest = u_access.Highest();
+ const ChanAccess *highest = u_access.Highest();
int u_level = (highest ? AccessChanAccess::DetermineLevel(highest) : 0);
for (unsigned i = ci->GetAccessCount(); i > 0; --i)
@@ -308,7 +308,7 @@ class CommandCSAccess : public Command
if (!number || number > ci->GetAccessCount())
return;
- ChanAccess *access = ci->GetAccess(number - 1);
+ const ChanAccess *access = ci->GetAccess(number - 1);
Anope::string timebuf;
if (ci->c)
@@ -339,7 +339,7 @@ class CommandCSAccess : public Command
{
for (unsigned i = 0, end = ci->GetAccessCount(); i < end; ++i)
{
- ChanAccess *access = ci->GetAccess(i);
+ const ChanAccess *access = ci->GetAccess(i);
if (!nick.empty() && !Anope::Match(access->mask, nick))
continue;
@@ -470,7 +470,7 @@ class CommandCSAccess : public Command
has_access = true;
else if (is_del)
{
- NickAlias *na = findnick(nick);
+ const NickAlias *na = findnick(nick);
if (na && na->nc == u->Account())
has_access = true;
}
diff --git a/modules/commands/cs_akick.cpp b/modules/commands/cs_akick.cpp
index beaa8ffd3..107f97584 100644
--- a/modules/commands/cs_akick.cpp
+++ b/modules/commands/cs_akick.cpp
@@ -54,9 +54,9 @@ class CommandCSAKick : public Command
Anope::string mask = params[2];
Anope::string reason = params.size() > 3 ? params[3] : "";
- NickAlias *na = findnick(mask);
+ const NickAlias *na = findnick(mask);
NickCore *nc = NULL;
- AutoKick *akick;
+ const AutoKick *akick;
if (!na)
{
@@ -113,7 +113,7 @@ class CommandCSAKick : public Command
/* Match against the lastusermask of all nickalias's with equal
* or higher access. - Viper */
- for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; ++it)
+ for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it)
{
na = it->second;
@@ -166,7 +166,6 @@ class CommandCSAKick : public Command
User *u = source.u;
const Anope::string &mask = params[2];
- AutoKick *akick;
unsigned i, end;
if (!ci->GetAkickCount())
@@ -218,12 +217,12 @@ class CommandCSAKick : public Command
}
else
{
- NickAlias *na = findnick(mask);
- NickCore *nc = na ? na->nc : NULL;
+ const NickAlias *na = findnick(mask);
+ const NickCore *nc = na ? *na->nc : NULL;
for (i = 0, end = ci->GetAkickCount(); i < end; ++i)
{
- akick = ci->GetAkick(i);
+ const AutoKick *akick = ci->GetAkick(i);
if ((akick->HasFlag(AK_ISNICK) && akick->nc == nc) || (!akick->HasFlag(AK_ISNICK) && mask.equals_ci(akick->mask)))
break;
@@ -267,7 +266,7 @@ class CommandCSAKick : public Command
if (!number || number > ci->GetAkickCount())
return;
- AutoKick *akick = ci->GetAkick(number - 1);
+ const AutoKick *akick = ci->GetAkick(number - 1);
Anope::string timebuf, lastused;
if (akick->addtime)
@@ -296,7 +295,7 @@ class CommandCSAKick : public Command
{
for (unsigned i = 0, end = ci->GetAkickCount(); i < end; ++i)
{
- AutoKick *akick = ci->GetAkick(i);
+ const AutoKick *akick = ci->GetAkick(i);
if (!mask.empty())
{
diff --git a/modules/commands/cs_clone.cpp b/modules/commands/cs_clone.cpp
index 1676c70f6..be6907b81 100644
--- a/modules/commands/cs_clone.cpp
+++ b/modules/commands/cs_clone.cpp
@@ -41,6 +41,7 @@ public:
source.Reply(ACCESS_DENIED);
return;
}
+
ChannelInfo *target_ci = cs_findchan(target);
if (!target_ci)
{
@@ -58,10 +59,10 @@ public:
if (what.empty())
{
- delete target_ci;
+ target_ci->destroy();
target_ci = new ChannelInfo(*ci);
target_ci->name = target;
- RegisteredChannelList[target_ci->name] = target_ci;
+ (*RegisteredChannelList)[target_ci->name] = target_ci;
target_ci->c = findchan(target_ci->name);
if (target_ci->c)
{
@@ -107,7 +108,7 @@ public:
{
for (unsigned i = 0; i < ci->GetAccessCount(); ++i)
{
- ChanAccess *taccess = ci->GetAccess(i);
+ const ChanAccess *taccess = ci->GetAccess(i);
AccessProvider *provider = taccess->provider;
ChanAccess *newaccess = provider->Create();
@@ -128,7 +129,7 @@ public:
target_ci->ClearAkick();
for (unsigned i = 0; i < ci->GetAkickCount(); ++i)
{
- AutoKick *akick = ci->GetAkick(i);
+ const AutoKick *akick = ci->GetAkick(i);
if (akick->HasFlag(AK_ISNICK))
target_ci->AddAkick(akick->creator, akick->nc, akick->reason, akick->addtime, akick->last_used);
else
@@ -142,7 +143,7 @@ public:
target_ci->ClearBadWords();
for (unsigned i = 0; i < ci->GetBadWordCount(); ++i)
{
- BadWord *bw = ci->GetBadWord(i);
+ const BadWord *bw = ci->GetBadWord(i);
target_ci->AddBadWord(bw->word, bw->type);
}
diff --git a/modules/commands/cs_drop.cpp b/modules/commands/cs_drop.cpp
index d2d05c457..fb9da23b8 100644
--- a/modules/commands/cs_drop.cpp
+++ b/modules/commands/cs_drop.cpp
@@ -59,7 +59,7 @@ class CommandCSDrop : public Command
FOREACH_MOD(I_OnChanDrop, OnChanDrop(ci));
Channel *c = ci->c;
- delete ci;
+ ci->destroy();
source.Reply(_("Channel \002%s\002 has been dropped."), chan.c_str());
diff --git a/modules/commands/cs_enforce.cpp b/modules/commands/cs_enforce.cpp
index 1c5cabddd..62c8e0c6d 100644
--- a/modules/commands/cs_enforce.cpp
+++ b/modules/commands/cs_enforce.cpp
@@ -20,9 +20,9 @@ class CommandCSEnforce : public Command
private:
void DoSet(Channel *c)
{
- ChannelInfo *ci;
+ const ChannelInfo *ci = c->ci;
- if (!(ci = c->ci))
+ if (!ci)
return;
if (ci->HasFlag(CI_SECUREOPS))
@@ -39,10 +39,9 @@ class CommandCSEnforce : public Command
void DoSecureOps(Channel *c)
{
- ChannelInfo *ci;
- bool hadsecureops = false;
+ ChannelInfo *ci = c->ci;
- if (!(ci = c->ci))
+ if (!ci)
return;
/* Dirty hack to allow chan_set_correct_modes to work ok.
@@ -50,6 +49,7 @@ class CommandCSEnforce : public Command
* part of the code. This way we can enforce SECUREOPS even
* if it's off.
*/
+ bool hadsecureops = false;
if (!ci->HasFlag(CI_SECUREOPS))
{
ci->SetFlag(CI_SECUREOPS);
@@ -91,10 +91,10 @@ class CommandCSEnforce : public Command
void DoCModeR(Channel *c)
{
- ChannelInfo *ci;
+ ChannelInfo *ci = c->ci;
Anope::string mask;
- if (!(ci = c->ci))
+ if (!ci)
return;
for (CUserList::iterator it = c->users.begin(), it_end = c->users.end(); it != it_end; )
diff --git a/modules/commands/cs_entrymsg.cpp b/modules/commands/cs_entrymsg.cpp
index 477f68cb2..9b5a6753c 100644
--- a/modules/commands/cs_entrymsg.cpp
+++ b/modules/commands/cs_entrymsg.cpp
@@ -15,7 +15,7 @@
struct EntryMsg : Serializable
{
- ChannelInfo *ci;
+ serialize_obj<ChannelInfo> ci;
Anope::string creator;
Anope::string message;
time_t when;
@@ -29,14 +29,14 @@ struct EntryMsg : Serializable
this->when = ct;
}
- Anope::string serialize_name() const anope_override
+ const Anope::string serialize_name() const anope_override
{
return "EntryMsg";
}
- serialized_data serialize() anope_override
+ Serialize::Data serialize() const anope_override
{
- serialized_data data;
+ Serialize::Data data;
data["ci"] << this->ci->name;
data["creator"] << this->creator;
@@ -46,7 +46,7 @@ struct EntryMsg : Serializable
return data;
}
- static void unserialize(serialized_data &data);
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &data);
};
static unsigned MaxEntries = 0;
@@ -55,11 +55,21 @@ struct EntryMessageList : std::vector<EntryMsg>, ExtensibleItem
{
};
-void EntryMsg::unserialize(serialized_data &data)
+Serializable* EntryMsg::unserialize(Serializable *obj, Serialize::Data &data)
{
ChannelInfo *ci = cs_findchan(data["ci"].astr());
if (!ci)
- return;
+ return NULL;
+
+ if (obj)
+ {
+ EntryMsg *msg = debug_cast<EntryMsg *>(obj);
+ msg->ci = ci;
+ data["creator"] >> msg->creator;
+ data["message"] >> msg->message;
+ data["when"] >> msg->when;
+ return msg;
+ }
EntryMessageList *messages = ci->GetExt<EntryMessageList *>("cs_entrymsg");
if (messages == NULL)
@@ -69,6 +79,7 @@ void EntryMsg::unserialize(serialized_data &data)
}
messages->push_back(EntryMsg(ci, data["creator"].astr(), data["message"].astr()));
+ return &messages->back();
}
class CommandEntryMessage : public Command
diff --git a/modules/commands/cs_fantasy_stats.cpp b/modules/commands/cs_fantasy_stats.cpp
index 7a4419e30..3e9d482b8 100644
--- a/modules/commands/cs_fantasy_stats.cpp
+++ b/modules/commands/cs_fantasy_stats.cpp
@@ -106,7 +106,7 @@ class CSStats : public Module
Anope::string display;
if (params.empty())
display = source.u->Account()->display;
- else if (NickAlias *na = findnick(params[0]))
+ else if (const NickAlias *na = findnick(params[0]))
display = na->nc->display;
else
{
@@ -165,4 +165,5 @@ void CommandCSGStats::Execute(CommandSource &source, const std::vector<Anope::st
me->DoStats(source, true, params);
}
-MODULE_INIT(CSStats) \ No newline at end of file
+MODULE_INIT(CSStats)
+
diff --git a/modules/commands/cs_flags.cpp b/modules/commands/cs_flags.cpp
index aceb28192..222409eca 100644
--- a/modules/commands/cs_flags.cpp
+++ b/modules/commands/cs_flags.cpp
@@ -32,7 +32,7 @@ class FlagsChanAccess : public ChanAccess
return false;
}
- Anope::string Serialize()
+ Anope::string Serialize() const
{
return Anope::string(this->flags.begin(), this->flags.end());
}
@@ -43,7 +43,7 @@ class FlagsChanAccess : public ChanAccess
this->flags.insert(data[i - 1]);
}
- static Anope::string DetermineFlags(ChanAccess *access)
+ static Anope::string DetermineFlags(const ChanAccess *access)
{
if (access->provider->name == "access/flags")
return access->Serialize();
@@ -88,7 +88,7 @@ class CommandCSFlags : public Command
AccessGroup u_access = ci->AccessFor(u);
- if (mask.find_first_of("!*@") == Anope::string::npos && findnick(mask) == NULL)
+ if (mask.find_first_of("!*@") == Anope::string::npos && !findnick(mask))
{
User *targ = finduser(mask);
if (targ != NULL)
@@ -234,7 +234,7 @@ class CommandCSFlags : public Command
unsigned count = 0;
for (unsigned i = 0, end = ci->GetAccessCount(); i < end; ++i)
{
- ChanAccess *access = ci->GetAccess(i);
+ const ChanAccess *access = ci->GetAccess(i);
const Anope::string &flags = FlagsChanAccess::DetermineFlags(access);
if (!arg.empty())
diff --git a/modules/commands/cs_info.cpp b/modules/commands/cs_info.cpp
index 290ead3ba..47ba4d3b0 100644
--- a/modules/commands/cs_info.cpp
+++ b/modules/commands/cs_info.cpp
@@ -13,9 +13,11 @@
#include "module.h"
+struct ExtensibleString : Anope::string, ExtensibleItem { };
+
class CommandCSInfo : public Command
{
- void CheckOptStr(Anope::string &buf, ChannelInfoFlag opt, const char *str, ChannelInfo *ci, NickCore *nc)
+ void CheckOptStr(Anope::string &buf, ChannelInfoFlag opt, const char *str, const ChannelInfo *ci, const NickCore *nc)
{
if (ci->HasFlag(opt))
{
@@ -68,7 +70,7 @@ class CommandCSInfo : public Command
info["Registered"] = do_strftime(ci->time_registered);
info["Last used"] = do_strftime(ci->last_used);
- ModeLock *secret = ci->GetMLock(CMODE_SECRET);
+ const ModeLock *secret = ci->GetMLock(CMODE_SECRET);
if (!ci->last_topic.empty() && (show_all || ((!secret || secret->set == false) && (!ci->c || !ci->c->HasMode(CMODE_SECRET)))))
{
info["Last topic"] = ci->last_topic;
diff --git a/modules/commands/cs_list.cpp b/modules/commands/cs_list.cpp
index 77d7613fe..8385fc38b 100644
--- a/modules/commands/cs_list.cpp
+++ b/modules/commands/cs_list.cpp
@@ -76,9 +76,9 @@ class CommandCSList : public Command
ListFormatter list;
list.addColumn("Name").addColumn("Description");
- for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it)
+ for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it)
{
- ChannelInfo *ci = it->second;
+ const ChannelInfo *ci = it->second;
if (!is_servadmin && (ci->HasFlag(CI_PRIVATE) || ci->HasFlag(CI_SUSPENDED)))
continue;
diff --git a/modules/commands/cs_log.cpp b/modules/commands/cs_log.cpp
index 28c7e6f91..163789b53 100644
--- a/modules/commands/cs_log.cpp
+++ b/modules/commands/cs_log.cpp
@@ -36,23 +36,23 @@ public:
source.Reply(ACCESS_DENIED);
else if (params.size() == 1)
{
- if (ci->log_settings.empty())
+ if (ci->log_settings->empty())
source.Reply(_("There currently are no logging configurations for %s."), ci->name.c_str());
else
{
ListFormatter list;
list.addColumn("Number").addColumn("Service").addColumn("Command").addColumn("Method").addColumn("");
- for (unsigned i = 0; i < ci->log_settings.size(); ++i)
+ for (unsigned i = 0; i < ci->log_settings->size(); ++i)
{
- LogSetting &log = ci->log_settings[i];
+ const LogSetting *log = ci->log_settings->at(i);
ListFormatter::ListEntry entry;
entry["Number"] = stringify(i + 1);
- entry["Service"] = log.command_service;
- entry["Command"] = log.command_name;
- entry["Method"] = log.method;
- entry[""] = log.extra;
+ entry["Service"] = log->command_service;
+ entry["Command"] = log->command_name;
+ entry["Method"] = log->method;
+ entry[""] = log->extra;
list.addEntry(entry);
}
@@ -110,21 +110,22 @@ public:
bool override = !ci->AccessFor(u).HasPriv("SET");
- for (unsigned i = ci->log_settings.size(); i > 0; --i)
+ for (unsigned i = ci->log_settings->size(); i > 0; --i)
{
- LogSetting &log = ci->log_settings[i - 1];
+ LogSetting *log = ci->log_settings->at(i - 1);
- if (log.service_name == bi->commands[command_name].name && log.method.equals_ci(method))
+ if (log->service_name == bi->commands[command_name].name && log->method.equals_ci(method))
{
- if (log.extra == extra)
+ if (log->extra == extra)
{
- ci->log_settings.erase(ci->log_settings.begin() + i - 1);
+ log->destroy();
+ ci->log_settings->erase(ci->log_settings->begin() + i - 1);
Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "to remove logging for " << command << " with method " << method << (extra == "" ? "" : " ") << extra;
source.Reply(_("Logging for command %s on %s with log method %s%s%s has been removed."), command_name.c_str(), bi->nick.c_str(), method.c_str(), extra.empty() ? "" : " ", extra.empty() ? "" : extra.c_str());
}
else
{
- log.extra = extra;
+ log->extra = extra;
Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "to change logging for " << command << " to method " << method << (extra == "" ? "" : " ") << extra;
source.Reply(_("Logging changed for command %s on %s, now using log method %s%s%s."), command_name.c_str(), bi->nick.c_str(), method.c_str(), extra.empty() ? "" : " ", extra.empty() ? "" : extra.c_str());
}
@@ -132,17 +133,17 @@ public:
}
}
- LogSetting log;
- log.ci = ci;
- log.service_name = bi->commands[command_name].name;
- log.command_service = bi->nick;
- log.command_name = command_name;
- log.method = method;
- log.extra = extra;
- log.created = Anope::CurTime;
- log.creator = u->nick;
-
- ci->log_settings.push_back(log);
+ LogSetting *log = new LogSetting();
+ log->ci = ci;
+ log->service_name = bi->commands[command_name].name;
+ log->command_service = bi->nick;
+ log->command_name = command_name;
+ log->method = method;
+ log->extra = extra;
+ log->created = Anope::CurTime;
+ log->creator = u->nick;
+
+ ci->log_settings->push_back(log);
Log(override ? LOG_OVERRIDE : LOG_COMMAND, u, this, ci) << "to log " << command << " with method " << method << (extra == "" ? "" : " ") << extra;
source.Reply(_("Logging is now active for command %s on %s, using log method %s%s%s."), command_name.c_str(), bi->nick.c_str(), method.c_str(), extra.empty() ? "" : " ", extra.empty() ? "" : extra.c_str());
@@ -197,19 +198,19 @@ class CSLog : public Module
if (l->Type != LOG_COMMAND || l->u == NULL || l->c == NULL || l->ci == NULL || !Me || !Me->IsSynced())
return;
- for (unsigned i = l->ci->log_settings.size(); i > 0; --i)
+ for (unsigned i = l->ci->log_settings->size(); i > 0; --i)
{
- LogSetting &log = l->ci->log_settings[i - 1];
+ const LogSetting *log = l->ci->log_settings->at(i - 1);
- if (log.service_name == l->c->name)
+ if (log->service_name == l->c->name)
{
- Anope::string buffer = l->u->nick + " used " + log.command_name + " " + l->buf.str();
+ Anope::string buffer = l->u->nick + " used " + log->command_name + " " + l->buf.str();
- if (log.method.equals_ci("MESSAGE") && l->ci->c && l->ci->bi && l->ci->c->FindUser(l->ci->bi) != NULL)
- ircdproto->SendPrivmsg(l->ci->bi, log.extra + l->ci->c->name, "%s", buffer.c_str());
- else if (log.method.equals_ci("NOTICE") && l->ci->c && l->ci->bi && l->ci->c->FindUser(l->ci->bi) != NULL)
- ircdproto->SendNotice(l->ci->bi, log.extra + l->ci->c->name, "%s", buffer.c_str());
- else if (log.method.equals_ci("MEMO") && memoserv && l->ci->WhoSends() != NULL)
+ if (log->method.equals_ci("MESSAGE") && l->ci->c && l->ci->bi && l->ci->c->FindUser(l->ci->bi) != NULL)
+ ircdproto->SendPrivmsg(l->ci->bi, log->extra + l->ci->c->name, "%s", buffer.c_str());
+ else if (log->method.equals_ci("NOTICE") && l->ci->c && l->ci->bi && l->ci->c->FindUser(l->ci->bi) != NULL)
+ ircdproto->SendNotice(l->ci->bi, log->extra + l->ci->c->name, "%s", buffer.c_str());
+ else if (log->method.equals_ci("MEMO") && memoserv && l->ci->WhoSends() != NULL)
memoserv->Send(l->ci->WhoSends()->nick, l->ci->name, buffer, true);
}
}
diff --git a/modules/commands/cs_mode.cpp b/modules/commands/cs_mode.cpp
index c9d7c112a..425a54a01 100644
--- a/modules/commands/cs_mode.cpp
+++ b/modules/commands/cs_mode.cpp
@@ -151,7 +151,7 @@ class CommandCSMode : public Command
}
else if (subcommand.equals_ci("LIST"))
{
- const std::multimap<ChannelModeName, ModeLock> &mlocks = ci->GetMLock();
+ const ChannelInfo::ModeList &mlocks = ci->GetMLock();
if (mlocks.empty())
{
source.Reply(_("Channel %s has no mode locks."), ci->name.c_str());
@@ -161,18 +161,18 @@ class CommandCSMode : public Command
ListFormatter list;
list.addColumn("Mode").addColumn("Param").addColumn("Creator").addColumn("Created");
- for (std::multimap<ChannelModeName, ModeLock>::const_iterator it = mlocks.begin(), it_end = mlocks.end(); it != it_end; ++it)
+ for (ChannelInfo::ModeList::const_iterator it = mlocks.begin(), it_end = mlocks.end(); it != it_end; ++it)
{
- const ModeLock &ml = it->second;
- ChannelMode *cm = ModeManager::FindChannelModeByName(ml.name);
+ const ModeLock *ml = it->second;
+ ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name);
if (!cm)
continue;
ListFormatter::ListEntry entry;
- entry["Mode"] = Anope::printf("%c%c", ml.set ? '+' : '-', cm->ModeChar);
- entry["Param"] = ml.param;
- entry["Creator"] = ml.setter;
- entry["Created"] = do_strftime(ml.created, source.u->Account(), false);
+ entry["Mode"] = Anope::printf("%c%c", ml->set ? '+' : '-', cm->ModeChar);
+ entry["Param"] = ml->param;
+ entry["Creator"] = ml->setter;
+ entry["Created"] = do_strftime(ml->created, source.u->Account(), false);
list.addEntry(entry);
}
diff --git a/modules/commands/cs_modes.cpp b/modules/commands/cs_modes.cpp
index a460c6c87..37d710505 100644
--- a/modules/commands/cs_modes.cpp
+++ b/modules/commands/cs_modes.cpp
@@ -20,19 +20,31 @@ class CommandModeBase : public Command
User *u = source.u;
User *u2 = finduser(nick);
Channel *c = findchan(chan);
- ChannelInfo *ci = c ? c->ci : NULL;
-
- bool is_same = u == u2;
-
- AccessGroup u_access = ci ? ci->AccessFor(u) : AccessGroup(), u2_access = ci && u2 ? ci->AccessFor(u2) : AccessGroup();
if (!c)
+ {
source.Reply(CHAN_X_NOT_IN_USE, chan.c_str());
- else if (!ci)
- source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str());
- else if (!u2)
+ return;
+
+ }
+
+ if (!u2)
+ {
source.Reply(NICK_X_NOT_IN_USE, nick.c_str());
- else if (is_same ? !ci->AccessFor(u).HasPriv(levelself) : !ci->AccessFor(u).HasPriv(level))
+ return;
+ }
+
+ ChannelInfo *ci = c->ci;
+ if (!ci)
+ {
+ source.Reply(CHAN_X_NOT_REGISTERED, c->name.c_str());
+ return;
+ }
+
+ bool is_same = u == u2;
+ AccessGroup u_access = ci->AccessFor(u), u2_access = ci->AccessFor(u2);
+
+ if (is_same ? !ci->AccessFor(u).HasPriv(levelself) : !ci->AccessFor(u).HasPriv(level))
source.Reply(ACCESS_DENIED);
else if (!set && !is_same && ci->HasFlag(CI_PEACE) && u2_access >= u_access)
source.Reply(ACCESS_DENIED);
diff --git a/modules/commands/cs_register.cpp b/modules/commands/cs_register.cpp
index 570fd8125..fd62ff754 100644
--- a/modules/commands/cs_register.cpp
+++ b/modules/commands/cs_register.cpp
@@ -46,7 +46,7 @@ class CommandCSRegister : public Command
else if (c && !c->HasUserStatus(u, CMODE_OP))
source.Reply(_("You must be a channel operator to register the channel."));
else if (Config->CSMaxReg && u->Account()->channelcount >= Config->CSMaxReg && !u->HasPriv("chanserv/no-register-limit"))
- source.Reply(u->Account()->channelcount > Config->CSMaxReg ? CHAN_EXCEEDED_CHANNEL_LIMIT : _(CHAN_REACHED_CHANNEL_LIMIT), Config->CSMaxReg);
+ source.Reply(u->Account()->channelcount > Config->CSMaxReg ? CHAN_EXCEEDED_CHANNEL_LIMIT : CHAN_REACHED_CHANNEL_LIMIT, Config->CSMaxReg);
else
{
ci = new ChannelInfo(chan);
@@ -54,11 +54,12 @@ class CommandCSRegister : public Command
if (!chdesc.empty())
ci->desc = chdesc;
- ci->mode_locks = def_mode_locks;
- for (ChannelInfo::ModeList::iterator it = ci->mode_locks.begin(), it_end = ci->mode_locks.end(); it != it_end; ++it)
+ for (ChannelInfo::ModeList::iterator it = def_mode_locks.begin(), it_end = def_mode_locks.end(); it != it_end; ++it)
{
- it->second.setter = u->nick;
- it->second.ci = ci;
+ ModeLock *ml = new ModeLock(*it->second);
+ ml->setter = u->nick;
+ ml->ci = ci;
+ ci->mode_locks->insert(std::make_pair(it->first, ml));
}
if (c && !c->topic.empty())
diff --git a/modules/commands/cs_saset.cpp b/modules/commands/cs_saset.cpp
index c564a9c90..c2e7b13d5 100644
--- a/modules/commands/cs_saset.cpp
+++ b/modules/commands/cs_saset.cpp
@@ -37,10 +37,10 @@ class CommandCSSASet : public Command
" \n"
"Available options:"));
Anope::string this_name = source.command;
- for (BotInfo::command_map::iterator it = source.owner->commands.begin(), it_end = source.owner->commands.end(); it != it_end; ++it)
+ for (BotInfo::command_map::const_iterator it = source.owner->commands.begin(), it_end = source.owner->commands.end(); it != it_end; ++it)
{
const Anope::string &c_name = it->first;
- CommandInfo &info = it->second;
+ const CommandInfo &info = it->second;
if (c_name.find_ci(this_name + " ") == 0)
{
service_reference<Command> command("Command", info.name);
diff --git a/modules/commands/cs_seen.cpp b/modules/commands/cs_seen.cpp
index 0143f50d6..3f7b276f7 100644
--- a/modules/commands/cs_seen.cpp
+++ b/modules/commands/cs_seen.cpp
@@ -37,14 +37,14 @@ struct SeenInfo : Serializable
{
}
- Anope::string serialize_name() const anope_override
+ const Anope::string serialize_name() const anope_override
{
return "SeenInfo";
}
- serialized_data serialize() anope_override
+ Serialize::Data serialize() const anope_override
{
- serialized_data data;
+ Serialize::Data data;
data["nick"] << nick;
data["vhost"] << vhost;
@@ -57,9 +57,13 @@ struct SeenInfo : Serializable
return data;
}
- static void unserialize(serialized_data &data)
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &data)
{
- SeenInfo *s = new SeenInfo();
+ SeenInfo *s;
+ if (obj)
+ s = debug_cast<SeenInfo *>(obj);
+ else
+ s = new SeenInfo();
data["nick"] >> s->nick;
data["vhost"] >> s->vhost;
@@ -71,7 +75,9 @@ struct SeenInfo : Serializable
data["message"] >> s->message;
data["last"] >> s->last;
- database[s->nick] = s;
+ if (!s)
+ database[s->nick] = s;
+ return s;
}
};
@@ -89,7 +95,7 @@ static SeenInfo *FindInfo(const Anope::string &nick)
static bool ShouldHide(const Anope::string &channel, User *u)
{
Channel *targetchan = findchan(channel);
- ChannelInfo *targetchan_ci = targetchan ? targetchan->ci : cs_findchan(channel);
+ const ChannelInfo *targetchan_ci = targetchan ? *targetchan->ci : cs_findchan(channel);
if (targetchan && targetchan->HasMode(CMODE_SECRET))
return true;
@@ -303,7 +309,7 @@ class DataBasePurger : public CallBack
if ((Anope::CurTime - cur->second->last) > purgetime)
{
Log(LOG_DEBUG) << cur->first << " was last seen " << do_strftime(cur->second->last) << ", purging entry";
- delete cur->second;
+ cur->second->destroy();
database.erase(cur);
}
}
diff --git a/modules/commands/cs_set.cpp b/modules/commands/cs_set.cpp
index ac91d213f..0d23b5550 100644
--- a/modules/commands/cs_set.cpp
+++ b/modules/commands/cs_set.cpp
@@ -37,10 +37,10 @@ class CommandCSSet : public Command
" \n"
"Available options:"));
Anope::string this_name = source.command;
- for (BotInfo::command_map::iterator it = source.owner->commands.begin(), it_end = source.owner->commands.end(); it != it_end; ++it)
+ for (BotInfo::command_map::const_iterator it = source.owner->commands.begin(), it_end = source.owner->commands.end(); it != it_end; ++it)
{
const Anope::string &c_name = it->first;
- CommandInfo &info = it->second;
+ const CommandInfo &info = it->second;
if (c_name.find_ci(this_name + " ") == 0)
{
service_reference<Command> command("Command", info.name);
diff --git a/modules/commands/cs_set_founder.cpp b/modules/commands/cs_set_founder.cpp
index 0d375f760..5f2990196 100644
--- a/modules/commands/cs_set_founder.cpp
+++ b/modules/commands/cs_set_founder.cpp
@@ -22,7 +22,7 @@ class CommandCSSetFounder : public Command
this->SetSyntax(_("\037channel\037 \037nick\037"));
}
- void Execute(CommandSource &source, const std::vector<Anope::string> &params)anope_override
+ void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
{
User *u = source.u;
ChannelInfo *ci = cs_findchan(params[0]);
@@ -44,8 +44,7 @@ class CommandCSSetFounder : public Command
return;
}
- NickAlias *na = findnick(params[1]);
-
+ const NickAlias *na = findnick(params[1]);
if (!na)
{
source.Reply(NICK_X_NOT_REGISTERED, params[1].c_str());
diff --git a/modules/commands/cs_set_misc.cpp b/modules/commands/cs_set_misc.cpp
index 75794697d..ab40f9fdc 100644
--- a/modules/commands/cs_set_misc.cpp
+++ b/modules/commands/cs_set_misc.cpp
@@ -12,9 +12,9 @@
#include "module.h"
-struct CSMiscData : Anope::string, ExtensibleItem, Serializable
+struct CSMiscData : ExtensibleItem, Serializable
{
- ChannelInfo *ci;
+ serialize_obj<ChannelInfo> ci;
Anope::string name;
Anope::string data;
@@ -22,14 +22,14 @@ struct CSMiscData : Anope::string, ExtensibleItem, Serializable
{
}
- Anope::string serialize_name() const anope_override
+ const Anope::string serialize_name() const anope_override
{
return "CSMiscData";
}
- serialized_data serialize() anope_override
+ Serialize::Data serialize() const anope_override
{
- serialized_data sdata;
+ Serialize::Data sdata;
sdata["ci"] << this->ci->name;
sdata["name"] << this->name;
@@ -38,13 +38,27 @@ struct CSMiscData : Anope::string, ExtensibleItem, Serializable
return sdata;
}
- static void unserialize(serialized_data &data)
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &data)
{
ChannelInfo *ci = cs_findchan(data["ci"].astr());
if (ci == NULL)
- return;
+ return NULL;
+
+ CSMiscData *d;
+ if (obj)
+ {
+ d = debug_cast<CSMiscData *>(obj);
+ d->ci = ci;
+ data["name"] >> d->name;
+ data["data"] >> d->data;
+ }
+ else
+ {
+ d = new CSMiscData(ci, data["name"].astr(), data["data"].astr());
+ ci->Extend(data["name"].astr(), d);
+ }
- ci->Extend(data["name"].astr(), new CSMiscData(ci, data["name"].astr(), data["data"].astr()));
+ return d;
}
};
diff --git a/modules/commands/cs_set_successor.cpp b/modules/commands/cs_set_successor.cpp
index fe2860920..e0f05e67b 100644
--- a/modules/commands/cs_set_successor.cpp
+++ b/modules/commands/cs_set_successor.cpp
@@ -48,7 +48,7 @@ class CommandCSSetSuccessor : public Command
if (params.size() > 1)
{
- NickAlias *na = findnick(params[1]);
+ const NickAlias *na = findnick(params[1]);
if (!na)
{
diff --git a/modules/commands/cs_suspend.cpp b/modules/commands/cs_suspend.cpp
index 676ffebfa..d5898083e 100644
--- a/modules/commands/cs_suspend.cpp
+++ b/modules/commands/cs_suspend.cpp
@@ -13,6 +13,11 @@
#include "module.h"
+struct ExtensibleString : Anope::string, ExtensibleItem
+{
+ ExtensibleString(const Anope::string &s) : Anope::string(s) { }
+};
+
struct ChanSuspend : ExtensibleItem, Serializable
{
Anope::string chan;
@@ -22,14 +27,14 @@ struct ChanSuspend : ExtensibleItem, Serializable
{
}
- Anope::string serialize_name() const
+ const Anope::string serialize_name() const
{
return "ChanSuspend";
}
- serialized_data serialize() anope_override
+ Serialize::Data serialize() const anope_override
{
- serialized_data sd;
+ Serialize::Data sd;
sd["chan"] << this->chan;
sd["when"] << this->when;
@@ -37,18 +42,24 @@ struct ChanSuspend : ExtensibleItem, Serializable
return sd;
}
- static void unserialize(serialized_data &sd)
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &sd)
{
ChannelInfo *ci = cs_findchan(sd["chan"].astr());
if (ci == NULL)
- return;
+ return NULL;
- ChanSuspend *cs = new ChanSuspend();
+ ChanSuspend *cs;
+ if (obj)
+ cs = debug_cast<ChanSuspend *>(obj);
+ else
+ cs = new ChanSuspend();
sd["chan"] >> cs->chan;
sd["when"] >> cs->when;
- ci->Extend("ci_suspend_expire", cs);
+ if (!obj)
+ ci->Extend("ci_suspend_expire", cs);
+ return cs;
}
};
@@ -220,11 +231,12 @@ class CSSuspend : public Module
~CSSuspend()
{
- for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it)
+ for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it)
{
- it->second->Shrink("cs_suspend_expire");
- it->second->Shrink("suspend_by");
- it->second->Shrink("suspend_reason");
+ ChannelInfo *ci = it->second;
+ ci->Shrink("cs_suspend_expire");
+ ci->Shrink("suspend_by");
+ ci->Shrink("suspend_reason");
}
}
diff --git a/modules/commands/cs_updown.cpp b/modules/commands/cs_updown.cpp
index da272835f..11b2f4749 100644
--- a/modules/commands/cs_updown.cpp
+++ b/modules/commands/cs_updown.cpp
@@ -39,7 +39,7 @@ class CommandCSUp : public Command
if (c == NULL)
source.Reply(CHAN_X_NOT_IN_USE, channel.c_str());
- else if (c->ci == NULL)
+ else if (!c->ci)
source.Reply(CHAN_X_NOT_REGISTERED, channel.c_str());
else
chan_set_correct_modes(u, c, 1);
@@ -94,7 +94,7 @@ class CommandCSDown : public Command
if (c == NULL)
source.Reply(CHAN_X_NOT_IN_USE, channel.c_str());
- else if (c->ci == NULL)
+ else if (!c->ci)
source.Reply(CHAN_X_NOT_REGISTERED, channel.c_str());
else
RemoveAll(u, c);
diff --git a/modules/commands/cs_xop.cpp b/modules/commands/cs_xop.cpp
index 7935467c2..807cbe1f6 100644
--- a/modules/commands/cs_xop.cpp
+++ b/modules/commands/cs_xop.cpp
@@ -116,7 +116,7 @@ class XOPChanAccess : public ChanAccess
return false;
}
- Anope::string Serialize()
+ Anope::string Serialize() const
{
for (int i = 0; xopAccess[i].type != XOP_UNKNOWN; ++i)
{
@@ -145,11 +145,11 @@ class XOPChanAccess : public ChanAccess
this->type = XOP_UNKNOWN;
}
- static XOPType DetermineLevel(ChanAccess *access)
+ static XOPType DetermineLevel(const ChanAccess *access)
{
if (access->provider->name == "access/xop")
{
- XOPChanAccess *xaccess = debug_cast<XOPChanAccess *>(access);
+ const XOPChanAccess *xaccess = debug_cast<const XOPChanAccess *>(access);
return xaccess->type;
}
else
@@ -216,7 +216,7 @@ class XOPBase : public Command
}
AccessGroup access = ci->AccessFor(u);
- ChanAccess *highest = access.Highest();
+ const ChanAccess *highest = access.Highest();
int u_level = (highest ? XOPChanAccess::DetermineLevel(highest) : 0);
if ((!access.Founder && !access.HasPriv("ACCESS_CHANGE") && !u->HasPriv("chanserv/access/modify")) || (level <= u_level && !access.Founder))
@@ -225,7 +225,7 @@ class XOPBase : public Command
return;
}
- if (mask.find_first_of("!*@") == Anope::string::npos && findnick(mask) == NULL)
+ if (mask.find_first_of("!*@") == Anope::string::npos && !findnick(mask))
{
User *targ = finduser(mask);
if (targ != NULL)
@@ -239,7 +239,7 @@ class XOPBase : public Command
for (unsigned i = 0; i < ci->GetAccessCount(); ++i)
{
- ChanAccess *a = ci->GetAccess(i);
+ const ChanAccess *a = ci->GetAccess(i);
if (a->mask.equals_ci(mask))
{
@@ -304,7 +304,7 @@ class XOPBase : public Command
}
AccessGroup access = ci->AccessFor(u);
- ChanAccess *highest = access.Highest();
+ const ChanAccess *highest = access.Highest();
bool override = false;
if ((!mask.equals_ci(u->Account()->display) && !access.HasPriv("ACCESS_CHANGE") && !access.Founder) || ((!highest || level <= XOPChanAccess::DetermineLevel(highest)) && !access.Founder))
{
@@ -436,7 +436,7 @@ class XOPBase : public Command
if (!Number || Number > ci->GetAccessCount())
return;
- ChanAccess *a = ci->GetAccess(Number - 1);
+ const ChanAccess *a = ci->GetAccess(Number - 1);
if (this->type != XOPChanAccess::DetermineLevel(a))
return;
@@ -453,7 +453,7 @@ class XOPBase : public Command
{
for (unsigned i = 0, end = ci->GetAccessCount(); i < end; ++i)
{
- ChanAccess *a = ci->GetAccess(i);
+ const ChanAccess *a = ci->GetAccess(i);
if (XOPChanAccess::DetermineLevel(a) != level)
continue;
@@ -507,7 +507,7 @@ class XOPBase : public Command
for (unsigned i = ci->GetAccessCount(); i > 0; --i)
{
- ChanAccess *access = ci->GetAccess(i - 1);
+ const ChanAccess *access = ci->GetAccess(i - 1);
if (XOPChanAccess::DetermineLevel(access) == level)
ci->EraseAccess(i - 1);
}
diff --git a/modules/commands/help.cpp b/modules/commands/help.cpp
index a329eb63c..7b7c52110 100644
--- a/modules/commands/help.cpp
+++ b/modules/commands/help.cpp
@@ -31,14 +31,14 @@ class CommandHelp : public Command
return;
User *u = source.u;
- BotInfo *bi = source.owner;
+ const BotInfo *bi = source.owner;
if (params.empty())
{
- for (BotInfo::command_map::iterator it = bi->commands.begin(), it_end = bi->commands.end(); it != it_end; ++it)
+ for (BotInfo::command_map::const_iterator it = bi->commands.begin(), it_end = bi->commands.end(); it != it_end; ++it)
{
const Anope::string &c_name = it->first;
- CommandInfo &info = it->second;
+ const CommandInfo &info = it->second;
// Smaller command exists
Anope::string cmd = myStrGetToken(c_name, ' ', 0);
@@ -65,11 +65,11 @@ class CommandHelp : public Command
full_command += " " + params[i];
full_command.erase(full_command.begin());
- BotInfo::command_map::iterator it = bi->commands.find(full_command);
+ BotInfo::command_map::const_iterator it = bi->commands.find(full_command);
if (it == bi->commands.end())
continue;
- CommandInfo &info = it->second;
+ const CommandInfo &info = it->second;
service_reference<Command> c("Command", info.name);
if (!c)
diff --git a/modules/commands/hs_del.cpp b/modules/commands/hs_del.cpp
index 80b8333d9..48e11c08c 100644
--- a/modules/commands/hs_del.cpp
+++ b/modules/commands/hs_del.cpp
@@ -65,8 +65,8 @@ class CommandHSDelAll : public Command
if (na)
{
FOREACH_MOD(I_OnDeleteVhost, OnDeleteVhost(na));
- NickCore *nc = na->nc;
- for (std::list<NickAlias *>::iterator it = nc->aliases.begin(), it_end = nc->aliases.end(); it != it_end; ++it)
+ const NickCore *nc = na->nc;
+ for (std::list<serialize_obj<NickAlias> >::const_iterator it = nc->aliases.begin(), it_end = nc->aliases.end(); it != it_end; ++it)
{
na = *it;
na->RemoveVhost();
diff --git a/modules/commands/hs_group.cpp b/modules/commands/hs_group.cpp
index 79db12536..a9c3dc232 100644
--- a/modules/commands/hs_group.cpp
+++ b/modules/commands/hs_group.cpp
@@ -15,15 +15,16 @@
class CommandHSGroup : public Command
{
- void Sync(NickAlias *na)
+ void Sync(const NickAlias *na)
{
if (!na || !na->HasVhost())
return;
- for (std::list<NickAlias *>::iterator it = na->nc->aliases.begin(), it_end = na->nc->aliases.end(); it != it_end; ++it)
+ for (std::list<serialize_obj<NickAlias> >::const_iterator it = na->nc->aliases.begin(), it_end = na->nc->aliases.end(); it != it_end;)
{
- NickAlias *nick = *it;
- nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator());
+ NickAlias *nick = *it++;
+ if (nick)
+ nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator());
}
}
diff --git a/modules/commands/hs_list.cpp b/modules/commands/hs_list.cpp
index 3bc8be862..9e708f0b4 100644
--- a/modules/commands/hs_list.cpp
+++ b/modules/commands/hs_list.cpp
@@ -59,9 +59,9 @@ class CommandHSList : public Command
ListFormatter list;
list.addColumn("Number").addColumn("Nick").addColumn("Vhost").addColumn("Creator").addColumn("Created");
- for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; ++it)
+ for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it)
{
- NickAlias *na = it->second;
+ const NickAlias *na = it->second;
if (!na->HasVhost())
continue;
diff --git a/modules/commands/hs_off.cpp b/modules/commands/hs_off.cpp
index c9c2fecd1..bf7d92dba 100644
--- a/modules/commands/hs_off.cpp
+++ b/modules/commands/hs_off.cpp
@@ -25,7 +25,7 @@ class CommandHSOff : public Command
void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
{
User *u = source.u;
- NickAlias *na = findnick(u->nick);
+ const NickAlias *na = findnick(u->nick);
if (!na || !na->HasVhost())
source.Reply(HOST_NOT_ASSIGNED);
diff --git a/modules/commands/hs_on.cpp b/modules/commands/hs_on.cpp
index 2dfa18c12..223f169fc 100644
--- a/modules/commands/hs_on.cpp
+++ b/modules/commands/hs_on.cpp
@@ -25,7 +25,7 @@ class CommandHSOn : public Command
void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
{
User *u = source.u;
- NickAlias *na = findnick(u->nick);
+ const NickAlias *na = findnick(u->nick);
if (na && u->Account() == na->nc && na->HasVhost())
{
if (!na->GetVhostIdent().empty())
diff --git a/modules/commands/hs_request.cpp b/modules/commands/hs_request.cpp
index 06308c8cb..e44fa06e2 100644
--- a/modules/commands/hs_request.cpp
+++ b/modules/commands/hs_request.cpp
@@ -30,14 +30,14 @@ struct HostRequest : ExtensibleItem, Serializable
Anope::string host;
time_t time;
- Anope::string serialize_name() const anope_override
+ const Anope::string serialize_name() const anope_override
{
return "HostRequest";
}
- serialized_data serialize() anope_override
+ Serialize::Data serialize() const anope_override
{
- serialized_data data;
+ Serialize::Data data;
data["nick"] << this->nick;
data["ident"] << this->ident;
@@ -47,19 +47,25 @@ struct HostRequest : ExtensibleItem, Serializable
return data;
}
- static void unserialize(serialized_data &data)
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &data)
{
NickAlias *na = findnick(data["nick"].astr());
if (na == NULL)
- return;
+ return NULL;
- HostRequest *req = new HostRequest;
+ HostRequest *req;
+ if (obj)
+ req = debug_cast<HostRequest *>(obj);
+ else
+ req = new HostRequest;
req->nick = na->nick;
data["ident"] >> req->ident;
data["host"] >> req->host;
data["time"] >> req->time;
- na->Extend("hs_request", req);
+ if (!obj)
+ na->Extend("hs_request", req);
+ return req;
}
};
@@ -282,9 +288,9 @@ class CommandHSWaiting : public Command
list.addColumn("Number").addColumn("Nick").addColumn("Vhost").addColumn("Created");
- for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; ++it)
+ for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it)
{
- NickAlias *na = it->second;
+ const NickAlias *na = it->second;
HostRequest *hr = na->GetExt<HostRequest *>("hs_request");
if (!hr)
continue;
@@ -358,8 +364,11 @@ class HSRequest : public Module
~HSRequest()
{
- for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; ++it)
- it->second->Shrink("hs_request");
+ for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it)
+ {
+ NickAlias *na = it->second;
+ na->Shrink("hs_request");
+ }
}
void OnReload() anope_override
@@ -387,7 +396,7 @@ void req_send_memos(CommandSource &source, const Anope::string &vIdent, const An
{
Oper *o = Config->Opers[i];
- NickAlias *na = findnick(o->name);
+ const NickAlias *na = findnick(o->name);
if (!na)
continue;
diff --git a/modules/commands/hs_set.cpp b/modules/commands/hs_set.cpp
index 5e73fd800..d4fbe9d5c 100644
--- a/modules/commands/hs_set.cpp
+++ b/modules/commands/hs_set.cpp
@@ -104,15 +104,16 @@ class CommandHSSet : public Command
class CommandHSSetAll : public Command
{
- void Sync(NickAlias *na)
+ void Sync(const NickAlias *na)
{
if (!na || !na->HasVhost())
return;
- for (std::list<NickAlias *>::iterator it = na->nc->aliases.begin(), it_end = na->nc->aliases.end(); it != it_end; ++it)
+ for (std::list<serialize_obj<NickAlias> >::const_iterator it = na->nc->aliases.begin(), it_end = na->nc->aliases.end(); it != it_end;)
{
- NickAlias *nick = *it;
- nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator());
+ NickAlias *nick = *it++;
+ if (nick)
+ nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator());
}
}
diff --git a/modules/commands/ms_cancel.cpp b/modules/commands/ms_cancel.cpp
index 46f410aec..059ca2f06 100644
--- a/modules/commands/ms_cancel.cpp
+++ b/modules/commands/ms_cancel.cpp
@@ -39,11 +39,20 @@ class CommandMSCancel : public Command
source.Reply(ischan ? CHAN_X_NOT_REGISTERED : _(NICK_X_NOT_REGISTERED), nname.c_str());
else
{
- for (int i = mi->memos.size() - 1; i >= 0; --i)
- if (mi->memos[i]->HasFlag(MF_UNREAD) && u->Account()->display.equals_ci(mi->memos[i]->sender))
+ ChannelInfo *ci;
+ NickAlias *na;
+ if (ischan)
+ ci = cs_findchan(nname);
+ else
+ na = findnick(nname);
+ for (int i = mi->memos->size() - 1; i >= 0; --i)
+ if (mi->GetMemo(i)->HasFlag(MF_UNREAD) && u->Account()->display.equals_ci(mi->GetMemo(i)->sender))
{
- FOREACH_MOD(I_OnMemoDel, OnMemoDel(findnick(nname)->nc, mi, mi->memos[i]));
- mi->Del(mi->memos[i]);
+ if (ischan)
+ FOREACH_MOD(I_OnMemoDel, OnMemoDel(ci, mi, mi->GetMemo(i)));
+ else
+ FOREACH_MOD(I_OnMemoDel, OnMemoDel(na->nc, mi, mi->GetMemo(i)));
+ mi->Del(i);
source.Reply(_("Last memo to \002%s\002 has been cancelled."), nname.c_str());
return;
}
diff --git a/modules/commands/ms_check.cpp b/modules/commands/ms_check.cpp
index a77b7192f..5b031e8ec 100644
--- a/modules/commands/ms_check.cpp
+++ b/modules/commands/ms_check.cpp
@@ -30,28 +30,28 @@ class CommandMSCheck : public Command
bool found = false;
- NickAlias *na = findnick(recipient);
+ const NickAlias *na = findnick(recipient);
if (!na)
{
source.Reply(NICK_X_NOT_REGISTERED, recipient.c_str());
return;
}
- MemoInfo *mi = &na->nc->memos;
+ MemoInfo *mi = const_cast<MemoInfo *>(&na->nc->memos);
/* Okay, I know this looks strange but we wanna get the LAST memo, so we
have to loop backwards */
- for (int i = mi->memos.size() - 1; i >= 0; --i)
+ for (int i = mi->memos->size() - 1; i >= 0; --i)
{
- if (u->Account()->display.equals_ci(mi->memos[i]->sender))
+ if (u->Account()->display.equals_ci(mi->GetMemo(i)->sender))
{
found = true; /* Yes, we've found the memo */
- if (mi->memos[i]->HasFlag(MF_UNREAD))
- source.Reply(_("The last memo you sent to %s (sent on %s) has not yet been read."), na->nick.c_str(), do_strftime(mi->memos[i]->time).c_str());
+ if (mi->GetMemo(i)->HasFlag(MF_UNREAD))
+ source.Reply(_("The last memo you sent to %s (sent on %s) has not yet been read."), na->nick.c_str(), do_strftime(mi->GetMemo(i)->time).c_str());
else
- source.Reply(_("The last memo you sent to %s (sent on %s) has been read."), na->nick.c_str(), do_strftime(mi->memos[i]->time).c_str());
+ source.Reply(_("The last memo you sent to %s (sent on %s) has been read."), na->nick.c_str(), do_strftime(mi->GetMemo(i)->time).c_str());
break;
}
}
diff --git a/modules/commands/ms_del.cpp b/modules/commands/ms_del.cpp
index 65969b025..0ad906c49 100644
--- a/modules/commands/ms_del.cpp
+++ b/modules/commands/ms_del.cpp
@@ -25,13 +25,13 @@ class MemoDelCallback : public NumberList
void HandleNumber(unsigned Number) anope_override
{
- if (!Number || Number > mi->memos.size())
+ if (!Number || Number > mi->memos->size())
return;
if (ci)
- FOREACH_MOD(I_OnMemoDel, OnMemoDel(ci, mi, mi->memos[Number - 1]));
+ FOREACH_MOD(I_OnMemoDel, OnMemoDel(ci, mi, mi->GetMemo(Number - 1)));
else
- FOREACH_MOD(I_OnMemoDel, OnMemoDel(source.u->Account(), mi, mi->memos[Number - 1]));
+ FOREACH_MOD(I_OnMemoDel, OnMemoDel(source.u->Account(), mi, mi->GetMemo(Number - 1)));
mi->Del(Number - 1);
source.Reply(_("Memo %d has been deleted."), Number);
@@ -52,7 +52,7 @@ class CommandMSDel : public Command
User *u = source.u;
MemoInfo *mi;
- ChannelInfo *ci = NULL;
+ ChannelInfo *ci;
Anope::string numstr = !params.empty() ? params[0] : "", chan;
if (!numstr.empty() && numstr[0] == '#')
@@ -60,7 +60,8 @@ class CommandMSDel : public Command
chan = numstr;
numstr = params.size() > 1 ? params[1] : "";
- if (!(ci = cs_findchan(chan)))
+ ci = cs_findchan(chan);
+ if (!ci)
{
source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str());
return;
@@ -78,10 +79,10 @@ class CommandMSDel : public Command
mi = &ci->memos;
}
else
- mi = &u->Account()->memos;
+ mi = const_cast<MemoInfo *>(&u->Account()->memos);
if (numstr.empty() || (!isdigit(numstr[0]) && !numstr.equals_ci("ALL") && !numstr.equals_ci("LAST")))
this->OnSyntaxError(source, numstr);
- else if (mi->memos.empty())
+ else if (mi->memos->empty())
{
if (!chan.empty())
source.Reply(MEMO_X_HAS_NO_MEMOS, chan.c_str());
@@ -99,24 +100,24 @@ class CommandMSDel : public Command
{
/* Delete last memo. */
if (ci)
- FOREACH_MOD(I_OnMemoDel, OnMemoDel(ci, mi, mi->memos[mi->memos.size() - 1]));
+ FOREACH_MOD(I_OnMemoDel, OnMemoDel(ci, mi, mi->GetMemo(mi->memos->size() - 1)));
else
- FOREACH_MOD(I_OnMemoDel, OnMemoDel(u->Account(), mi, mi->memos[mi->memos.size() - 1]));
- mi->Del(mi->memos[mi->memos.size() - 1]);
- source.Reply(_("Memo %d has been deleted."), mi->memos.size() + 1);
+ FOREACH_MOD(I_OnMemoDel, OnMemoDel(u->Account(), mi, mi->GetMemo(mi->memos->size() - 1)));
+ mi->Del(mi->memos->size() - 1);
+ source.Reply(_("Memo %d has been deleted."), mi->memos->size() + 1);
}
else
{
/* Delete all memos. */
- for (unsigned i = 0, end = mi->memos.size(); i < end; ++i)
+ for (unsigned i = 0, end = mi->memos->size(); i < end; ++i)
{
if (ci)
- FOREACH_MOD(I_OnMemoDel, OnMemoDel(ci, mi, mi->memos[i]));
+ FOREACH_MOD(I_OnMemoDel, OnMemoDel(ci, mi, mi->GetMemo(i)));
else
- FOREACH_MOD(I_OnMemoDel, OnMemoDel(u->Account(), mi, mi->memos[i]));
- delete mi->memos[i];
+ FOREACH_MOD(I_OnMemoDel, OnMemoDel(u->Account(), mi, mi->GetMemo(i)));
+ mi->GetMemo(i)->destroy();
}
- mi->memos.clear();
+ mi->memos->clear();
if (!chan.empty())
source.Reply(_("All memos for channel %s have been deleted."), chan.c_str());
else
diff --git a/modules/commands/ms_info.cpp b/modules/commands/ms_info.cpp
index 1cb6199a8..3f132f1d2 100644
--- a/modules/commands/ms_info.cpp
+++ b/modules/commands/ms_info.cpp
@@ -27,8 +27,8 @@ class CommandMSInfo : public Command
User *u = source.u;
const MemoInfo *mi;
- NickAlias *na = NULL;
- ChannelInfo *ci = NULL;
+ const NickAlias *na = NULL;
+ ChannelInfo *ci;
const Anope::string &nname = !params.empty() ? params[0] : "";
int hardmax = 0;
@@ -45,7 +45,8 @@ class CommandMSInfo : public Command
}
else if (!nname.empty() && nname[0] == '#')
{
- if (!(ci = cs_findchan(nname)))
+ ci = cs_findchan(nname);
+ if (!ci)
{
source.Reply(CHAN_X_NOT_REGISTERED, nname.c_str());
return;
@@ -71,11 +72,11 @@ class CommandMSInfo : public Command
if (!nname.empty() && (ci || na->nc != u->Account()))
{
- if (mi->memos.empty())
+ if (mi->memos->empty())
source.Reply(_("%s currently has no memos."), nname.c_str());
- else if (mi->memos.size() == 1)
+ else if (mi->memos->size() == 1)
{
- if (mi->memos[0]->HasFlag(MF_UNREAD))
+ if (mi->GetMemo(0)->HasFlag(MF_UNREAD))
source.Reply(_("%s currently has \0021\002 memo, and it has not yet been read."), nname.c_str());
else
source.Reply(_("%s currently has \0021\002 memo."), nname.c_str());
@@ -83,17 +84,17 @@ class CommandMSInfo : public Command
else
{
unsigned count = 0, i, end;
- for (i = 0, end = mi->memos.size(); i < end; ++i)
- if (mi->memos[i]->HasFlag(MF_UNREAD))
+ for (i = 0, end = mi->memos->size(); i < end; ++i)
+ if (mi->GetMemo(i)->HasFlag(MF_UNREAD))
++count;
- if (count == mi->memos.size())
+ if (count == mi->memos->size())
source.Reply(_("%s currently has \002%d\002 memos; all of them are unread."), nname.c_str(), count);
else if (!count)
- source.Reply(_("%s currently has \002%d\002 memos."), nname.c_str(), mi->memos.size());
+ source.Reply(_("%s currently has \002%d\002 memos."), nname.c_str(), mi->memos->size());
else if (count == 1)
- source.Reply(_("%s currently has \002%d\002 memos, of which \0021\002 is unread."), nname.c_str(), mi->memos.size());
+ source.Reply(_("%s currently has \002%d\002 memos, of which \0021\002 is unread."), nname.c_str(), mi->memos->size());
else
- source.Reply(_("%s currently has \002%d\002 memos, of which \002%d\002 are unread."), nname.c_str(), mi->memos.size(), count);
+ source.Reply(_("%s currently has \002%d\002 memos, of which \002%d\002 are unread."), nname.c_str(), mi->memos->size(), count);
}
if (!mi->memomax)
{
@@ -128,11 +129,11 @@ class CommandMSInfo : public Command
}
else /* !nname || (!ci || na->nc == u->Account()) */
{
- if (mi->memos.empty())
+ if (mi->memos->empty())
source.Reply(_("You currently have no memos."));
- else if (mi->memos.size() == 1)
+ else if (mi->memos->size() == 1)
{
- if (mi->memos[0]->HasFlag(MF_UNREAD))
+ if (mi->GetMemo(0)->HasFlag(MF_UNREAD))
source.Reply(_("You currently have \0021\002 memo, and it has not yet been read."));
else
source.Reply(_("You currently have \0021\002 memo."));
@@ -140,17 +141,17 @@ class CommandMSInfo : public Command
else
{
unsigned count = 0, i, end;
- for (i = 0, end = mi->memos.size(); i < end; ++i)
- if (mi->memos[i]->HasFlag(MF_UNREAD))
+ for (i = 0, end = mi->memos->size(); i < end; ++i)
+ if (mi->GetMemo(i)->HasFlag(MF_UNREAD))
++count;
- if (count == mi->memos.size())
+ if (count == mi->memos->size())
source.Reply(_("You currently have \002%d\002 memos; all of them are unread."), count);
else if (!count)
- source.Reply(_("You currently have \002%d\002 memos."), mi->memos.size());
+ source.Reply(_("You currently have \002%d\002 memos."), mi->memos->size());
else if (count == 1)
- source.Reply(_("You currently have \002%d\002 memos, of which \0021\002 is unread."), mi->memos.size());
+ source.Reply(_("You currently have \002%d\002 memos, of which \0021\002 is unread."), mi->memos->size());
else
- source.Reply(_("You currently have \002%d\002 memos, of which \002%d\002 are unread."), mi->memos.size(), count);
+ source.Reply(_("You currently have \002%d\002 memos, of which \002%d\002 are unread."), mi->memos->size(), count);
}
if (!mi->memomax)
diff --git a/modules/commands/ms_list.cpp b/modules/commands/ms_list.cpp
index 41b0d05a7..bbf245b46 100644
--- a/modules/commands/ms_list.cpp
+++ b/modules/commands/ms_list.cpp
@@ -27,7 +27,7 @@ class CommandMSList : public Command
User *u = source.u;
Anope::string param = !params.empty() ? params[0] : "", chan;
- ChannelInfo *ci = NULL;
+ ChannelInfo *ci;
const MemoInfo *mi;
if (!param.empty() && param[0] == '#')
@@ -35,7 +35,8 @@ class CommandMSList : public Command
chan = param;
param = params.size() > 1 ? params[1] : "";
- if (!(ci = cs_findchan(chan)))
+ ci = cs_findchan(chan);
+ if (!ci)
{
source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str());
return;
@@ -52,7 +53,7 @@ class CommandMSList : public Command
if (!param.empty() && !isdigit(param[0]) && !param.equals_ci("NEW"))
this->OnSyntaxError(source, param);
- else if (!mi->memos.size())
+ else if (!mi->memos->size())
{
if (!chan.empty())
source.Reply(MEMO_X_HAS_NO_MEMOS, chan.c_str());
@@ -79,10 +80,10 @@ class CommandMSList : public Command
void HandleNumber(unsigned Number) anope_override
{
- if (!Number || Number > mi->memos.size())
+ if (!Number || Number > mi->memos->size())
return;
- Memo *m = mi->memos[Number];
+ const Memo *m = mi->GetMemo(Number);
ListFormatter::ListEntry entry;
entry["Number"] = (m->HasFlag(MF_UNREAD) ? "* " : " ") + stringify(Number + 1);
@@ -99,8 +100,8 @@ class CommandMSList : public Command
if (!param.empty())
{
unsigned i, end;
- for (i = 0, end = mi->memos.size(); i < end; ++i)
- if (mi->memos[i]->HasFlag(MF_UNREAD))
+ for (i = 0, end = mi->memos->size(); i < end; ++i)
+ if (mi->GetMemo(i)->HasFlag(MF_UNREAD))
break;
if (i == end)
{
@@ -112,12 +113,12 @@ class CommandMSList : public Command
}
}
- for (unsigned i = 0, end = mi->memos.size(); i < end; ++i)
+ for (unsigned i = 0, end = mi->memos->size(); i < end; ++i)
{
- if (!param.empty() && !mi->memos[i]->HasFlag(MF_UNREAD))
+ if (!param.empty() && !mi->GetMemo(i)->HasFlag(MF_UNREAD))
continue;
- Memo *m = mi->memos[i];
+ const Memo *m = mi->GetMemo(i);
ListFormatter::ListEntry entry;
entry["Number"] = (m->HasFlag(MF_UNREAD) ? "* " : " ") + stringify(i + 1);
diff --git a/modules/commands/ms_read.cpp b/modules/commands/ms_read.cpp
index 01dba1592..c9d0c4345 100644
--- a/modules/commands/ms_read.cpp
+++ b/modules/commands/ms_read.cpp
@@ -14,19 +14,19 @@
#include "module.h"
#include "memoserv.h"
-void rsend_notify(CommandSource &source, MemoInfo *mi, Memo *m, const Anope::string &targ)
+static void rsend_notify(CommandSource &source, MemoInfo *mi, Memo *m, const Anope::string &targ)
{
/* Only send receipt if memos are allowed */
if (memoserv && !readonly)
{
/* Get nick alias for sender */
- NickAlias *na = findnick(m->sender);
+ const NickAlias *na = findnick(m->sender);
if (!na)
return;
/* Get nick core for sender */
- NickCore *nc = na->nc;
+ const NickCore *nc = na->nc;
if (!nc)
return;
@@ -52,23 +52,23 @@ class MemoListCallback : public NumberList
{
CommandSource &source;
MemoInfo *mi;
- ChannelInfo *ci;
+ const ChannelInfo *ci;
public:
- MemoListCallback(CommandSource &_source, MemoInfo *_mi, ChannelInfo *_ci, const Anope::string &numlist) : NumberList(numlist, false), source(_source), mi(_mi), ci(_ci)
+ MemoListCallback(CommandSource &_source, MemoInfo *_mi, const ChannelInfo *_ci, const Anope::string &numlist) : NumberList(numlist, false), source(_source), mi(_mi), ci(_ci)
{
}
void HandleNumber(unsigned Number) anope_override
{
- if (!Number || Number > mi->memos.size())
+ if (!Number || Number > mi->memos->size())
return;
MemoListCallback::DoRead(source, mi, ci, Number - 1);
}
- static void DoRead(CommandSource &source, MemoInfo *mi, ChannelInfo *ci, unsigned index)
+ static void DoRead(CommandSource &source, MemoInfo *mi, const ChannelInfo *ci, unsigned index)
{
- Memo *m = mi->memos[index];
+ Memo *m = mi->GetMemo(index);
if (ci)
source.Reply(_("Memo %d from %s (%s). To delete, type: \002%s%s DEL %s %d\002"), index + 1, m->sender.c_str(), do_strftime(m->time).c_str(), Config->UseStrictPrivMsgString.c_str(), Config->MemoServ.c_str(), ci->name.c_str(), index + 1);
else
@@ -96,7 +96,7 @@ class CommandMSRead : public Command
User *u = source.u;
MemoInfo *mi;
- ChannelInfo *ci = NULL;
+ ChannelInfo *ci;
Anope::string numstr = params[0], chan;
if (!numstr.empty() && numstr[0] == '#')
@@ -104,7 +104,8 @@ class CommandMSRead : public Command
chan = numstr;
numstr = params.size() > 1 ? params[1] : "";
- if (!(ci = cs_findchan(chan)))
+ ci = cs_findchan(chan);
+ if (!ci)
{
source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str());
return;
@@ -117,11 +118,11 @@ class CommandMSRead : public Command
mi = &ci->memos;
}
else
- mi = &u->Account()->memos;
+ mi = const_cast<MemoInfo *>(&u->Account()->memos);
if (numstr.empty() || (!numstr.equals_ci("LAST") && !numstr.equals_ci("NEW") && !numstr.is_number_only()))
this->OnSyntaxError(source, numstr);
- else if (mi->memos.empty())
+ else if (mi->memos->empty())
{
if (!chan.empty())
source.Reply(MEMO_X_HAS_NO_MEMOS, chan.c_str());
@@ -135,8 +136,8 @@ class CommandMSRead : public Command
if (numstr.equals_ci("NEW"))
{
int readcount = 0;
- for (i = 0, end = mi->memos.size(); i < end; ++i)
- if (mi->memos[i]->HasFlag(MF_UNREAD))
+ for (i = 0, end = mi->memos->size(); i < end; ++i)
+ if (mi->GetMemo(i)->HasFlag(MF_UNREAD))
{
MemoListCallback::DoRead(source, mi, ci, i);
++readcount;
@@ -151,7 +152,7 @@ class CommandMSRead : public Command
}
else if (numstr.equals_ci("LAST"))
{
- for (i = 0, end = mi->memos.size() - 1; i < end; ++i);
+ for (i = 0, end = mi->memos->size() - 1; i < end; ++i);
MemoListCallback::DoRead(source, mi, ci, i);
}
else /* number[s] */
diff --git a/modules/commands/ms_rsend.cpp b/modules/commands/ms_rsend.cpp
index aca957b05..bf5292dbc 100644
--- a/modules/commands/ms_rsend.cpp
+++ b/modules/commands/ms_rsend.cpp
@@ -32,7 +32,7 @@ class CommandMSRSend : public Command
const Anope::string &nick = params[0];
const Anope::string &text = params[1];
- NickAlias *na = NULL;
+ const NickAlias *na = NULL;
/* prevent user from rsend to themselves */
if ((na = findnick(nick)) && na->nc == u->Account())
@@ -65,7 +65,7 @@ class CommandMSRSend : public Command
MemoInfo *mi = memoserv->GetMemoInfo(nick, ischan);
if (mi == NULL)
throw CoreException("NULL mi in ms_rsend");
- Memo *m = (mi->memos.size() ? mi->memos[mi->memos.size() - 1] : NULL);
+ Memo *m = (mi->memos->size() ? mi->GetMemo(mi->memos->size() - 1) : NULL);
if (m != NULL)
m->SetFlag(MF_RECEIPT);
}
diff --git a/modules/commands/ms_sendall.cpp b/modules/commands/ms_sendall.cpp
index db72a4905..5a7abdd70 100644
--- a/modules/commands/ms_sendall.cpp
+++ b/modules/commands/ms_sendall.cpp
@@ -37,11 +37,11 @@ class CommandMSSendAll : public Command
return;
}
- NickAlias *na = findnick(u->nick);
+ const NickAlias *na = findnick(u->nick);
- for (nickcore_map::const_iterator it = NickCoreList.begin(), it_end = NickCoreList.end(); it != it_end; ++it)
+ for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it)
{
- NickCore *nc = it->second;
+ const NickCore *nc = it->second;
if ((na && na->nc == nc) || !nc->display.equals_ci(u->nick))
memoserv->Send(u->nick, nc->display, text);
diff --git a/modules/commands/ms_set.cpp b/modules/commands/ms_set.cpp
index b4ffa95c1..ee159c466 100644
--- a/modules/commands/ms_set.cpp
+++ b/modules/commands/ms_set.cpp
@@ -20,30 +20,31 @@ class CommandMSSet : public Command
{
User *u = source.u;
const Anope::string &param = params[1];
+ NickCore *nc = u->Account();
if (param.equals_ci("ON"))
{
- u->Account()->SetFlag(NI_MEMO_SIGNON);
- u->Account()->SetFlag(NI_MEMO_RECEIVE);
+ nc->SetFlag(NI_MEMO_SIGNON);
+ nc->SetFlag(NI_MEMO_RECEIVE);
source.Reply(_("%s will now notify you of memos when you log on and when they are sent to you."), Config->MemoServ.c_str());
}
else if (param.equals_ci("LOGON"))
{
- u->Account()->SetFlag(NI_MEMO_SIGNON);
- u->Account()->UnsetFlag(NI_MEMO_RECEIVE);
+ nc->SetFlag(NI_MEMO_SIGNON);
+ nc->UnsetFlag(NI_MEMO_RECEIVE);
source.Reply(_("%s will now notify you of memos when you log on or unset /AWAY."), Config->MemoServ.c_str());
}
else if (param.equals_ci("NEW"))
{
- u->Account()->UnsetFlag(NI_MEMO_SIGNON);
- u->Account()->SetFlag(NI_MEMO_RECEIVE);
+ nc->UnsetFlag(NI_MEMO_SIGNON);
+ nc->SetFlag(NI_MEMO_RECEIVE);
source.Reply(_("%s will now notify you of memos when they are sent to you."), Config->MemoServ.c_str());
}
else if (param.equals_ci("MAIL"))
{
- if (!u->Account()->email.empty())
+ if (!nc->email.empty())
{
- u->Account()->SetFlag(NI_MEMO_MAIL);
+ nc->SetFlag(NI_MEMO_MAIL);
source.Reply(_("You will now be informed about new memos via email."));
}
else
@@ -51,14 +52,14 @@ class CommandMSSet : public Command
}
else if (param.equals_ci("NOMAIL"))
{
- u->Account()->UnsetFlag(NI_MEMO_MAIL);
+ nc->UnsetFlag(NI_MEMO_MAIL);
source.Reply(_("You will no longer be informed via email."));
}
else if (param.equals_ci("OFF"))
{
- u->Account()->UnsetFlag(NI_MEMO_SIGNON);
- u->Account()->UnsetFlag(NI_MEMO_RECEIVE);
- u->Account()->UnsetFlag(NI_MEMO_MAIL);
+ nc->UnsetFlag(NI_MEMO_SIGNON);
+ nc->UnsetFlag(NI_MEMO_RECEIVE);
+ nc->UnsetFlag(NI_MEMO_MAIL);
source.Reply(_("%s will not send you any notification of memos."), Config->MemoServ.c_str());
}
else
@@ -86,7 +87,9 @@ class CommandMSSet : public Command
p1 = p2;
p2 = p3;
p3 = params.size() > 4 ? params[4] : "";
- if (!(ci = cs_findchan(chan)))
+
+ ci = cs_findchan(chan);
+ if (!ci)
{
source.Reply(CHAN_X_NOT_REGISTERED, chan.c_str());
return;
@@ -102,14 +105,14 @@ class CommandMSSet : public Command
{
if (!p2.empty() && !p2.equals_ci("HARD") && chan.empty())
{
- NickAlias *na;
+ const NickAlias *na;
if (!(na = findnick(p1)))
{
source.Reply(NICK_X_NOT_REGISTERED, p1.c_str());
return;
}
user = p1;
- mi = &na->nc->memos;
+ mi = const_cast<MemoInfo *>(&na->nc->memos);
nc = na->nc;
p1 = p2;
p2 = p3;
@@ -209,7 +212,7 @@ class CommandMSSet : public Command
{
User *u = source.u;
const Anope::string &cmd = params[0];
- MemoInfo *mi = &u->Account()->memos;
+ MemoInfo *mi = const_cast<MemoInfo *>(&u->Account()->memos);
if (readonly)
source.Reply(_("Sorry, memo option setting is temporarily disabled."));
diff --git a/modules/commands/ms_staff.cpp b/modules/commands/ms_staff.cpp
index 254a12b7b..adfe51d68 100644
--- a/modules/commands/ms_staff.cpp
+++ b/modules/commands/ms_staff.cpp
@@ -36,9 +36,9 @@ class CommandMSStaff : public Command
return;
}
- for (nickcore_map::const_iterator it = NickCoreList.begin(), it_end = NickCoreList.end(); it != it_end; ++it)
+ for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it)
{
- NickCore *nc = it->second;
+ const NickCore *nc = it->second;
if (nc->IsServicesOper())
memoserv->Send(source.u->nick, nc->display, text, true);
diff --git a/modules/commands/ns_access.cpp b/modules/commands/ns_access.cpp
index 2d63c472e..48a06d088 100644
--- a/modules/commands/ns_access.cpp
+++ b/modules/commands/ns_access.cpp
@@ -18,7 +18,6 @@ class CommandNSAccess : public Command
private:
void DoAdd(CommandSource &source, NickCore *nc, const Anope::string &mask)
{
-
if (mask.empty())
{
this->OnSyntaxError(source, "ADD");
@@ -110,7 +109,7 @@ class CommandNSAccess : public Command
NickCore *nc;
if (!nick.empty())
{
- NickAlias *na = findnick(nick);
+ const NickAlias *na = findnick(nick);
if (na == NULL)
{
source.Reply(NICK_X_NOT_REGISTERED, nick.c_str());
diff --git a/modules/commands/ns_ajoin.cpp b/modules/commands/ns_ajoin.cpp
index 2e64ebfe0..50bce89e3 100644
--- a/modules/commands/ns_ajoin.cpp
+++ b/modules/commands/ns_ajoin.cpp
@@ -15,18 +15,18 @@
struct AJoinList : std::vector<std::pair<Anope::string, Anope::string> >, ExtensibleItem, Serializable
{
- NickCore *nc;
+ serialize_obj<NickCore> nc;
AJoinList(NickCore *n) : nc(n) { }
- Anope::string serialize_name() const anope_override
+ const Anope::string serialize_name() const anope_override
{
return "AJoinList";
}
- serialized_data serialize() anope_override
+ Serialize::Data serialize() const anope_override
{
- serialized_data sd;
+ Serialize::Data sd;
sd["nc"] << this->nc->display;
Anope::string channels;
@@ -43,14 +43,20 @@ struct AJoinList : std::vector<std::pair<Anope::string, Anope::string> >, Extens
return sd;
}
- static void unserialize(serialized_data &sd)
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &sd)
{
NickCore *nc = findcore(sd["nc"].astr());
if (nc == NULL)
- return;
+ return NULL;
- AJoinList *aj = new AJoinList(nc);
- nc->Extend("ns_ajoin_channels", aj);
+ AJoinList *aj;
+ if (obj)
+ aj = debug_cast<AJoinList *>(obj);
+ else
+ {
+ aj = new AJoinList(nc);
+ nc->Extend("ns_ajoin_channels", aj);
+ }
Anope::string token;
spacesepstream ssep(sd["channels"].astr());
@@ -68,6 +74,8 @@ struct AJoinList : std::vector<std::pair<Anope::string, Anope::string> >, Extens
aj->push_back(std::make_pair(chan, key));
}
+
+ return aj;
}
};
@@ -200,7 +208,7 @@ class NSAJoin : public Module
void OnNickIdentify(User *u) anope_override
{
AJoinList *channels = u->Account()->GetExt<AJoinList *>("ns_ajoin_channels");
- BotInfo *bi = findbot(Config->NickServ);
+ const BotInfo *bi = findbot(Config->NickServ);
if (channels == NULL || bi == NULL)
return;
@@ -208,9 +216,12 @@ class NSAJoin : public Module
for (unsigned i = 0; i < channels->size(); ++i)
{
Channel *c = findchan(channels->at(i).first);
- ChannelInfo *ci = c != NULL ? c->ci : cs_findchan(channels->at(i).first);
- if (c == NULL && ci != NULL)
- c = ci->c;
+ ChannelInfo *ci;
+
+ if (c)
+ ci = c->ci;
+ else
+ ci = cs_findchan(channels->at(i).first);
bool need_invite = false;
Anope::string key = channels->at(i).second;
diff --git a/modules/commands/ns_alist.cpp b/modules/commands/ns_alist.cpp
index abb8c722c..3ce429e7d 100644
--- a/modules/commands/ns_alist.cpp
+++ b/modules/commands/ns_alist.cpp
@@ -30,7 +30,7 @@ class CommandNSAList : public Command
if (params.size() && u->IsServicesOper())
nick = params[0];
- NickAlias *na = findnick(nick);
+ const NickAlias *na = findnick(nick);
if (!na)
{
@@ -45,7 +45,7 @@ class CommandNSAList : public Command
source.Reply(_("Channels that \002%s\002 has access on:"), na->nick.c_str());
- for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it)
+ for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it)
{
ChannelInfo *ci = it->second;
ListFormatter::ListEntry entry;
diff --git a/modules/commands/ns_cert.cpp b/modules/commands/ns_cert.cpp
index 6ad106161..2117ed994 100644
--- a/modules/commands/ns_cert.cpp
+++ b/modules/commands/ns_cert.cpp
@@ -16,7 +16,7 @@
class CommandNSCert : public Command
{
private:
- void DoServAdminList(CommandSource &source, NickCore *nc)
+ void DoServAdminList(CommandSource &source, const NickCore *nc)
{
if (nc->cert.empty())
{
@@ -112,7 +112,7 @@ class CommandNSCert : public Command
return;
}
- void DoList(CommandSource &source, NickCore *nc)
+ void DoList(CommandSource &source, const NickCore *nc)
{
User *u = source.u;
@@ -154,18 +154,20 @@ class CommandNSCert : public Command
const Anope::string &cmd = params[0];
const Anope::string &mask = params.size() > 1 ? params[1] : "";
- NickAlias *na;
+ const NickAlias *na;
if (cmd.equals_ci("LIST") && u->IsServicesOper() && !mask.empty() && (na = findnick(mask)))
return this->DoServAdminList(source, na->nc);
+ NickCore *nc = u->Account();
+
if (u->Account()->HasFlag(NI_SUSPENDED))
source.Reply(NICK_X_SUSPENDED, u->Account()->display.c_str());
else if (cmd.equals_ci("ADD"))
- return this->DoAdd(source, u->Account(), mask);
+ return this->DoAdd(source, nc, mask);
else if (cmd.equals_ci("DEL"))
- return this->DoDel(source, u->Account(), mask);
+ return this->DoDel(source, nc, mask);
else if (cmd.equals_ci("LIST"))
- return this->DoList(source, u->Account());
+ return this->DoList(source, nc);
else
this->OnSyntaxError(source, cmd);
@@ -203,7 +205,7 @@ class NSCert : public Module
void DoAutoIdentify(User *u)
{
- BotInfo *bi = findbot(Config->NickServ);
+ const BotInfo *bi = findbot(Config->NickServ);
NickAlias *na = findnick(u->nick);
if (!bi || !na)
return;
diff --git a/modules/commands/ns_drop.cpp b/modules/commands/ns_drop.cpp
index 0bb6eecc2..3f3a5dd46 100644
--- a/modules/commands/ns_drop.cpp
+++ b/modules/commands/ns_drop.cpp
@@ -63,7 +63,7 @@ class CommandNSDrop : public Command
FOREACH_MOD(I_OnNickDrop, OnNickDrop(u, na));
Log(!is_mine ? LOG_OVERRIDE : LOG_COMMAND, u, this) << "to drop nickname " << na->nick << " (group: " << na->nc->display << ") (email: " << (!na->nc->email.empty() ? na->nc->email : "none") << ")";
- delete na;
+ na->destroy();
if (!is_mine)
{
diff --git a/modules/commands/ns_getemail.cpp b/modules/commands/ns_getemail.cpp
index f8ace530d..6301ddd4e 100644
--- a/modules/commands/ns_getemail.cpp
+++ b/modules/commands/ns_getemail.cpp
@@ -34,9 +34,9 @@ class CommandNSGetEMail : public Command
Log(LOG_ADMIN, u, this) << "on " << email;
- for (nickcore_map::const_iterator it = NickCoreList.begin(), it_end = NickCoreList.end(); it != it_end; ++it)
+ for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it)
{
- NickCore *nc = it->second;
+ const NickCore *nc = it->second;
if (!nc->email.empty() && nc->email.equals_ci(email))
{
diff --git a/modules/commands/ns_getpass.cpp b/modules/commands/ns_getpass.cpp
index 8ffc85520..f8c044119 100644
--- a/modules/commands/ns_getpass.cpp
+++ b/modules/commands/ns_getpass.cpp
@@ -27,7 +27,7 @@ class CommandNSGetPass : public Command
User *u = source.u;
const Anope::string &nick = params[0];
Anope::string tmp_pass;
- NickAlias *na;
+ const NickAlias *na;
if (!(na = findnick(nick)))
source.Reply(NICK_X_NOT_REGISTERED, nick.c_str());
diff --git a/modules/commands/ns_ghost.cpp b/modules/commands/ns_ghost.cpp
index 8b861e889..f68ddb83e 100644
--- a/modules/commands/ns_ghost.cpp
+++ b/modules/commands/ns_ghost.cpp
@@ -30,7 +30,7 @@ class CommandNSGhost : public Command
User *u = source.u;
User *user = finduser(nick);
- NickAlias *na = findnick(nick);
+ const NickAlias *na = findnick(nick);
if (!user)
source.Reply(NICK_X_NOT_IN_USE, nick.c_str());
diff --git a/modules/commands/ns_group.cpp b/modules/commands/ns_group.cpp
index 2f8617c11..dad004eee 100644
--- a/modules/commands/ns_group.cpp
+++ b/modules/commands/ns_group.cpp
@@ -58,7 +58,7 @@ class CommandNSGroup : public Command
Log(LOG_COMMAND, u, this) << "tried to use GROUP for SUSPENDED nick " << target->nick;
source.Reply(NICK_X_SUSPENDED, target->nick.c_str());
}
- else if (na && target->nc == na->nc)
+ else if (na && *target->nc == *na->nc)
source.Reply(_("You are already a member of the group of \002%s\002."), target->nick.c_str());
else if (na && na->nc != u->Account())
source.Reply(NICK_IDENTIFY_REQUIRED, Config->UseStrictPrivMsgString.c_str(), Config->NickServ.c_str());
@@ -88,7 +88,7 @@ class CommandNSGroup : public Command
* If not, check that it is valid.
*/
if (na)
- delete na;
+ na->destroy();
else
{
size_t prefixlen = Config->NSGuestNickPrefix.length();
@@ -108,7 +108,7 @@ class CommandNSGroup : public Command
na->last_realname = u->realname;
na->time_registered = na->last_seen = Anope::CurTime;
- u->Login(na->nc);
+ u->Login(target->nc);
ircdproto->SendLogin(u);
if (!Config->NoNicknameOwnership && na->nc == u->Account() && na->nc->HasFlag(NI_UNCONFIRMED) == false)
u->SetMode(findbot(Config->NickServ), UMODE_REGISTERED);
@@ -188,22 +188,23 @@ class CommandNSUngroup : public Command
{
NickCore *oldcore = na->nc;
- std::list<NickAlias *>::iterator it = std::find(oldcore->aliases.begin(), oldcore->aliases.end(), na);
+ std::list<serialize_obj<NickAlias> >::iterator it = std::find(oldcore->aliases.begin(), oldcore->aliases.end(), na);
if (it != oldcore->aliases.end())
oldcore->aliases.erase(it);
if (na->nick.equals_ci(oldcore->display))
change_core_display(oldcore);
- na->nc = new NickCore(na->nick);
- na->nc->aliases.push_back(na);
+ NickCore *nc = new NickCore(na->nick);
+ na->nc = nc;
+ nc->aliases.push_back(na);
- na->nc->pass = oldcore->pass;
+ nc->pass = oldcore->pass;
if (!oldcore->email.empty())
- na->nc->email = oldcore->email;
+ nc->email = oldcore->email;
if (!oldcore->greet.empty())
- na->nc->greet = oldcore->greet;
- na->nc->language = oldcore->language;
+ nc->greet = oldcore->greet;
+ nc->language = oldcore->language;
source.Reply(_("Nick %s has been ungrouped from %s."), na->nick.c_str(), oldcore->display.c_str());
@@ -240,37 +241,50 @@ class CommandNSGList : public Command
void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
{
User *u = source.u;
- Anope::string nick = !params.empty() ? params[0] : "";
-
- const NickCore *nc = u->Account();
+ const Anope::string &nick = !params.empty() ? params[0] : "";
+ const NickCore *nc;
- if (!nick.empty() && (!nick.equals_ci(u->nick) && !u->IsServicesOper()))
- source.Reply(ACCESS_DENIED, Config->NickServ.c_str());
- else if (!nick.empty() && (!findnick(nick) || !(nc = findnick(nick)->nc)))
- source.Reply(nick.empty() ? NICK_NOT_REGISTERED : _(NICK_X_NOT_REGISTERED), nick.c_str());
- else
+ if (!nick.empty())
{
- ListFormatter list;
- list.addColumn("Nick").addColumn("Expires");
- for (std::list<NickAlias *>::const_iterator it = nc->aliases.begin(), it_end = nc->aliases.end(); it != it_end; ++it)
+ const NickAlias *na = findnick(nick);
+ if (!na)
{
- NickAlias *na2 = *it;
-
- ListFormatter::ListEntry entry;
- entry["Nick"] = na2->nick;
- entry["Expires"] = (na2->HasFlag(NS_NO_EXPIRE) || !Config->NSExpire) ? "Does not expire" : ("expires in " + do_strftime(na2->last_seen + Config->NSExpire));
- list.addEntry(entry);
+ source.Reply(NICK_X_NOT_REGISTERED, nick.c_str());
+ return;
+ }
+ else if (!u->IsServicesOper())
+ {
+ source.Reply(ACCESS_DENIED, Config->NickServ.c_str());
+ return;
}
- source.Reply(!nick.empty() ? _("List of nicknames in the group of \002%s\002:") : _("List of nicknames in your group:"), nc->display.c_str());
- std::vector<Anope::string> replies;
- list.Process(replies);
-
- for (unsigned i = 0; i < replies.size(); ++i)
- source.Reply(replies[i]);
+ nc = na->nc;
+ }
+ else
+ nc = u->Account();
- source.Reply(_("%d nicknames in the group."), nc->aliases.size());
+ ListFormatter list;
+ list.addColumn("Nick").addColumn("Expires");
+ for (std::list<serialize_obj<NickAlias> >::const_iterator it = nc->aliases.begin(), it_end = nc->aliases.end(); it != it_end;)
+ {
+ const NickAlias *na2 = *it++;
+ if (!na2)
+ continue;
+
+ ListFormatter::ListEntry entry;
+ entry["Nick"] = na2->nick;
+ entry["Expires"] = (na2->HasFlag(NS_NO_EXPIRE) || !Config->NSExpire) ? "Does not expire" : ("expires in " + do_strftime(na2->last_seen + Config->NSExpire));
+ list.addEntry(entry);
}
+
+ source.Reply(!nick.empty() ? _("List of nicknames in the group of \002%s\002:") : _("List of nicknames in your group:"), nc->display.c_str());
+ std::vector<Anope::string> replies;
+ list.Process(replies);
+
+ for (unsigned i = 0; i < replies.size(); ++i)
+ source.Reply(replies[i]);
+
+ source.Reply(_("%d nicknames in the group."), nc->aliases.size());
}
bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override
diff --git a/modules/commands/ns_info.cpp b/modules/commands/ns_info.cpp
index a30b5452b..20ed6ee42 100644
--- a/modules/commands/ns_info.cpp
+++ b/modules/commands/ns_info.cpp
@@ -16,7 +16,7 @@
class CommandNSInfo : public Command
{
private:
- template<typename T, unsigned END> void CheckOptStr(User *u, Anope::string &buf, T opt, const char *str, Flags<T, END> *nc, bool reverse_logic = false)
+ template<typename T, unsigned END> void CheckOptStr(User *u, Anope::string &buf, T opt, const char *str, const Flags<T, END> *nc, bool reverse_logic = false)
{
if (reverse_logic ? !nc->HasFlag(opt) : nc->HasFlag(opt))
{
diff --git a/modules/commands/ns_list.cpp b/modules/commands/ns_list.cpp
index de2852302..2c27f4d47 100644
--- a/modules/commands/ns_list.cpp
+++ b/modules/commands/ns_list.cpp
@@ -75,9 +75,9 @@ class CommandNSList : public Command
list.addColumn("Nick").addColumn("Last usermask");
- for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; ++it)
+ for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it)
{
- NickAlias *na = it->second;
+ const NickAlias *na = it->second;
/* Don't show private nicks to non-services admins. */
if (na->nc->HasFlag(NI_PRIVATE) && !is_servadmin && na->nc != mync)
diff --git a/modules/commands/ns_register.cpp b/modules/commands/ns_register.cpp
index 6050e88fb..bbac6d766 100644
--- a/modules/commands/ns_register.cpp
+++ b/modules/commands/ns_register.cpp
@@ -13,7 +13,12 @@
#include "module.h"
-static bool SendRegmail(User *u, NickAlias *na, BotInfo *bi);
+static bool SendRegmail(User *u, const NickAlias *na, const BotInfo *bi);
+
+struct ExtensibleString : Anope::string, ExtensibleItem
+{
+ ExtensibleString(const Anope::string &s) : Anope::string(s) { }
+};
class CommandNSConfirm : public Command
{
@@ -49,13 +54,14 @@ class CommandNSConfirm : public Command
Anope::string *code = u->Account()->GetExt<ExtensibleString *>("ns_register_passcode");
if (code != NULL && *code == passcode)
{
- u->Account()->Shrink("ns_register_passcode");
+ NickCore *nc = u->Account();
+ nc->Shrink("ns_register_passcode");
Log(LOG_COMMAND, u, this) << "to confirm their email";
source.Reply(_("Your email address of \002%s\002 has been confirmed."), u->Account()->email.c_str());
- u->Account()->UnsetFlag(NI_UNCONFIRMED);
+ nc->UnsetFlag(NI_UNCONFIRMED);
ircdproto->SendLogin(u);
- NickAlias *na = findnick(u->nick);
+ const NickAlias *na = findnick(u->nick);
if (!Config->NoNicknameOwnership && na != NULL && na->nc == u->Account() && na->nc->HasFlag(NI_UNCONFIRMED) == false)
u->SetMode(findbot(Config->NickServ), UMODE_REGISTERED);
}
@@ -170,18 +176,19 @@ class CommandNSRegister : public Command
source.Reply(MAIL_X_INVALID, email.c_str());
else
{
- na = new NickAlias(u->nick, new NickCore(u->nick));
- enc_encrypt(pass, na->nc->pass);
+ NickCore *nc = new NickCore(u->nick);
+ na = new NickAlias(u->nick, nc);
+ enc_encrypt(pass, nc->pass);
if (!email.empty())
- na->nc->email = email;
+ nc->email = email;
Anope::string last_usermask = u->GetIdent() + "@" + u->GetDisplayedHost();
na->last_usermask = last_usermask;
na->last_realname = u->realname;
if (Config->NSAddAccessOnReg)
- na->nc->AddAccess(create_mask(u));
+ nc->AddAccess(create_mask(u));
- u->Login(na->nc);
+ u->Login(nc);
Log(LOG_COMMAND, u, this) << "to register " << na->nick << " (email: " << (!na->nc->email.empty() ? na->nc->email : "none") << ")";
@@ -198,12 +205,12 @@ class CommandNSRegister : public Command
if (Config->NSRegistration.equals_ci("admin"))
{
- na->nc->SetFlag(NI_UNCONFIRMED);
+ nc->SetFlag(NI_UNCONFIRMED);
source.Reply(_("All new accounts must be validated by an administrator. Please wait for your registration to be confirmed."));
}
else if (Config->NSRegistration.equals_ci("mail"))
{
- na->nc->SetFlag(NI_UNCONFIRMED);
+ nc->SetFlag(NI_UNCONFIRMED);
if (SendRegmail(u, na, source.owner))
{
source.Reply(_("A passcode has been sent to %s, please type %s%s confirm <passcode> to confirm your email address."), email.c_str(), Config->UseStrictPrivMsgString.c_str(), Config->NickServ.c_str());
@@ -276,7 +283,7 @@ class CommandNSResend : public Command
return;
User *u = source.u;
- NickAlias *na = findnick(u->nick);
+ const NickAlias *na = findnick(u->nick);
if (na == NULL)
source.Reply(NICK_NOT_REGISTERED);
@@ -335,8 +342,10 @@ class NSRegister : public Module
}
};
-static bool SendRegmail(User *u, NickAlias *na, BotInfo *bi)
+static bool SendRegmail(User *u, const NickAlias *na, const BotInfo *bi)
{
+ NickCore *nc = na->nc;
+
Anope::string *code = na->nc->GetExt<ExtensibleString *>("ns_register_passcode");
Anope::string codebuf;
if (code == NULL)
@@ -351,7 +360,7 @@ static bool SendRegmail(User *u, NickAlias *na, BotInfo *bi)
int idx, min = 1, max = 62;
for (idx = 0; idx < 9; ++idx)
codebuf += chars[1 + static_cast<int>((static_cast<float>(max - min)) * static_cast<uint16_t>(rand()) / 65536.0) + min];
- na->nc->Extend("ns_register_passcode", new ExtensibleString(codebuf));
+ nc->Extend("ns_register_passcode", new ExtensibleString(codebuf));
}
else
codebuf = *code;
@@ -367,7 +376,7 @@ static bool SendRegmail(User *u, NickAlias *na, BotInfo *bi)
message = message.replace_all_cs("%N", Config->NetworkName);
message = message.replace_all_cs("%c", codebuf);
- return Mail(u, na->nc, bi, subject, message);
+ return Mail(u, nc, bi, subject, message);
}
MODULE_INIT(NSRegister)
diff --git a/modules/commands/ns_resetpass.cpp b/modules/commands/ns_resetpass.cpp
index f0dfe1aad..21c5d7a4f 100644
--- a/modules/commands/ns_resetpass.cpp
+++ b/modules/commands/ns_resetpass.cpp
@@ -13,7 +13,7 @@
#include "module.h"
-static bool SendResetEmail(User *u, NickAlias *na, BotInfo *bi);
+static bool SendResetEmail(User *u, const NickAlias *na, const BotInfo *bi);
class CommandNSResetPass : public Command
{
@@ -28,7 +28,7 @@ class CommandNSResetPass : public Command
void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
{
User *u = source.u;
- NickAlias *na;
+ const NickAlias *na;
if (Config->RestrictMail && (!u->Account() || !u->HasCommand("nickserv/resetpass")))
source.Reply(ACCESS_DENIED);
@@ -89,19 +89,20 @@ class NSResetPass : public Module
ResetInfo *ri = na ? na->nc->GetExt<ResetInfo *>("ns_resetpass") : NULL;
if (na && ri)
{
+ NickCore *nc = na->nc;
const Anope::string &passcode = params[1];
if (ri->time < Anope::CurTime - 3600)
{
- na->nc->Shrink("ns_resetpass");
+ nc->Shrink("ns_resetpass");
source.Reply(_("Your password reset request has expired."));
}
else if (passcode.equals_cs(ri->code))
{
- na->nc->Shrink("ns_resetpass");
+ nc->Shrink("ns_resetpass");
Log(LOG_COMMAND, u, &commandnsresetpass) << "confirmed RESETPASS to forcefully identify to " << na->nick;
- na->nc->UnsetFlag(NI_UNCONFIRMED);
+ nc->UnsetFlag(NI_UNCONFIRMED);
u->Identify(na);
source.Reply(_("You are now identified for your nick. Change your password now."));
@@ -118,7 +119,7 @@ class NSResetPass : public Module
}
};
-static bool SendResetEmail(User *u, NickAlias *na, BotInfo *bi)
+static bool SendResetEmail(User *u, const NickAlias *na, const BotInfo *bi)
{
int min = 1, max = 62;
int chars[] = {
@@ -148,9 +149,10 @@ static bool SendResetEmail(User *u, NickAlias *na, BotInfo *bi)
ResetInfo *ri = new ResetInfo;
ri->code = passcode;
ri->time = Anope::CurTime;
- na->nc->Extend("ns_resetpass", ri);
+ NickCore *nc = na->nc;
+ nc->Extend("ns_resetpass", ri);
- return Mail(u, na->nc, bi, subject, message);
+ return Mail(u, nc, bi, subject, message);
}
MODULE_INIT(NSResetPass)
diff --git a/modules/commands/ns_saset.cpp b/modules/commands/ns_saset.cpp
index 1b77c2b57..3721dcda3 100644
--- a/modules/commands/ns_saset.cpp
+++ b/modules/commands/ns_saset.cpp
@@ -33,10 +33,10 @@ class CommandNSSASet : public Command
this->SendSyntax(source);
source.Reply(_("Sets various nickname options. \037option\037 can be one of:"));
Anope::string this_name = source.command;
- for (BotInfo::command_map::iterator it = source.owner->commands.begin(), it_end = source.owner->commands.end(); it != it_end; ++it)
+ for (BotInfo::command_map::const_iterator it = source.owner->commands.begin(), it_end = source.owner->commands.end(); it != it_end; ++it)
{
const Anope::string &c_name = it->first;
- CommandInfo &info = it->second;
+ const CommandInfo &info = it->second;
if (c_name.find_ci(this_name + " ") == 0)
{
@@ -67,7 +67,7 @@ class CommandNSSASetPassword : public Command
void Execute(CommandSource &source, const std::vector<Anope::string> &params) anope_override
{
User *u = source.u;
- NickAlias *setter_na = findnick(params[0]);
+ const NickAlias *setter_na = findnick(params[0]);
if (setter_na == NULL)
{
source.Reply(NICK_X_NOT_REGISTERED, params[0].c_str());
diff --git a/modules/commands/ns_sendpass.cpp b/modules/commands/ns_sendpass.cpp
index 678518d5d..deff5419c 100644
--- a/modules/commands/ns_sendpass.cpp
+++ b/modules/commands/ns_sendpass.cpp
@@ -13,7 +13,7 @@
#include "module.h"
-static bool SendPassMail(User *u, NickAlias *na, BotInfo *bi, const Anope::string &pass);
+static bool SendPassMail(User *u, const NickAlias *na, const BotInfo *bi, const Anope::string &pass);
class CommandNSSendPass : public Command
{
@@ -29,7 +29,7 @@ class CommandNSSendPass : public Command
{
User *u = source.u;
const Anope::string &nick = params[0];
- NickAlias *na;
+ const NickAlias *na;
if (Config->RestrictMail && (!u->Account() || !u->HasCommand("nickserv/sendpass")))
source.Reply(ACCESS_DENIED);
@@ -86,7 +86,7 @@ class NSSendPass : public Module
}
};
-static bool SendPassMail(User *u, NickAlias *na, BotInfo *bi, const Anope::string &pass)
+static bool SendPassMail(User *u, const NickAlias *na, const BotInfo *bi, const Anope::string &pass)
{
Anope::string subject = translate(na->nc, Config->MailSendpassSubject.c_str());
Anope::string message = translate(na->nc, Config->MailSendpassMessage.c_str());
diff --git a/modules/commands/ns_set.cpp b/modules/commands/ns_set.cpp
index d81c4c3c8..110373853 100644
--- a/modules/commands/ns_set.cpp
+++ b/modules/commands/ns_set.cpp
@@ -34,10 +34,10 @@ class CommandNSSet : public Command
source.Reply(" ");
source.Reply(_("Sets various nickname options. \037option\037 can be one of:"));
Anope::string this_name = source.command;
- for (BotInfo::command_map::iterator it = source.owner->commands.begin(), it_end = source.owner->commands.end(); it != it_end; ++it)
+ for (BotInfo::command_map::const_iterator it = source.owner->commands.begin(), it_end = source.owner->commands.end(); it != it_end; ++it)
{
const Anope::string &c_name = it->first;
- CommandInfo &info = it->second;
+ const CommandInfo &info = it->second;
if (c_name.find_ci(this_name + " ") == 0)
{
diff --git a/modules/commands/ns_set_autoop.cpp b/modules/commands/ns_set_autoop.cpp
index 452717c3d..0cf9c649a 100644
--- a/modules/commands/ns_set_autoop.cpp
+++ b/modules/commands/ns_set_autoop.cpp
@@ -24,7 +24,7 @@ class CommandNSSetAutoOp : public Command
void Run(CommandSource &source, const Anope::string &user, const Anope::string &param)
{
- NickAlias *na = findnick(user);
+ const NickAlias *na = findnick(user);
if (na == NULL)
{
source.Reply(NICK_X_NOT_REGISTERED, user.c_str());
diff --git a/modules/commands/ns_set_display.cpp b/modules/commands/ns_set_display.cpp
index e89655f06..3a4973181 100644
--- a/modules/commands/ns_set_display.cpp
+++ b/modules/commands/ns_set_display.cpp
@@ -24,14 +24,14 @@ class CommandNSSetDisplay : public Command
void Run(CommandSource &source, const Anope::string &user, const Anope::string &param)
{
- NickAlias *user_na = findnick(user), *na = findnick(param);
+ const NickAlias *user_na = findnick(user), *na = findnick(param);
if (user_na == NULL)
{
source.Reply(NICK_X_NOT_REGISTERED, user.c_str());
return;
}
- else if (!na || na->nc != user_na->nc)
+ else if (!na || *na->nc != *user_na->nc)
{
source.Reply(_("The new display MUST be a nickname of the nickname group %s"), user_na->nc->display.c_str());
return;
diff --git a/modules/commands/ns_set_email.cpp b/modules/commands/ns_set_email.cpp
index 09ef8732c..e8b2778e5 100644
--- a/modules/commands/ns_set_email.cpp
+++ b/modules/commands/ns_set_email.cpp
@@ -13,7 +13,12 @@
#include "module.h"
-static bool SendConfirmMail(User *u, BotInfo *bi)
+struct ExtensibleString : Anope::string, ExtensibleItem
+{
+ ExtensibleString(const Anope::string &s) : Anope::string(s) { }
+};
+
+static bool SendConfirmMail(User *u, const BotInfo *bi)
{
int chars[] = {
' ', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
@@ -26,6 +31,7 @@ static bool SendConfirmMail(User *u, BotInfo *bi)
Anope::string code;
for (idx = 0; idx < 9; ++idx)
code += chars[1 + static_cast<int>((static_cast<float>(max - min)) * static_cast<uint16_t>(rand()) / 65536.0) + min];
+
u->Account()->Extend("ns_set_email_passcode", new ExtensibleString(code));
Anope::string subject = Config->MailEmailchangeSubject;
@@ -54,7 +60,7 @@ class CommandNSSetEmail : public Command
void Run(CommandSource &source, const Anope::string &user, const Anope::string &param)
{
User *u = source.u;
- NickAlias *na = findnick(user);
+ const NickAlias *na = findnick(user);
if (!na)
{
source.Reply(NICK_X_NOT_REGISTERED, user.c_str());
@@ -168,11 +174,12 @@ class NSSetEmail : public Module
{
if (params[0] == *passcode)
{
- u->Account()->email = *new_email;
+ NickCore *uac = u->Account();
+ uac->email = *new_email;
Log(LOG_COMMAND, u, command) << "to confirm their email address change to " << u->Account()->email;
source.Reply(_("Your email address has been changed to \002%s\002."), u->Account()->email.c_str());
- u->Account()->Shrink("ns_set_email");
- u->Account()->Shrink("ns_set_email_passcode");
+ uac->Shrink("ns_set_email");
+ uac->Shrink("ns_set_email_passcode");
return EVENT_STOP;
}
}
diff --git a/modules/commands/ns_set_greet.cpp b/modules/commands/ns_set_greet.cpp
index ed620dc05..0bdb1b371 100644
--- a/modules/commands/ns_set_greet.cpp
+++ b/modules/commands/ns_set_greet.cpp
@@ -24,7 +24,7 @@ class CommandNSSetGreet : public Command
void Run(CommandSource &source, const Anope::string &user, const Anope::string &param)
{
- NickAlias *na = findnick(user);
+ const NickAlias *na = findnick(user);
if (!na)
{
source.Reply(NICK_X_NOT_REGISTERED, user.c_str());
diff --git a/modules/commands/ns_set_hide.cpp b/modules/commands/ns_set_hide.cpp
index 8d0ee7fb3..1bdecb181 100644
--- a/modules/commands/ns_set_hide.cpp
+++ b/modules/commands/ns_set_hide.cpp
@@ -24,7 +24,7 @@ class CommandNSSetHide : public Command
void Run(CommandSource &source, const Anope::string &user, const Anope::string &param, const Anope::string &arg)
{
- NickAlias *na = findnick(user);
+ const NickAlias *na = findnick(user);
if (!na)
{
source.Reply(NICK_X_NOT_REGISTERED, user.c_str());
diff --git a/modules/commands/ns_set_kill.cpp b/modules/commands/ns_set_kill.cpp
index 0fc64196d..d2e40268e 100644
--- a/modules/commands/ns_set_kill.cpp
+++ b/modules/commands/ns_set_kill.cpp
@@ -24,7 +24,7 @@ class CommandNSSetKill : public Command
void Run(CommandSource &source, const Anope::string &user, const Anope::string &param)
{
- NickAlias *na = findnick(user);
+ const NickAlias *na = findnick(user);
if (!na)
{
source.Reply(NICK_X_NOT_REGISTERED, user.c_str());
diff --git a/modules/commands/ns_set_language.cpp b/modules/commands/ns_set_language.cpp
index ecd8d9259..4d3ba2c0e 100644
--- a/modules/commands/ns_set_language.cpp
+++ b/modules/commands/ns_set_language.cpp
@@ -24,7 +24,7 @@ class CommandNSSetLanguage : public Command
void Run(CommandSource &source, const Anope::string &user, const Anope::string &param)
{
- NickAlias *na = findnick(user);
+ const NickAlias *na = findnick(user);
if (!na)
{
source.Reply(NICK_X_NOT_REGISTERED, user.c_str());
diff --git a/modules/commands/ns_set_message.cpp b/modules/commands/ns_set_message.cpp
index cb0d5107a..06aae4748 100644
--- a/modules/commands/ns_set_message.cpp
+++ b/modules/commands/ns_set_message.cpp
@@ -24,7 +24,7 @@ class CommandNSSetMessage : public Command
void Run(CommandSource &source, const Anope::string &user, const Anope::string &param)
{
- NickAlias *na = findnick(user);
+ const NickAlias *na = findnick(user);
if (!na)
{
source.Reply(NICK_X_NOT_REGISTERED, user.c_str());
diff --git a/modules/commands/ns_set_misc.cpp b/modules/commands/ns_set_misc.cpp
index 184eddf40..f09b4ddee 100644
--- a/modules/commands/ns_set_misc.cpp
+++ b/modules/commands/ns_set_misc.cpp
@@ -13,9 +13,9 @@
#include "module.h"
-struct NSMiscData : Anope::string, ExtensibleItem, Serializable
+struct NSMiscData : ExtensibleItem, Serializable
{
- NickCore *nc;
+ serialize_obj<NickCore> nc;
Anope::string name;
Anope::string data;
@@ -23,14 +23,14 @@ struct NSMiscData : Anope::string, ExtensibleItem, Serializable
{
}
- Anope::string serialize_name() const anope_override
+ const Anope::string serialize_name() const anope_override
{
return "NSMiscData";
}
- serialized_data serialize() anope_override
+ Serialize::Data serialize() const anope_override
{
- serialized_data sdata;
+ Serialize::Data sdata;
sdata["nc"] << this->nc->display;
sdata["name"] << this->name;
@@ -39,13 +39,27 @@ struct NSMiscData : Anope::string, ExtensibleItem, Serializable
return sdata;
}
- static void unserialize(serialized_data &data)
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &data)
{
NickCore *nc = findcore(data["nc"].astr());
if (nc == NULL)
- return;
+ return NULL;
+
+ NSMiscData *d;
+ if (obj)
+ {
+ d = debug_cast<NSMiscData *>(obj);
+ d->nc = nc;
+ data["name"] >> d->name;
+ data["data"] >> d->data;
+ }
+ else
+ {
+ d = new NSMiscData(nc, data["name"].astr(), data["data"].astr());
+ nc->Extend(data["name"].astr(), d);
+ }
- nc->Extend(data["name"].astr(), new NSMiscData(nc, data["name"].astr(), data["data"].astr()));
+ return d;
}
};
@@ -67,7 +81,7 @@ class CommandNSSetMisc : public Command
void Run(CommandSource &source, const Anope::string &user, const Anope::string &param)
{
- NickAlias *na = findnick(user);
+ const NickAlias *na = findnick(user);
if (!na)
{
source.Reply(NICK_X_NOT_REGISTERED, user.c_str());
diff --git a/modules/commands/ns_set_private.cpp b/modules/commands/ns_set_private.cpp
index a7d29b39c..7b175942d 100644
--- a/modules/commands/ns_set_private.cpp
+++ b/modules/commands/ns_set_private.cpp
@@ -24,7 +24,7 @@ class CommandNSSetPrivate : public Command
void Run(CommandSource &source, const Anope::string &user, const Anope::string &param)
{
- NickAlias *na = findnick(user);
+ const NickAlias *na = findnick(user);
if (!na)
{
source.Reply(NICK_X_NOT_REGISTERED, user.c_str());
diff --git a/modules/commands/ns_set_secure.cpp b/modules/commands/ns_set_secure.cpp
index 3827197ba..46be1a250 100644
--- a/modules/commands/ns_set_secure.cpp
+++ b/modules/commands/ns_set_secure.cpp
@@ -24,7 +24,7 @@ class CommandNSSetSecure : public Command
void Run(CommandSource &source, const Anope::string &user, const Anope::string &param)
{
- NickAlias *na = findnick(user);
+ const NickAlias *na = findnick(user);
if (!na)
{
source.Reply(NICK_X_NOT_REGISTERED, user.c_str());
diff --git a/modules/commands/ns_status.cpp b/modules/commands/ns_status.cpp
index b0ce63797..b6a06b7a0 100644
--- a/modules/commands/ns_status.cpp
+++ b/modules/commands/ns_status.cpp
@@ -27,7 +27,7 @@ class CommandNSStatus : public Command
{
User *u = source.u;
const Anope::string &nick = !params.empty() ? params[0] : u->nick;
- NickAlias *na = findnick(nick);
+ const NickAlias *na = findnick(nick);
spacesepstream sep(nick);
Anope::string nickbuf;
diff --git a/modules/commands/ns_suspend.cpp b/modules/commands/ns_suspend.cpp
index 40989c84c..dd20e47b8 100644
--- a/modules/commands/ns_suspend.cpp
+++ b/modules/commands/ns_suspend.cpp
@@ -22,14 +22,14 @@ struct NickSuspend : ExtensibleItem, Serializable
{
}
- Anope::string serialize_name() const
+ const Anope::string serialize_name() const
{
return "NickSuspend";
}
- serialized_data serialize() anope_override
+ Serialize::Data serialize() const anope_override
{
- serialized_data sd;
+ Serialize::Data sd;
sd["nick"] << this->nick;
sd["when"] << this->when;
@@ -37,18 +37,25 @@ struct NickSuspend : ExtensibleItem, Serializable
return sd;
}
- static void unserialize(serialized_data &sd)
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &sd)
{
- NickAlias *na = findnick(sd["nick"].astr());
+ const NickAlias *na = findnick(sd["nick"].astr());
if (na == NULL)
- return;
+ return NULL;
- NickSuspend *ns = new NickSuspend();
+ NickSuspend *ns;
+ if (obj)
+ ns = debug_cast<NickSuspend *>(obj);
+ else
+ ns = new NickSuspend();
sd["nick"] >> ns->nick;
sd["when"] >> ns->when;
- na->nc->Extend("ns_suspend_expire", ns);
+ if (!obj)
+ na->nc->Extend("ns_suspend_expire", ns);
+
+ return ns;
}
};
@@ -98,17 +105,19 @@ class CommandNSSuspend : public Command
return;
}
- na->nc->SetFlag(NI_SUSPENDED);
- na->nc->SetFlag(NI_SECURE);
- na->nc->UnsetFlag(NI_KILLPROTECT);
- na->nc->UnsetFlag(NI_KILL_QUICK);
- na->nc->UnsetFlag(NI_KILL_IMMED);
+ NickCore *nc = na->nc;
+
+ nc->SetFlag(NI_SUSPENDED);
+ nc->SetFlag(NI_SECURE);
+ nc->UnsetFlag(NI_KILLPROTECT);
+ nc->UnsetFlag(NI_KILL_QUICK);
+ nc->UnsetFlag(NI_KILL_IMMED);
- for (std::list<NickAlias *>::iterator it = na->nc->aliases.begin(), it_end = na->nc->aliases.end(); it != it_end; ++it)
+ for (std::list<serialize_obj<NickAlias> >::iterator it = nc->aliases.begin(), it_end = nc->aliases.end(); it != it_end;)
{
- NickAlias *na2 = *it;
+ NickAlias *na2 = *it++;
- if (na2->nc == na->nc)
+ if (na2 && *na2->nc == *na->nc)
{
na2->last_quit = reason;
@@ -127,7 +136,7 @@ class CommandNSSuspend : public Command
ns->nick = na->nick;
ns->when = Anope::CurTime + expiry_secs;
- na->nc->Extend("ns_suspend_expire", ns);
+ nc->Extend("ns_suspend_expire", ns);
}
Log(LOG_ADMIN, u, this) << "for " << nick << " (" << (!reason.empty() ? reason : "No reason") << "), expires in " << (expiry_secs ? do_strftime(Anope::CurTime + expiry_secs) : "never");
@@ -221,7 +230,7 @@ class NSSuspend : public Module
~NSSuspend()
{
- for (nickcore_map::const_iterator it = NickCoreList.begin(), it_end = NickCoreList.end(); it != it_end; ++it)
+ for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it)
it->second->Shrink("ns_suspend_expire");
}
diff --git a/modules/commands/os_akill.cpp b/modules/commands/os_akill.cpp
index f59c26e1f..dec9b9ae9 100644
--- a/modules/commands/os_akill.cpp
+++ b/modules/commands/os_akill.cpp
@@ -173,7 +173,7 @@ class CommandOSAKill : public Command
{
source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str());
Log(LOG_ADMIN, u, this) << "tried to akill " << percent << "% of the network (" << affected << " users)";
- delete x;
+ x->destroy();
return;
}
@@ -181,7 +181,7 @@ class CommandOSAKill : public Command
FOREACH_RESULT(I_OnAddXLine, OnAddXLine(u, x, akills));
if (MOD_RESULT == EVENT_STOP)
{
- delete x;
+ x->destroy();
return;
}
@@ -264,7 +264,7 @@ class CommandOSAKill : public Command
if (!number)
return;
- XLine *x = akills->GetEntry(number - 1);
+ const XLine *x = akills->GetEntry(number - 1);
if (!x)
return;
@@ -286,7 +286,7 @@ class CommandOSAKill : public Command
{
for (unsigned i = 0, end = akills->GetCount(); i < end; ++i)
{
- XLine *x = akills->GetEntry(i);
+ const XLine *x = akills->GetEntry(i);
if (mask.empty() || mask.equals_ci(x->Mask) || mask == x->UID || Anope::Match(x->Mask, mask, false, true))
{
diff --git a/modules/commands/os_forbid.cpp b/modules/commands/os_forbid.cpp
index d305de3c6..bd67d13da 100644
--- a/modules/commands/os_forbid.cpp
+++ b/modules/commands/os_forbid.cpp
@@ -31,7 +31,7 @@ class MyForbidService : public ForbidService
std::vector<ForbidData *>::iterator it = std::find(this->forbidData.begin(), this->forbidData.end(), d);
if (it != this->forbidData.end())
this->forbidData.erase(it);
- delete d;
+ d->destroy();
}
ForbidData *FindForbid(const Anope::string &mask, ForbidType ftype) anope_override
@@ -42,7 +42,7 @@ class MyForbidService : public ForbidService
ForbidData *d = this->forbidData[i - 1];
if ((ftype == FT_NONE || ftype == d->type) && Anope::Match(mask, d->mask, false, true))
- return d;
+ d->destroy();
}
return NULL;
}
@@ -65,7 +65,7 @@ class MyForbidService : public ForbidService
Log(LOG_NORMAL, "expire/forbid") << "Expiring forbid for " << d->mask << " type " << ftype;
this->forbidData.erase(this->forbidData.begin() + i - 1);
- delete d;
+ d->destroy();
}
}
@@ -257,7 +257,7 @@ class OSForbid : public Module
ForbidData *d = this->forbidService.FindForbid(u->nick, FT_NICK);
if (d != NULL)
{
- BotInfo *bi = findbot(Config->OperServ);
+ const BotInfo *bi = findbot(Config->OperServ);
if (bi)
{
if (d->reason.empty())
diff --git a/modules/commands/os_forbid.h b/modules/commands/os_forbid.h
index fec721420..30fdb9611 100644
--- a/modules/commands/os_forbid.h
+++ b/modules/commands/os_forbid.h
@@ -18,9 +18,9 @@ struct ForbidData : Serializable
time_t expires;
ForbidType type;
- Anope::string serialize_name() const anope_override { return "ForbidData"; }
- serialized_data serialize() anope_override;
- static void unserialize(serialized_data &data);
+ const Anope::string serialize_name() const anope_override { return "ForbidData"; }
+ Serialize::Data serialize() const anope_override;
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &data);
};
class ForbidService : public Service
@@ -39,9 +39,9 @@ class ForbidService : public Service
static service_reference<ForbidService> forbid_service("ForbidService", "forbid");
-Serializable::serialized_data ForbidData::serialize()
+Serialize::Data ForbidData::serialize() const
{
- serialized_data data;
+ Serialize::Data data;
data["mask"] << this->mask;
data["creator"] << this->creator;
@@ -53,12 +53,16 @@ Serializable::serialized_data ForbidData::serialize()
return data;
}
-void ForbidData::unserialize(serialized_data &data)
+Serializable* ForbidData::unserialize(Serializable *obj, Serialize::Data &data)
{
if (!forbid_service)
- return;
+ return NULL;
- ForbidData *fb = new ForbidData;
+ ForbidData *fb;
+ if (obj)
+ fb = debug_cast<ForbidData *>(obj);
+ else
+ fb = new ForbidData;
data["mask"] >> fb->mask;
data["creator"] >> fb->creator;
@@ -69,7 +73,9 @@ void ForbidData::unserialize(serialized_data &data)
data["type"] >> t;
fb->type = static_cast<ForbidType>(t);
- forbid_service->AddForbid(fb);
+ if (!obj)
+ forbid_service->AddForbid(fb);
+ return fb;
}
#endif
diff --git a/modules/commands/os_ignore.cpp b/modules/commands/os_ignore.cpp
index 3d84a4635..68f4c5517 100644
--- a/modules/commands/os_ignore.cpp
+++ b/modules/commands/os_ignore.cpp
@@ -19,7 +19,7 @@ class OSIgnoreService : public IgnoreService
public:
OSIgnoreService(Module *o) : IgnoreService(o) { }
- void AddIgnore(const Anope::string &mask, const Anope::string &creator, const Anope::string &reason, time_t delta = Anope::CurTime) anope_override
+ IgnoreData* AddIgnore(const Anope::string &mask, const Anope::string &creator, const Anope::string &reason, time_t delta = Anope::CurTime) anope_override
{
/* If it s an existing user, we ignore the hostmask. */
Anope::string realmask = mask;
@@ -36,7 +36,7 @@ class OSIgnoreService : public IgnoreService
{
/* this should never happen */
if (user > host)
- return;
+ return NULL;
}
else
/* We have user@host. Add nick wildcard. */
@@ -54,6 +54,7 @@ class OSIgnoreService : public IgnoreService
ign->time = 0;
else
ign->time = Anope::CurTime + delta;
+ return ign;
}
/* Create new entry.. */
else
@@ -64,6 +65,7 @@ class OSIgnoreService : public IgnoreService
newign.reason = reason;
newign.time = delta ? Anope::CurTime + delta : 0;
this->ignores.push_back(newign);
+ return &this->ignores.back();
}
}
diff --git a/modules/commands/os_ignore.h b/modules/commands/os_ignore.h
index 44235f7cc..1eb505398 100644
--- a/modules/commands/os_ignore.h
+++ b/modules/commands/os_ignore.h
@@ -17,9 +17,9 @@ struct IgnoreData : Serializable
Anope::string reason;
time_t time; /* When do we stop ignoring them? */
- Anope::string serialize_name() const anope_override { return "IgnoreData"; }
- serialized_data serialize() anope_override;
- static void unserialize(serialized_data &data);
+ const Anope::string serialize_name() const anope_override { return "IgnoreData"; }
+ Serialize::Data serialize() const anope_override;
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &data);
};
class IgnoreService : public Service
@@ -30,7 +30,7 @@ class IgnoreService : public Service
IgnoreService(Module *c) : Service(c, "IgnoreService", "ignore") { }
public:
- virtual void AddIgnore(const Anope::string &mask, const Anope::string &creator, const Anope::string &reason, time_t delta = Anope::CurTime) = 0;
+ virtual IgnoreData* AddIgnore(const Anope::string &mask, const Anope::string &creator, const Anope::string &reason, time_t delta = Anope::CurTime) = 0;
virtual bool DelIgnore(const Anope::string &mask) = 0;
@@ -43,9 +43,9 @@ class IgnoreService : public Service
static service_reference<IgnoreService> ignore_service("IgnoreService", "ignore");
-Serializable::serialized_data IgnoreData::serialize()
+Serialize::Data IgnoreData::serialize() const
{
- serialized_data data;
+ Serialize::Data data;
data["mask"] << this->mask;
data["creator"] << this->creator;
@@ -55,14 +55,24 @@ Serializable::serialized_data IgnoreData::serialize()
return data;
}
-void IgnoreData::unserialize(serialized_data &data)
+Serializable* IgnoreData::unserialize(Serializable *obj, Serialize::Data &data)
{
if (!ignore_service)
- return;
+ return NULL;
+
+ if (obj)
+ {
+ IgnoreData *ign = debug_cast<IgnoreData *>(obj);
+ data["mask"] >> ign->mask;
+ data["creator"] >> ign->creator;
+ data["reason"] >> ign->reason;
+ data["time"] >> ign->time;
+ return ign;
+ }
time_t t;
data["time"] >> t;
- ignore_service->AddIgnore(data["mask"].astr(), data["creator"].astr(), data["reason"].astr(), t);
+ return ignore_service->AddIgnore(data["mask"].astr(), data["creator"].astr(), data["reason"].astr(), t);
}
diff --git a/modules/commands/os_modinfo.cpp b/modules/commands/os_modinfo.cpp
index 032db21f9..60fe8293f 100644
--- a/modules/commands/os_modinfo.cpp
+++ b/modules/commands/os_modinfo.cpp
@@ -40,9 +40,9 @@ class CommandOSModInfo : public Command
source.Reply(_(" Providing service: \002%s\002"), c->name.c_str());
- for (botinfo_map::const_iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it)
+ for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
{
- BotInfo *bi = it->second;
+ const BotInfo *bi = it->second;
for (BotInfo::command_map::const_iterator cit = bi->commands.begin(), cit_end = bi->commands.end(); cit != cit_end; ++cit)
{
diff --git a/modules/commands/os_news.cpp b/modules/commands/os_news.cpp
index 268f2ef0d..456661c46 100644
--- a/modules/commands/os_news.cpp
+++ b/modules/commands/os_news.cpp
@@ -72,7 +72,7 @@ class MyNewsService : public NewsService
{
for (unsigned i = 0; i < 3; ++i)
for (unsigned j = 0; j < newsItems[i].size(); ++j)
- delete newsItems[i][j];
+ newsItems[i][j]->destroy();
}
void AddNewsItem(NewsItem *n)
@@ -86,7 +86,7 @@ class MyNewsService : public NewsService
std::vector<NewsItem *>::iterator it = std::find(list.begin(), list.end(), n);
if (it != list.end())
list.erase(it);
- delete n;
+ n->destroy();
}
std::vector<NewsItem *> &GetNewsList(NewsType t)
@@ -364,10 +364,10 @@ class OSNews : public Module
if (Type == NEWS_RANDOM && i != cur_rand_news)
continue;
- BotInfo *gl = findbot(Config->Global);
- if (!gl && !BotListByNick.empty())
- gl = BotListByNick.begin()->second;
- BotInfo *os = findbot(Config->OperServ);
+ const BotInfo *gl = findbot(Config->Global);
+ if (!gl && !BotListByNick->empty())
+ gl = BotListByNick->begin()->second;
+ const BotInfo *os = findbot(Config->OperServ);
if (!os)
os = gl;
if (gl)
diff --git a/modules/commands/os_news.h b/modules/commands/os_news.h
index d848d73ad..f2507473a 100644
--- a/modules/commands/os_news.h
+++ b/modules/commands/os_news.h
@@ -22,9 +22,9 @@ struct NewsItem : Serializable
Anope::string who;
time_t time;
- Anope::string serialize_name() const anope_override { return "NewsItem"; }
- serialized_data serialize() anope_override;
- static void unserialize(serialized_data &data);
+ const Anope::string serialize_name() const anope_override { return "NewsItem"; }
+ Serialize::Data serialize() const anope_override;
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &data);
};
class NewsService : public Service
@@ -41,9 +41,9 @@ class NewsService : public Service
static service_reference<NewsService> news_service("NewsService", "news");
-Serializable::serialized_data NewsItem::serialize()
+Serialize::Data NewsItem::serialize() const
{
- serialized_data data;
+ Serialize::Data data;
data["type"] << this->type;
data["text"] << this->text;
@@ -53,12 +53,16 @@ Serializable::serialized_data NewsItem::serialize()
return data;
}
-void NewsItem::unserialize(serialized_data &data)
+Serializable* NewsItem::unserialize(Serializable *obj, Serialize::Data &data)
{
if (!news_service)
- return;
+ return NULL;
- NewsItem *ni = new NewsItem();
+ NewsItem *ni;
+ if (obj)
+ ni = debug_cast<NewsItem *>(obj);
+ else
+ ni = new NewsItem();
unsigned int t;
data["type"] >> t;
@@ -67,7 +71,9 @@ void NewsItem::unserialize(serialized_data &data)
data["who"] >> ni->who;
data["time"] >> ni->time;
- news_service->AddNewsItem(ni);
+ if (!obj)
+ news_service->AddNewsItem(ni);
+ return ni;
}
#endif // OS_NEWS
diff --git a/modules/commands/os_oper.cpp b/modules/commands/os_oper.cpp
index 6e8800e74..22560dd18 100644
--- a/modules/commands/os_oper.cpp
+++ b/modules/commands/os_oper.cpp
@@ -17,14 +17,14 @@ struct MyOper : Oper, Serializable
{
MyOper(const Anope::string &n, OperType *o) : Oper(n, o) { }
- Anope::string serialize_name() const anope_override
+ const Anope::string serialize_name() const anope_override
{
return "Oper";
}
- serialized_data serialize() anope_override
+ Serialize::Data serialize() const anope_override
{
- serialized_data data;
+ Serialize::Data data;
data["name"] << this->name;
data["type"] << this->ot->GetName();
@@ -32,17 +32,23 @@ struct MyOper : Oper, Serializable
return data;
}
- static void unserialize(serialized_data &data)
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &data)
{
OperType *ot = OperType::Find(data["type"].astr());
if (ot == NULL)
- return;
+ return NULL;
NickCore *nc = findcore(data["name"].astr());
if (nc == NULL)
- return;
+ return NULL;
- nc->o = new MyOper(nc->display, ot);
+ MyOper *myo;
+ if (obj)
+ myo = debug_cast<MyOper *>(obj);
+ else
+ myo = new MyOper(nc->display, ot);
+ nc->o = myo;
Log(LOG_NORMAL, "operserv/oper") << "Tied oper " << nc->display << " to type " << ot->GetName();
+ return myo;
}
};
@@ -67,7 +73,7 @@ class CommandOSOper : public Command
const Anope::string &oper = params[1];
const Anope::string &otype = params[2];
- NickAlias *na = findnick(oper);
+ const NickAlias *na = findnick(oper);
if (na == NULL)
source.Reply(NICK_X_NOT_REGISTERED, oper.c_str());
else if (na->nc->o)
@@ -90,7 +96,7 @@ class CommandOSOper : public Command
{
const Anope::string &oper = params[1];
- NickAlias *na = findnick(oper);
+ const NickAlias *na = findnick(oper);
if (na == NULL)
source.Reply(NICK_X_NOT_REGISTERED, oper.c_str());
else if (!na->nc || !na->nc->o)
@@ -107,9 +113,9 @@ class CommandOSOper : public Command
else if (subcommand.equals_ci("LIST"))
{
source.Reply(_("Name Type"));
- for (nickcore_map::const_iterator it = NickCoreList.begin(), it_end = NickCoreList.end(); it != it_end; ++it)
+ for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it)
{
- NickCore *nc = it->second;
+ const NickCore *nc = it->second;
if (!nc->o)
continue;
@@ -117,7 +123,7 @@ class CommandOSOper : public Command
source.Reply(_("%-8s %s"), nc->o->name.c_str(), nc->o->ot->GetName().c_str());
if (nc->o->config)
source.Reply(_(" This oper is configured in the configuration file."));
- for (std::list<User *>::iterator uit = nc->Users.begin(); uit != nc->Users.end(); ++uit)
+ for (std::list<User *>::const_iterator uit = nc->Users.begin(); uit != nc->Users.end(); ++uit)
{
User *u = *uit;
source.Reply(_(" %s is online using this oper block."), u->nick.c_str());
@@ -213,9 +219,9 @@ class OSOper : public Module
~OSOper()
{
- for (nickcore_map::const_iterator it = NickCoreList.begin(), it_end = NickCoreList.end(); it != it_end; ++it)
+ for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it)
{
- NickCore *nc = it->second;
+ const NickCore *nc = it->second;
if (nc->o && !nc->o->config)
delete nc->o;
diff --git a/modules/commands/os_session.cpp b/modules/commands/os_session.cpp
index e9666c6d2..8383a88f8 100644
--- a/modules/commands/os_session.cpp
+++ b/modules/commands/os_session.cpp
@@ -102,7 +102,7 @@ class ExpireTimer : public Timer
continue;
Log(findbot(Config->OperServ), "expire/exception") << "Session exception for " << e->mask << "has expired.";
session_service->DelException(e);
- delete e;
+ e->destroy();
}
}
};
@@ -143,7 +143,7 @@ class ExceptionDelCallback : public NumberList
FOREACH_MOD(I_OnExceptionDel, OnExceptionDel(source.u, e));
session_service->DelException(e);
- delete e;
+ e->destroy();
}
};
@@ -346,7 +346,7 @@ class CommandOSException : public Command
EventReturn MOD_RESULT;
FOREACH_RESULT(I_OnExceptionAdd, OnExceptionAdd(exception));
if (MOD_RESULT == EVENT_STOP)
- delete exception;
+ exception->destroy();
else
{
session_service->AddException(exception);
@@ -635,7 +635,7 @@ class OSSession : public Module
if (kill && !exempt)
{
- BotInfo *bi = findbot(Config->OperServ);
+ const BotInfo *bi = findbot(Config->OperServ);
if (bi)
{
if (!Config->SessionLimitExceeded.empty())
diff --git a/modules/commands/os_session.h b/modules/commands/os_session.h
index 561280170..b40177a32 100644
--- a/modules/commands/os_session.h
+++ b/modules/commands/os_session.h
@@ -17,9 +17,9 @@ struct Exception : Serializable
time_t time; /* When this exception was added */
time_t expires; /* Time when it expires. 0 == no expiry */
- Anope::string serialize_name() const anope_override { return "Exception"; }
- serialized_data serialize() anope_override;
- static void unserialize(serialized_data &data);
+ const Anope::string serialize_name() const anope_override { return "Exception"; }
+ Serialize::Data serialize() const anope_override;
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &data);
};
class SessionService : public Service
@@ -51,9 +51,9 @@ class SessionService : public Service
static service_reference<SessionService> session_service("SessionService", "session");
-Serializable::serialized_data Exception::serialize()
+Serialize::Data Exception::serialize() const
{
- serialized_data data;
+ Serialize::Data data;
data["mask"] << this->mask;
data["limit"] << this->limit;
@@ -65,12 +65,16 @@ Serializable::serialized_data Exception::serialize()
return data;
}
-void Exception::unserialize(Serializable::serialized_data &data)
+Serializable* Exception::unserialize(Serializable *obj, Serialize::Data &data)
{
if (!session_service)
- return;
+ return NULL;
- Exception *ex = new Exception;
+ Exception *ex;
+ if (obj)
+ ex = debug_cast<Exception *>(obj);
+ else
+ ex = new Exception;
data["mask"] >> ex->mask;
data["limit"] >> ex->limit;
data["who"] >> ex->who;
@@ -78,7 +82,9 @@ void Exception::unserialize(Serializable::serialized_data &data)
data["time"] >> ex->time;
data["expires"] >> ex->expires;
- session_service->AddException(ex);
+ if (!obj)
+ session_service->AddException(ex);
+ return ex;
}
#endif
diff --git a/modules/commands/os_stats.cpp b/modules/commands/os_stats.cpp
index 19ac54a27..7b593e421 100644
--- a/modules/commands/os_stats.cpp
+++ b/modules/commands/os_stats.cpp
@@ -15,14 +15,14 @@
struct Stats : Serializable
{
- Anope::string serialize_name() const
+ const Anope::string serialize_name() const
{
return "Stats";
}
- serialized_data serialize() anope_override
+ Serialize::Data serialize() const anope_override
{
- serialized_data data;
+ Serialize::Data data;
data["maxusercnt"] << maxusercnt;
data["maxusertime"] << maxusertime;
@@ -30,10 +30,11 @@ struct Stats : Serializable
return data;
}
- static void unserialize(serialized_data &data)
+ static Serializable* unserialize(Serializable *obj, Serialize::Data &data)
{
data["maxusercnt"] >> maxusercnt;
data["maxusertime"] >> maxusertime;
+ return NULL;
}
};
diff --git a/modules/commands/os_sxline.cpp b/modules/commands/os_sxline.cpp
index d6c2ba094..c828b8d52 100644
--- a/modules/commands/os_sxline.cpp
+++ b/modules/commands/os_sxline.cpp
@@ -132,7 +132,7 @@ class CommandOSSXLineBase : public Command
if (!Number)
return;
- XLine *x = this->xlm->GetEntry(Number - 1);
+ const XLine *x = this->xlm->GetEntry(Number - 1);
if (!x)
return;
@@ -154,7 +154,7 @@ class CommandOSSXLineBase : public Command
{
for (unsigned i = 0, end = this->xlm()->GetCount(); i < end; ++i)
{
- XLine *x = this->xlm()->GetEntry(i);
+ const XLine *x = this->xlm()->GetEntry(i);
if (mask.empty() || mask.equals_ci(x->Mask) || mask == x->UID || Anope::Match(x->Mask, mask, false, true))
{
@@ -369,7 +369,7 @@ class CommandOSSNLine : public CommandOSSXLineBase
{
source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str());
Log(LOG_ADMIN, u, this) << "tried to " << source.command << " " << percent << "% of the network (" << affected << " users)";
- delete x;
+ x->destroy();
return;
}
@@ -377,7 +377,7 @@ class CommandOSSNLine : public CommandOSSXLineBase
FOREACH_RESULT(I_OnAddXLine, OnAddXLine(u, x, this->xlm()));
if (MOD_RESULT == EVENT_STOP)
{
- delete x;
+ x->destroy();
return;
}
@@ -576,7 +576,7 @@ class CommandOSSQLine : public CommandOSSXLineBase
{
source.Reply(USERHOST_MASK_TOO_WIDE, mask.c_str());
Log(LOG_ADMIN, u, this) << "tried to SQLine " << percent << "% of the network (" << affected << " users)";
- delete x;
+ x->destroy();
return;
}
@@ -584,7 +584,7 @@ class CommandOSSQLine : public CommandOSSXLineBase
FOREACH_RESULT(I_OnAddXLine, OnAddXLine(u, x, this->xlm()));
if (MOD_RESULT == EVENT_STOP)
{
- delete x;
+ x->destroy();
return;
}
diff --git a/modules/database/db_flatfile.cpp b/modules/database/db_flatfile.cpp
index 259851b18..14e894e0c 100644
--- a/modules/database/db_flatfile.cpp
+++ b/modules/database/db_flatfile.cpp
@@ -91,8 +91,8 @@ class DBFlatFile : public Module
}
SerializeType *st = NULL;
- Serializable::serialized_data data;
- std::multimap<SerializeType *, Serializable::serialized_data> objects;
+ Serialize::Data data;
+ std::multimap<SerializeType *, Serialize::Data> objects;
for (Anope::string buf, token; std::getline(db, buf.str());)
{
spacesepstream sep(buf);
@@ -121,11 +121,11 @@ class DBFlatFile : public Module
{
SerializeType *stype = SerializeType::Find(type_order[i]);
- std::multimap<SerializeType *, Serializable::serialized_data>::iterator it = objects.find(stype), it_end = objects.upper_bound(stype);
+ std::multimap<SerializeType *, Serialize::Data>::iterator it = objects.find(stype), it_end = objects.upper_bound(stype);
if (it == objects.end())
continue;
for (; it != it_end; ++it)
- it->first->Create(it->second);
+ it->first->Unserialize(NULL, it->second);
}
db.close();
@@ -155,10 +155,10 @@ class DBFlatFile : public Module
for (std::list<Serializable *>::const_iterator it = items.begin(), it_end = items.end(); it != it_end; ++it)
{
Serializable *base = *it;
- Serializable::serialized_data data = base->serialize();
+ Serialize::Data data = base->serialize();
db << "OBJECT " << base->serialize_name() << "\n";
- for (Serializable::serialized_data::iterator dit = data.begin(), dit_end = data.end(); dit != dit_end; ++dit)
+ for (Serialize::Data::iterator dit = data.begin(), dit_end = data.end(); dit != dit_end; ++dit)
db << "DATA " << dit->first << " " << dit->second.astr() << "\n";
db << "END\n";
}
diff --git a/modules/database/db_old.cpp b/modules/database/db_old.cpp
index c455aa265..2783a29b2 100644
--- a/modules/database/db_old.cpp
+++ b/modules/database/db_old.cpp
@@ -516,7 +516,7 @@ static void LoadNicks()
m->sender = sbuf;
READ(read_string(m->text, f));
m->owner = nc->display;
- nc->memos.memos.push_back(m);
+ nc->memos.memos->push_back(m);
}
READ(read_uint16(&u16, f));
READ(read_int16(&i16, f));
@@ -798,7 +798,7 @@ static void LoadChannels()
m->sender = sbuf;
READ(read_string(m->text, f));
m->owner = ci->name;
- ci->memos.memos.push_back(m);
+ ci->memos.memos->push_back(m);
}
READ(read_string(buffer, f));
diff --git a/modules/database/db_plain.cpp b/modules/database/db_plain.cpp
index edf41c7f0..935ef95a2 100644
--- a/modules/database/db_plain.cpp
+++ b/modules/database/db_plain.cpp
@@ -17,6 +17,11 @@
Anope::string DatabaseFile;
std::stringstream db_buffer;
+struct ExtensibleString : Anope::string, ExtensibleItem
+{
+ ExtensibleString(const Anope::string &s) : Anope::string(s) { }
+};
+
class DatabaseException : public CoreException
{
public:
@@ -60,7 +65,7 @@ EventReturn OnDatabaseRead(const std::vector<Anope::string> &params)
LoadOperInfo(otherparams);
return EVENT_CONTINUE;
- }
+}
EventReturn OnDatabaseReadMetadata(NickCore *nc, const Anope::string &key, const std::vector<Anope::string> &params)
{
@@ -93,7 +98,7 @@ EventReturn OnDatabaseReadMetadata(NickCore *nc, const Anope::string &key, const
m->SetFlag(MF_RECEIPT);
}
m->text = params[params.size() - 1];
- nc->memos.memos.push_back(m);
+ nc->memos.memos->push_back(m);
}
else if (key.equals_ci("MIG"))
nc->memos.ignores.push_back(params[0].ci_str());
@@ -173,7 +178,7 @@ EventReturn OnDatabaseReadMetadata(ChannelInfo *ci, const Anope::string &key, co
if (!provider)
throw DatabaseException("Old access entry for nonexistant provider");
- ChanAccess *access = provider->Create();
+ ChanAccess *access = const_cast<ChanAccess *>(provider->Create());
access->ci = ci;
access->mask = params[0];
access->Unserialize(params[1]);
@@ -189,7 +194,7 @@ EventReturn OnDatabaseReadMetadata(ChannelInfo *ci, const Anope::string &key, co
if (!provider)
throw DatabaseException("Access entry for nonexistant provider " + params[0]);
- ChanAccess *access = provider->Create();
+ ChanAccess *access = const_cast<ChanAccess *>(provider->Create());
access->ci = ci;
access->mask = params[1];
access->Unserialize(params[2]);
@@ -222,18 +227,18 @@ EventReturn OnDatabaseReadMetadata(ChannelInfo *ci, const Anope::string &key, co
}
else if (key.equals_ci("LOG"))
{
- LogSetting l;
-
- l.ci = ci;
- l.service_name = params[0];
- l.command_service = params[1];
- l.command_name = params[2];
- l.method = params[3];
- l.creator = params[4];
- l.created = params[5].is_pos_number_only() ? convertTo<time_t>(params[5]) : Anope::CurTime;
- l.extra = params.size() > 6 ? params[6] : "";
-
- ci->log_settings.push_back(l);
+ LogSetting *l = new LogSetting();
+
+ l->ci = ci;
+ l->service_name = params[0];
+ l->command_service = params[1];
+ l->command_name = params[2];
+ l->method = params[3];
+ l->creator = params[4];
+ l->created = params[5].is_pos_number_only() ? convertTo<time_t>(params[5]) : Anope::CurTime;
+ l->extra = params.size() > 6 ? params[6] : "";
+
+ ci->log_settings->push_back(l);
}
else if (key.equals_ci("MLOCK"))
{
@@ -241,12 +246,12 @@ EventReturn OnDatabaseReadMetadata(ChannelInfo *ci, const Anope::string &key, co
Anope::string mode_name = params[1];
Anope::string setter = params[2];
time_t mcreated = params[3].is_pos_number_only() ? convertTo<time_t>(params[3]) : Anope::CurTime;
- Anope::string param = params.size() > 4 ? params[4] : "";
- for (size_t i = CMODE_BEGIN + 1; i < CMODE_END; ++i)
+ Anope::string param = params.size() > 4 ? params[4] : "";
+ for (size_t i = CMODE_BEGIN + 1; i < CMODE_END; ++i)
if (ChannelModeNameStrings[i] == mode_name)
{
ChannelModeName n = static_cast<ChannelModeName>(i);
- ci->mode_locks.insert(std::make_pair(n, ModeLock(ci, set, n, param, setter, mcreated)));
+ ci->mode_locks->insert(std::make_pair(n, new ModeLock(ci, set, n, param, setter, mcreated)));
break;
}
}
@@ -263,7 +268,7 @@ EventReturn OnDatabaseReadMetadata(ChannelInfo *ci, const Anope::string &key, co
m->SetFlag(MF_RECEIPT);
}
m->text = params[params.size() - 1];
- ci->memos.memos.push_back(m);
+ ci->memos.memos->push_back(m);
}
else if (key.equals_ci("MIG"))
ci->memos.ignores.push_back(params[0].ci_str());
@@ -666,9 +671,9 @@ class DBPlain : public Module
db_buffer << "VER 2" << endl;
- for (nickcore_map::const_iterator nit = NickCoreList.begin(), nit_end = NickCoreList.end(); nit != nit_end; ++nit)
+ for (nickcore_map::const_iterator nit = NickCoreList->begin(), nit_end = NickCoreList->end(); nit != nit_end; ++nit)
{
- NickCore *nc = nit->second;
+ const NickCore *nc = nit->second;
db_buffer << "NC " << nc->display << " " << nc->pass << endl;
@@ -683,34 +688,35 @@ class DBPlain : public Module
if (!nc->access.empty())
{
- for (std::vector<Anope::string>::iterator it = nc->access.begin(), it_end = nc->access.end(); it != it_end; ++it)
+ for (std::vector<Anope::string>::const_iterator it = nc->access.begin(), it_end = nc->access.end(); it != it_end; ++it)
db_buffer << "MD ACCESS " << *it << endl;
}
if (!nc->cert.empty())
{
- for (std::vector<Anope::string>::iterator it = nc->cert.begin(), it_end = nc->cert.end(); it != it_end; ++it)
+ for (std::vector<Anope::string>::const_iterator it = nc->cert.begin(), it_end = nc->cert.end(); it != it_end; ++it)
db_buffer << "MD CERT " << *it << endl;
}
if (nc->FlagCount())
db_buffer << "MD FLAGS " << nc->ToString() << endl;
- MemoInfo *mi = &nc->memos;
- for (unsigned k = 0, end = mi->memos.size(); k < end; ++k)
+ const MemoInfo *mi = &nc->memos;
+ for (unsigned k = 0, end = mi->memos->size(); k < end; ++k)
{
- db_buffer << "MD MI " << mi->memos[k]->time << " " << mi->memos[k]->sender;
- if (mi->memos[k]->HasFlag(MF_UNREAD))
+ const Memo *m = mi->GetMemo(k);
+ db_buffer << "MD MI " << m->time << " " << m->sender;
+ if (m->HasFlag(MF_UNREAD))
db_buffer << " UNREAD";
- if (mi->memos[k]->HasFlag(MF_RECEIPT))
+ if (m->HasFlag(MF_RECEIPT))
db_buffer << " RECEIPT";
- db_buffer << " :" << mi->memos[k]->text << endl;
+ db_buffer << " :" << m->text << endl;
}
for (unsigned k = 0, end = mi->ignores.size(); k < end; ++k)
db_buffer << "MD MIG " << Anope::string(mi->ignores[k]) << endl;
//FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteMetadata, nc));
}
- for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; ++it)
+ for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; ++it)
{
- NickAlias *na = it->second;
+ const NickAlias *na = it->second;
db_buffer << "NA " << na->nc->display << " " << na->nick << " " << na->time_registered << " " << na->last_seen << endl;
if (!na->last_usermask.empty())
@@ -729,7 +735,7 @@ class DBPlain : public Module
//FOREACH_MOD(I_OnDatabaseWriteMetadata, OnDatabaseWriteMetadata(WriteMetadata, na));
}
- for (Anope::insensitive_map<BotInfo *>::const_iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it)
+ for (Anope::insensitive_map<BotInfo *>::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
{
BotInfo *bi = it->second;
@@ -741,9 +747,9 @@ class DBPlain : public Module
db_buffer << "MD FLAGS " << bi->ToString() << endl;
}
- for (registered_channel_map::const_iterator cit = RegisteredChannelList.begin(), cit_end = RegisteredChannelList.end(); cit != cit_end; ++cit)
+ for (registered_channel_map::const_iterator cit = RegisteredChannelList->begin(), cit_end = RegisteredChannelList->end(); cit != cit_end; ++cit)
{
- ChannelInfo *ci = cit->second;
+ const ChannelInfo *ci = cit->second;
db_buffer << "CH " << ci->name << " " << ci->time_registered << " " << ci->last_used << endl;
db_buffer << "MD BANTYPE " << ci->bantype << endl;
@@ -774,7 +780,7 @@ class DBPlain : public Module
}
for (unsigned k = 0, end = ci->GetAccessCount(); k < end; ++k)
{
- ChanAccess *access = ci->GetAccess(k);
+ const ChanAccess *access = ci->GetAccess(k);
db_buffer << "MD ACCESS2 " << access->provider->name << " " << access->mask << " " << access->Serialize() << " " << access->last_seen << " " << access->creator << " " << access->created << endl;
}
for (unsigned k = 0, end = ci->GetAkickCount(); k < end; ++k)
@@ -785,28 +791,29 @@ class DBPlain : public Module
db_buffer << ci->GetAkick(k)->reason;
db_buffer << endl;
}
- for (unsigned k = 0, end = ci->log_settings.size(); k < end; ++k)
+ for (unsigned k = 0, end = ci->log_settings->size(); k < end; ++k)
{
- LogSetting &l = ci->log_settings[k];
+ const LogSetting &l = *ci->log_settings->at(k);
db_buffer << "MD LOG " << l.service_name << " " << l.command_service << " " << l.command_name << " " << l.method << " " << l.creator << " " << l.created << " " << l.extra << endl;
}
- for (std::multimap<ChannelModeName, ModeLock>::const_iterator it = ci->GetMLock().begin(), it_end = ci->GetMLock().end(); it != it_end; ++it)
+ for (ChannelInfo::ModeList::const_iterator it = ci->GetMLock().begin(), it_end = ci->GetMLock().end(); it != it_end; ++it)
{
- const ModeLock &ml = it->second;
+ const ModeLock &ml = *it->second;
ChannelMode *cm = ModeManager::FindChannelModeByName(ml.name);
if (cm != NULL)
db_buffer << "MD MLOCK " << (ml.set ? 1 : 0) << " " << cm->NameAsString() << " " << ml.setter << " " << ml.created << " " << ml.param << endl;
}
- MemoInfo *memos = &ci->memos;
- for (unsigned k = 0, end = memos->memos.size(); k < end; ++k)
+ const MemoInfo *memos = &ci->memos;
+ for (unsigned k = 0, end = memos->memos->size(); k < end; ++k)
{
- db_buffer << "MD MI " << memos->memos[k]->time << " " << memos->memos[k]->sender;
- if (memos->memos[k]->HasFlag(MF_UNREAD))
+ const Memo *m = memos->GetMemo(k);
+ db_buffer << "MD MI " << m->time << " " << m->sender;
+ if (m->HasFlag(MF_UNREAD))
db_buffer << " UNREAD";
- if (memos->memos[k]->HasFlag(MF_RECEIPT))
+ if (m->HasFlag(MF_RECEIPT))
db_buffer << " RECEIPT";
- db_buffer << " :" << memos->memos[k]->text << endl;
+ db_buffer << " :" << m->text << endl;
}
for (unsigned k = 0, end = memos->ignores.size(); k < end; ++k)
db_buffer << "MD MIG " << Anope::string(memos->ignores[k]) << endl;
@@ -839,7 +846,7 @@ class DBPlain : public Module
XLineManager *xl = *it;
for (unsigned i = 0, end = xl->GetCount(); i < end; ++i)
{
- XLine *x = xl->GetEntry(i);
+ const XLine *x = xl->GetEntry(i);
db_buffer << "OS SXLINE " << xl->Type() << " " << x->GetUser() << " " << x->GetHost() << " " << x->By << " " << x->Created << " " << x->Expires << " :" << x->Reason << endl;
}
}
diff --git a/modules/database/db_sql.cpp b/modules/database/db_sql.cpp
index c8379ca12..c2ba84a5f 100644
--- a/modules/database/db_sql.cpp
+++ b/modules/database/db_sql.cpp
@@ -60,41 +60,20 @@ class DBSQL : public Module
}
}
- void AlterTable(const Anope::string &table, std::set<Anope::string> &data, const Serializable::serialized_data &newd)
- {
- for (Serializable::serialized_data::const_iterator it = newd.begin(), it_end = newd.end(); it != it_end; ++it)
- {
- if (data.count(it->first) > 0)
- continue;
-
- data.insert(it->first);
-
- Anope::string query_text = "ALTER TABLE `" + table + "` ADD `" + it->first + "` ";
- if (it->second.getType() == Serialize::DT_INT)
- query_text += "int(11)";
- else if (it->second.getMax() > 0)
- query_text += "varchar(" + stringify(it->second.getMax()) + ")";
- else
- query_text += "text";
-
- this->RunBackground(SQLQuery(query_text));
- }
- }
-
- void Insert(const Anope::string &table, const Serializable::serialized_data &data)
+ void Insert(const Anope::string &table, const Serialize::Data &data)
{
Anope::string query_text = "INSERT INTO `" + table + "` (";
- for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
+ for (Serialize::Data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
query_text += "`" + it->first + "`,";
query_text.erase(query_text.end() - 1);
query_text += ") VALUES (";
- for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
+ for (Serialize::Data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
query_text += "@" + it->first + "@,";
query_text.erase(query_text.end() - 1);
query_text += ")";
SQLQuery query(query_text);
- for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
+ for (Serialize::Data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
query.setValue(it->first, it->second.astr());
this->RunBackground(query);
@@ -132,28 +111,21 @@ class DBSQL : public Module
this->DropAll();
- std::map<Anope::string, std::set<Anope::string> > table_layout;
for (std::list<Serializable *>::const_iterator it = items.begin(), it_end = items.end(); it != it_end; ++it)
{
Serializable *base = *it;
- Serializable::serialized_data data = base->serialize();
+ Serialize::Data data = base->serialize();
if (data.empty())
continue;
- std::set<Anope::string> &layout = table_layout[base->serialize_name()];
- if (layout.empty())
- {
- this->RunBackground(this->sql->CreateTable(base->serialize_name(), data));
-
- for (Serializable::serialized_data::iterator it2 = data.begin(), it2_end = data.end(); it2 != it2_end; ++it2)
- layout.insert(it2->first);
- }
- else
- this->AlterTable(base->serialize_name(), layout, data);
+ std::vector<SQLQuery> create_queries = this->sql->CreateTable(base->serialize_name(), data);
+ for (unsigned i = 0; i < create_queries.size(); ++i)
+ this->RunBackground(create_queries[i]);
this->Insert(base->serialize_name(), data);
}
+
return EVENT_CONTINUE;
}
@@ -174,12 +146,12 @@ class DBSQL : public Module
SQLResult res = this->sql->RunQuery(query);
for (int j = 0; j < res.Rows(); ++j)
{
- Serializable::serialized_data data;
+ Serialize::Data data;
const std::map<Anope::string, Anope::string> &row = res.Row(j);
for (std::map<Anope::string, Anope::string>::const_iterator rit = row.begin(), rit_end = row.end(); rit != rit_end; ++rit)
data[rit->first] << rit->second;
- sb->Create(data);
+ sb->Unserialize(NULL, data);
}
}
diff --git a/modules/database/db_sql_live.cpp b/modules/database/db_sql_live.cpp
new file mode 100644
index 000000000..4b939e23b
--- /dev/null
+++ b/modules/database/db_sql_live.cpp
@@ -0,0 +1,311 @@
+#include "module.h"
+#include "../extra/sql.h"
+#include "../commands/os_session.h"
+
+class MySQLInterface : public SQLInterface
+{
+ public:
+ MySQLInterface(Module *o) : SQLInterface(o) { }
+
+ void OnResult(const SQLResult &r) anope_override
+ {
+ Log(LOG_DEBUG) << "SQLive successfully executed query: " << r.finished_query;
+ }
+
+ void OnError(const SQLResult &r) anope_override
+ {
+ if (!r.GetQuery().query.empty())
+ Log(LOG_DEBUG) << "Error executing query " << r.finished_query << ": " << r.GetError();
+ else
+ Log(LOG_DEBUG) << "Error executing query: " << r.GetError();
+ }
+};
+
+class DBMySQL : public Module, public Pipe
+{
+ private:
+ MySQLInterface sqlinterface;
+ Anope::string engine;
+ service_reference<SQLProvider> SQL;
+ time_t lastwarn;
+ bool ro;
+ bool init;
+ std::set<dynamic_reference<Serializable> > updated_items;
+
+ bool CheckSQL()
+ {
+ if (SQL)
+ {
+ if (readonly && this->ro)
+ {
+ readonly = this->ro = false;
+ const BotInfo *bi = findbot(Config->OperServ);
+ if (bi)
+ ircdproto->SendGlobops(bi, "Found SQL again, going out of readonly mode...");
+ }
+
+ return true;
+ }
+ else
+ {
+ if (Anope::CurTime - Config->UpdateTimeout > lastwarn)
+ {
+ const BotInfo *bi = findbot(Config->OperServ);
+ if (bi)
+ ircdproto->SendGlobops(bi, "Unable to locate SQL reference, going to readonly...");
+ readonly = this->ro = true;
+ this->lastwarn = Anope::CurTime;
+ }
+
+ return false;
+ }
+ }
+
+ bool CheckInit()
+ {
+ return init && SQL;
+ }
+
+ void RunQuery(const SQLQuery &query)
+ {
+ /* Can this be threaded? */
+ this->RunQueryResult(query);
+ }
+
+ SQLResult RunQueryResult(const SQLQuery &query)
+ {
+ if (this->CheckSQL())
+ {
+ SQLResult res = SQL->RunQuery(query);
+ if (!res.GetError().empty())
+ Log(LOG_DEBUG) << "SQlive got error " << res.GetError() << " for " + res.finished_query;
+ else
+ Log(LOG_DEBUG) << "SQLive got " << res.Rows() << " rows for " << res.finished_query;
+ return res;
+ }
+ throw SQLException("No SQL!");
+ }
+
+ SQLQuery BuildInsert(const Anope::string &table, unsigned int id, const Serialize::Data &data)
+ {
+ if (this->SQL)
+ {
+ std::vector<SQLQuery> create_queries = this->SQL->CreateTable(table, data);
+ for (unsigned i = 0; i < create_queries.size(); ++i)
+ this->RunQuery(create_queries[i]);
+ }
+
+ Anope::string query_text = "INSERT INTO `" + table + "` (`id`";
+ for (Serialize::Data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
+ query_text += ",`" + it->first + "`";
+ query_text += ") VALUES (" + stringify(id);
+ for (Serialize::Data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
+ query_text += ",@" + it->first + "@";
+ query_text += ") ON DUPLICATE KEY UPDATE ";
+ for (Serialize::Data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
+ query_text += "`" + it->first + "`=VALUES(`" + it->first + "`),";
+ query_text.erase(query_text.end() - 1);
+
+ SQLQuery query(query_text);
+ for (Serialize::Data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
+ query.setValue(it->first, it->second.astr());
+
+ return query;
+ }
+
+ public:
+ DBMySQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE), sqlinterface(this), SQL("", "")
+ {
+ this->lastwarn = 0;
+ this->ro = false;
+ this->init = false;
+
+ Implementation i[] = { I_OnReload, I_OnShutdown, I_OnLoadDatabase, I_OnSerializableConstruct, I_OnSerializableDestruct, I_OnSerializePtrAssign, I_OnSerializeCheck, I_OnSerializableUpdate };
+ ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation));
+
+ OnReload();
+ }
+
+ void OnNotify() anope_override
+ {
+ if (!this->CheckInit())
+ return;
+
+ for (std::set<dynamic_reference<Serializable> >::iterator it = this->updated_items.begin(), it_end = this->updated_items.end(); it != it_end; ++it)
+ {
+ dynamic_reference<Serializable> obj = *it;
+
+ if (obj)
+ {
+ if (obj->IsCached())
+ continue;
+ obj->UpdateCache();
+
+ static std::set<Serializable *> working_objects; // XXX
+ if (working_objects.count(obj))
+ continue;
+ working_objects.insert(obj);
+
+ SQLResult res = this->RunQueryResult(BuildInsert(obj->serialize_name(), obj->id, obj->serialize()));
+ if (res.GetID() > 0)
+ obj->id = res.GetID();
+ SerializeType *type = SerializeType::Find(obj->serialize_name());
+ if (type)
+ type->objects.erase(obj->id);
+
+ working_objects.erase(obj);
+ }
+ }
+
+ this->updated_items.clear();
+ }
+
+ EventReturn OnLoadDatabase() anope_override
+ {
+ init = true;
+ return EVENT_STOP;
+ }
+
+ void OnShutdown() anope_override
+ {
+ init = false;
+ }
+
+ void OnReload() anope_override
+ {
+ ConfigReader config;
+ this->engine = config.ReadValue("db_sql", "engine", "", 0);
+ this->SQL = service_reference<SQLProvider>("SQLProvider", this->engine);
+ }
+
+ void OnSerializableConstruct(Serializable *obj) anope_override
+ {
+ if (!this->CheckInit())
+ return;
+ this->updated_items.insert(obj);
+ this->Notify();
+ }
+
+ void OnSerializableDestruct(Serializable *obj) anope_override
+ {
+ if (!this->CheckInit())
+ return;
+ this->RunQuery("DELETE FROM `" + obj->serialize_name() + "` WHERE `id` = " + stringify(obj->id));
+ SerializeType *type = SerializeType::Find(obj->serialize_name());
+ if (type)
+ type->objects.erase(obj->id);
+ }
+
+ void OnSerializePtrAssign(Serializable *obj) anope_override
+ {
+ SerializeType *stype = SerializeType::Find(obj->serialize_name());
+ if (stype == NULL || !this->CheckInit() || stype->GetTimestamp() == Anope::CurTime)
+ return;
+
+ if (obj->IsCached())
+ return;
+ obj->UpdateCache();
+
+ SQLResult res = this->RunQueryResult("SELECT * FROM `" + obj->serialize_name() + "` WHERE `id` = " + stringify(obj->id));
+
+ if (res.Rows() == 0)
+ obj->destroy();
+ else
+ {
+ const std::map<Anope::string, Anope::string> &row = res.Row(0);
+
+ if (res.Get(0, "timestamp").empty())
+ {
+ obj->destroy();
+ stype->objects.erase(obj->id);
+ }
+ else
+ {
+ Serialize::Data data;
+
+ for (std::map<Anope::string, Anope::string>::const_iterator it = row.begin(), it_end = row.end(); it != it_end; ++it)
+ data[it->first] << it->second;
+
+ if (stype->Unserialize(obj, data) == NULL)
+ obj->destroy();
+ }
+ }
+ }
+
+ void OnSerializeCheck(SerializeType *obj)
+ {
+ if (!this->CheckInit() || obj->GetTimestamp() == Anope::CurTime)
+ return;
+
+ SQLQuery query("SELECT * FROM `" + obj->GetName() + "` WHERE (`timestamp` > FROM_UNIXTIME(@ts@) OR `timestamp` IS NULL)");
+ query.setValue("ts", obj->GetTimestamp());
+
+ obj->UpdateTimestamp();
+
+ SQLResult res = this->RunQueryResult(query);
+
+ bool clear_null = false;
+ for (int i = 0; i < res.Rows(); ++i)
+ {
+ const std::map<Anope::string, Anope::string> &row = res.Row(i);
+
+ unsigned int id;
+ try
+ {
+ id = convertTo<unsigned int>(res.Get(i, "id"));
+ }
+ catch (const ConvertException &)
+ {
+ Log(LOG_DEBUG) << "Unable to convert id from " << obj->GetName();
+ continue;
+ }
+
+ if (res.Get(i, "timestamp").empty())
+ {
+ clear_null = true;
+ std::map<unsigned int, Serializable *>::iterator it = obj->objects.find(id);
+ if (it != obj->objects.end())
+ {
+ it->second->destroy();
+ obj->objects.erase(it);
+ }
+ }
+ else
+ {
+ Serialize::Data data;
+
+ for (std::map<Anope::string, Anope::string>::const_iterator it = row.begin(), it_end = row.end(); it != it_end; ++it)
+ data[it->first] << it->second;
+
+ Serializable *s = NULL;
+ std::map<unsigned int, Serializable *>::iterator it = obj->objects.find(id);
+ if (it != obj->objects.end())
+ s = it->second;
+
+ Serializable *new_s = obj->Unserialize(s, data);
+ if (new_s)
+ {
+ new_s->id = id;
+ obj->objects[id] = new_s;
+ }
+ else
+ s->destroy();
+ }
+ }
+
+ if (clear_null)
+ {
+ query = "DELETE FROM `" + obj->GetName() + "` WHERE `timestamp` IS NULL";
+ this->RunQuery(query);
+ }
+ }
+
+ void OnSerializableUpdate(Serializable *obj)
+ {
+ this->updated_items.insert(obj);
+ this->Notify();
+ }
+};
+
+MODULE_INIT(DBMySQL)
+
diff --git a/modules/database/db_sql_live_read.cpp b/modules/database/db_sql_live_read.cpp
deleted file mode 100644
index 38e5f6fef..000000000
--- a/modules/database/db_sql_live_read.cpp
+++ /dev/null
@@ -1,179 +0,0 @@
-#include "module.h"
-#include "../extra/sql.h"
-
-class SQLCache : public Timer
-{
- typedef std::map<Anope::string, time_t, ci::less> cache_map;
- cache_map cache;
- public:
-
- SQLCache() : Timer(300, Anope::CurTime, true) { }
-
- bool Check(const Anope::string &item)
- {
- cache_map::iterator it = this->cache.find(item);
- if (it != this->cache.end() && Anope::CurTime - it->second < 5)
- return true;
-
- this->cache[item] = Anope::CurTime;
- return false;
- }
-
- void Tick(time_t) anope_override
- {
- for (cache_map::iterator it = this->cache.begin(), next_it; it != this->cache.end(); it = next_it)
- {
- next_it = it;
- ++next_it;
-
- if (Anope::CurTime - it->second > 5)
- this->cache.erase(it);
- }
- }
-};
-
-class MySQLLiveModule : public Module
-{
- service_reference<SQLProvider> SQL;
-
- SQLCache chan_cache, nick_cache, core_cache;
-
- SQLResult RunQuery(const SQLQuery &query)
- {
- if (!this->SQL)
- throw SQLException("Unable to locate SQL reference, is db_sql loaded and configured correctly?");
-
- SQLResult res = SQL->RunQuery(query);
- if (!res.GetError().empty())
- throw SQLException(res.GetError());
- return res;
- }
-
- public:
- MySQLLiveModule(const Anope::string &modname, const Anope::string &creator) :
- Module(modname, creator, DATABASE), SQL("", "")
- {
- this->OnReload();
-
- Implementation i[] = { I_OnReload, I_OnFindChan, I_OnFindNick, I_OnFindCore, I_OnShutdown };
- ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation));
- }
-
- void OnReload() anope_override
- {
- ConfigReader config;
- Anope::string engine = config.ReadValue("db_sql", "engine", "", 0);
- this->SQL = service_reference<SQLProvider>("SQLProvider", engine);
- }
-
- void OnShutdown() anope_override
- {
- Implementation i[] = { I_OnFindChan, I_OnFindNick, I_OnFindCore };
- for (size_t j = 0; j < 3; ++j)
- ModuleManager::Detach(i[j], this);
- }
-
- void OnFindChan(const Anope::string &chname) anope_override
- {
- if (chan_cache.Check(chname))
- return;
-
- try
- {
- SQLQuery query("SELECT * FROM `ChannelInfo` WHERE `name` = @name@");
- query.setValue("name", chname);
- SQLResult res = this->RunQuery(query);
-
- if (res.Rows() == 0)
- {
- delete cs_findchan(chname);
- return;
- }
-
- SerializeType *sb = SerializeType::Find("ChannelInfo");
- if (sb == NULL)
- return;
-
- Serializable::serialized_data data;
- const std::map<Anope::string, Anope::string> &row = res.Row(0);
- for (std::map<Anope::string, Anope::string>::const_iterator rit = row.begin(), rit_end = row.end(); rit != rit_end; ++rit)
- data[rit->first] << rit->second;
-
- sb->Create(data);
- }
- catch (const SQLException &ex)
- {
- Log(LOG_DEBUG) << "OnFindChan: " << ex.GetReason();
- }
- }
-
- void OnFindNick(const Anope::string &nick) anope_override
- {
- if (nick_cache.Check(nick))
- return;
-
- try
- {
- SQLQuery query("SELECT * FROM `NickAlias` WHERE `nick` = @nick@");
- query.setValue("nick", nick);
- SQLResult res = this->RunQuery(query);
-
- if (res.Rows() == 0)
- {
- delete findnick(nick);
- return;
- }
-
- SerializeType *sb = SerializeType::Find("NickAlias");
- if (sb == NULL)
- return;
-
- Serializable::serialized_data data;
- const std::map<Anope::string, Anope::string> &row = res.Row(0);
- for (std::map<Anope::string, Anope::string>::const_iterator rit = row.begin(), rit_end = row.end(); rit != rit_end; ++rit)
- data[rit->first] << rit->second;
-
- sb->Create(data);
- }
- catch (const SQLException &ex)
- {
- Log(LOG_DEBUG) << "OnFindNick: " << ex.GetReason();
- }
- }
-
- void OnFindCore(const Anope::string &nick) anope_override
- {
- if (core_cache.Check(nick))
- return;
-
- try
- {
- SQLQuery query("SELECT * FROM `NickCore` WHERE `display` = @display@");
- query.setValue("display", nick);
- SQLResult res = this->RunQuery(query);
-
- if (res.Rows() == 0)
- {
- delete findcore(nick);
- return;
- }
-
- SerializeType *sb = SerializeType::Find("NickCore");
- if (sb == NULL)
- return;
-
- Serializable::serialized_data data;
- const std::map<Anope::string, Anope::string> &row = res.Row(0);
- for (std::map<Anope::string, Anope::string>::const_iterator rit = row.begin(), rit_end = row.end(); rit != rit_end; ++rit)
- data[rit->first] << rit->second;
-
- sb->Create(data);
- }
- catch (const SQLException &ex)
- {
- Log(LOG_DEBUG) << "OnFindCore: " << ex.GetReason();
- }
- }
-};
-
-MODULE_INIT(MySQLLiveModule)
diff --git a/modules/database/db_sql_live_write.cpp b/modules/database/db_sql_live_write.cpp
deleted file mode 100644
index 0692f7f30..000000000
--- a/modules/database/db_sql_live_write.cpp
+++ /dev/null
@@ -1,440 +0,0 @@
-#include "module.h"
-#include "../extra/sql.h"
-#include "../commands/os_session.h"
-
-class MySQLInterface : public SQLInterface
-{
- public:
- MySQLInterface(Module *o) : SQLInterface(o) { }
-
- void OnResult(const SQLResult &r) anope_override
- {
- Log(LOG_DEBUG) << "SQL successfully executed query: " << r.finished_query;
- }
-
- void OnError(const SQLResult &r) anope_override
- {
- if (!r.GetQuery().query.empty())
- Log(LOG_DEBUG) << "Error executing query " << r.finished_query << ": " << r.GetError();
- else
- Log(LOG_DEBUG) << "Error executing query: " << r.GetError();
- }
-};
-
-class DBMySQL : public Module
-{
- private:
- MySQLInterface sqlinterface;
- service_reference<SQLProvider> SQL;
- std::set<Anope::string> tables;
-
- void RunQuery(const SQLQuery &query)
- {
- if (SQL)
- {
- if (readonly && this->ro)
- {
- readonly = this->ro = false;
- BotInfo *bi = findbot(Config->OperServ);
- if (bi)
- ircdproto->SendGlobops(bi, "Found SQL again, going out of readonly mode...");
- }
-
- SQL->Run(&sqlinterface, query);
- }
- else
- {
- if (Anope::CurTime - Config->UpdateTimeout > lastwarn)
- {
- BotInfo *bi = findbot(Config->OperServ);
- if (bi)
- ircdproto->SendGlobops(bi, "Unable to locate SQL reference, going to readonly...");
- readonly = this->ro = true;
- this->lastwarn = Anope::CurTime;
- }
- }
- }
-
- void Insert(const Anope::string &table, const Serializable::serialized_data &data)
- {
- if (tables.count(table) == 0 && SQL)
- {
- this->RunQuery(this->SQL->CreateTable(table, data));
- tables.insert(table);
- }
-
- Anope::string query_text = "INSERT INTO `" + table + "` (";
- for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
- query_text += "`" + it->first + "`,";
- query_text.erase(query_text.end() - 1);
- query_text += ") VALUES (";
- for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
- query_text += "@" + it->first + "@,";
- query_text.erase(query_text.end() - 1);
- query_text += ") ON DUPLICATE KEY UPDATE ";
- for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
- query_text += "`" + it->first + "`=VALUES(`" + it->first + "`),";
- query_text.erase(query_text.end() - 1);
-
- SQLQuery query(query_text);
- for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
- query.setValue(it->first, it->second.astr());
-
- this->RunQuery(query);
- }
-
- void Delete(const Anope::string &table, const Serializable::serialized_data &data)
- {
- Anope::string query_text = "DELETE FROM `" + table + "` WHERE ", arg_text;
- for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
- {
- if (!arg_text.empty())
- arg_text += " AND ";
- arg_text += "`" + it->first + "` = @" + it->first + "@";
- }
-
- query_text += arg_text;
-
- SQLQuery query(query_text);
- for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
- query.setValue(it->first, it->second.astr());
-
- this->RunQuery(query);
- }
-
- public:
- time_t lastwarn;
- bool ro;
-
- DBMySQL(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, DATABASE), sqlinterface(this), SQL("", "")
- {
- this->lastwarn = 0;
- this->ro = false;
-
- Implementation i[] = { I_OnReload, I_OnServerConnect };
- ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation));
-
- OnReload();
-
- if (CurrentUplink)
- OnServerConnect();
- }
-
- void OnReload() anope_override
- {
- ConfigReader config;
- Anope::string engine = config.ReadValue("db_sql", "engine", "", 0);
- this->SQL = service_reference<SQLProvider>("SQLProvider", engine);
- }
-
- void OnServerConnect() anope_override
- {
- Implementation i[] = {
- /* Misc */
- I_OnPostCommand,
- /* NickServ */
- I_OnNickAddAccess, I_OnNickEraseAccess, I_OnNickClearAccess,
- I_OnDelCore, I_OnNickForbidden, I_OnNickGroup,
- I_OnNickRegister, I_OnChangeCoreDisplay,
- I_OnNickSuspended, I_OnDelNick,
- /* ChanServ */
- I_OnAccessAdd, I_OnAccessDel, I_OnAccessClear, I_OnLevelChange,
- I_OnDelChan, I_OnChanRegistered, I_OnChanSuspend,
- I_OnAkickAdd, I_OnAkickDel, I_OnMLock, I_OnUnMLock,
- /* BotServ */
- I_OnBotCreate, I_OnBotChange, I_OnBotDelete,
- I_OnBotAssign, I_OnBotUnAssign,
- I_OnBadWordAdd, I_OnBadWordDel,
- /* MemoServ */
- I_OnMemoSend, I_OnMemoDel,
- /* OperServ */
- I_OnExceptionAdd, I_OnExceptionDel,
- I_OnAddXLine, I_OnDelXLine,
- /* HostServ */
- I_OnSetVhost, I_OnDeleteVhost
- };
- ModuleManager::Attach(i, this, sizeof(i) / sizeof(Implementation));
- }
-
- void OnPostCommand(CommandSource &source, Command *command, const std::vector<Anope::string> &params) anope_override
- {
- User *u = source.u;
-
- if (command->name.find("nickserv/set/") == 0)
- {
- NickAlias *na = findnick(source.u->nick);
- if (na)
- this->Insert(na->nc->serialize_name(), na->nc->serialize());
-
- }
- else if (command->name.find("nickserv/saset/") == 0)
- {
- NickAlias *na = findnick(params[0]);
- if (na)
- this->Insert(na->nc->serialize_name(), na->nc->serialize());
- }
- else if (command->name.find("chanserv/set") == 0 || command->name.find("chanserv/saset") == 0)
- {
- ChannelInfo *ci = params.size() > 0 ? cs_findchan(params[0]) : NULL;
- if (ci)
- this->Insert(ci->serialize_name(), ci->serialize());
- }
- else if (command->name == "botserv/kick" && params.size() > 2)
- {
- ChannelInfo *ci = cs_findchan(params[0]);
- if (!ci)
- return;
- if (!ci->AccessFor(u).HasPriv("SET") && !u->HasPriv("botserv/administration"))
- return;
- this->Insert(ci->serialize_name(), ci->serialize());
- }
- else if (command->name == "botserv/set" && params.size() > 1)
- {
- ChannelInfo *ci = cs_findchan(params[0]);
- BotInfo *bi = NULL;
- if (!ci)
- bi = findbot(params[0]);
- if (bi && params[1].equals_ci("PRIVATE") && u->HasPriv("botserv/set/private"))
- this->Insert(bi->serialize_name(), bi->serialize());
- else if (ci && !ci->AccessFor(u).HasPriv("SET") && !u->HasPriv("botserv/administration"))
- this->Insert(ci->serialize_name(), ci->serialize());
- }
- else if (command->name == "memoserv/ignore" && params.size() > 0)
- {
- Anope::string target = params[0];
- if (target[0] != '#')
- {
- NickCore *nc = u->Account();
- if (nc)
- this->Insert(nc->serialize_name(), nc->serialize());
- }
- else
- {
- ChannelInfo *ci = cs_findchan(target);
- if (ci && ci->AccessFor(u).HasPriv("MEMO"))
- this->Insert(ci->serialize_name(), ci->serialize());
- }
- }
- }
-
- void OnNickAddAccess(NickCore *nc, const Anope::string &entry) anope_override
- {
- this->Insert(nc->serialize_name(), nc->serialize());
- }
-
- void OnNickEraseAccess(NickCore *nc, const Anope::string &entry) anope_override
- {
- this->Insert(nc->serialize_name(), nc->serialize());
- }
-
- void OnNickClearAccess(NickCore *nc) anope_override
- {
- this->Insert(nc->serialize_name(), nc->serialize());
- }
-
- void OnDelCore(NickCore *nc) anope_override
- {
- this->Delete(nc->serialize_name(), nc->serialize());
- }
-
- void OnNickForbidden(NickAlias *na) anope_override
- {
- this->Insert(na->serialize_name(), na->serialize());
- }
-
- void OnNickGroup(User *u, NickAlias *) anope_override
- {
- OnNickRegister(findnick(u->nick));
- }
-
- void InsertAlias(NickAlias *na)
- {
- this->Insert(na->serialize_name(), na->serialize());
- }
-
- void InsertCore(NickCore *nc)
- {
- this->Insert(nc->serialize_name(), nc->serialize());
- }
-
- void OnNickRegister(NickAlias *na) anope_override
- {
- this->InsertCore(na->nc);
- this->InsertAlias(na);
- }
-
- void OnChangeCoreDisplay(NickCore *nc, const Anope::string &newdisplay) anope_override
- {
- Serializable::serialized_data data = nc->serialize();
- this->Delete(nc->serialize_name(), data);
- data.erase("display");
- data["display"] << newdisplay;
- this->Insert(nc->serialize_name(), data);
-
- for (std::list<NickAlias *>::iterator it = nc->aliases.begin(), it_end = nc->aliases.end(); it != it_end; ++it)
- {
- NickAlias *na = *it;
- data = na->serialize();
-
- this->Delete(na->serialize_name(), data);
- data.erase("nc");
- data["nc"] << newdisplay;
- this->Insert(na->serialize_name(), data);
- }
- }
-
- void OnNickSuspend(NickAlias *na) anope_override
- {
- this->Insert(na->serialize_name(), na->serialize());
- }
-
- void OnDelNick(NickAlias *na) anope_override
- {
- this->Delete(na->serialize_name(), na->serialize());
- }
-
- void OnAccessAdd(ChannelInfo *ci, User *, ChanAccess *access) anope_override
- {
- this->Insert(access->serialize_name(), access->serialize());
- }
-
- void OnAccessDel(ChannelInfo *ci, User *u, ChanAccess *access) anope_override
- {
- this->Delete(access->serialize_name(), access->serialize());
- }
-
- void OnAccessClear(ChannelInfo *ci, User *u) anope_override
- {
- for (unsigned i = 0; i < ci->GetAccessCount(); ++i)
- this->OnAccessDel(ci, NULL, ci->GetAccess(i));
- }
-
- void OnLevelChange(User *u, ChannelInfo *ci, const Anope::string &priv, int16_t what) anope_override
- {
- this->Insert(ci->serialize_name(), ci->serialize());
- }
-
- void OnDelChan(ChannelInfo *ci) anope_override
- {
- this->Delete(ci->serialize_name(), ci->serialize());
- }
-
- void OnChanRegistered(ChannelInfo *ci) anope_override
- {
- this->Insert(ci->serialize_name(), ci->serialize());
- }
-
- void OnChanSuspend(ChannelInfo *ci) anope_override
- {
- this->Insert(ci->serialize_name(), ci->serialize());
- }
-
- void OnAkickAdd(User *u, ChannelInfo *ci, AutoKick *ak) anope_override
- {
- this->Insert(ak->serialize_name(), ak->serialize());
- }
-
- void OnAkickDel(User *u, ChannelInfo *ci, AutoKick *ak) anope_override
- {
- this->Delete(ak->serialize_name(), ak->serialize());
- }
-
- EventReturn OnMLock(ChannelInfo *ci, ModeLock *lock) anope_override
- {
- this->Insert(lock->serialize_name(), lock->serialize());
- return EVENT_CONTINUE;
- }
-
- EventReturn OnUnMLock(ChannelInfo *ci, ModeLock *lock) anope_override
- {
- this->Delete(lock->serialize_name(), lock->serialize());
- return EVENT_CONTINUE;
- }
-
- void OnBotCreate(BotInfo *bi) anope_override
- {
- this->Insert(bi->serialize_name(), bi->serialize());
- }
-
- void OnBotChange(BotInfo *bi) anope_override
- {
- OnBotCreate(bi);
- }
-
- void OnBotDelete(BotInfo *bi) anope_override
- {
- this->Delete(bi->serialize_name(), bi->serialize());
- }
-
- EventReturn OnBotAssign(User *sender, ChannelInfo *ci, BotInfo *bi) anope_override
- {
- this->Insert(ci->serialize_name(), ci->serialize());
- return EVENT_CONTINUE;
- }
-
- EventReturn OnBotUnAssign(User *sender, ChannelInfo *ci) anope_override
- {
- this->Insert(ci->serialize_name(), ci->serialize());
- return EVENT_CONTINUE;
- }
-
- void OnBadWordAdd(ChannelInfo *ci, BadWord *bw) anope_override
- {
- this->Insert(bw->serialize_name(), bw->serialize());
- }
-
- void OnBadWordDel(ChannelInfo *ci, BadWord *bw) anope_override
- {
- this->Delete(bw->serialize_name(), bw->serialize());
- }
-
- void OnMemoSend(const Anope::string &source, const Anope::string &target, MemoInfo *mi, Memo *m) anope_override
- {
- this->Insert(m->serialize_name(), m->serialize());
- }
-
- void OnMemoDel(const NickCore *nc, MemoInfo *mi, Memo *m) anope_override
- {
- this->Delete(m->serialize_name(), m->serialize());
- }
-
- void OnMemoDel(ChannelInfo *ci, MemoInfo *mi, Memo *m) anope_override
- {
- this->Delete(m->serialize_name(), m->serialize());
- }
-
- EventReturn OnExceptionAdd(Exception *ex) anope_override
- {
- this->Insert(ex->serialize_name(), ex->serialize());
- return EVENT_CONTINUE;
- }
-
- void OnExceptionDel(User *, Exception *ex) anope_override
- {
- this->Delete(ex->serialize_name(), ex->serialize());
- }
-
- EventReturn OnAddXLine(User *u, XLine *x, XLineManager *xlm) anope_override
- {
- this->Insert(x->serialize_name(), x->serialize());
- return EVENT_CONTINUE;
- }
-
- void OnDelXLine(User *, XLine *x, XLineManager *xlm) anope_override
- {
- this->Delete(x->serialize_name(), x->serialize());
- }
-
- void OnDeleteVhost(NickAlias *na) anope_override
- {
- this->Insert(na->serialize_name(), na->serialize());
- }
-
- void OnSetVhost(NickAlias *na) anope_override
- {
- this->Insert(na->serialize_name(), na->serialize());
- }
-};
-
-MODULE_INIT(DBMySQL)
-
diff --git a/modules/encryption/enc_md5.cpp b/modules/encryption/enc_md5.cpp
index 0831fea22..73bc29557 100644
--- a/modules/encryption/enc_md5.cpp
+++ b/modules/encryption/enc_md5.cpp
@@ -341,10 +341,10 @@ class EMD5 : public Module
EventReturn OnCheckAuthentication(Command *c, CommandSource *source, const std::vector<Anope::string> &params, const Anope::string &account, const Anope::string &password) anope_override
{
- NickAlias *na = findnick(account);
- NickCore *nc = na ? na->nc : NULL;
+ const NickAlias *na = findnick(account);
if (na == NULL)
return EVENT_CONTINUE;
+ NickCore *nc = na->nc;
size_t pos = nc->pass.find(':');
if (pos == Anope::string::npos)
diff --git a/modules/encryption/enc_none.cpp b/modules/encryption/enc_none.cpp
index e528e821c..778ed6cba 100644
--- a/modules/encryption/enc_none.cpp
+++ b/modules/encryption/enc_none.cpp
@@ -43,10 +43,10 @@ class ENone : public Module
EventReturn OnCheckAuthentication(Command *c, CommandSource *source, const std::vector<Anope::string> &params, const Anope::string &account, const Anope::string &password) anope_override
{
- NickAlias *na = findnick(account);
- NickCore *nc = na ? na->nc : NULL;
+ const NickAlias *na = findnick(account);
if (na == NULL)
return EVENT_CONTINUE;
+ NickCore *nc = na->nc;
size_t pos = nc->pass.find(':');
if (pos == Anope::string::npos)
diff --git a/modules/encryption/enc_old.cpp b/modules/encryption/enc_old.cpp
index 9b1dad701..9fba199dc 100644
--- a/modules/encryption/enc_old.cpp
+++ b/modules/encryption/enc_old.cpp
@@ -351,10 +351,10 @@ class EOld : public Module
EventReturn OnCheckAuthentication(Command *c, CommandSource *source, const std::vector<Anope::string> &params, const Anope::string &account, const Anope::string &password) anope_override
{
- NickAlias *na = findnick(account);
- NickCore *nc = na ? na->nc : NULL;
+ const NickAlias *na = findnick(account);
if (na == NULL)
return EVENT_CONTINUE;
+ NickCore *nc = na->nc;
size_t pos = nc->pass.find(':');
if (pos == Anope::string::npos)
diff --git a/modules/encryption/enc_sha1.cpp b/modules/encryption/enc_sha1.cpp
index d5d49b63e..3735e65bc 100644
--- a/modules/encryption/enc_sha1.cpp
+++ b/modules/encryption/enc_sha1.cpp
@@ -194,10 +194,10 @@ class ESHA1 : public Module
EventReturn OnCheckAuthentication(Command *c, CommandSource *source, const std::vector<Anope::string> &params, const Anope::string &account, const Anope::string &password) anope_override
{
- NickAlias *na = findnick(account);
- NickCore *nc = na ? na->nc : NULL;
+ const NickAlias *na = findnick(account);
if (na == NULL)
return EVENT_CONTINUE;
+ NickCore *nc = na->nc;
size_t pos = nc->pass.find(':');
if (pos == Anope::string::npos)
diff --git a/modules/encryption/enc_sha256.cpp b/modules/encryption/enc_sha256.cpp
index aa31dc9c3..b119eeba6 100644
--- a/modules/encryption/enc_sha256.cpp
+++ b/modules/encryption/enc_sha256.cpp
@@ -280,10 +280,10 @@ class ESHA256 : public Module
EventReturn OnCheckAuthentication(Command *c, CommandSource *source, const std::vector<Anope::string> &params, const Anope::string &account, const Anope::string &password) anope_override
{
- NickAlias *na = findnick(account);
- NickCore *nc = na ? na->nc : NULL;
+ const NickAlias *na = findnick(account);
if (na == NULL)
return EVENT_CONTINUE;
+ NickCore *nc = na->nc;
size_t pos = nc->pass.find(':');
if (pos == Anope::string::npos)
diff --git a/modules/extra/m_dnsbl.cpp b/modules/extra/m_dnsbl.cpp
index d4c49501c..ed9776e84 100644
--- a/modules/extra/m_dnsbl.cpp
+++ b/modules/extra/m_dnsbl.cpp
@@ -61,7 +61,7 @@ class DNSBLResolver : public DNSRequest
reason = reason.replace_all_cs("%r", record_reason);
reason = reason.replace_all_cs("%N", Config->NetworkName);
- BotInfo *operserv = findbot(Config->OperServ);
+ const BotInfo *operserv = findbot(Config->OperServ);
Log(operserv) << "DNSBL: " << user->GetMask() << " (" << user->ip << ") appears in " << this->blacklist.name;
XLine *x = new XLine("*@" + user->ip, Config->OperServ, Anope::CurTime + this->blacklist.bantime, reason, XLineManager::GenerateUID());
if (this->add_to_akill && akills)
@@ -72,7 +72,7 @@ class DNSBLResolver : public DNSRequest
else
{
ircdproto->SendAkill(NULL, x);
- delete x;
+ x->destroy();
}
}
};
diff --git a/modules/extra/m_ldap_authentication.cpp b/modules/extra/m_ldap_authentication.cpp
index a34e6a709..e3267f9e0 100644
--- a/modules/extra/m_ldap_authentication.cpp
+++ b/modules/extra/m_ldap_authentication.cpp
@@ -58,7 +58,7 @@ class IdentifyInterface : public LDAPInterface
if (Config->NSAddAccessOnReg)
na->nc->AddAccess(create_mask(u));
- BotInfo *bi = findbot(Config->NickServ);
+ const BotInfo *bi = findbot(Config->NickServ);
if (bi)
u->SendMessage(bi, _("Your account \002%s\002 has been successfully created."), na->nick.c_str());
}
@@ -123,10 +123,11 @@ class OnIdentifyInterface : public LDAPInterface
const LDAPAttributes &attr = r.get(0);
Anope::string email = attr.get(email_attribute);
- if (!email.equals_ci(u->Account()->email))
+ NickCore *nc = u->Account();
+ if (!email.equals_ci(nc->email))
{
- u->Account()->email = email;
- BotInfo *bi = findbot(Config->NickServ);
+ nc->email = email;
+ const BotInfo *bi = findbot(Config->NickServ);
if (bi)
u->SendMessage(bi, _("Your email has been updated to \002%s\002"), email.c_str());
Log() << "m_ldap_authentication: Updated email address for " << u->nick << " (" << u->Account()->display << ") to " << email;
diff --git a/modules/extra/m_ldap_oper.cpp b/modules/extra/m_ldap_oper.cpp
index 6a3bec89f..f432f35b8 100644
--- a/modules/extra/m_ldap_oper.cpp
+++ b/modules/extra/m_ldap_oper.cpp
@@ -31,6 +31,8 @@ class IdentifyInterface : public LDAPInterface
if (!u || !u->Account())
return;
+ NickCore *nc = u->Account();
+
try
{
const LDAPAttributes &attr = r.get(0);
@@ -38,9 +40,9 @@ class IdentifyInterface : public LDAPInterface
const Anope::string &opertype = attr.get(opertype_attribute);
OperType *ot = OperType::Find(opertype);
- if (ot != NULL && (u->Account()->o == NULL || ot != u->Account()->o->ot))
+ if (ot != NULL && (nc->o == NULL || ot != nc->o->ot))
{
- Oper *o = u->Account()->o;
+ Oper *o = nc->o;
if (o != NULL && my_opers.count(o) > 0)
{
my_opers.erase(o);
@@ -48,22 +50,22 @@ class IdentifyInterface : public LDAPInterface
}
o = new Oper(u->nick, ot);
my_opers.insert(o);
- u->Account()->o = o;
- Log() << "m_ldap_oper: Tied " << u->nick << " (" << u->Account()->display << ") to opertype " << ot->GetName();
+ nc->o = o;
+ Log() << "m_ldap_oper: Tied " << u->nick << " (" << nc->display << ") to opertype " << ot->GetName();
}
}
catch (const LDAPException &ex)
{
- if (u->Account()->o != NULL)
+ if (nc->o != NULL)
{
- if (my_opers.count(u->Account()->o) > 0)
+ if (my_opers.count(nc->o) > 0)
{
- my_opers.erase(u->Account()->o);
- delete u->Account()->o;
+ my_opers.erase(nc->o);
+ delete nc->o;
}
- u->Account()->o = NULL;
+ nc->o = NULL;
- Log() << "m_ldap_oper: Removed services operator from " << u->nick << " (" << u->Account()->display << ")";
+ Log() << "m_ldap_oper: Removed services operator from " << u->nick << " (" << nc->display << ")";
}
}
}
diff --git a/modules/extra/m_mysql.cpp b/modules/extra/m_mysql.cpp
index e83e78c7c..0696955cd 100644
--- a/modules/extra/m_mysql.cpp
+++ b/modules/extra/m_mysql.cpp
@@ -49,7 +49,7 @@ class MySQLResult : public SQLResult
MYSQL_RES *res;
public:
- MySQLResult(const SQLQuery &q, const Anope::string &fq, MYSQL_RES *r) : SQLResult(q, fq), res(r)
+ MySQLResult(unsigned int i, const SQLQuery &q, const Anope::string &fq, MYSQL_RES *r) : SQLResult(i, q, fq), res(r)
{
unsigned num_fields = res ? mysql_num_fields(res) : 0;
@@ -80,7 +80,7 @@ class MySQLResult : public SQLResult
}
}
- MySQLResult(const SQLQuery &q, const Anope::string &fq, const Anope::string &err) : SQLResult(q, fq, err), res(NULL)
+ MySQLResult(const SQLQuery &q, const Anope::string &fq, const Anope::string &err) : SQLResult(0, q, fq, err), res(NULL)
{
}
@@ -95,6 +95,8 @@ class MySQLResult : public SQLResult
*/
class MySQLService : public SQLProvider
{
+ std::map<Anope::string, std::set<Anope::string> > active_schema;
+
Anope::string database;
Anope::string server;
Anope::string user;
@@ -123,7 +125,7 @@ class MySQLService : public SQLProvider
SQLResult RunQuery(const SQLQuery &query) anope_override;
- SQLQuery CreateTable(const Anope::string &table, const Serializable::serialized_data &data) anope_override;
+ std::vector<SQLQuery> CreateTable(const Anope::string &table, const Serialize::Data &data) anope_override;
SQLQuery GetTables() anope_override;
@@ -305,7 +307,7 @@ MySQLService::~MySQLService()
if (r.service == this)
{
if (r.sqlinterface)
- r.sqlinterface->OnError(SQLResult(r.query, "SQL Interface is going away"));
+ r.sqlinterface->OnError(SQLResult(0, r.query, "SQL Interface is going away"));
me->QueryRequests.erase(me->QueryRequests.begin() + i - 1);
}
}
@@ -329,10 +331,11 @@ SQLResult MySQLService::RunQuery(const SQLQuery &query)
if (this->CheckConnection() && !mysql_real_query(this->sql, real_query.c_str(), real_query.length()))
{
- MYSQL_RES *res = mysql_use_result(this->sql);
+ MYSQL_RES *res = mysql_store_result(this->sql);
+ unsigned int id = mysql_insert_id(this->sql);
this->Lock.Unlock();
- return MySQLResult(query, real_query, res);
+ return MySQLResult(id, query, real_query, res);
}
else
{
@@ -342,38 +345,50 @@ SQLResult MySQLService::RunQuery(const SQLQuery &query)
}
}
-SQLQuery MySQLService::CreateTable(const Anope::string &table, const Serializable::serialized_data &data)
+std::vector<SQLQuery> MySQLService::CreateTable(const Anope::string &table, const Serialize::Data &data)
{
- Anope::string query_text = "CREATE TABLE `" + table + "` (", key_buf;
- for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
- {
- query_text += "`" + it->first + "` ";
- if (it->second.getType() == Serialize::DT_INT)
- query_text += "int(11)";
- else if (it->second.getMax() > 0)
- query_text += "varchar(" + stringify(it->second.getMax()) + ")";
- else
- query_text += "text";
- query_text += ",";
+ std::vector<SQLQuery> queries;
+ std::set<Anope::string> &known_cols = this->active_schema[table];
- if (it->second.getKey())
+ if (known_cols.empty())
+ {
+ Anope::string query_text = "CREATE TABLE IF NOT EXISTS `" + table + "` (`id` int(10) unsigned NOT NULL AUTO_INCREMENT,"
+ " `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP";
+ for (Serialize::Data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
{
- if (key_buf.empty())
- key_buf = "UNIQUE KEY `ukey` (";
- key_buf += "`" + it->first + "`,";
+ known_cols.insert(it->first);
+
+ query_text += ", `" + it->first + "` ";
+ if (it->second.getType() == Serialize::DT_INT)
+ query_text += "int(11)";
+ else if (it->second.getMax() > 0)
+ query_text += "varchar(" + stringify(it->second.getMax()) + ")";
+ else
+ query_text += "text";
}
- }
- if (!key_buf.empty())
- {
- key_buf.erase(key_buf.end() - 1);
- key_buf += ")";
- query_text += " " + key_buf;
+ query_text += ", PRIMARY KEY (`id`), KEY `timestamp_idx` (`timestamp`))";
+ queries.push_back(query_text);
}
else
- query_text.erase(query_text.end() - 1);
- query_text += ")";
+ for (Serialize::Data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
+ {
+ if (known_cols.count(it->first) > 0)
+ continue;
+
+ known_cols.insert(it->first);
+
+ Anope::string query_text = "ALTER TABLE `" + table + "` ADD `" + it->first + "` ";
+ if (it->second.getType() == Serialize::DT_INT)
+ query_text += "int(11)";
+ else if (it->second.getMax() > 0)
+ query_text += "varchar(" + stringify(it->second.getMax()) + ")";
+ else
+ query_text += "text";
+
+ queries.push_back(query_text);
+ }
- return SQLQuery(query_text);
+ return queries;
}
SQLQuery MySQLService::GetTables()
@@ -391,7 +406,9 @@ void MySQLService::Connect()
bool connect = mysql_real_connect(this->sql, this->server.c_str(), this->user.c_str(), this->password.c_str(), this->database.c_str(), this->port, NULL, 0);
if (!connect)
- throw SQLException("Unable to connect to SQL service " + this->name + ": " + mysql_error(this->sql));
+ throw SQLException("Unable to connect to MySQL service " + this->name + ": " + mysql_error(this->sql));
+
+ Log(LOG_DEBUG) << "Successfully connected to MySQL service " << this->name << " at " << this->server << ":" << this->port;
}
diff --git a/modules/extra/m_proxyscan.cpp b/modules/extra/m_proxyscan.cpp
index badc293fc..f7fa3fdad 100644
--- a/modules/extra/m_proxyscan.cpp
+++ b/modules/extra/m_proxyscan.cpp
@@ -98,7 +98,7 @@ class ProxyConnect : public ConnectionSocket
ircdproto->SendSZLine(NULL, x);
else
ircdproto->SendAkill(NULL, x);
- delete x;
+ x->destroy();
}
}
};
@@ -360,7 +360,7 @@ class ModuleProxyScan : public Module
if (!this->con_notice.empty() && !this->con_source.empty())
{
- BotInfo *bi = findbot(this->con_source);
+ const BotInfo *bi = findbot(this->con_source);
if (bi)
user->SendMessage(bi, this->con_notice);
}
diff --git a/modules/extra/m_sqlite.cpp b/modules/extra/m_sqlite.cpp
index 2dd8ed148..1c82f3459 100644
--- a/modules/extra/m_sqlite.cpp
+++ b/modules/extra/m_sqlite.cpp
@@ -11,11 +11,11 @@
class SQLiteResult : public SQLResult
{
public:
- SQLiteResult(const SQLQuery &q, const Anope::string &fq) : SQLResult(q, fq)
+ SQLiteResult(unsigned int i, const SQLQuery &q, const Anope::string &fq) : SQLResult(i, q, fq)
{
}
- SQLiteResult(const SQLQuery &q, const Anope::string &fq, const Anope::string &err) : SQLResult(q, fq, err)
+ SQLiteResult(const SQLQuery &q, const Anope::string &fq, const Anope::string &err) : SQLResult(0, q, fq, err)
{
}
@@ -29,6 +29,8 @@ class SQLiteResult : public SQLResult
*/
class SQLiteService : public SQLProvider
{
+ std::map<Anope::string, std::set<Anope::string> > active_schema;
+
Anope::string database;
sqlite3 *sql;
@@ -44,7 +46,7 @@ class SQLiteService : public SQLProvider
SQLResult RunQuery(const SQLQuery &query);
- SQLQuery CreateTable(const Anope::string &table, const Serializable::serialized_data &data) anope_override;
+ std::vector<SQLQuery> CreateTable(const Anope::string &table, const Serialize::Data &data) anope_override;
SQLQuery GetTables();
@@ -156,7 +158,7 @@ SQLResult SQLiteService::RunQuery(const SQLQuery &query)
for (int i = 0; i < cols; ++i)
columns[i] = sqlite3_column_name(stmt, i);
- SQLiteResult result(query, real_query);
+ SQLiteResult result(0, query, real_query);
while ((err = sqlite3_step(stmt)) == SQLITE_ROW)
{
@@ -170,6 +172,8 @@ SQLResult SQLiteService::RunQuery(const SQLQuery &query)
result.addRow(items);
}
+ result.id = sqlite3_last_insert_rowid(this->sql);
+
sqlite3_finalize(stmt);
if (err != SQLITE_DONE)
@@ -178,38 +182,58 @@ SQLResult SQLiteService::RunQuery(const SQLQuery &query)
return result;
}
-SQLQuery SQLiteService::CreateTable(const Anope::string &table, const Serializable::serialized_data &data)
+std::vector<SQLQuery> SQLiteService::CreateTable(const Anope::string &table, const Serialize::Data &data)
{
- Anope::string query_text = "CREATE TABLE `" + table + "` (", key_buf;
- for (Serializable::serialized_data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
+ std::vector<SQLQuery> queries;
+ std::set<Anope::string> &known_cols = this->active_schema[table];
+
+ if (active_schema.empty())
{
- query_text += "`" + it->first + "` ";
- if (it->second.getType() == Serialize::DT_INT)
- query_text += "int(11)";
- else if (it->second.getMax() > 0)
- query_text += "varchar(" + stringify(it->second.getMax()) + ")";
- else
- query_text += "text";
- query_text += ",";
-
- if (it->second.getKey())
+ Anope::string query_text = "CREATE TABLE IF NOT EXISTS `" + table + "` (id INTEGER PRIMARY KEY, `timestamp` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, ";
+
+ for (Serialize::Data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
{
- if (key_buf.empty())
- key_buf = "UNIQUE (";
- key_buf += "`" + it->first + "`,";
+ known_cols.insert(it->first);
+
+ query_text += ", `" + it->first + "` ";
+ if (it->second.getType() == Serialize::DT_INT)
+ query_text += "int(11)";
+ else
+ query_text += "text";
}
- }
- if (!key_buf.empty())
- {
- key_buf.erase(key_buf.end() - 1);
- key_buf += ")";
- query_text += " " + key_buf;
+
+ query_text.erase(query_text.end() - 1);
+ query_text += ")";
+
+ queries.push_back(query_text);
+
+ query_text = "CREATE UNIQUE INDEX IF NOT EXISTS `id_idx` ON `" + table + "` (`id`)";
+ queries.push_back(query_text);
+
+ query_text = "CREATE INDEX IF NOT EXISTS `timestamp_idx` ON `" + table + "` (`timestamp`)";
+ queries.push_back(query_text);
+
+ query_text = "CREATE TRIGGER `" + table + "_trigger` AFTER UPDATE ON `" + table + "` FOR EACH ROW BEGIN UPDATE `" + table + "` SET `timestamp` = CURRENT_TIMESTAMP WHERE `id` = `old.id`; end;";
+ queries.push_back(query_text);
}
else
- query_text.erase(query_text.end() - 1);
- query_text += ")";
+ for (Serialize::Data::const_iterator it = data.begin(), it_end = data.end(); it != it_end; ++it)
+ {
+ if (known_cols.count(it->first) > 0)
+ continue;
+
+ known_cols.insert(it->first);
+
+ Anope::string query_text = "ALTER TABLE `" + table + "` ADD `" + it->first + "` ";
+ if (it->second.getType() == Serialize::DT_INT)
+ query_text += "int(11)";
+ else
+ query_text += "text";
+
+ queries.push_back(query_text);
+ }
- return SQLQuery(query_text);
+ return queries;
}
SQLQuery SQLiteService::GetTables()
diff --git a/modules/extra/m_xmlrpc_main.cpp b/modules/extra/m_xmlrpc_main.cpp
index 06ed55c86..0dec9997a 100644
--- a/modules/extra/m_xmlrpc_main.cpp
+++ b/modules/extra/m_xmlrpc_main.cpp
@@ -5,7 +5,7 @@
class XMLRPCUser : public User
{
Anope::string out;
- dynamic_reference<NickAlias> na;
+ NickAlias *na;
public:
XMLRPCUser(const Anope::string &nnick) : User(nnick, Config->NSEnforcerUser, Config->NSEnforcerHost, ""), na(findnick(nick))
@@ -14,22 +14,22 @@ class XMLRPCUser : public User
this->server = Me;
}
- void SendMessage(BotInfo *, Anope::string msg) anope_override
+ void SendMessage(const BotInfo *, Anope::string msg) anope_override
{
this->out += msg + "\n";
}
- NickCore *Account() anope_override
+ NickCore *Account() const anope_override
{
- return (na ? na->nc : NULL);
+ return (na ? *na->nc : NULL);
}
- bool IsIdentified(bool CheckNick = false) anope_override
+ bool IsIdentified(bool CheckNick = false) const anope_override
{
return na;
}
- bool IsRecognized(bool CheckSecure = true) anope_override
+ bool IsRecognized(bool CheckSecure = true) const anope_override
{
return na;
}
@@ -111,7 +111,7 @@ class MyXMLRPCEvent : public XMLRPCEvent
request->reply("error", "Invalid parameters");
else
{
- NickAlias *na = findnick(username);
+ const NickAlias *na = findnick(username);
if (!na)
request->reply("error", "Invalid account");
diff --git a/modules/extra/ns_maxemail.cpp b/modules/extra/ns_maxemail.cpp
index 350913fab..d8d7d3ec6 100644
--- a/modules/extra/ns_maxemail.cpp
+++ b/modules/extra/ns_maxemail.cpp
@@ -42,9 +42,9 @@ class NSMaxEmail : public Module
if (email.empty())
return 0;
- for (nickcore_map::const_iterator it = NickCoreList.begin(), it_end = NickCoreList.end(); it != it_end; ++it)
+ for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it)
{
- NickCore *nc = it->second;
+ const NickCore *nc = it->second;
if (!(u->Account() && u->Account() == nc) && !nc->email.empty() && nc->email.equals_ci(email))
++count;
diff --git a/modules/extra/sql.h b/modules/extra/sql.h
index b23466dee..a986cf794 100644
--- a/modules/extra/sql.h
+++ b/modules/extra/sql.h
@@ -65,12 +65,15 @@ class SQLResult
SQLQuery query;
Anope::string error;
public:
+ unsigned int id;
Anope::string finished_query;
- SQLResult(const SQLQuery &q, const Anope::string &fq, const Anope::string &err = "") : query(q), error(err), finished_query(fq) { }
+ SQLResult() : id(0) { }
+ SQLResult(unsigned int i, const SQLQuery &q, const Anope::string &fq, const Anope::string &err = "") : query(q), error(err), id(i), finished_query(fq) { }
inline operator bool() const { return this->error.empty(); }
+ inline const unsigned int GetID() const { return this->id; }
inline const SQLQuery &GetQuery() const { return this->query; }
inline const Anope::string &GetError() const { return this->error; }
@@ -124,7 +127,7 @@ class SQLProvider : public Service
virtual SQLResult RunQuery(const SQLQuery &query) = 0;
- virtual SQLQuery CreateTable(const Anope::string &table, const Serializable::serialized_data &data) = 0;
+ virtual std::vector<SQLQuery> CreateTable(const Anope::string &table, const Serialize::Data &data) = 0;
virtual SQLQuery GetTables() = 0;
};
diff --git a/modules/protocol/bahamut.cpp b/modules/protocol/bahamut.cpp
index ebb5c75ff..d5d607c1b 100644
--- a/modules/protocol/bahamut.cpp
+++ b/modules/protocol/bahamut.cpp
@@ -154,7 +154,7 @@ class BahamutIRCdProto : public IRCDProto
}
/* JOIN - SJOIN */
- void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override
+ void SendJoin(const User *user, Channel *c, const ChannelStatus *status) anope_override
{
UplinkSocket::Message(user) << "SJOIN " << c->creation_time << " " << c->name;
if (status)
@@ -168,7 +168,7 @@ class BahamutIRCdProto : public IRCDProto
if (uc != NULL)
uc->Status->ClearFlags();
- BotInfo *setter = findbot(user->nick);
+ const BotInfo *setter = findbot(user->nick);
for (unsigned i = 0; i < ModeManager::ChannelModes.size(); ++i)
if (cs.HasFlag(ModeManager::ChannelModes[i]->Name))
c->SetMode(setter, ModeManager::ChannelModes[i], user->nick, false);
@@ -188,7 +188,7 @@ class BahamutIRCdProto : public IRCDProto
return;
}
- XLine *old = x;
+ const XLine *old = x;
if (old->manager->HasEntry("*@" + u->host))
return;
@@ -279,13 +279,13 @@ class BahamutIRCdProto : public IRCDProto
void SendLogin(User *u) anope_override
{
- BotInfo *ns = findbot(Config->NickServ);
+ const BotInfo *ns = findbot(Config->NickServ);
ircdproto->SendMode(ns, u, "+d %d", u->timestamp);
}
void SendLogout(User *u) anope_override
{
- BotInfo *ns = findbot(Config->NickServ);
+ const BotInfo *ns = findbot(Config->NickServ);
ircdproto->SendMode(ns, u, "+d 1");
}
};
@@ -332,10 +332,11 @@ class BahamutIRCdMessage : public IRCdMessage
User *user = do_nick(source, params[0], params[4], params[5], params[6], params[9], Anope::string(params[2]).is_pos_number_only() ? convertTo<time_t>(params[2]) : 0, ip.addr(), "", "", params[3]);
if (user && nickserv)
{
- NickAlias *na;
+ const NickAlias *na;
if (user->timestamp == convertTo<time_t>(params[7]) && (na = findnick(user->nick)))
{
- user->Login(na->nc);
+ NickCore *nc = na->nc;
+ user->Login(nc);
if (!Config->NoNicknameOwnership && na->nc->HasFlag(NI_UNCONFIRMED) == false)
user->SetMode(findbot(Config->NickServ), UMODE_REGISTERED);
}
diff --git a/modules/protocol/inspircd-ts6.h b/modules/protocol/inspircd-ts6.h
index 21b8f6ad0..602040fc4 100644
--- a/modules/protocol/inspircd-ts6.h
+++ b/modules/protocol/inspircd-ts6.h
@@ -51,7 +51,7 @@ class InspIRCdTS6Proto : public IRCDProto
void SendAkillDel(const XLine *x) anope_override
{
- BotInfo *bi = findbot(Config->OperServ);
+ const BotInfo *bi = findbot(Config->OperServ);
/* InspIRCd may support regex bans */
if (x->IsRegex() && has_rlinemod)
@@ -92,7 +92,7 @@ class InspIRCdTS6Proto : public IRCDProto
if (timeleft > 172800 || !x->Expires)
timeleft = 172800;
- BotInfo *bi = findbot(Config->OperServ);
+ const BotInfo *bi = findbot(Config->OperServ);
/* InspIRCd may support regex bans, if they do we can send this and forget about it */
if (x->IsRegex() && has_rlinemod)
{
@@ -114,7 +114,7 @@ class InspIRCdTS6Proto : public IRCDProto
return;
}
- XLine *old = x;
+ const XLine *old = x;
if (old->manager->HasEntry("*@" + u->host))
return;
@@ -169,7 +169,7 @@ class InspIRCdTS6Proto : public IRCDProto
}
/* JOIN */
- void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override
+ void SendJoin(const User *user, Channel *c, const ChannelStatus *status) anope_override
{
UplinkSocket::Message(Me) << "FJOIN " << c->name << " " << c->creation_time << " +" << c->GetModes(true, true) << " :," << user->GetUID();
/* Note that we can send this with the FJOIN but choose not to
@@ -187,7 +187,7 @@ class InspIRCdTS6Proto : public IRCDProto
if (uc != NULL)
uc->Status->ClearFlags();
- BotInfo *setter = findbot(user->nick);
+ const BotInfo *setter = findbot(user->nick);
for (unsigned i = 0; i < ModeManager::ChannelModes.size(); ++i)
if (cs.HasFlag(ModeManager::ChannelModes[i]->Name))
c->SetMode(setter, ModeManager::ChannelModes[i], user->nick, false);
@@ -231,7 +231,7 @@ class InspIRCdTS6Proto : public IRCDProto
/* SVSHOLD - set */
void SendSVSHold(const Anope::string &nick) anope_override
{
- BotInfo *bi = findbot(Config->NickServ);
+ const BotInfo *bi = findbot(Config->NickServ);
if (bi)
UplinkSocket::Message(bi) << "SVSHOLD " << nick << " " << Config->NSReleaseTimeout << " :Being held for registered user";
}
@@ -239,7 +239,7 @@ class InspIRCdTS6Proto : public IRCDProto
/* SVSHOLD - release */
void SendSVSHoldDel(const Anope::string &nick) anope_override
{
- BotInfo *bi = findbot(Config->NickServ);
+ const BotInfo *bi = findbot(Config->NickServ);
if (bi)
UplinkSocket::Message(bi) << "SVSHOLD " << nick;
}
@@ -497,7 +497,7 @@ class InspircdIRCdMessage : public IRCdMessage
bool event_idle(const Anope::string &source, const std::vector<Anope::string> &params)
{
- BotInfo *bi = findbot(params[0]);
+ const BotInfo *bi = findbot(params[0]);
if (bi)
UplinkSocket::Message(bi) << "IDLE " << source << " " << start_time << " " << (Anope::CurTime - bi->lastmsg);
return true;
diff --git a/modules/protocol/inspircd11.cpp b/modules/protocol/inspircd11.cpp
index 615a733bd..21fb0cd27 100644
--- a/modules/protocol/inspircd11.cpp
+++ b/modules/protocol/inspircd11.cpp
@@ -13,6 +13,11 @@
#include "module.h"
+struct ExtensibleString : Anope::string, ExtensibleItem
+{
+ ExtensibleString(const Anope::string &s) : Anope::string(s) { }
+};
+
IRCDVar myIrcd = {
"InspIRCd 1.1", /* ircd name */
"+I", /* Modes used by pseudoclients */
@@ -48,7 +53,7 @@ static bool has_hidechansmod = false;
/* CHGHOST */
void inspircd_cmd_chghost(const Anope::string &nick, const Anope::string &vhost)
{
- BotInfo *bi = findbot(Config->OperServ);
+ const BotInfo *bi = findbot(Config->OperServ);
if (has_chghostmod)
{
if (nick.empty() || vhost.empty())
@@ -64,7 +69,7 @@ void inspircd_cmd_chghost(const Anope::string &nick, const Anope::string &vhost)
bool event_idle(const Anope::string &source, const std::vector<Anope::string> &params)
{
- BotInfo *bi = findbot(params[0]);
+ const BotInfo *bi = findbot(params[0]);
UplinkSocket::Message(bi) << "IDLE " << source << " " << start_time << " " << (bi ? Anope::CurTime - bi->lastmsg : 0);
return true;
}
@@ -128,7 +133,7 @@ class InspIRCdProto : public IRCDProto
return;
}
- XLine *old = x;
+ const XLine *old = x;
if (old->manager->HasEntry("*@" + u->host))
return;
@@ -210,7 +215,7 @@ class InspIRCdProto : public IRCDProto
}
/* JOIN */
- void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override
+ void SendJoin(const User *user, Channel *c, const ChannelStatus *status) anope_override
{
UplinkSocket::Message(user) << "JOIN " << c->name << " " << c->creation_time;
if (status)
@@ -224,7 +229,7 @@ class InspIRCdProto : public IRCDProto
if (uc != NULL)
uc->Status->ClearFlags();
- BotInfo *setter = findbot(user->nick);
+ const BotInfo *setter = findbot(user->nick);
for (unsigned i = 0; i < ModeManager::ChannelModes.size(); ++i)
if (cs.HasFlag(ModeManager::ChannelModes[i]->Name))
c->SetMode(setter, ModeManager::ChannelModes[i], user->nick, false);
@@ -386,7 +391,8 @@ class InspircdIRCdMessage : public IRCdMessage
Anope::string *svidbuf = na ? na->nc->GetExt<ExtensibleString *>("authenticationtoken") : NULL;
if (na && svidbuf && *svidbuf == params[0])
{
- user->Login(na->nc);
+ NickCore *nc = na->nc;
+ user->Login(nc);
if (!Config->NoNicknameOwnership && na->nc->HasFlag(NI_UNCONFIRMED) == false)
user->SetMode(findbot(Config->NickServ), UMODE_REGISTERED);
}
diff --git a/modules/protocol/inspircd12.cpp b/modules/protocol/inspircd12.cpp
index b2985c08a..291a9a595 100644
--- a/modules/protocol/inspircd12.cpp
+++ b/modules/protocol/inspircd12.cpp
@@ -220,7 +220,7 @@ bool event_metadata(const Anope::string &source, const std::vector<Anope::string
{
u->Login(nc);
- NickAlias *user_na = findnick(u->nick);
+ const NickAlias *user_na = findnick(u->nick);
if (!Config->NoNicknameOwnership && nickserv && user_na && user_na->nc == nc && user_na->nc->HasFlag(NI_UNCONFIRMED) == false)
u->SetMode(findbot(Config->NickServ), UMODE_REGISTERED);
}
@@ -266,7 +266,7 @@ class InspIRCdExtBan : public ChannelModeList
public:
InspIRCdExtBan(ChannelModeName mName, char modeChar) : ChannelModeList(mName, modeChar) { }
- bool Matches(User *u, const Entry *e) anope_override
+ bool Matches(const User *u, const Entry *e) anope_override
{
const Anope::string &mask = e->mask;
@@ -721,7 +721,7 @@ class ProtoInspIRCd : public Module
Config->Numeric = numeric;
}
- for (botinfo_map::iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it)
+ for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
it->second->GenerateUID();
}
diff --git a/modules/protocol/inspircd20.cpp b/modules/protocol/inspircd20.cpp
index f58f6e172..e4bb63c64 100644
--- a/modules/protocol/inspircd20.cpp
+++ b/modules/protocol/inspircd20.cpp
@@ -232,7 +232,7 @@ bool event_metadata(const Anope::string &source, const std::vector<Anope::string
{
u->Login(nc);
- NickAlias *user_na = findnick(u->nick);
+ const NickAlias *user_na = findnick(u->nick);
if (!Config->NoNicknameOwnership && nickserv && user_na && user_na->nc == nc && user_na->nc->HasFlag(NI_UNCONFIRMED) == false)
u->SetMode(findbot(Config->NickServ), UMODE_REGISTERED);
}
@@ -278,7 +278,7 @@ class InspIRCdExtBan : public ChannelModeList
public:
InspIRCdExtBan(ChannelModeName mName, char modeChar) : ChannelModeList(mName, modeChar) { }
- bool Matches(User *u, const Entry *e) anope_override
+ bool Matches(const User *u, const Entry *e) anope_override
{
const Anope::string &mask = e->mask;
@@ -740,7 +740,7 @@ class ProtoInspIRCd : public Module
Config->Numeric = numeric;
}
- for (botinfo_map::iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it)
+ for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
it->second->GenerateUID();
}
diff --git a/modules/protocol/plexus.cpp b/modules/protocol/plexus.cpp
index 33de15861..d81dda874 100644
--- a/modules/protocol/plexus.cpp
+++ b/modules/protocol/plexus.cpp
@@ -52,13 +52,13 @@ class PlexusProto : public IRCDProto
void SendSGLineDel(const XLine *x) anope_override
{
- BotInfo *bi = findbot(Config->OperServ);
+ const BotInfo *bi = findbot(Config->OperServ);
UplinkSocket::Message(bi) << "UNXLINE * " << x->Mask;
}
void SendSGLine(User *, const XLine *x) anope_override
{
- BotInfo *bi = findbot(Config->OperServ);
+ const BotInfo *bi = findbot(Config->OperServ);
UplinkSocket::Message(bi) << "XLINE * " << x->Mask << " 0 :" << x->GetReason();
}
@@ -67,7 +67,7 @@ class PlexusProto : public IRCDProto
if (x->IsRegex() || x->HasNickOrReal())
return;
- BotInfo *bi = findbot(Config->OperServ);
+ const BotInfo *bi = findbot(Config->OperServ);
UplinkSocket::Message(bi) << "UNKLINE * " << x->GetUser() << " " << x->GetHost();
}
@@ -76,7 +76,7 @@ class PlexusProto : public IRCDProto
UplinkSocket::Message(Me) << "UNRESV * " << x->Mask;
}
- void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override
+ void SendJoin(const User *user, Channel *c, const ChannelStatus *status) anope_override
{
UplinkSocket::Message(Me) << "SJOIN " << c->creation_time << " " << c->name << " +" << c->GetModes(true, true) << " :" << user->GetUID();
if (status)
@@ -90,7 +90,7 @@ class PlexusProto : public IRCDProto
if (uc != NULL)
uc->Status->ClearFlags();
- BotInfo *setter = findbot(user->nick);
+ const BotInfo *setter = findbot(user->nick);
for (unsigned i = 0; i < ModeManager::ChannelModes.size(); ++i)
if (cs.HasFlag(ModeManager::ChannelModes[i]->Name))
c->SetMode(setter, ModeManager::ChannelModes[i], user->nick, false);
@@ -99,7 +99,7 @@ class PlexusProto : public IRCDProto
void SendAkill(User *u, XLine *x) anope_override
{
- BotInfo *bi = findbot(Config->OperServ);
+ const BotInfo *bi = findbot(Config->OperServ);
if (x->IsRegex() || x->HasNickOrReal())
{
@@ -112,14 +112,15 @@ class PlexusProto : public IRCDProto
return;
}
- XLine *old = x;
+ const XLine *old = x;
if (old->manager->HasEntry("*@" + u->host))
return;
/* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */
- x = new XLine("*@" + u->host, old->By, old->Expires, old->Reason, old->UID);
- old->manager->AddXLine(x);
+ XLine *xline = new XLine("*@" + u->host, old->By, old->Expires, old->Reason, old->UID);
+ old->manager->AddXLine(xline);
+ x = xline;
Log(bi, "akill") << "AKILL: Added an akill for " << x->Mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->Mask;
}
@@ -146,7 +147,7 @@ class PlexusProto : public IRCDProto
void SendVhostDel(User *u) anope_override
{
- BotInfo *bi = findbot(Config->HostServ);
+ const BotInfo *bi = findbot(Config->HostServ);
if (u->HasMode(UMODE_CLOAK))
u->RemoveMode(bi, UMODE_CLOAK);
else
@@ -538,7 +539,7 @@ bool event_encap(const Anope::string &source, const std::vector<Anope::string> &
else if (params[1].equals_cs("SU"))
{
User *u = finduser(params[2]);
- NickAlias *user_na = findnick(params[2]);
+ const NickAlias *user_na = findnick(params[2]);
NickCore *nc = findcore(params[3]);
if (u && nc)
{
@@ -665,7 +666,7 @@ class ProtoPlexus : public Module
Config->Numeric = numeric;
}
- for (botinfo_map::iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it)
+ for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
it->second->GenerateUID();
}
diff --git a/modules/protocol/ratbox.cpp b/modules/protocol/ratbox.cpp
index b277396c9..adf9a8d0c 100644
--- a/modules/protocol/ratbox.cpp
+++ b/modules/protocol/ratbox.cpp
@@ -52,13 +52,13 @@ class RatboxProto : public IRCDProto
void SendSGLineDel(const XLine *x) anope_override
{
- BotInfo *bi = findbot(Config->OperServ);
+ const BotInfo *bi = findbot(Config->OperServ);
UplinkSocket::Message(bi) << "UNXLINE * " << x->Mask;
}
void SendSGLine(User *, const XLine *x) anope_override
{
- BotInfo *bi = findbot(Config->OperServ);
+ const BotInfo *bi = findbot(Config->OperServ);
UplinkSocket::Message(bi) << "XLINE * " << x->Mask << " 0 :" << x->GetReason();
}
@@ -67,7 +67,7 @@ class RatboxProto : public IRCDProto
if (x->IsRegex() || x->HasNickOrReal())
return;
- BotInfo *bi = findbot(Config->OperServ);
+ const BotInfo *bi = findbot(Config->OperServ);
UplinkSocket::Message(bi) << "UNKLINE * " << x->GetUser() << " " << x->GetHost();
}
@@ -76,7 +76,7 @@ class RatboxProto : public IRCDProto
UplinkSocket::Message(Me) << "UNRESV * " << x->Mask;
}
- void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override
+ void SendJoin(const User *user, Channel *c, const ChannelStatus *status) anope_override
{
/* Note that we must send our modes with the SJOIN and
* can not add them to the mode stacker because ratbox
@@ -94,7 +94,7 @@ class RatboxProto : public IRCDProto
void SendAkill(User *u, XLine *x) anope_override
{
- BotInfo *bi = findbot(Config->OperServ);
+ const BotInfo *bi = findbot(Config->OperServ);
if (x->IsRegex() || x->HasNickOrReal())
{
@@ -107,14 +107,15 @@ class RatboxProto : public IRCDProto
return;
}
- XLine *old = x;
+ const XLine *old = x;
if (old->manager->HasEntry("*@" + u->host))
return;
/* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */
- x = new XLine("*@" + u->host, old->By, old->Expires, old->Reason, old->UID);
- old->manager->AddXLine(x);
+ XLine *xline = new XLine("*@" + u->host, old->By, old->Expires, old->Reason, old->UID);
+ old->manager->AddXLine(xline);
+ x = xline;
Log(bi, "akill") << "AKILL: Added an akill for " << x->Mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->Mask;
}
@@ -454,7 +455,7 @@ bool event_encap(const Anope::string &source, const std::vector<Anope::string> &
return true;
u->Login(nc);
- NickAlias *user_na = findnick(u->nick);
+ const NickAlias *user_na = findnick(u->nick);
if (!Config->NoNicknameOwnership && user_na && user_na->nc == nc && user_na->nc->HasFlag(NI_UNCONFIRMED) == false)
u->SetMode(findbot(Config->NickServ), UMODE_REGISTERED);
}
@@ -577,7 +578,7 @@ class ProtoRatbox : public Module
Config->Numeric = numeric;
}
- for (botinfo_map::iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it)
+ for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
it->second->GenerateUID();
}
diff --git a/modules/protocol/unreal.cpp b/modules/protocol/unreal.cpp
index 6a7970341..fef8633a9 100644
--- a/modules/protocol/unreal.cpp
+++ b/modules/protocol/unreal.cpp
@@ -73,7 +73,7 @@ class UnrealIRCdProto : public IRCDProto
void SendVhostDel(User *u) anope_override
{
- BotInfo *bi = findbot(Config->HostServ);
+ const BotInfo *bi = findbot(Config->HostServ);
u->RemoveMode(bi, UMODE_CLOAK);
u->RemoveMode(bi, UMODE_VHOST);
ModeManager::ProcessModes();
@@ -93,14 +93,15 @@ class UnrealIRCdProto : public IRCDProto
return;
}
- XLine *old = x;
+ const XLine *old = x;
if (old->manager->HasEntry("*@" + u->host))
return;
/* We can't akill x as it has a nick and/or realname included, so create a new akill for *@host */
- x = new XLine("*@" + u->host, old->By, old->Expires, old->Reason, old->UID);
- old->manager->AddXLine(x);
+ XLine *xline = new XLine("*@" + u->host, old->By, old->Expires, old->Reason, old->UID);
+ old->manager->AddXLine(xline);
+ x = xline;
Log(findbot(Config->OperServ), "akill") << "AKILL: Added an akill for " << x->Mask << " because " << u->GetMask() << "#" << u->realname << " matches " << old->Mask;
}
@@ -164,7 +165,7 @@ class UnrealIRCdProto : public IRCDProto
}
/* JOIN */
- void SendJoin(User *user, Channel *c, const ChannelStatus *status) anope_override
+ void SendJoin(const User *user, Channel *c, const ChannelStatus *status) anope_override
{
UplinkSocket::Message(Me) << "~ " << c->creation_time << " " << c->name << " :" << user->nick;
if (status)
@@ -178,7 +179,7 @@ class UnrealIRCdProto : public IRCDProto
if (uc != NULL)
uc->Status->ClearFlags();
- BotInfo *setter = findbot(user->nick);
+ const BotInfo *setter = findbot(user->nick);
for (unsigned i = 0; i < ModeManager::ChannelModes.size(); ++i)
if (cs.HasFlag(ModeManager::ChannelModes[i]->Name))
c->SetMode(setter, ModeManager::ChannelModes[i], user->nick, false);
@@ -349,7 +350,7 @@ class UnrealIRCdProto : public IRCDProto
if (!u->Account())
return;
- BotInfo *ns = findbot(Config->NickServ);
+ const BotInfo *ns = findbot(Config->NickServ);
if (Capab.count("ESVID") > 0)
ircdproto->SendMode(ns, u, "+d %s", u->Account()->display.c_str());
else
@@ -358,7 +359,7 @@ class UnrealIRCdProto : public IRCDProto
void SendLogout(User *u) anope_override
{
- BotInfo *ns = findbot(Config->NickServ);
+ const BotInfo *ns = findbot(Config->NickServ);
ircdproto->SendMode(ns, u, "+d 1");
}
@@ -368,7 +369,7 @@ class UnrealIRCdProto : public IRCDProto
* so we will join and part us now
*/
BotInfo *bi = c->ci->WhoSends();
- if (bi == NULL)
+ if (!bi)
;
else if (c->FindUser(bi) == NULL)
{
@@ -388,7 +389,7 @@ class UnrealExtBan : public ChannelModeList
public:
UnrealExtBan(ChannelModeName mName, char modeChar) : ChannelModeList(mName, modeChar) { }
- bool Matches(User *u, const Entry *e) anope_override
+ bool Matches(const User *u, const Entry *e) anope_override
{
const Anope::string &mask = e->mask;
@@ -578,7 +579,7 @@ class Unreal32IRCdMessage : public IRCdMessage
User *user = do_nick(source, params[0], params[3], params[4], params[5], params[10], Anope::string(params[2]).is_pos_number_only() ? convertTo<time_t>(params[2]) : 0, ip.addr(), vhost, "", params[7]);
if (user)
{
- NickAlias *na = NULL;
+ const NickAlias *na = NULL;
if (params[6] == "0")
;
@@ -612,7 +613,7 @@ class Unreal32IRCdMessage : public IRCdMessage
User *user = do_nick(source, params[0], params[3], params[4], params[5], params[9], Anope::string(params[2]).is_pos_number_only() ? convertTo<time_t>(params[2]) : 0, "", vhost, "", params[7]);
if (user)
{
- NickAlias *na = NULL;
+ const NickAlias *na = NULL;
if (params[6] == "0")
;
diff --git a/modules/pseudoclients/botserv.cpp b/modules/pseudoclients/botserv.cpp
index 6b8c91d4e..8c7b08ae4 100644
--- a/modules/pseudoclients/botserv.cpp
+++ b/modules/pseudoclients/botserv.cpp
@@ -21,7 +21,7 @@ class BotServCore : public Module
{
this->SetAuthor("Anope");
- BotInfo *BotServ = findbot(Config->BotServ);
+ const BotInfo *BotServ = findbot(Config->BotServ);
if (BotServ == NULL)
throw ModuleException("No bot named " + Config->BotServ);
@@ -160,7 +160,7 @@ class BotServCore : public Module
if (c->HasFlag(CH_INHABIT))
return;
- if (c->ci && c->ci->bi && u != c->ci->bi && c->users.size() - 1 <= Config->BSMinUsers && c->FindUser(c->ci->bi))
+ if (c->ci && c->ci->bi && u != *c->ci->bi && c->users.size() - 1 <= Config->BSMinUsers && c->FindUser(c->ci->bi))
{
bool persist = c->HasFlag(CH_PERSIST);
c->SetFlag(CH_PERSIST);
@@ -203,7 +203,7 @@ class BotServCore : public Module
{
if (Config->BSSmartJoin && Name == CMODE_BAN && c->ci && c->ci->bi && c->FindUser(c->ci->bi))
{
- BotInfo *bi = c->ci->bi;
+ const BotInfo *bi = c->ci->bi;
Entry ban(CMODE_BAN, param);
if (ban.Matches(bi))
diff --git a/modules/pseudoclients/chanserv.cpp b/modules/pseudoclients/chanserv.cpp
index f1ad3ec6a..408815afc 100644
--- a/modules/pseudoclients/chanserv.cpp
+++ b/modules/pseudoclients/chanserv.cpp
@@ -23,7 +23,7 @@ class ExpireCallback : public CallBack
if (!Config->CSExpire || noexpire || readonly)
return;
- for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; )
+ for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; )
{
ChannelInfo *ci = it->second;
++it;
@@ -46,7 +46,7 @@ class ExpireCallback : public CallBack
Log(LOG_NORMAL, "chanserv/expire") << "Expiring " << extra << "channel " << ci->name << " (founder: " << (ci->GetFounder() ? ci->GetFounder()->display : "(none)") << ")";
FOREACH_MOD(I_OnChanExpire, OnChanExpire(ci));
- delete ci;
+ ci->destroy();
}
}
}
@@ -61,7 +61,7 @@ class ChanServCore : public Module
{
this->SetAuthor("Anope");
- BotInfo *ChanServ = findbot(Config->ChanServ);
+ const BotInfo *ChanServ = findbot(Config->ChanServ);
if (ChanServ == NULL)
throw ModuleException("No bot named " + Config->ChanServ);
@@ -83,7 +83,7 @@ class ChanServCore : public Module
void OnDelCore(NickCore *nc) anope_override
{
// XXX this is slightly inefficient
- for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end;)
+ for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end;)
{
ChannelInfo *ci = it->second;
++it;
@@ -95,11 +95,11 @@ class ChanServCore : public Module
newowner = ci->successor;
else
{
- ChanAccess *highest = NULL;
+ const ChanAccess *highest = NULL;
for (unsigned j = 0; j < ci->GetAccessCount(); ++j)
{
- ChanAccess *ca = ci->GetAccess(j);
- NickCore *anc = findcore(ca->mask);
+ const ChanAccess *ca = ci->GetAccess(j);
+ const NickCore *anc = findcore(ca->mask);
if (!anc || (!anc->IsServicesOper() && Config->CSMaxReg && anc->channelcount >= Config->CSMaxReg) || (anc == nc))
continue;
@@ -120,7 +120,7 @@ class ChanServCore : public Module
{
Log(LOG_NORMAL, "chanserv/expire") << "Deleting channel " << ci->name << " owned by deleted nick " << nc->display;
- delete ci;
+ ci->destroy();
continue;
}
}
@@ -130,8 +130,8 @@ class ChanServCore : public Module
for (unsigned j = 0; j < ci->GetAccessCount(); ++j)
{
- ChanAccess *ca = ci->GetAccess(j);
- NickCore *anc = findcore(ca->mask);
+ const ChanAccess *ca = ci->GetAccess(j);
+ const NickCore *anc = findcore(ca->mask);
if (anc && anc == nc)
{
@@ -142,7 +142,7 @@ class ChanServCore : public Module
for (unsigned j = ci->GetAkickCount(); j > 0; --j)
{
- AutoKick *akick = ci->GetAkick(j - 1);
+ const AutoKick *akick = ci->GetAkick(j - 1);
if (akick->HasFlag(AK_ISNICK) && akick->nc == nc)
ci->EraseAkick(j - 1);
}
@@ -183,10 +183,12 @@ class ChanServCore : public Module
EventReturn OnCheckModes(Channel *c) anope_override
{
if (!Config->CSRequire.empty())
+ {
if (c->ci)
c->SetModes(NULL, false, "+%s", Config->CSRequire.c_str());
else
c->SetModes(NULL, false, "-%s", Config->CSRequire.c_str());
+ }
return EVENT_CONTINUE;
}
diff --git a/modules/pseudoclients/global.cpp b/modules/pseudoclients/global.cpp
index 363c29a1e..3fdfbf4e0 100644
--- a/modules/pseudoclients/global.cpp
+++ b/modules/pseudoclients/global.cpp
@@ -16,18 +16,18 @@
class MyGlobalService : public GlobalService
{
- void ServerGlobal(Server *s, const Anope::string &message)
+ void ServerGlobal(const BotInfo *sender, Server *s, const Anope::string &message)
{
if (s != Me && !s->HasFlag(SERVER_JUPED))
- s->Notice(findbot(Config->Global), message);
+ s->Notice(sender, message);
for (unsigned i = 0, j = s->GetLinks().size(); i < j; ++i)
- this->ServerGlobal(s->GetLinks()[i], message);
+ this->ServerGlobal(sender, s->GetLinks()[i], message);
}
public:
MyGlobalService(Module *m) : GlobalService(m) { }
- void SendGlobal(BotInfo *sender, const Anope::string &source, const Anope::string &message) anope_override
+ void SendGlobal(const BotInfo *sender, const Anope::string &source, const Anope::string &message) anope_override
{
if (Me->GetLinks().empty())
return;
@@ -39,7 +39,7 @@ class MyGlobalService : public GlobalService
else
rmessage = message;
- this->ServerGlobal(Me->GetLinks().front(), rmessage);
+ this->ServerGlobal(sender, Me->GetLinks().front(), rmessage);
}
};
@@ -53,7 +53,7 @@ class GlobalCore : public Module
{
this->SetAuthor("Anope");
- BotInfo *Global = findbot(Config->Global);
+ const BotInfo *Global = findbot(Config->Global);
if (Global == NULL)
throw ModuleException("No bot named " + Config->Global);
diff --git a/modules/pseudoclients/global.h b/modules/pseudoclients/global.h
index 8aaa26a37..75d783399 100644
--- a/modules/pseudoclients/global.h
+++ b/modules/pseudoclients/global.h
@@ -11,7 +11,7 @@ class GlobalService : public Service
* @param source The sender of the global
* @param message The message
*/
- virtual void SendGlobal(BotInfo *sender, const Anope::string &source, const Anope::string &message) = 0;
+ virtual void SendGlobal(const BotInfo *sender, const Anope::string &source, const Anope::string &message) = 0;
};
static service_reference<GlobalService> global("GlobalService", "Global");
diff --git a/modules/pseudoclients/hostserv.cpp b/modules/pseudoclients/hostserv.cpp
index 0e7699c5f..c350903d0 100644
--- a/modules/pseudoclients/hostserv.cpp
+++ b/modules/pseudoclients/hostserv.cpp
@@ -23,7 +23,7 @@ class HostServCore : public Module
if (!ircd || !ircd->vhost)
throw ModuleException("Your IRCd does not suppor vhosts");
- BotInfo *HostServ = findbot(Config->HostServ);
+ const BotInfo *HostServ = findbot(Config->HostServ);
if (HostServ == NULL)
throw ModuleException("No bot named " + Config->HostServ);
@@ -33,7 +33,7 @@ class HostServCore : public Module
void OnNickIdentify(User *u) anope_override
{
- NickAlias *na = findnick(u->nick);
+ const NickAlias *na = findnick(u->nick);
if (!na || !na->HasVhost())
na = findnick(u->Account()->display);
if (!na || !na->HasVhost())
@@ -50,7 +50,7 @@ class HostServCore : public Module
if (ircd->vident && !na->GetVhostIdent().empty())
u->SetVIdent(na->GetVhostIdent());
- BotInfo *bi = findbot(Config->HostServ);
+ const BotInfo *bi = findbot(Config->HostServ);
if (bi)
{
if (!na->GetVhostIdent().empty())
diff --git a/modules/pseudoclients/memoserv.cpp b/modules/pseudoclients/memoserv.cpp
index 32eaa9f3f..f24b69edf 100644
--- a/modules/pseudoclients/memoserv.cpp
+++ b/modules/pseudoclients/memoserv.cpp
@@ -14,8 +14,6 @@
#include "module.h"
#include "memoserv.h"
-static BotInfo *MemoServ;
-
static bool SendMemoMail(NickCore *nc, MemoInfo *mi, Memo *m)
{
Anope::string subject = translate(nc, Config->MailMemoSubject.c_str());
@@ -74,7 +72,7 @@ class MyMemoServService : public MemoServService
return MEMO_TOO_FAST;
else if (!mi->memomax)
return MEMO_TARGET_FULL;
- else if (mi->memomax > 0 && mi->memos.size() >= mi->memomax)
+ else if (mi->memomax > 0 && mi->memos->size() >= mi->memomax)
return MEMO_TARGET_FULL;
else if (mi->HasIgnore(sender))
return MEMO_SUCCESS;
@@ -84,7 +82,7 @@ class MyMemoServService : public MemoServService
sender->lastmemosend = Anope::CurTime;
Memo *m = new Memo();
- mi->memos.push_back(m);
+ mi->memos->push_back(m);
m->owner = target;
m->sender = source;
m->time = Anope::CurTime;
@@ -106,7 +104,7 @@ class MyMemoServService : public MemoServService
if (ci->AccessFor(cu->user).HasPriv("MEMO"))
{
if (cu->user->Account() && cu->user->Account()->HasFlag(NI_MEMO_RECEIVE))
- cu->user->SendMessage(MemoServ, MEMO_NEW_X_MEMO_ARRIVED, ci->name.c_str(), Config->UseStrictPrivMsgString.c_str(), Config->MemoServ.c_str(), ci->name.c_str(), mi->memos.size());
+ cu->user->SendMessage(findbot(Config->MemoServ), MEMO_NEW_X_MEMO_ARRIVED, ci->name.c_str(), Config->UseStrictPrivMsgString.c_str(), Config->MemoServ.c_str(), ci->name.c_str(), mi->memos->size());
}
}
}
@@ -117,12 +115,14 @@ class MyMemoServService : public MemoServService
if (nc->HasFlag(NI_MEMO_RECEIVE))
{
- for (std::list<NickAlias *>::iterator it = nc->aliases.begin(), it_end = nc->aliases.end(); it != it_end; ++it)
+ for (std::list<serialize_obj<NickAlias> >::const_iterator it = nc->aliases.begin(), it_end = nc->aliases.end(); it != it_end;)
{
- NickAlias *na = *it;
+ const NickAlias *na = *it++;
+ if (!na)
+ continue;
User *user = finduser(na->nick);
if (user && user->IsIdentified())
- user->SendMessage(MemoServ, MEMO_NEW_MEMO_ARRIVED, source.c_str(), Config->UseStrictPrivMsgString.c_str(), Config->MemoServ.c_str(), mi->memos.size());
+ user->SendMessage(findbot(Config->MemoServ), MEMO_NEW_MEMO_ARRIVED, source.c_str(), Config->UseStrictPrivMsgString.c_str(), Config->MemoServ.c_str(), mi->memos->size());
}
}
@@ -136,24 +136,23 @@ class MyMemoServService : public MemoServService
void Check(User *u)
{
- NickCore *nc = u->Account();
+ const NickCore *nc = u->Account();
if (!nc)
return;
+ const BotInfo *ms = findbot(Config->MemoServ);
- unsigned i = 0, end = nc->memos.memos.size(), newcnt = 0;
+ unsigned i = 0, end = nc->memos.memos->size(), newcnt = 0;
for (; i < end; ++i)
- {
- if (nc->memos.memos[i]->HasFlag(MF_UNREAD))
+ if (nc->memos.GetMemo(i)->HasFlag(MF_UNREAD))
++newcnt;
- }
if (newcnt > 0)
- u->SendMessage(MemoServ, newcnt == 1 ? _("You have 1 new memo.") : _("You have %d new memos."), newcnt);
- if (nc->memos.memomax > 0 && nc->memos.memos.size() >= nc->memos.memomax)
+ u->SendMessage(ms, newcnt == 1 ? _("You have 1 new memo.") : _("You have %d new memos."), newcnt);
+ if (nc->memos.memomax > 0 && nc->memos.memos->size() >= nc->memos.memomax)
{
- if (nc->memos.memos.size() > nc->memos.memomax)
- u->SendMessage(MemoServ, _("You are over your maximum number of memos (%d). You will be unable to receive any new memos until you delete some of your current ones."), nc->memos.memomax);
+ if (nc->memos.memos->size() > nc->memos.memomax)
+ u->SendMessage(ms, _("You are over your maximum number of memos (%d). You will be unable to receive any new memos until you delete some of your current ones."), nc->memos.memomax);
else
- u->SendMessage(MemoServ, _("You have reached your maximum number of memos (%d). You will be unable to receive any new memos until you delete some of your current ones."), nc->memos.memomax);
+ u->SendMessage(ms, _("You have reached your maximum number of memos (%d). You will be unable to receive any new memos until you delete some of your current ones."), nc->memos.memomax);
}
}
};
@@ -167,8 +166,7 @@ class MemoServCore : public Module
{
this->SetAuthor("Anope");
- MemoServ = findbot(Config->MemoServ);
- if (MemoServ == NULL)
+ if (!findbot(Config->MemoServ))
throw ModuleException("No bot named " + Config->MemoServ);
Implementation i[] = { I_OnNickIdentify, I_OnJoinChannel, I_OnUserAway, I_OnNickUpdate, I_OnPreHelp, I_OnPostHelp };
@@ -182,12 +180,12 @@ class MemoServCore : public Module
void OnJoinChannel(User *u, Channel *c) anope_override
{
- if (c->ci && c->ci->AccessFor(u).HasPriv("MEMO") && c->ci->memos.memos.size() > 0)
+ if (c->ci && c->ci->AccessFor(u).HasPriv("MEMO") && c->ci->memos.memos->size() > 0)
{
- if (c->ci->memos.memos.size() == 1)
- u->SendMessage(MemoServ, _("There is \002%d\002 memo on channel %s."), c->ci->memos.memos.size(), c->ci->name.c_str());
+ if (c->ci->memos.memos->size() == 1)
+ u->SendMessage(findbot(Config->MemoServ), _("There is \002%d\002 memo on channel %s."), c->ci->memos.memos->size(), c->ci->name.c_str());
else
- u->SendMessage(MemoServ, _("There are \002%d\002 memos on channel %s."), c->ci->memos.memos.size(), c->ci->name.c_str());
+ u->SendMessage(findbot(Config->MemoServ), _("There are \002%d\002 memos on channel %s."), c->ci->memos.memos->size(), c->ci->name.c_str());
}
}
diff --git a/modules/pseudoclients/nickserv.cpp b/modules/pseudoclients/nickserv.cpp
index 9dc517fd1..dd0501cd4 100644
--- a/modules/pseudoclients/nickserv.cpp
+++ b/modules/pseudoclients/nickserv.cpp
@@ -14,8 +14,6 @@
#include "module.h"
#include "nickserv.h"
-static BotInfo *NickServ;
-
class NickServCollide;
class NickServRelease;
@@ -80,6 +78,7 @@ class MyNickServService : public NickServService
NickAlias *na = findnick(u->nick);
if (!na)
return;
+ const BotInfo *NickServ = findbot(Config->NickServ);
if (na->nc->HasFlag(NI_SUSPENDED))
{
@@ -148,7 +147,7 @@ class ExpireCallback : public CallBack
if (noexpire || readonly)
return;
- for (nickalias_map::const_iterator it = NickAliasList.begin(), it_end = NickAliasList.end(); it != it_end; )
+ for (nickalias_map::const_iterator it = NickAliasList->begin(), it_end = NickAliasList->end(); it != it_end; )
{
NickAlias *na = it->second;
++it;
@@ -176,7 +175,7 @@ class ExpireCallback : public CallBack
extra = "suspended ";
Log(LOG_NORMAL, "expire") << "Expiring " << extra << "nickname " << na->nick << " (group: " << na->nc->display << ") (e-mail: " << (na->nc->email.empty() ? "none" : na->nc->email) << ")";
FOREACH_MOD(I_OnNickExpire, OnNickExpire(na));
- delete na;
+ na->destroy();
}
}
}
@@ -192,8 +191,7 @@ class NickServCore : public Module
{
this->SetAuthor("Anope");
- NickServ = findbot(Config->NickServ);
- if (NickServ == NULL)
+ if (!findbot(Config->NickServ))
throw ModuleException("No bot named " + Config->NickServ);
Implementation i[] = { I_OnDelNick, I_OnDelCore, I_OnChangeCoreDisplay, I_OnNickIdentify, I_OnNickGroup,
@@ -207,14 +205,14 @@ class NickServCore : public Module
if (u && u->Account() == na->nc)
{
ircdproto->SendLogout(u);
- u->RemoveMode(NickServ, UMODE_REGISTERED);
+ u->RemoveMode(findbot(Config->NickServ), UMODE_REGISTERED);
u->Logout();
}
}
void OnDelCore(NickCore *nc) anope_override
{
- Log(NickServ, "nick") << "deleting nickname group " << nc->display;
+ Log(findbot(Config->NickServ), "nick") << "deleting nickname group " << nc->display;
/* Clean up this nick core from any users online using it
* (ones that /nick but remain unidentified)
@@ -223,7 +221,7 @@ class NickServCore : public Module
{
User *user = *it++;
ircdproto->SendLogout(user);
- user->RemoveMode(NickServ, UMODE_REGISTERED);
+ user->RemoveMode(findbot(Config->NickServ), UMODE_REGISTERED);
user->Logout();
FOREACH_MOD(I_OnNickLogout, OnNickLogout(user));
}
@@ -232,14 +230,16 @@ class NickServCore : public Module
void OnChangeCoreDisplay(NickCore *nc, const Anope::string &newdisplay) anope_override
{
- Log(LOG_NORMAL, "nick", NickServ) << "Changing " << nc->display << " nickname group display to " << newdisplay;
+ Log(LOG_NORMAL, "nick", findbot(Config->NickServ)) << "Changing " << nc->display << " nickname group display to " << newdisplay;
}
void OnNickIdentify(User *u) anope_override
{
+ const BotInfo *NickServ = findbot(Config->NickServ);
+
if (!Config->NoNicknameOwnership)
{
- NickAlias *this_na = findnick(u->nick);
+ const NickAlias *this_na = findnick(u->nick);
if (this_na && this_na->nc == u->Account() && u->Account()->HasFlag(NI_UNCONFIRMED) == false)
u->SetMode(NickServ, UMODE_REGISTERED);
}
@@ -266,7 +266,7 @@ class NickServCore : public Module
if (u->Account()->HasFlag(NI_UNCONFIRMED))
{
u->SendMessage(NickServ, _("Your email address is not confirmed. To confirm it, follow the instructions that were emailed to you when you registered."));
- NickAlias *this_na = findnick(u->Account()->display);
+ const NickAlias *this_na = findnick(u->Account()->display);
time_t time_registered = Anope::CurTime - this_na->time_registered;
if (Config->NSUnconfirmedExpire > time_registered)
u->SendMessage(NickServ, _("Your account will expire, if not confirmed, in %s"), duration(Config->NSUnconfirmedExpire - time_registered).c_str());
@@ -276,7 +276,7 @@ class NickServCore : public Module
void OnNickGroup(User *u, NickAlias *target) anope_override
{
if (target->nc->HasFlag(NI_UNCONFIRMED) == false)
- u->SetMode(NickServ, UMODE_REGISTERED);
+ u->SetMode(findbot(Config->NickServ), UMODE_REGISTERED);
}
void OnNickUpdate(User *u) anope_override
@@ -292,7 +292,8 @@ class NickServCore : public Module
void OnUserNickChange(User *u, const Anope::string &oldnick) anope_override
{
- NickAlias *na = findnick(u->nick);
+ const NickAlias *na = findnick(u->nick);
+ const BotInfo *NickServ = findbot(Config->NickServ);
/* If the new nick isnt registerd or its registerd and not yours */
if (!na || na->nc != u->Account())
{
@@ -305,7 +306,7 @@ class NickServCore : public Module
{
ircdproto->SendLogin(u);
if (!Config->NoNicknameOwnership && na->nc == u->Account() && na->nc->HasFlag(NI_UNCONFIRMED) == false)
- u->SetMode(findbot(Config->NickServ), UMODE_REGISTERED);
+ u->SetMode(NickServ, UMODE_REGISTERED);
Log(NickServ) << u->GetMask() << " automatically identified for group " << u->Account()->display;
}
}
@@ -313,7 +314,7 @@ class NickServCore : public Module
void OnUserModeSet(User *u, UserModeName Name) anope_override
{
if (Name == UMODE_REGISTERED && !u->IsIdentified())
- u->RemoveMode(NickServ, Name);
+ u->RemoveMode(findbot(Config->NickServ), Name);
}
EventReturn OnPreHelp(CommandSource &source, const std::vector<Anope::string> &params) anope_override
@@ -353,8 +354,8 @@ class NickServCore : public Module
void OnUserConnect(dynamic_reference<User> &u, bool &exempt) anope_override
{
- if (!Config->NoNicknameOwnership && !Config->NSUnregisteredNotice.empty() && u && findnick(u->nick) == NULL)
- u->SendMessage(NickServ, Config->NSUnregisteredNotice);
+ if (!Config->NoNicknameOwnership && !Config->NSUnregisteredNotice.empty() && u && !findnick(u->nick))
+ u->SendMessage(findbot(Config->NickServ), Config->NSUnregisteredNotice);
}
};
diff --git a/modules/pseudoclients/operserv.cpp b/modules/pseudoclients/operserv.cpp
index 8b969489e..d9fa44597 100644
--- a/modules/pseudoclients/operserv.cpp
+++ b/modules/pseudoclients/operserv.cpp
@@ -13,8 +13,6 @@
#include "module.h"
-static BotInfo *OperServ;
-
class SGLineManager : public XLineManager
{
public:
@@ -25,9 +23,9 @@ class SGLineManager : public XLineManager
this->Send(u, x);
}
- void OnExpire(XLine *x) anope_override
+ void OnExpire(const XLine *x) anope_override
{
- Log(OperServ, "expire/akill") << "AKILL on \2" << x->Mask << "\2 has expired";
+ Log(findbot(Config->OperServ), "expire/akill") << "AKILL on \2" << x->Mask << "\2 has expired";
}
void Send(User *u, XLine *x) anope_override
@@ -52,7 +50,7 @@ class SGLineManager : public XLineManager
}
}
- bool Check(User *u, XLine *x) anope_override
+ bool Check(User *u, const XLine *x) anope_override
{
if (x->regex)
{
@@ -101,9 +99,9 @@ class SQLineManager : public XLineManager
this->Send(u, x);
}
- void OnExpire(XLine *x) anope_override
+ void OnExpire(const XLine *x) anope_override
{
- Log(OperServ, "expire/sqline") << "SQLINE on \2" << x->Mask << "\2 has expired";
+ Log(findbot(Config->OperServ), "expire/sqline") << "SQLINE on \2" << x->Mask << "\2 has expired";
}
void Send(User *u, XLine *x) anope_override
@@ -116,7 +114,7 @@ class SQLineManager : public XLineManager
ircdproto->SendSQLineDel(x);
}
- bool Check(User *u, XLine *x) anope_override
+ bool Check(User *u, const XLine *x) anope_override
{
if (x->regex)
return x->regex->Matches(u->nick);
@@ -142,9 +140,9 @@ class SNLineManager : public XLineManager
this->Send(u, x);
}
- void OnExpire(XLine *x) anope_override
+ void OnExpire(const XLine *x) anope_override
{
- Log(OperServ, "expire/snline") << "SNLINE on \2" << x->Mask << "\2 has expired";
+ Log(findbot(Config->OperServ), "expire/snline") << "SNLINE on \2" << x->Mask << "\2 has expired";
}
void Send(User *u, XLine *x) anope_override
@@ -157,7 +155,7 @@ class SNLineManager : public XLineManager
ircdproto->SendSGLineDel(x);
}
- bool Check(User *u, XLine *x) anope_override
+ bool Check(User *u, const XLine *x) anope_override
{
if (x->regex)
return x->regex->Matches(u->realname);
@@ -177,8 +175,7 @@ class OperServCore : public Module
{
this->SetAuthor("Anope");
- OperServ = findbot(Config->OperServ);
- if (OperServ == NULL)
+ if (!findbot(Config->OperServ))
throw ModuleException("No bot named " + Config->OperServ);
Implementation i[] = { I_OnBotPrivmsg, I_OnServerQuit, I_OnUserModeSet, I_OnUserModeUnset, I_OnUserConnect, I_OnUserNickChange, I_OnPreHelp };
@@ -206,7 +203,7 @@ class OperServCore : public Module
if (Config->OSOpersOnly && !u->HasMode(UMODE_OPER) && bi->nick == Config->OperServ)
{
u->SendMessage(bi, ACCESS_DENIED);
- Log(OperServ, "bados") << "Denied access to " << Config->OperServ << " from " << u->GetMask() << " (non-oper)";
+ Log(findbot(Config->OperServ), "bados") << "Denied access to " << Config->OperServ << " from " << u->GetMask() << " (non-oper)";
return EVENT_STOP;
}
@@ -216,19 +213,19 @@ class OperServCore : public Module
void OnServerQuit(Server *server) anope_override
{
if (server->HasFlag(SERVER_JUPED))
- Log(server, "squit", OperServ) << "Received SQUIT for juped server " << server->GetName();
+ Log(server, "squit", findbot(Config->OperServ)) << "Received SQUIT for juped server " << server->GetName();
}
void OnUserModeSet(User *u, UserModeName Name) anope_override
{
if (Name == UMODE_OPER)
- Log(u, "oper", OperServ) << "is now an IRC operator.";
+ Log(u, "oper", findbot(Config->OperServ)) << "is now an IRC operator.";
}
void OnUserModeUnset(User *u, UserModeName Name) anope_override
{
if (Name == UMODE_OPER)
- Log(u, "oper", OperServ) << "is no longer an IRC operator";
+ Log(u, "oper", findbot(Config->OperServ)) << "is no longer an IRC operator";
}
void OnUserConnect(dynamic_reference<User> &u, bool &exempt) anope_override
diff --git a/src/access.cpp b/src/access.cpp
index 4ed19c7fe..1100d8e7c 100644
--- a/src/access.cpp
+++ b/src/access.cpp
@@ -46,8 +46,11 @@ void PrivilegeManager::RemovePrivilege(Privilege &p)
if (it != privs.end())
privs.erase(it);
- for (registered_channel_map::const_iterator cit = RegisteredChannelList.begin(), cit_end = RegisteredChannelList.end(); cit != cit_end; ++cit)
+ for (registered_channel_map::const_iterator cit = RegisteredChannelList->begin(), cit_end = RegisteredChannelList->end(); cit != cit_end; ++cit)
+ {
+ cit->second->QueueUpdate();
cit->second->RemoveLevel(p.name);
+ }
}
Privilege *PrivilegeManager::FindPrivilege(const Anope::string &name)
@@ -84,14 +87,14 @@ ChanAccess::~ChanAccess()
{
}
-Anope::string ChanAccess::serialize_name() const
+const Anope::string ChanAccess::serialize_name() const
{
return "ChanAccess";
}
-Serializable::serialized_data ChanAccess::serialize()
+Serialize::Data ChanAccess::serialize() const
{
- serialized_data data;
+ Serialize::Data data;
data["provider"] << this->provider->name;
data["ci"] << this->ci->name;
@@ -104,14 +107,18 @@ Serializable::serialized_data ChanAccess::serialize()
return data;
}
-void ChanAccess::unserialize(serialized_data &data)
+Serializable* ChanAccess::unserialize(Serializable *obj, Serialize::Data &data)
{
service_reference<AccessProvider> aprovider("AccessProvider", data["provider"].astr());
ChannelInfo *ci = cs_findchan(data["ci"].astr());
if (!aprovider || !ci)
- return;
+ return NULL;
- ChanAccess *access = aprovider->Create();
+ ChanAccess *access;
+ if (obj)
+ access = debug_cast<ChanAccess *>(obj);
+ else
+ access = const_cast<ChanAccess *>(aprovider->Create());
access->provider = aprovider;
access->ci = ci;
data["mask"] >> access->mask;
@@ -120,10 +127,12 @@ void ChanAccess::unserialize(serialized_data &data)
data["created"] >> access->created;
access->Unserialize(data["data"].astr());
- ci->AddAccess(access);
+ if (!obj)
+ ci->AddAccess(access);
+ return access;
}
-bool ChanAccess::Matches(User *u, NickCore *nc)
+bool ChanAccess::Matches(const User *u, const NickCore *nc) const
{
bool is_mask = this->mask.find_first_of("!@?*") != Anope::string::npos;
if (u && is_mask && Anope::Match(u->nick, this->mask))
@@ -131,10 +140,10 @@ bool ChanAccess::Matches(User *u, NickCore *nc)
else if (u && Anope::Match(u->GetDisplayedMask(), this->mask))
return true;
else if (nc)
- for (std::list<NickAlias *>::iterator it = nc->aliases.begin(); it != nc->aliases.end(); ++it)
+ for (std::list<serialize_obj<NickAlias> >::const_iterator it = nc->aliases.begin(); it != nc->aliases.end();)
{
- NickAlias *na = *it;
- if (Anope::Match(na->nick, this->mask))
+ const NickAlias *na = *it++;
+ if (na && Anope::Match(na->nick, this->mask))
return true;
}
return false;
@@ -245,7 +254,7 @@ bool AccessGroup::HasPriv(const Anope::string &name) const
return false;
}
-ChanAccess *AccessGroup::Highest() const
+const ChanAccess *AccessGroup::Highest() const
{
const std::vector<Privilege> &privs = PrivilegeManager::GetPrivileges();
for (unsigned i = privs.size(); i > 0; --i)
diff --git a/src/actions.cpp b/src/actions.cpp
index 5536596e6..657973e3c 100644
--- a/src/actions.cpp
+++ b/src/actions.cpp
@@ -51,7 +51,7 @@ bool bad_password(User *u)
* @param full True to match against the users real host and IP
* @return void
*/
-void common_unban(ChannelInfo *ci, User *u, bool full)
+void common_unban(const ChannelInfo *ci, User *u, bool full)
{
if (!u || !ci || !ci->c || !ci->c->HasMode(CMODE_BAN))
return;
diff --git a/src/bots.cpp b/src/bots.cpp
index 242b7d4f2..e9d279c3e 100644
--- a/src/bots.cpp
+++ b/src/bots.cpp
@@ -16,9 +16,10 @@
#include "config.h"
#include "language.h"
#include "extern.h"
+#include "serialize.h"
-Anope::insensitive_map<BotInfo *> BotListByNick;
-Anope::map<BotInfo *> BotListByUID;
+serialize_checker<botinfo_map> BotListByNick("BotInfo");
+serialize_checker<botinfouid_map> BotListByUID("BotInfo");
BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const Anope::string &nhost, const Anope::string &nreal, const Anope::string &bmodes) : User(nnick, nuser, nhost, ts6_uid_retrieve()), Flags<BotFlag, BI_END>(BotFlagString), botmodes(bmodes)
{
@@ -28,9 +29,9 @@ BotInfo::BotInfo(const Anope::string &nnick, const Anope::string &nuser, const A
this->lastmsg = this->created = Anope::CurTime;
this->introduced = false;
- BotListByNick[this->nick] = this;
+ (*BotListByNick)[this->nick] = this;
if (!this->uid.empty())
- BotListByUID[this->uid] = this;
+ (*BotListByUID)[this->uid] = this;
// If we're synchronised with the uplink already, send the bot.
if (Me && Me->IsSynced())
@@ -57,29 +58,32 @@ BotInfo::~BotInfo()
ircdproto->SendSQLineDel(&x);
}
- for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it)
+ for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it)
{
ChannelInfo *ci = it->second;
if (ci->bi == this)
+ {
+ ci->QueueUpdate();
ci->bi = NULL;
+ }
}
- BotListByNick.erase(this->nick);
+ BotListByNick->erase(this->nick);
if (!this->uid.empty())
- BotListByUID.erase(this->uid);
+ BotListByUID->erase(this->uid);
}
-Anope::string BotInfo::serialize_name() const
+const Anope::string BotInfo::serialize_name() const
{
return "BotInfo";
}
-Serializable::serialized_data BotInfo::serialize()
+Serialize::Data BotInfo::serialize() const
{
- serialized_data data;
+ Serialize::Data data;
- data["nick"] << this->nick;
+ data["nick"].setMax(64) << this->nick;
data["user"] << this->ident;
data["host"] << this->host;
data["realname"] << this->realname;
@@ -89,13 +93,16 @@ Serializable::serialized_data BotInfo::serialize()
return data;
}
-void BotInfo::unserialize(serialized_data &data)
+Serializable* BotInfo::unserialize(Serializable *obj, Serialize::Data &data)
{
- BotInfo *bi = findbot(data["nick"].astr());
- if (bi == NULL)
+ BotInfo *bi;
+ if (obj)
+ bi = debug_cast<BotInfo *>(obj);
+ else if (!(bi = findbot(data["nick"].astr())))
bi = new BotInfo(data["nick"].astr(), data["user"].astr(), data["host"].astr(), data["realname"].astr());
data["created"] >> bi->created;
bi->FromString(data["flags"].astr());
+ return bi;
}
void BotInfo::GenerateUID()
@@ -103,26 +110,26 @@ void BotInfo::GenerateUID()
if (!this->uid.empty())
throw CoreException("Bot already has a uid?");
this->uid = ts6_uid_retrieve();
- BotListByUID[this->uid] = this;
+ (*BotListByUID)[this->uid] = this;
UserListByUID[this->uid] = this;
}
void BotInfo::SetNewNick(const Anope::string &newnick)
{
UserListByNick.erase(this->nick);
- BotListByNick.erase(this->nick);
+ BotListByNick->erase(this->nick);
this->nick = newnick;
UserListByNick[this->nick] = this;
- BotListByNick[this->nick] = this;
+ (*BotListByNick)[this->nick] = this;
}
void BotInfo::RejoinAll()
{
- for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it)
+ for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it)
{
- ChannelInfo *ci = it->second;
+ const ChannelInfo *ci = it->second;
if (ci->bi == this && ci->c && ci->c->users.size() >= Config->BSMinUsers)
this->Join(ci->c);
@@ -162,12 +169,12 @@ void BotInfo::UnAssign(User *u, ChannelInfo *ci)
ci->bi = NULL;
}
-unsigned BotInfo::GetChannelCount()
+unsigned BotInfo::GetChannelCount() const
{
unsigned count = 0;
- for (registered_channel_map::const_iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it)
+ for (registered_channel_map::const_iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it)
{
- ChannelInfo *ci = it->second;
+ const ChannelInfo *ci = it->second;
if (ci->bi == this)
++count;
@@ -234,7 +241,7 @@ void BotInfo::OnMessage(User *u, const Anope::string &message)
std::vector<Anope::string> params = BuildStringVector(message);
bool has_help = this->commands.find("HELP") != this->commands.end();
- BotInfo::command_map::iterator it = this->commands.end();
+ BotInfo::command_map::const_iterator it = this->commands.end();
unsigned count = 0;
for (unsigned max = params.size(); it == this->commands.end() && max > 0; --max)
{
@@ -256,7 +263,7 @@ void BotInfo::OnMessage(User *u, const Anope::string &message)
return;
}
- CommandInfo &info = it->second;
+ const CommandInfo &info = it->second;
service_reference<Command> c("Command", info.name);
if (!c)
{
diff --git a/src/botserv.cpp b/src/botserv.cpp
index 962f2b80e..4ec6465a1 100644
--- a/src/botserv.cpp
+++ b/src/botserv.cpp
@@ -21,24 +21,24 @@
#include "access.h"
#include "channels.h"
-BotInfo *findbot(const Anope::string &nick)
+BotInfo* findbot(const Anope::string &nick)
{
BotInfo *bi = NULL;
if (isdigit(nick[0]) && ircd->ts6)
{
- Anope::map<BotInfo *>::iterator it = BotListByUID.find(nick);
- if (it != BotListByUID.end())
+ botinfouid_map::iterator it = BotListByUID->find(nick);
+ if (it != BotListByUID->end())
bi = it->second;
}
else
{
- Anope::insensitive_map<BotInfo *>::iterator it = BotListByNick.find(nick);
- if (it != BotListByNick.end())
+ botinfo_map::iterator it = BotListByNick->find(nick);
+ if (it != BotListByNick->end())
bi = it->second;
}
-
- FOREACH_MOD(I_OnFindBot, OnFindBot(nick));
-
+
+ if (bi)
+ bi->QueueUpdate();
return bi;
}
diff --git a/src/channels.cpp b/src/channels.cpp
index 6035d1657..283da3440 100644
--- a/src/channels.cpp
+++ b/src/channels.cpp
@@ -102,7 +102,7 @@ void Channel::Reset()
void Channel::Sync()
{
- if (!this->HasMode(CMODE_PERM) && (this->users.empty() || (this->users.size() == 1 && this->ci && this->ci->bi == this->users.front()->user)))
+ if (!this->HasMode(CMODE_PERM) && (this->users.empty() || (this->users.size() == 1 && this->ci && this->ci->bi && *this->ci->bi == this->users.front()->user)))
{
this->Hold();
}
@@ -141,30 +141,30 @@ void Channel::CheckModes()
return;
if (this->ci)
- for (std::multimap<ChannelModeName, ModeLock>::const_iterator it = this->ci->GetMLock().begin(), it_end = this->ci->GetMLock().end(); it != it_end; ++it)
+ for (ChannelInfo::ModeList::const_iterator it = this->ci->GetMLock().begin(), it_end = this->ci->GetMLock().end(); it != it_end; ++it)
{
- const ModeLock &ml = it->second;
- ChannelMode *cm = ModeManager::FindChannelModeByName(ml.name);
+ const ModeLock *ml = it->second;
+ ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name);
if (!cm)
continue;
if (cm->Type == MODE_REGULAR)
{
- if (!this->HasMode(cm->Name) && ml.set)
+ if (!this->HasMode(cm->Name) && ml->set)
this->SetMode(NULL, cm);
- else if (this->HasMode(cm->Name) && !ml.set)
+ else if (this->HasMode(cm->Name) && !ml->set)
this->RemoveMode(NULL, cm);
}
else if (cm->Type == MODE_PARAM)
{
/* If the channel doesnt have the mode, or it does and it isn't set correctly */
- if (ml.set)
+ if (ml->set)
{
Anope::string param;
this->GetParam(cm->Name, param);
- if (!this->HasMode(cm->Name) || (!param.empty() && !ml.param.empty() && !param.equals_cs(ml.param)))
- this->SetMode(NULL, cm, ml.param);
+ if (!this->HasMode(cm->Name) || (!param.empty() && !ml->param.empty() && !param.equals_cs(ml->param)))
+ this->SetMode(NULL, cm, ml->param);
}
else
{
@@ -175,10 +175,10 @@ void Channel::CheckModes()
}
else if (cm->Type == MODE_LIST)
{
- if (ml.set)
- this->SetMode(NULL, cm, ml.param);
+ if (ml->set)
+ this->SetMode(NULL, cm, ml->param);
else
- this->RemoveMode(NULL, cm, ml.param);
+ this->RemoveMode(NULL, cm, ml->param);
}
}
}
@@ -260,9 +260,9 @@ void Channel::DeleteUser(User *user)
* @param u The user
* @return A user container if found, else NULL
*/
-UserContainer *Channel::FindUser(User *u)
+UserContainer *Channel::FindUser(const User *u) const
{
- for (CUserList::iterator it = this->users.begin(), it_end = this->users.end(); it != it_end; ++it)
+ for (CUserList::const_iterator it = this->users.begin(), it_end = this->users.end(); it != it_end; ++it)
if ((*it)->user == u)
return *it;
return NULL;
@@ -273,7 +273,7 @@ UserContainer *Channel::FindUser(User *u)
* @param cms The status mode, or NULL to represent no status
* @return true or false
*/
-bool Channel::HasUserStatus(User *u, ChannelModeStatus *cms) const
+bool Channel::HasUserStatus(const User *u, ChannelModeStatus *cms) const
{
if (!u || (cms && cms->Type != MODE_STATUS))
throw CoreException("Channel::HasUserStatus got bad mode");
@@ -297,7 +297,7 @@ bool Channel::HasUserStatus(User *u, ChannelModeStatus *cms) const
* @param Name The Mode name, eg CMODE_OP, CMODE_VOICE
* @return true or false
*/
-bool Channel::HasUserStatus(User *u, ChannelModeName Name) const
+bool Channel::HasUserStatus(const User *u, ChannelModeName Name) const
{
return HasUserStatus(u, debug_cast<ChannelModeStatus *>(ModeManager::FindChannelModeByName(Name)));
}
@@ -395,8 +395,8 @@ void Channel::SetModeInternal(User *setter, ChannelMode *cm, const Anope::string
if (cm->Name == CMODE_PERM)
{
this->SetFlag(CH_PERSIST);
- if (ci)
- ci->SetFlag(CI_PERSIST);
+ if (this->ci)
+ this->ci->SetFlag(CI_PERSIST);
}
/* Check if we should enforce mlock */
@@ -429,8 +429,8 @@ void Channel::RemoveModeInternal(User *setter, ChannelMode *cm, const Anope::str
return;
}
- BotInfo *bi = findbot(param);
- User *u = bi ? bi : finduser(param);
+ const BotInfo *bi = findbot(param);
+ const User *u = bi ? bi : finduser(param);
if (!u)
{
@@ -482,8 +482,8 @@ void Channel::RemoveModeInternal(User *setter, ChannelMode *cm, const Anope::str
{
this->UnsetFlag(CH_PERSIST);
- if (ci)
- ci->UnsetFlag(CI_PERSIST);
+ if (this->ci)
+ this->ci->UnsetFlag(CI_PERSIST);
if (this->users.empty())
{
@@ -506,7 +506,7 @@ void Channel::RemoveModeInternal(User *setter, ChannelMode *cm, const Anope::str
* @param param Optional param arg for the mode
* @param EnforceMLock true if mlocks should be enforced, false to override mlock
*/
-void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string &param, bool EnforceMLock)
+void Channel::SetMode(const BotInfo *bi, ChannelMode *cm, const Anope::string &param, bool EnforceMLock)
{
if (!cm)
return;
@@ -547,7 +547,7 @@ void Channel::SetMode(BotInfo *bi, ChannelMode *cm, const Anope::string &param,
* @param param Optional param arg for the mode
* @param EnforceMLock true if mlocks should be enforced, false to override mlock
*/
-void Channel::SetMode(BotInfo *bi, ChannelModeName Name, const Anope::string &param, bool EnforceMLock)
+void Channel::SetMode(const BotInfo *bi, ChannelModeName Name, const Anope::string &param, bool EnforceMLock)
{
SetMode(bi, ModeManager::FindChannelModeByName(Name), param, EnforceMLock);
}
@@ -558,7 +558,7 @@ void Channel::SetMode(BotInfo *bi, ChannelModeName Name, const Anope::string &pa
* @param param Optional param arg for the mode
* @param EnforceMLock true if mlocks should be enforced, false to override mlock
*/
-void Channel::RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string &param, bool EnforceMLock)
+void Channel::RemoveMode(const BotInfo *bi, ChannelMode *cm, const Anope::string &param, bool EnforceMLock)
{
if (!cm)
return;
@@ -599,7 +599,7 @@ void Channel::RemoveMode(BotInfo *bi, ChannelMode *cm, const Anope::string &para
* @param param Optional param arg for the mode
* @param EnforceMLock true if mlocks should be enforced, false to override mlock
*/
-void Channel::RemoveMode(BotInfo *bi, ChannelModeName Name, const Anope::string &param, bool EnforceMLock)
+void Channel::RemoveMode(const BotInfo *bi, ChannelModeName Name, const Anope::string &param, bool EnforceMLock)
{
RemoveMode(bi, ModeManager::FindChannelModeByName(Name), param, EnforceMLock);
}
@@ -631,7 +631,7 @@ bool Channel::GetParam(ChannelModeName Name, Anope::string &Target) const
* @param EnforceMLock Should mlock be enforced on this mode change
* @param cmodes The modes to set
*/
-void Channel::SetModes(BotInfo *bi, bool EnforceMLock, const char *cmodes, ...)
+void Channel::SetModes(const BotInfo *bi, bool EnforceMLock, const char *cmodes, ...)
{
char buf[BUFSIZE] = "";
va_list args;
@@ -879,9 +879,7 @@ void Channel::ChangeTopicInternal(const Anope::string &user, const Anope::string
FOREACH_MOD(I_OnTopicUpdated, OnTopicUpdated(this, u, this->topic));
if (this->ci)
- {
this->ci->CheckTopic();
- }
}
void Channel::ChangeTopic(const Anope::string &user, const Anope::string &newtopic, time_t ts)
@@ -896,9 +894,7 @@ void Channel::ChangeTopic(const Anope::string &user, const Anope::string &newtop
FOREACH_MOD(I_OnTopicUpdated, OnTopicUpdated(this, u, this->topic));
if (this->ci)
- {
this->ci->CheckTopic();
- }
}
/** A timer used to keep the BotServ bot/ChanServ in the channel
@@ -1157,7 +1153,7 @@ void do_cmode(const Anope::string &source, const Anope::string &channel, const A
* @param give_modes Set to 1 to give modes, 0 to not give modes
* @return void
**/
-void chan_set_correct_modes(User *user, Channel *c, int give_modes)
+void chan_set_correct_modes(const User *user, Channel *c, int give_modes)
{
ChannelMode *owner = ModeManager::FindChannelModeByName(CMODE_OWNER),
*admin = ModeManager::FindChannelModeByName(CMODE_PROTECT),
@@ -1208,20 +1204,20 @@ void chan_set_correct_modes(User *user, Channel *c, int give_modes)
}
// Check mlock
- for (std::multimap<ChannelModeName, ModeLock>::const_iterator it = ci->GetMLock().begin(), it_end = ci->GetMLock().end(); it != it_end; ++it)
+ for (ChannelInfo::ModeList::const_iterator it = ci->GetMLock().begin(), it_end = ci->GetMLock().end(); it != it_end; ++it)
{
- const ModeLock &ml = it->second;
- ChannelMode *cm = ModeManager::FindChannelModeByName(ml.name);
+ const ModeLock *ml = it->second;
+ ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name);
if (!cm || cm->Type != MODE_STATUS)
continue;
- if (Anope::Match(user->nick, ml.param) || Anope::Match(user->GetDisplayedMask(), ml.param))
+ if (Anope::Match(user->nick, ml->param) || Anope::Match(user->GetDisplayedMask(), ml->param))
{
- if ((ml.set && !c->HasUserStatus(user, ml.name)) || (!ml.set && c->HasUserStatus(user, ml.name)))
+ if ((ml->set && !c->HasUserStatus(user, ml->name)) || (!ml->set && c->HasUserStatus(user, ml->name)))
{
- if (ml.set)
+ if (ml->set)
c->SetMode(NULL, cm, user->nick, false);
- else if (!ml.set)
+ else if (!ml->set)
c->RemoveMode(NULL, cm, user->nick, false);
}
}
@@ -1326,7 +1322,7 @@ const Anope::string Entry::GetMask()
* @param full True to match against a users real host and IP
* @return true on match
*/
-bool Entry::Matches(User *u, bool full) const
+bool Entry::Matches(const User *u, bool full) const
{
bool ret = true;
diff --git a/src/chanserv.cpp b/src/chanserv.cpp
index fd7fb88f9..67b77a432 100644
--- a/src/chanserv.cpp
+++ b/src/chanserv.cpp
@@ -18,17 +18,14 @@
#include "channels.h"
#include "access.h"
-registered_channel_map RegisteredChannelList;
-
-/*************************************************************************/
-
-ChannelInfo *cs_findchan(const Anope::string &chan)
+ChannelInfo* cs_findchan(const Anope::string &chan)
{
- FOREACH_MOD(I_OnFindChan, OnFindChan(chan));
-
- registered_channel_map::const_iterator it = RegisteredChannelList.find(chan);
- if (it != RegisteredChannelList.end())
+ registered_channel_map::const_iterator it = RegisteredChannelList->find(chan);
+ if (it != RegisteredChannelList->end())
+ {
+ it->second->QueueUpdate();
return it->second;
+ }
return NULL;
}
@@ -40,7 +37,7 @@ ChannelInfo *cs_findchan(const Anope::string &chan)
* @param ci The channel
* @return true or false
*/
-bool IsFounder(User *user, ChannelInfo *ci)
+bool IsFounder(const User *user, const ChannelInfo *ci)
{
if (!user || !ci)
return false;
@@ -71,7 +68,7 @@ void update_cs_lastseen(User *user, ChannelInfo *ci)
/* Returns the best ban possible for a user depending of the bantype
value. */
-int get_idealban(ChannelInfo *ci, User *u, Anope::string &ret)
+int get_idealban(const ChannelInfo *ci, User *u, Anope::string &ret)
{
Anope::string mask;
diff --git a/src/config.cpp b/src/config.cpp
index 790f5c82f..66d8f6a8c 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -620,9 +620,13 @@ static bool DoneOperTypes(ServerConfig *, const Anope::string &)
static bool InitOpers(ServerConfig *config, const Anope::string &)
{
- for (nickcore_map::const_iterator it = NickCoreList.begin(), it_end = NickCoreList.end(); it != it_end; ++it)
- if (it->second->o && it->second->o->config)
- it->second->o = NULL;
+ for (nickcore_map::const_iterator it = NickCoreList->begin(), it_end = NickCoreList->end(); it != it_end; ++it)
+ {
+ NickCore *nc = it->second;
+ nc->QueueUpdate();
+ if (nc->o && nc->o->config)
+ nc->o = NULL;
+ }
for (unsigned i = 0; i < config->Opers.size(); ++i)
delete config->Opers[i];
@@ -674,7 +678,7 @@ static bool DoneOpers(ServerConfig *config, const Anope::string &)
{
Oper *o = config->Opers[i];
- NickAlias *na = findnick(o->name);
+ const NickAlias *na = findnick(o->name);
if (!na)
// Nonexistant nick
continue;
@@ -817,8 +821,15 @@ static bool DoneLogs(ServerConfig *config, const Anope::string &)
static bool InitCommands(ServerConfig *config, const Anope::string &)
{
- for (botinfo_map::iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it)
- it->second->commands.clear();
+ for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
+ {
+ BotInfo *bi = it->second;
+ if (bi)
+ {
+ bi->QueueUpdate();
+ bi->commands.clear();
+ }
+ }
return true;
}
@@ -929,8 +940,8 @@ static bool DoServices(ServerConfig *config, const Anope::string &, const Anope:
throw ConfigException("One or more values in your configuration file failed to validate. Please see your log for more information.");
services.insert(nick);
- BotInfo *bi = findbot(nick);
- if (bi == NULL)
+ BotInfo* bi = findbot(nick);
+ if (!bi)
bi = new BotInfo(nick, user, host, gecos, modes);
bi->SetFlag(BI_CONF);
@@ -1000,13 +1011,13 @@ static bool DoServices(ServerConfig *config, const Anope::string &, const Anope:
static bool DoneServices(ServerConfig *config, const Anope::string &)
{
- for (botinfo_map::iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end;)
+ for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end;)
{
BotInfo *bi = it->second;
++it;
if (bi->HasFlag(BI_CONF) && services.count(bi->nick) == 0)
- delete bi;
+ bi->destroy();
}
services.clear();
return true;
diff --git a/src/init.cpp b/src/init.cpp
index 55ad04bae..08d4aed08 100644
--- a/src/init.cpp
+++ b/src/init.cpp
@@ -453,7 +453,7 @@ void Init(int ac, char **av)
/* Create me */
Me = new Server(NULL, Config->ServerName, 0, Config->ServerDesc, Config->Numeric);
- for (botinfo_map::iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it)
+ for (botinfo_map::const_iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
it->second->server = Me;
/* Announce ourselves to the logfile. */
diff --git a/src/language.cpp b/src/language.cpp
index 1a374c0bc..8b680077b 100644
--- a/src/language.cpp
+++ b/src/language.cpp
@@ -63,7 +63,7 @@ const char *translate(User *u, const char *string)
return translate(u ? u->Account() : NULL, string);
}
-const char *translate(NickCore *nc, const char *string)
+const char *translate(const NickCore *nc, const char *string)
{
return anope_gettext(nc ? nc->language.c_str() : Config->NSDefLanguage.c_str(), string);
}
diff --git a/src/logger.cpp b/src/logger.cpp
index fb720963c..2b27e1478 100644
--- a/src/logger.cpp
+++ b/src/logger.cpp
@@ -75,15 +75,15 @@ Anope::string LogFile::GetName() const
return this->filename;
}
-Log::Log(LogType type, const Anope::string &category, BotInfo *b) : bi(b), u(NULL), c(NULL), chan(NULL), ci(NULL), s(NULL), Type(type), Category(category)
+Log::Log(LogType type, const Anope::string &category, const BotInfo *b) : bi(b), u(NULL), c(NULL), chan(NULL), ci(NULL), s(NULL), Type(type), Category(category)
{
- if (!bi)
- bi = Config ? findbot(Config->Global) : NULL;
+ if (!bi && Config)
+ bi = findbot(Config->Global);
if (bi)
this->Sources.push_back(bi->nick);
}
-Log::Log(LogType type, User *_u, Command *_c, ChannelInfo *_ci) : u(_u), c(_c), chan(NULL), ci(_ci), s(NULL), Type(type)
+Log::Log(LogType type, const User *_u, Command *_c, const ChannelInfo *_ci) : u(_u), c(_c), chan(NULL), ci(_ci), s(NULL), Type(type)
{
if (!u || !c)
throw CoreException("Invalid pointers passed to Log::Log");
@@ -95,8 +95,8 @@ Log::Log(LogType type, User *_u, Command *_c, ChannelInfo *_ci) : u(_u), c(_c),
this->bi = NULL;
if (sl != Anope::string::npos)
this->bi = findbot(c->name.substr(0, sl));
- if (this->bi == NULL)
- this->bi = Config ? findbot(Config->Global) : NULL;
+ if (this->bi == NULL && Config)
+ this->bi = findbot(Config->Global);
this->Category = c->name;
if (this->bi)
this->Sources.push_back(this->bi->nick);
@@ -106,12 +106,13 @@ Log::Log(LogType type, User *_u, Command *_c, ChannelInfo *_ci) : u(_u), c(_c),
this->Sources.push_back(ci->name);
}
-Log::Log(User *_u, Channel *ch, const Anope::string &category) : u(_u), c(NULL), chan(ch), ci(chan ? chan->ci : NULL), s(NULL), Type(LOG_CHANNEL)
+Log::Log(const User *_u, Channel *ch, const Anope::string &category) : bi(NULL), u(_u), c(NULL), chan(ch), ci(chan ? *chan->ci : NULL), s(NULL), Type(LOG_CHANNEL)
{
if (!chan)
throw CoreException("Invalid pointers passed to Log::Log");
- this->bi = Config ? findbot(Config->ChanServ) : NULL;
+ if (Config)
+ this->bi = findbot(Config->ChanServ);
this->Category = category;
if (this->bi)
this->Sources.push_back(this->bi->nick);
@@ -120,36 +121,36 @@ Log::Log(User *_u, Channel *ch, const Anope::string &category) : u(_u), c(NULL),
this->Sources.push_back(chan->name);
}
-Log::Log(User *_u, const Anope::string &category, BotInfo *_bi) : bi(_bi), u(_u), c(NULL), chan(NULL), ci(NULL), s(NULL), Type(LOG_USER), Category(category)
+Log::Log(const User *_u, const Anope::string &category, const BotInfo *_bi) : bi(_bi), u(_u), c(NULL), chan(NULL), ci(NULL), s(NULL), Type(LOG_USER), Category(category)
{
if (!u)
throw CoreException("Invalid pointers passed to Log::Log");
- if (!this->bi)
- this->bi = Config ? findbot(Config->Global) : NULL;
+ if (!this->bi && Config)
+ this->bi = findbot(Config->Global);
if (this->bi)
this->Sources.push_back(this->bi->nick);
this->Sources.push_back(u->nick);
}
-Log::Log(Server *serv, const Anope::string &category, BotInfo *_bi) : bi(_bi), u(NULL), c(NULL), chan(NULL), ci(NULL), s(serv), Type(LOG_SERVER), Category(category)
+Log::Log(Server *serv, const Anope::string &category, const BotInfo *_bi) : bi(_bi), u(NULL), c(NULL), chan(NULL), ci(NULL), s(serv), Type(LOG_SERVER), Category(category)
{
if (!s)
throw CoreException("Invalid pointer passed to Log::Log");
- if (!this->bi)
- this->bi = Config ? findbot(Config->OperServ) : NULL;
- if (!this->bi)
- this->bi = Config ? findbot(Config->Global) : NULL;
+ if (!this->bi && Config)
+ this->bi = findbot(Config->OperServ);
+ if (!this->bi && Config)
+ this->bi = findbot(Config->Global);
if (this->bi)
this->Sources.push_back(this->bi->nick);
this->Sources.push_back(s->GetName());
}
-Log::Log(BotInfo *b, const Anope::string &category) : bi(b), u(NULL), c(NULL), chan(NULL), ci(NULL), s(NULL), Type(LOG_NORMAL), Category(category)
+Log::Log(const BotInfo *b, const Anope::string &category) : bi(b), u(NULL), c(NULL), chan(NULL), ci(NULL), s(NULL), Type(LOG_NORMAL), Category(category)
{
- if (!this->bi)
- this->bi = Config ? findbot(Config->Global) : NULL;
+ if (!this->bi && Config)
+ this->bi = findbot(Config->Global);
if (this->bi)
this->Sources.push_back(bi->nick);
}
diff --git a/src/mail.cpp b/src/mail.cpp
index cc1541640..aaf564bc6 100644
--- a/src/mail.cpp
+++ b/src/mail.cpp
@@ -51,7 +51,7 @@ void MailThread::Run()
SetExitState();
}
-bool Mail(User *u, NickCore *nc, BotInfo *service, const Anope::string &subject, const Anope::string &message)
+bool Mail(User *u, NickCore *nc, const BotInfo *service, const Anope::string &subject, const Anope::string &message)
{
if (!u || !nc || !service || subject.empty() || message.empty())
return false;
diff --git a/src/main.cpp b/src/main.cpp
index 303b6b076..cacfec814 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -124,7 +124,7 @@ UplinkSocket::~UplinkSocket()
{
/* Don't use quitmsg here, it may contain information you don't want people to see */
ircdproto->SendQuit(u, "Shutting down");
- BotInfo *bi = findbot(u->nick);
+ BotInfo* bi = findbot(u->nick);
if (bi != NULL)
bi->introduced = false;
}
@@ -224,7 +224,7 @@ UplinkSocket::Message::~Message()
return;
}
- BotInfo *bi = findbot(this->user->nick);
+ const BotInfo *bi = findbot(this->user->nick);
if (bi != NULL && bi->introduced == false)
{
Log(LOG_DEBUG) << "Attempted to send \"" << this->buffer.str() << "\" from " << bi->nick << " when not introduced";
diff --git a/src/memoserv.cpp b/src/memoserv.cpp
index 1407e8521..92c027702 100644
--- a/src/memoserv.cpp
+++ b/src/memoserv.cpp
@@ -20,14 +20,14 @@
Memo::Memo() : Flags<MemoFlag>(MemoFlagStrings) { }
-Anope::string Memo::serialize_name() const
+const Anope::string Memo::serialize_name() const
{
return "Memo";
}
-Serializable::serialized_data Memo::serialize()
+Serialize::Data Memo::serialize() const
{
- serialized_data data;
+ Serialize::Data data;
data["owner"] << this->owner;
data["time"].setType(Serialize::DT_INT) << this->time;
@@ -38,50 +38,69 @@ Serializable::serialized_data Memo::serialize()
return data;
}
-void Memo::unserialize(serialized_data &data)
+Serializable* Memo::unserialize(Serializable *obj, Serialize::Data &data)
{
if (!memoserv)
- return;
+ return NULL;
bool ischan;
MemoInfo *mi = memoserv->GetMemoInfo(data["owner"].astr(), ischan);
if (!mi)
- return;
+ return NULL;
- Memo *m = new Memo();
+ Memo *m;
+ if (obj)
+ m = debug_cast<Memo *>(obj);
+ else
+ m = new Memo();
data["owner"] >> m->owner;
data["time"] >> m->time;
data["sender"] >> m->sender;
data["text"] >> m->text;
m->FromString(data["flags"].astr());
- mi->memos.push_back(m);
+ if (obj == NULL)
+ mi->memos->push_back(m);
+ return m;
+}
+
+MemoInfo::MemoInfo() : memos("Memo")
+{
+}
+
+Memo *MemoInfo::GetMemo(unsigned index) const
+{
+ if (index >= this->memos->size())
+ return NULL;
+ Memo *m = (*memos)[index];
+ m->QueueUpdate();
+ return m;
}
unsigned MemoInfo::GetIndex(Memo *m) const
{
- for (unsigned i = 0; i < this->memos.size(); ++i)
- if (this->memos[i] == m)
+ for (unsigned i = 0; i < this->memos->size(); ++i)
+ if (this->GetMemo(i) == m)
return i;
return -1;
}
void MemoInfo::Del(unsigned index)
{
- if (index >= this->memos.size())
+ if (index >= this->memos->size())
return;
- delete this->memos[index];
- this->memos.erase(this->memos.begin() + index);
+ this->GetMemo(index)->destroy();
+ this->memos->erase(this->memos->begin() + index);
}
void MemoInfo::Del(Memo *memo)
{
- std::vector<Memo *>::iterator it = std::find(this->memos.begin(), this->memos.end(), memo);
+ std::vector<Memo *>::iterator it = std::find(this->memos->begin(), this->memos->end(), memo);
- if (it != this->memos.end())
+ if (it != this->memos->end())
{
- delete memo;
- this->memos.erase(it);
+ memo->destroy();
+ this->memos->erase(it);
}
}
diff --git a/src/messages.cpp b/src/messages.cpp
index 52e7c57c1..b34841094 100644
--- a/src/messages.cpp
+++ b/src/messages.cpp
@@ -47,7 +47,7 @@ bool OnStats(const Anope::string &source, const std::vector<Anope::string> &para
{
Oper *o = Config->Opers[i];
- NickAlias *na = findnick(o->name);
+ const NickAlias *na = findnick(o->name);
if (na)
ircdproto->SendNumeric(243, source, "O * * %s %s 0", o->name.c_str(), o->ot->GetName().c_str());
}
diff --git a/src/misc.cpp b/src/misc.cpp
index 855155409..fbc110ef3 100644
--- a/src/misc.cpp
+++ b/src/misc.cpp
@@ -305,7 +305,7 @@ time_t dotime(const Anope::string &s)
* @param seconds time in seconds
* @return buffer
*/
-Anope::string duration(const time_t &t, NickCore *nc)
+Anope::string duration(const time_t &t, const NickCore *nc)
{
/* We first calculate everything */
time_t days = (t / 86400);
@@ -339,7 +339,7 @@ Anope::string duration(const time_t &t, NickCore *nc)
}
}
-Anope::string do_strftime(const time_t &t, NickCore *nc, bool short_output)
+Anope::string do_strftime(const time_t &t, const NickCore *nc, bool short_output)
{
tm tm = *localtime(&t);
char buf[BUFSIZE];
@@ -514,7 +514,7 @@ bool nickIsServices(const Anope::string &tempnick, bool bot)
nick = nick.substr(0, at);
}
- BotInfo *bi = findbot(nick);
+ const BotInfo *bi = findbot(nick);
if (bi)
return bot ? true : bi->HasFlag(BI_CORE);
return false;
diff --git a/src/modes.cpp b/src/modes.cpp
index cbfdc093b..dd5897087 100644
--- a/src/modes.cpp
+++ b/src/modes.cpp
@@ -24,12 +24,14 @@ std::vector<UserMode *> ModeManager::UserModes;
/* Number of generic modes we support */
unsigned GenericChannelModes = 0, GenericUserModes = 0;
/* Default mlocked modes */
-std::multimap<ChannelModeName, ModeLock> def_mode_locks;
+ChannelInfo::ModeList def_mode_locks;
/** Parse the mode string from the config file and set the default mlocked modes
*/
void SetDefaultMLock(ServerConfig *config)
{
+ for (ChannelInfo::ModeList::iterator it = def_mode_locks.begin(), it_end = def_mode_locks.end(); it != it_end; ++it)
+ delete it->second;
def_mode_locks.clear();
Anope::string modes;
@@ -57,8 +59,15 @@ void SetDefaultMLock(ServerConfig *config)
}
if (cm->Type != MODE_LIST) // Only MODE_LIST can have duplicates
- def_mode_locks.erase(cm->Name);
- def_mode_locks.insert(std::make_pair(cm->Name, ModeLock(NULL, adding == 1, cm->Name, param)));
+ {
+ ChannelInfo::ModeList::iterator it = def_mode_locks.find(cm->Name);
+ if (it != def_mode_locks.end())
+ {
+ delete it->second;
+ def_mode_locks.erase(it);
+ }
+ }
+ def_mode_locks.insert(std::make_pair(cm->Name, new ModeLock(NULL, adding == 1, cm->Name, param)));
}
}
}
@@ -461,7 +470,7 @@ std::list<Anope::string> ModeManager::BuildModeStrings(StackerInfo *info)
* @param Param A param, if there is one
* @param Type The type this is, user or channel
*/
-void ModeManager::StackerAddInternal(BotInfo *bi, Base *Object, Mode *mode, bool Set, const Anope::string &Param, StackerType Type)
+void ModeManager::StackerAddInternal(const BotInfo *bi, Base *Object, Mode *mode, bool Set, const Anope::string &Param, StackerType Type)
{
StackerInfo *s = GetInfo(Object);
s->Type = Type;
@@ -646,7 +655,7 @@ char ModeManager::GetStatusChar(char Value)
* @param Set true for setting, false for removing
* @param Param The param, if there is one
*/
-void ModeManager::StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const Anope::string &Param)
+void ModeManager::StackerAdd(const BotInfo *bi, Channel *c, ChannelMode *cm, bool Set, const Anope::string &Param)
{
StackerAddInternal(bi, c, cm, Set, Param, ST_CHANNEL);
}
@@ -658,7 +667,7 @@ void ModeManager::StackerAdd(BotInfo *bi, Channel *c, ChannelMode *cm, bool Set,
* @param Set true for setting, false for removing
* @param param The param, if there is one
*/
-void ModeManager::StackerAdd(BotInfo *bi, User *u, UserMode *um, bool Set, const Anope::string &Param)
+void ModeManager::StackerAdd(const BotInfo *bi, User *u, UserMode *um, bool Set, const Anope::string &Param)
{
StackerAddInternal(bi, u, um, Set, Param, ST_USER);
}
diff --git a/src/nickalias.cpp b/src/nickalias.cpp
index 586add90e..18e581714 100644
--- a/src/nickalias.cpp
+++ b/src/nickalias.cpp
@@ -19,16 +19,17 @@
#include "servers.h"
#include "config.h"
-class NickServHeld;
+serialize_checker<nickalias_map> NickAliasList("NickAlias");
+class NickServHeld;
typedef std::map<Anope::string, NickServHeld *> nickservheld_map;
static nickservheld_map NickServHelds;
/** Default constructor
* @param nick The nick
- * @param nickcore The nickcofe for this nick
+ * @param nickcore The nickcore for this nick
*/
-NickAlias::NickAlias(const Anope::string &nickname, NickCore *nickcore) : Flags<NickNameFlag, NS_END>(NickNameFlagStrings)
+NickAlias::NickAlias(const Anope::string &nickname, NickCore* nickcore) : Flags<NickNameFlag, NS_END>(NickNameFlagStrings)
{
if (nickname.empty())
throw CoreException("Empty nick passed to NickAlias constructor");
@@ -38,16 +39,16 @@ NickAlias::NickAlias(const Anope::string &nickname, NickCore *nickcore) : Flags<
this->time_registered = this->last_seen = Anope::CurTime;
this->nick = nickname;
this->nc = nickcore;
- this->nc->aliases.push_back(this);
+ nickcore->aliases.push_back(this);
- NickAliasList[this->nick] = this;
+ (*NickAliasList)[this->nick] = this;
if (this->nc->o == NULL)
{
Oper *o = Oper::Find(this->nick);
if (o == NULL)
o = Oper::Find(this->nc->display);
- this->nc->o = o;
+ nickcore->o = o;
if (this->nc->o != NULL)
Log() << "Tied oper " << this->nc->display << " to type " << this->nc->o->ot->GetName();
}
@@ -63,7 +64,7 @@ NickAlias::~NickAlias()
if (this->nc)
{
/* Next: see if our core is still useful. */
- std::list<NickAlias *>::iterator it = std::find(this->nc->aliases.begin(), this->nc->aliases.end(), this);
+ std::list<serialize_obj<NickAlias> >::iterator it = std::find(this->nc->aliases.begin(), this->nc->aliases.end(), this);
if (it != this->nc->aliases.end())
this->nc->aliases.erase(it);
if (this->nc->aliases.empty())
@@ -80,7 +81,7 @@ NickAlias::~NickAlias()
}
/* Remove us from the aliases list */
- NickAliasList.erase(this->nick);
+ NickAliasList->erase(this->nick);
}
/** Release a nick from being held. This can be called from the core (ns_release)
@@ -242,16 +243,16 @@ time_t NickAlias::GetVhostCreated() const
return this->vhost_created;
}
-Anope::string NickAlias::serialize_name() const
+const Anope::string NickAlias::serialize_name() const
{
return "NickAlias";
}
-Serializable::serialized_data NickAlias::serialize()
+Serialize::Data NickAlias::serialize() const
{
- serialized_data data;
+ Serialize::Data data;
- data["nick"].setKey().setMax(Config->NickLen) << this->nick;
+ data["nick"].setMax(Config->NickLen) << this->nick;
data["last_quit"] << this->last_quit;
data["last_realname"] << this->last_realname;
data["last_usermask"] << this->last_usermask;
@@ -272,18 +273,21 @@ Serializable::serialized_data NickAlias::serialize()
return data;
}
-void NickAlias::unserialize(serialized_data &data)
+Serializable* NickAlias::unserialize(Serializable *obj, Serialize::Data &data)
{
NickCore *core = findcore(data["nc"].astr());
if (core == NULL)
- return;
+ return NULL;
- NickAlias *na = findnick(data["nick"].astr());
- if (na == NULL)
+ NickAlias *na;
+ if (obj)
+ na = debug_cast<NickAlias *>(obj);
+ else
na = new NickAlias(data["nick"].astr(), core);
- else if (na->nc != core)
+
+ if (na->nc != core)
{
- std::list<NickAlias *>::iterator it = std::find(na->nc->aliases.begin(), na->nc->aliases.end(), na);
+ std::list<serialize_obj<NickAlias> >::iterator it = std::find(na->nc->aliases.begin(), na->nc->aliases.end(), na);
if (it != na->nc->aliases.end())
na->nc->aliases.erase(it);
@@ -293,7 +297,7 @@ void NickAlias::unserialize(serialized_data &data)
change_core_display(na->nc);
na->nc = core;
- na->nc->aliases.push_back(na);
+ core->aliases.push_back(na);
}
data["last_quit"] >> na->last_quit;
@@ -307,5 +311,6 @@ void NickAlias::unserialize(serialized_data &data)
time_t vhost_time;
data["vhost_time"] >> vhost_time;
na->SetVhost(data["vhost_ident"].astr(), data["vhost_host"].astr(), data["vhost_creator"].astr(), vhost_time);
+ return na;
}
diff --git a/src/nickcore.cpp b/src/nickcore.cpp
index 62a3d7006..e68e7444d 100644
--- a/src/nickcore.cpp
+++ b/src/nickcore.cpp
@@ -14,6 +14,8 @@
#include "account.h"
#include "config.h"
+serialize_checker<nickcore_map> NickCoreList("NickCore");
+
/** Default constructor
* @param display The display nick
*/
@@ -35,7 +37,7 @@ NickCore::NickCore(const Anope::string &coredisplay) : Flags<NickCoreFlag, NI_EN
if (Config->NSDefFlags.HasFlag(static_cast<NickCoreFlag>(t)))
this->SetFlag(static_cast<NickCoreFlag>(t));
- NickCoreList[this->display] = this;
+ (*NickCoreList)[this->display] = this;
}
/** Default destructor
@@ -45,29 +47,29 @@ NickCore::~NickCore()
FOREACH_MOD(I_OnDelCore, OnDelCore(this));
/* Remove the core from the list */
- NickCoreList.erase(this->display);
+ NickCoreList->erase(this->display);
/* Clear access before deleting display name, we want to be able to use the display name in the clear access event */
this->ClearAccess();
- if (!this->memos.memos.empty())
+ if (!this->memos.memos->empty())
{
- for (unsigned i = 0, end = this->memos.memos.size(); i < end; ++i)
- delete this->memos.memos[i];
- this->memos.memos.clear();
+ for (unsigned i = 0, end = this->memos.memos->size(); i < end; ++i)
+ this->memos.GetMemo(i)->destroy();
+ this->memos.memos->clear();
}
}
-Anope::string NickCore::serialize_name() const
+const Anope::string NickCore::serialize_name() const
{
return "NickCore";
}
-Serializable::serialized_data NickCore::serialize()
+Serialize::Data NickCore::serialize() const
{
- serialized_data data;
+ Serialize::Data data;
- data["display"].setKey().setMax(Config->NickLen) << this->display;
+ data["display"].setMax(Config->NickLen) << this->display;
data["pass"] << this->pass;
data["email"] << this->email;
data["greet"] << this->greet;
@@ -84,11 +86,15 @@ Serializable::serialized_data NickCore::serialize()
return data;
}
-void NickCore::unserialize(serialized_data &data)
+Serializable* NickCore::unserialize(Serializable *obj, Serialize::Data &data)
{
- NickCore *nc = findcore(data["display"].astr());
- if (nc == NULL)
+ NickCore *nc;
+
+ if (obj)
+ nc = debug_cast<NickCore *>(obj);
+ else
nc = new NickCore(data["display"].astr());
+
data["pass"] >> nc->pass;
data["email"] >> nc->email;
data["greet"] >> nc->greet;
@@ -119,6 +125,8 @@ void NickCore::unserialize(serialized_data &data)
while (sep.GetToken(buf))
nc->memos.ignores.push_back(buf);
}
+
+ return nc;
}
bool NickCore::IsServicesOper() const
@@ -178,7 +186,7 @@ Anope::string NickCore::GetCert(unsigned entry) const
return this->cert[entry];
}
-bool NickCore::FindCert(const Anope::string &entry)
+bool NickCore::FindCert(const Anope::string &entry) const
{
for (unsigned i = 0, end = this->cert.size(); i < end; ++i)
if (this->cert[i] == entry)
diff --git a/src/nickserv.cpp b/src/nickserv.cpp
index 011ee685e..a66738c03 100644
--- a/src/nickserv.cpp
+++ b/src/nickserv.cpp
@@ -15,29 +15,28 @@
#include "users.h"
#include "protocol.h"
-nickalias_map NickAliasList;
-nickcore_map NickCoreList;
-
-NickAlias *findnick(const Anope::string &nick)
+NickAlias* findnick(const Anope::string &nick)
{
- FOREACH_MOD(I_OnFindNick, OnFindNick(nick));
-
- nickalias_map::const_iterator it = NickAliasList.find(nick);
- if (it != NickAliasList.end())
+ nickalias_map::const_iterator it = NickAliasList->find(nick);
+ if (it != NickAliasList->end())
+ {
+ it->second->QueueUpdate();
return it->second;
+ }
return NULL;
}
/*************************************************************************/
-NickCore *findcore(const Anope::string &nick)
+NickCore* findcore(const Anope::string &nick)
{
- FOREACH_MOD(I_OnFindCore, OnFindCore(nick));
-
- nickcore_map::const_iterator it = NickCoreList.find(nick);
- if (it != NickCoreList.end())
+ nickcore_map::const_iterator it = NickCoreList->find(nick);
+ if (it != NickCoreList->end())
+ {
+ it->second->QueueUpdate();
return it->second;
+ }
return NULL;
}
@@ -81,16 +80,16 @@ void change_core_display(NickCore *nc, const Anope::string &newdisplay)
FOREACH_MOD(I_OnChangeCoreDisplay, OnChangeCoreDisplay(nc, newdisplay));
/* Remove the core from the list */
- NickCoreList.erase(nc->display);
+ NickCoreList->erase(nc->display);
nc->display = newdisplay;
- NickCoreList[nc->display] = nc;
+ (*NickCoreList)[nc->display] = nc;
}
void change_core_display(NickCore *nc)
{
- NickAlias *na;
+ const NickAlias *na;
if (nc->aliases.empty())
return;
na = nc->aliases.front();
diff --git a/src/operserv.cpp b/src/operserv.cpp
index 018c9b4e0..59a91aa09 100644
--- a/src/operserv.cpp
+++ b/src/operserv.cpp
@@ -22,7 +22,7 @@
/* List of XLine managers we check users against in XLineManager::CheckAll */
std::list<XLineManager *> XLineManager::XLineManagers;
-std::multimap<Anope::string, XLine *, ci::less> XLineManager::XLinesByUID;
+serialize_checker<std::multimap<Anope::string, XLine *, ci::less> > XLineManager::XLinesByUID("XLine");
void XLine::InitRegex()
{
@@ -138,14 +138,14 @@ bool XLine::IsRegex() const
return !this->Mask.empty() && this->Mask[0] == '/' && this->Mask[this->Mask.length() - 1] == '/';
}
-Anope::string XLine::serialize_name() const
+const Anope::string XLine::serialize_name() const
{
return "XLine";
}
-Serializable::serialized_data XLine::serialize()
+Serialize::Data XLine::serialize() const
{
- serialized_data data;
+ Serialize::Data data;
data["mask"] << this->Mask;
data["by"] << this->By;
@@ -159,19 +159,39 @@ Serializable::serialized_data XLine::serialize()
return data;
}
-void XLine::unserialize(serialized_data &data)
+Serializable* XLine::unserialize(Serializable *obj, Serialize::Data &data)
{
service_reference<XLineManager> xlm("XLineManager", data["manager"].astr());
if (!xlm)
- return;
+ return NULL;
+
+ XLine *xl;
+ if (obj)
+ {
+ xl = debug_cast<XLine *>(obj);
+ data["mask"] >> xl->Mask;
+ data["by"] >> xl->By;
+ data["reason"] >> xl->Reason;
+ data["uid"] >> xl->UID;
+
+ if (xlm != xl->manager)
+ {
+ xl->manager->DelXLine(xl);
+ xlm->AddXLine(xl);
+ }
+ }
+ else
+ {
+ time_t expires;
+ data["expires"] >> expires;
+ xl = new XLine(data["mask"].astr(), data["by"].astr(), expires, data["reason"].astr(), data["uid"].astr());
+ xlm->AddXLine(xl);
+ }
- time_t expires;
- data["expires"] >> expires;
- XLine *xl = new XLine(data["mask"].astr(), data["by"].astr(), expires, data["reason"].astr(), data["uid"].astr());
data["created"] >> xl->Created;
xl->manager = xlm;
- xlm->AddXLine(xl);
+ return xl;
}
/** Register a XLineManager, places it in XLineManagers for use in XLineManager::CheckAll
@@ -220,7 +240,7 @@ Anope::string XLineManager::GenerateUID()
{
Anope::string id;
int count = 0;
- while (id.empty() || XLinesByUID.count(id) > 0)
+ while (id.empty() || XLinesByUID->count(id) > 0)
{
if (++count > 10)
{
@@ -244,7 +264,7 @@ Anope::string XLineManager::GenerateUID()
/** Constructor
*/
-XLineManager::XLineManager(Module *creator, const Anope::string &xname, char t) : Service(creator, "XLineManager", xname), type(t)
+XLineManager::XLineManager(Module *creator, const Anope::string &xname, char t) : Service(creator, "XLineManager", xname), type(t), XLines("XLine")
{
}
@@ -269,7 +289,7 @@ const char &XLineManager::Type()
*/
size_t XLineManager::GetCount() const
{
- return this->XLines.size();
+ return this->XLines->size();
}
/** Get the XLine vector
@@ -285,10 +305,9 @@ const std::vector<XLine *> &XLineManager::GetList() const
*/
void XLineManager::AddXLine(XLine *x)
{
- x->manager = this;
if (!x->UID.empty())
- XLinesByUID.insert(std::make_pair(x->UID, x));
- this->XLines.push_back(x);
+ XLinesByUID->insert(std::make_pair(x->UID, x));
+ this->XLines->push_back(x);
}
/** Delete an entry from this XLineManager
@@ -297,25 +316,25 @@ void XLineManager::AddXLine(XLine *x)
*/
bool XLineManager::DelXLine(XLine *x)
{
- std::vector<XLine *>::iterator it = std::find(this->XLines.begin(), this->XLines.end(), x);
+ std::vector<XLine *>::iterator it = std::find(this->XLines->begin(), this->XLines->end(), x);
if (!x->UID.empty())
{
- std::multimap<Anope::string, XLine *, ci::less>::iterator it2 = XLinesByUID.find(x->UID), it3 = XLinesByUID.upper_bound(x->UID);
- for (; it2 != XLinesByUID.end() && it2 != it3; ++it2)
+ std::multimap<Anope::string, XLine *, ci::less>::iterator it2 = XLinesByUID->find(x->UID), it3 = XLinesByUID->upper_bound(x->UID);
+ for (; it2 != XLinesByUID->end() && it2 != it3; ++it2)
if (it2->second == x)
{
- XLinesByUID.erase(it2);
+ XLinesByUID->erase(it2);
break;
}
}
- if (it != this->XLines.end())
+ if (it != this->XLines->end())
{
this->SendDel(x);
- delete x;
- this->XLines.erase(it);
+ x->destroy();
+ this->XLines->erase(it);
return true;
}
@@ -327,25 +346,28 @@ bool XLineManager::DelXLine(XLine *x)
* @param index The index
* @return The XLine, or NULL if the index is out of bounds
*/
-XLine *XLineManager::GetEntry(unsigned index)
+XLine* XLineManager::GetEntry(unsigned index)
{
- if (index >= this->XLines.size())
+ if (index >= this->XLines->size())
return NULL;
- return this->XLines[index];
+ XLine *x = this->XLines->at(index);
+ x->QueueUpdate();
+ return x;
}
/** Clear the XLine vector
*/
void XLineManager::Clear()
{
- for (unsigned i = 0; i < this->XLines.size(); ++i)
+ for (unsigned i = 0; i < this->XLines->size(); ++i)
{
- if (!this->XLines[i]->UID.empty())
- XLinesByUID.erase(this->XLines[i]->UID);
- delete this->XLines[i];
+ XLine *x = this->XLines->at(i);
+ if (!x->UID.empty())
+ XLinesByUID->erase(x->UID);
+ x->destroy();
}
- this->XLines.clear();
+ this->XLines->clear();
}
/** Checks if a mask can/should be added to the XLineManager
@@ -406,19 +428,25 @@ bool XLineManager::CanAdd(CommandSource &source, const Anope::string &mask, time
* @param mask The mask
* @return The XLine the user matches, or NULL
*/
-XLine *XLineManager::HasEntry(const Anope::string &mask)
+XLine* XLineManager::HasEntry(const Anope::string &mask)
{
- std::map<Anope::string, XLine *, ci::less>::iterator it = XLinesByUID.find(mask);
- if (it != XLinesByUID.end())
- for (std::map<Anope::string, XLine *, ci::less>::iterator it2 = XLinesByUID.upper_bound(mask); it != it2; ++it)
+ std::map<Anope::string, XLine *, ci::less>::iterator it = XLinesByUID->find(mask);
+ if (it != XLinesByUID->end())
+ for (std::map<Anope::string, XLine *, ci::less>::iterator it2 = XLinesByUID->upper_bound(mask); it != it2; ++it)
if (it->second->manager == NULL || it->second->manager == this)
+ {
+ it->second->QueueUpdate();
return it->second;
- for (unsigned i = 0, end = this->XLines.size(); i < end; ++i)
+ }
+ for (unsigned i = 0, end = this->XLines->size(); i < end; ++i)
{
- XLine *x = this->XLines[i];
+ XLine *x = this->XLines->at(i);
if (x->Mask.equals_ci(mask))
+ {
+ x->QueueUpdate();
return x;
+ }
}
return NULL;
@@ -430,9 +458,9 @@ XLine *XLineManager::HasEntry(const Anope::string &mask)
*/
XLine *XLineManager::CheckAllXLines(User *u)
{
- for (unsigned i = this->XLines.size(); i > 0; --i)
+ for (unsigned i = this->XLines->size(); i > 0; --i)
{
- XLine *x = this->XLines[i - 1];
+ XLine *x = this->XLines->at(i - 1);
if (x->Expires && x->Expires < Anope::CurTime)
{
@@ -454,7 +482,7 @@ XLine *XLineManager::CheckAllXLines(User *u)
/** Called when an XLine expires
* @param x The xline
*/
-void XLineManager::OnExpire(XLine *x)
+void XLineManager::OnExpire(const XLine *x)
{
}
diff --git a/src/protocol.cpp b/src/protocol.cpp
index f51880bbe..506b4def6 100644
--- a/src/protocol.cpp
+++ b/src/protocol.cpp
@@ -413,7 +413,7 @@ bool IRCdMessage::OnPrivmsg(const Anope::string &source, const std::vector<Anope
{
Log() << message << ": user record for " << source << " not found";
- BotInfo *bi = findbot(receiver);
+ const BotInfo *bi = findbot(receiver);
if (bi)
ircdproto->SendMessage(bi, source, "%s", "Internal error - unable to process request.");
@@ -443,7 +443,7 @@ bool IRCdMessage::OnPrivmsg(const Anope::string &source, const std::vector<Anope
}
else if (Config->UseStrictPrivMsg)
{
- BotInfo *bi = findbot(receiver);
+ const BotInfo *bi = findbot(receiver);
if (!bi)
return true;
Log(LOG_DEBUG) << "Ignored PRIVMSG without @ from " << source;
@@ -543,7 +543,7 @@ bool IRCdMessage::OnWhois(const Anope::string &source, const std::vector<Anope::
User *u = finduser(params[0]);
if (u && u->server == Me)
{
- BotInfo *bi = findbot(u->nick);
+ const BotInfo *bi = findbot(u->nick);
ircdproto->SendNumeric(311, source, "%s %s %s * :%s", u->nick.c_str(), u->GetIdent().c_str(), u->host.c_str(), u->realname.c_str());
if (bi)
ircdproto->SendNumeric(307, source, "%s :is a registered nick", bi->nick.c_str());
diff --git a/src/regchannel.cpp b/src/regchannel.cpp
index 42feddc7b..2ee66805a 100644
--- a/src/regchannel.cpp
+++ b/src/regchannel.cpp
@@ -21,52 +21,64 @@
#include "language.h"
#include "servers.h"
-Anope::string BadWord::serialize_name() const
+serialize_checker<registered_channel_map> RegisteredChannelList("ChannelInfo");
+
+const Anope::string BadWord::serialize_name() const
{
return "BadWord";
}
-Serializable::serialized_data BadWord::serialize()
+Serialize::Data BadWord::serialize() const
{
- serialized_data data;
+ Serialize::Data data;
- data["ci"] << this->ci->name;
- data["word"] << this->word;
+ data["ci"].setMax(64)/*XXX*/ << this->ci->name;
+ data["word"].setMax(512) << this->word;
data["type"].setType(Serialize::DT_INT) << this->type;
return data;
}
-void BadWord::unserialize(serialized_data &data)
+Serializable* BadWord::unserialize(Serializable *obj, Serialize::Data &data)
{
ChannelInfo *ci = cs_findchan(data["ci"].astr());
if (!ci)
- return;
-
+ return NULL;
+
unsigned int n;
data["type"] >> n;
-
- ci->AddBadWord(data["word"].astr(), static_cast<BadWordType>(n));
+
+ BadWord *bw;
+ if (obj)
+ {
+ bw = debug_cast<BadWord *>(obj);
+ data["word"] >> bw->word;
+ bw->type = static_cast<BadWordType>(n);
+ }
+ else
+ bw = ci->AddBadWord(data["word"].astr(), static_cast<BadWordType>(n));
+
+ return bw;
}
AutoKick::AutoKick() : Flags<AutoKickFlag>(AutoKickFlagString)
{
}
-Anope::string AutoKick::serialize_name() const
+const Anope::string AutoKick::serialize_name() const
{
return "AutoKick";
}
-Serializable::serialized_data AutoKick::serialize()
+Serialize::Data AutoKick::serialize() const
{
- serialized_data data;
+ Serialize::Data data;
- data["ci"] << this->ci->name;
+ data["ci"].setMax(64)/*XXX*/ << this->ci->name;
if (this->HasFlag(AK_ISNICK) && this->nc)
- data["nc"] << this->nc->display;
+ data["nc"].setMax(Config->NickLen) << this->nc->display;
else
- data["mask"] << this->mask;
+ data["mask"].setMax(Config->NickLen) << this->mask;
data["reason"] << this->reason;
data["creator"] << this->creator;
data["addtime"].setType(Serialize::DT_INT) << this->addtime;
@@ -76,54 +88,70 @@ Serializable::serialized_data AutoKick::serialize()
return data;
}
-void AutoKick::unserialize(serialized_data &data)
+Serializable* AutoKick::unserialize(Serializable *obj, Serialize::Data &data)
{
ChannelInfo *ci = cs_findchan(data["ci"].astr());
- if (ci == NULL)
- return;
-
- time_t addtime, lastused;
- data["addtime"] >> addtime;
- data["last_used"] >> lastused;
+ if (!ci)
+ return NULL;
+ AutoKick *ak;
NickCore *nc = findcore(data["nc"].astr());
- if (nc)
- ci->AddAkick(data["creator"].astr(), nc, data["reason"].astr(), addtime, lastused);
+ if (obj)
+ {
+ ak = debug_cast<AutoKick *>(obj);
+ data["creator"] >> ak->creator;
+ data["reason"] >> ak->reason;
+ ak->nc = findcore(data["nc"].astr());
+ data["mask"] >> ak->mask;
+ data["addtime"] >> ak->addtime;
+ data["last_used"] >> ak->last_used;
+ }
else
- ci->AddAkick(data["creator"].astr(), data["mask"].astr(), data["reason"].astr(), addtime, lastused);
+ {
+ time_t addtime, lastused;
+ data["addtime"] >> addtime;
+ data["last_used"] >> lastused;
+
+ if (nc)
+ ak = ci->AddAkick(data["creator"].astr(), nc, data["reason"].astr(), addtime, lastused);
+ else
+ ak = ci->AddAkick(data["creator"].astr(), data["mask"].astr(), data["reason"].astr(), addtime, lastused);
+ }
+
+ return ak;
}
ModeLock::ModeLock(ChannelInfo *ch, bool s, ChannelModeName n, const Anope::string &p, const Anope::string &se, time_t c) : ci(ch), set(s), name(n), param(p), setter(se), created(c)
{
}
-Anope::string ModeLock::serialize_name() const
+const Anope::string ModeLock::serialize_name() const
{
return "ModeLock";
}
-Serializable::serialized_data ModeLock::serialize()
+Serialize::Data ModeLock::serialize() const
{
- serialized_data data;
+ Serialize::Data data;
- if (this->ci == NULL)
+ if (!this->ci)
return data;
- data["ci"] << this->ci->name;
- data["set"] << this->set;
- data["name"] << ChannelModeNameStrings[this->name];
- data["param"] << this->param;
+ data["ci"].setMax(64)/*XXX*/ << this->ci->name;
+ data["set"].setMax(5) << this->set;
+ data["name"].setMax(64) << ChannelModeNameStrings[this->name];
+ data["param"].setMax(512) << this->param;
data["setter"] << this->setter;
data["created"].setType(Serialize::DT_INT) << this->created;
return data;
}
-void ModeLock::unserialize(serialized_data &data)
+Serializable* ModeLock::unserialize(Serializable *obj, Serialize::Data &data)
{
ChannelInfo *ci = cs_findchan(data["ci"].astr());
- if (ci == NULL)
- return;
+ if (!ci)
+ return NULL;
ChannelModeName name = CMODE_END;
@@ -134,28 +162,47 @@ void ModeLock::unserialize(serialized_data &data)
break;
}
if (name == CMODE_END)
- return;
-
- bool set;
- data["set"] >> set;
+ return NULL;
+
+ ModeLock *ml;
+ if (obj)
+ {
+ ml = debug_cast<ModeLock *>(obj);
+
+ data["set"] >> ml->set;
+ ml->name = name;
+ data["param"] >> ml->param;
+ data["setter"] >> ml->setter;
+ data["created"] >> ml->created;
+ return ml;
+ }
+ else
+ {
+ bool set;
+ data["set"] >> set;
- time_t created;
- data["created"] >> created;
+ time_t created;
+ data["created"] >> created;
- ModeLock ml(ci, set, name, "", data["setter"].astr(), created);
- data["param"] >> ml.param;
+ ml = new ModeLock(ci, set, name, "", data["setter"].astr(), created);
+ data["param"] >> ml->param;
- ci->mode_locks.insert(std::make_pair(ml.name, ml));
+ ci->mode_locks->insert(std::make_pair(ml->name, ml));
+ return ml;
+ }
}
-Anope::string LogSetting::serialize_name() const
+const Anope::string LogSetting::serialize_name() const
{
return "LogSetting";
}
-Serializable::serialized_data LogSetting::serialize()
+Serialize::Data LogSetting::serialize() const
{
- serialized_data data;
+ Serialize::Data data;
+
+ if (!ci)
+ return data;
data["ci"] << ci->name;
data["service_name"] << service_name;
@@ -169,35 +216,44 @@ Serializable::serialized_data LogSetting::serialize()
return data;
}
-void LogSetting::unserialize(serialized_data &data)
+Serializable* LogSetting::unserialize(Serializable *obj, Serialize::Data &data)
{
- LogSetting ls;
-
ChannelInfo *ci = cs_findchan(data["ci"].astr());
if (ci == NULL)
- return;
+ return NULL;
+
+ LogSetting *ls;
+ if (obj)
+ ls = debug_cast<LogSetting *>(obj);
+ else
+ {
+ ls = new LogSetting();
+ ci->log_settings->push_back(ls);
+ }
- ls.ci = ci;
- data["service_name"] >> ls.service_name;
- data["command_service"] >> ls.command_service;
- data["command_name"] >> ls.command_name;
- data["method"] >> ls.method;
- data["extra"] >> ls.extra;
- data["creator"] >> ls.creator;
- data["created"] >> ls.created;
+ ls->ci = ci;
+ data["service_name"] >> ls->service_name;
+ data["command_service"] >> ls->command_service;
+ data["command_name"] >> ls->command_name;
+ data["method"] >> ls->method;
+ data["extra"] >> ls->extra;
+ data["creator"] >> ls->creator;
+ data["created"] >> ls->created;
- ci->log_settings.push_back(ls);
+ return ls;
}
/** Default constructor
* @param chname The channel name
*/
-ChannelInfo::ChannelInfo(const Anope::string &chname) : Flags<ChannelInfoFlag, CI_END>(ChannelInfoFlagStrings), botflags(BotServFlagStrings)
+ChannelInfo::ChannelInfo(const Anope::string &chname) : Flags<ChannelInfoFlag, CI_END>(ChannelInfoFlagStrings), access("ChanAccess"), akick("AutoKick"),
+ badwords("BadWord"), mode_locks("ModeLock"), log_settings("LogSetting"), botflags(BotServFlagStrings)
{
if (chname.empty())
throw CoreException("Empty channel passed to ChannelInfo constructor");
- this->founder = this->successor = NULL;
+ this->founder = NULL;
+ this->successor = NULL;
this->last_topic_time = 0;
this->c = findchan(chname);
if (this->c)
@@ -227,7 +283,7 @@ ChannelInfo::ChannelInfo(const Anope::string &chname) : Flags<ChannelInfoFlag, C
for (int i = 0; i < TTB_SIZE; ++i)
this->ttb[i] = 0;
- RegisteredChannelList[this->name] = this;
+ (*RegisteredChannelList)[this->name] = this;
FOREACH_MOD(I_OnCreateChan, OnCreateChan(this));
}
@@ -235,23 +291,24 @@ ChannelInfo::ChannelInfo(const Anope::string &chname) : Flags<ChannelInfoFlag, C
/** Copy constructor
* @param ci The ChannelInfo to copy settings to
*/
-ChannelInfo::ChannelInfo(ChannelInfo &ci) : Flags<ChannelInfoFlag, CI_END>(ChannelInfoFlagStrings), botflags(BotServFlagStrings)
+ChannelInfo::ChannelInfo(const ChannelInfo &ci) : Flags<ChannelInfoFlag, CI_END>(ChannelInfoFlagStrings), access("ChanAccess"), akick("AutoKick"),
+ badwords("BadWord"), mode_locks("ModeLock"), log_settings("LogSetting"), botflags(BotServFlagStrings)
{
*this = ci;
if (this->founder)
- ++this->founder->channelcount;
+ --this->founder->channelcount;
- this->access.clear();
- this->akick.clear();
- this->badwords.clear();
+ this->access->clear();
+ this->akick->clear();
+ this->badwords->clear();
for (int i = 0; i < TTB_SIZE; ++i)
this->ttb[i] = ci.ttb[i];
for (unsigned i = 0; i < ci.GetAccessCount(); ++i)
{
- ChanAccess *taccess = ci.GetAccess(i);
+ const ChanAccess *taccess = ci.GetAccess(i);
AccessProvider *provider = taccess->provider;
ChanAccess *newaccess = provider->Create();
@@ -267,7 +324,7 @@ ChannelInfo::ChannelInfo(ChannelInfo &ci) : Flags<ChannelInfoFlag, CI_END>(Chann
for (unsigned i = 0; i < ci.GetAkickCount(); ++i)
{
- AutoKick *takick = ci.GetAkick(i);
+ const AutoKick *takick = ci.GetAkick(i);
if (takick->HasFlag(AK_ISNICK))
this->AddAkick(takick->creator, takick->nc, takick->reason, takick->addtime, takick->last_used);
else
@@ -275,17 +332,22 @@ ChannelInfo::ChannelInfo(ChannelInfo &ci) : Flags<ChannelInfoFlag, CI_END>(Chann
}
for (unsigned i = 0; i < ci.GetBadWordCount(); ++i)
{
- BadWord *bw = ci.GetBadWord(i);
+ const BadWord *bw = ci.GetBadWord(i);
this->AddBadWord(bw->word, bw->type);
}
+
+ for (unsigned i = 0; i < ci.log_settings->size(); ++i)
+ {
+ LogSetting *l = new LogSetting(*ci.log_settings->at(i));
+ l->ci = this;
+ this->log_settings->push_back(l);
+ }
}
/** Default destructor, cleans up the channel complete and removes it from the internal list
*/
ChannelInfo::~ChannelInfo()
{
- unsigned i, end;
-
FOREACH_MOD(I_OnDelChan, OnDelChan(this));
Log(LOG_DEBUG) << "Deleting channel " << this->name;
@@ -297,33 +359,41 @@ ChannelInfo::~ChannelInfo()
this->c->ci = NULL;
}
- RegisteredChannelList.erase(this->name);
+ RegisteredChannelList->erase(this->name);
this->ClearAccess();
this->ClearAkick();
this->ClearBadWords();
- if (!this->memos.memos.empty())
+ for (unsigned i = 0; i < this->log_settings->size(); ++i)
+ this->log_settings->at(i)->destroy();
+ this->log_settings->clear();
+
+ for (ChannelInfo::ModeList::iterator it = this->mode_locks->begin(), it_end = this->mode_locks->end(); it != it_end; ++it)
+ it->second->destroy();
+ this->mode_locks->clear();
+
+ if (!this->memos.memos->empty())
{
- for (i = 0, end = this->memos.memos.size(); i < end; ++i)
- delete this->memos.memos[i];
- this->memos.memos.clear();
+ for (unsigned i = 0, end = this->memos.memos->size(); i < end; ++i)
+ this->memos.GetMemo(i)->destroy();
+ this->memos.memos->clear();
}
if (this->founder)
--this->founder->channelcount;
}
-Anope::string ChannelInfo::serialize_name() const
+const Anope::string ChannelInfo::serialize_name() const
{
return "ChannelInfo";
}
-Serializable::serialized_data ChannelInfo::serialize()
+Serialize::Data ChannelInfo::serialize() const
{
- serialized_data data;
+ Serialize::Data data;
- data["name"].setKey().setMax(255) << this->name;
+ data["name"].setMax(255) << this->name;
if (this->founder)
data["founder"] << this->founder->display;
if (this->successor)
@@ -339,7 +409,7 @@ Serializable::serialized_data ChannelInfo::serialize()
data["botflags"] << this->botflags.ToString();
{
Anope::string levels_buffer;
- for (std::map<Anope::string, int16_t>::iterator it = this->levels.begin(), it_end = this->levels.end(); it != it_end; ++it)
+ for (std::map<Anope::string, int16_t>::const_iterator it = this->levels.begin(), it_end = this->levels.end(); it != it_end; ++it)
levels_buffer += it->first + " " + stringify(it->second) + " ";
data["levels"] << levels_buffer;
}
@@ -359,24 +429,26 @@ Serializable::serialized_data ChannelInfo::serialize()
return data;
}
-void ChannelInfo::unserialize(serialized_data &data)
+Serializable* ChannelInfo::unserialize(Serializable *obj, Serialize::Data &data)
{
- ChannelInfo *ci = cs_findchan(data["name"].astr());
- if (ci == NULL)
+ ChannelInfo *ci;
+ if (obj)
+ ci = debug_cast<ChannelInfo *>(obj);
+ else
ci = new ChannelInfo(data["name"].astr());
if (data.count("founder") > 0)
{
if (ci->founder)
- ci->founder->channelcount--;
+ --ci->founder->channelcount;
ci->founder = findcore(data["founder"].astr());
if (ci->founder)
- ci->founder->channelcount++;
+ --ci->founder->channelcount;
}
if (data.count("successor") > 0)
{
ci->successor = findcore(data["successor"].astr());
- if (ci->founder && ci->founder == ci->successor)
+ if (ci->founder && *ci->founder == *ci->successor)
ci->successor = NULL;
}
data["description"] >> ci->desc;
@@ -393,8 +465,15 @@ void ChannelInfo::unserialize(serialized_data &data)
for (unsigned i = 0; i + 1 < v.size(); i += 2)
ci->levels[v[i]] = convertTo<int16_t>(v[i + 1]);
}
- if (data.count("bi") > 0)
- ci->bi = findbot(data["bi"].astr());
+ BotInfo *bi = findbot(data["bi"].astr());
+ if (*ci->bi != bi)
+ {
+ if (ci->bi)
+ ci->bi->UnAssign(NULL, ci);
+ ci->bi = bi;
+ if (ci->bi)
+ ci->bi->Assign(NULL, ci);
+ }
data["capsmin"] >> ci->capsmin;
data["capspercent"] >> ci->capspercent;
data["floodlines"] >> ci->floodlines;
@@ -409,6 +488,8 @@ void ChannelInfo::unserialize(serialized_data &data)
while (sep.GetToken(buf))
ci->memos.ignores.push_back(buf);
}
+
+ return ci;
}
@@ -422,7 +503,7 @@ void ChannelInfo::SetFounder(NickCore *nc)
this->founder = nc;
if (this->founder)
++this->founder->channelcount;
- if (this->founder == this->successor)
+ if (*this->founder == *this->successor)
this->successor = NULL;
}
@@ -437,15 +518,15 @@ NickCore *ChannelInfo::GetFounder() const
/** Find which bot should send mode/topic/etc changes for this channel
* @return The bot
*/
-BotInfo *ChannelInfo::WhoSends()
+BotInfo *ChannelInfo::WhoSends() const
{
if (this && this->bi)
return this->bi;
BotInfo *tbi = findbot(Config->ChanServ);
if (tbi)
return tbi;
- else if (!BotListByNick.empty())
- return BotListByNick.begin()->second;
+ else if (!BotListByNick->empty())
+ return BotListByNick->begin()->second;
return NULL;
}
@@ -454,7 +535,7 @@ BotInfo *ChannelInfo::WhoSends()
*/
void ChannelInfo::AddAccess(ChanAccess *taccess)
{
- this->access.push_back(taccess);
+ this->access->push_back(taccess);
}
/** Get an entry from the channel access list by index
@@ -464,25 +545,27 @@ void ChannelInfo::AddAccess(ChanAccess *taccess)
*
* Retrieves an entry from the access list that matches the given index.
*/
-ChanAccess *ChannelInfo::GetAccess(unsigned index)
+ChanAccess *ChannelInfo::GetAccess(unsigned index) const
{
- if (this->access.empty() || index >= this->access.size())
+ if (this->access->empty() || index >= this->access->size())
return NULL;
- return this->access[index];
+ ChanAccess *acc = (*this->access)[index];
+ acc->QueueUpdate();
+ return acc;
}
-AccessGroup ChannelInfo::AccessFor(User *u)
+AccessGroup ChannelInfo::AccessFor(const User *u)
{
AccessGroup group;
if (u == NULL)
return group;
- NickCore *nc = u->Account();
+ const NickCore *nc = u->Account();
if (nc == NULL && u->IsRecognized())
{
- NickAlias *na = findnick(u->nick);
+ const NickAlias *na = findnick(u->nick);
if (na != NULL)
nc = na->nc;
}
@@ -492,9 +575,9 @@ AccessGroup ChannelInfo::AccessFor(User *u)
group.ci = this;
group.nc = nc;
- for (unsigned i = 0, end = this->access.size(); i < end; ++i)
- if (this->access[i]->Matches(u, nc))
- group.push_back(this->access[i]);
+ for (unsigned i = 0, end = this->GetAccessCount(); i < end; ++i)
+ if (this->GetAccess(i)->Matches(u, nc))
+ group.push_back(this->GetAccess(i));
if (group.Founder || !group.empty())
this->last_used = Anope::CurTime;
@@ -502,7 +585,7 @@ AccessGroup ChannelInfo::AccessFor(User *u)
return group;
}
-AccessGroup ChannelInfo::AccessFor(NickCore *nc)
+AccessGroup ChannelInfo::AccessFor(const NickCore *nc)
{
AccessGroup group;
@@ -510,9 +593,9 @@ AccessGroup ChannelInfo::AccessFor(NickCore *nc)
group.ci = this;
group.nc = nc;
- for (unsigned i = 0, end = this->access.size(); i < end; ++i)
- if (this->access[i]->Matches(NULL, nc))
- group.push_back(this->access[i]);
+ for (unsigned i = 0, end = this->GetAccessCount(); i < end; ++i)
+ if (this->GetAccess(i)->Matches(NULL, nc))
+ group.push_back(this->GetAccess(i));
if (group.Founder || !group.empty())
this->last_used = Anope::CurTime;
@@ -525,7 +608,7 @@ AccessGroup ChannelInfo::AccessFor(NickCore *nc)
*/
unsigned ChannelInfo::GetAccessCount() const
{
- return this->access.size();
+ return this->access->size();
}
/** Erase an entry from the channel access list
@@ -536,11 +619,11 @@ unsigned ChannelInfo::GetAccessCount() const
*/
void ChannelInfo::EraseAccess(unsigned index)
{
- if (this->access.empty() || index >= this->access.size())
+ if (this->access->empty() || index >= this->access->size())
return;
- delete this->access[index];
- this->access.erase(this->access.begin() + index);
+ this->access->at(index)->destroy();
+ this->access->erase(this->access->begin() + index);
}
/** Erase an entry from the channel access list
@@ -549,14 +632,14 @@ void ChannelInfo::EraseAccess(unsigned index)
*
* Clears the memory used by the given access entry and removes it from the vector.
*/
-void ChannelInfo::EraseAccess(ChanAccess *taccess)
+void ChannelInfo::EraseAccess(const ChanAccess *taccess)
{
- for (unsigned i = 0, end = this->access.size(); i < end; ++i)
+ for (unsigned i = 0, end = this->access->size(); i < end; ++i)
{
- if (this->access[i] == taccess)
+ if (this->GetAccess(i) == taccess)
{
- delete this->access[i];
- this->access.erase(this->access.begin() + i);
+ this->GetAccess(i)->destroy();
+ this->EraseAccess(i);
break;
}
}
@@ -568,9 +651,9 @@ void ChannelInfo::EraseAccess(ChanAccess *taccess)
*/
void ChannelInfo::ClearAccess()
{
- for (unsigned i = this->access.size(); i > 0; --i)
- delete this->access[i - 1];
- this->access.clear();
+ for (unsigned i = this->access->size(); i > 0; --i)
+ this->GetAccess(i - 1)->destroy();
+ this->access->clear();
}
/** Add an akick entry to the channel by NickCore
@@ -583,9 +666,6 @@ void ChannelInfo::ClearAccess()
*/
AutoKick *ChannelInfo::AddAkick(const Anope::string &user, NickCore *akicknc, const Anope::string &reason, time_t t, time_t lu)
{
- if (!akicknc)
- return NULL;
-
AutoKick *autokick = new AutoKick();
autokick->ci = this;
autokick->SetFlag(AK_ISNICK);
@@ -595,7 +675,7 @@ AutoKick *ChannelInfo::AddAkick(const Anope::string &user, NickCore *akicknc, co
autokick->addtime = t;
autokick->last_used = lu;
- this->akick.push_back(autokick);
+ this->akick->push_back(autokick);
return autokick;
}
@@ -619,7 +699,7 @@ AutoKick *ChannelInfo::AddAkick(const Anope::string &user, const Anope::string &
autokick->addtime = t;
autokick->last_used = lu;
- this->akick.push_back(autokick);
+ this->akick->push_back(autokick);
return autokick;
}
@@ -628,12 +708,14 @@ AutoKick *ChannelInfo::AddAkick(const Anope::string &user, const Anope::string &
* @param index The index in the akick vector
* @return The akick structure, or NULL if not found
*/
-AutoKick *ChannelInfo::GetAkick(unsigned index)
+AutoKick *ChannelInfo::GetAkick(unsigned index) const
{
- if (this->akick.empty() || index >= this->akick.size())
+ if (this->akick->empty() || index >= this->akick->size())
return NULL;
- return this->akick[index];
+ AutoKick *ak = (*this->akick)[index];
+ ak->QueueUpdate();
+ return ak;
}
/** Get the size of the akick vector for this channel
@@ -641,7 +723,7 @@ AutoKick *ChannelInfo::GetAkick(unsigned index)
*/
unsigned ChannelInfo::GetAkickCount() const
{
- return this->akick.empty() ? 0 : this->akick.size();
+ return this->akick->size();
}
/** Erase an entry from the channel akick list
@@ -649,18 +731,18 @@ unsigned ChannelInfo::GetAkickCount() const
*/
void ChannelInfo::EraseAkick(unsigned index)
{
- if (this->akick.empty() || index >= this->akick.size())
+ if (this->akick->empty() || index >= this->akick->size())
return;
- delete this->akick[index];
- this->akick.erase(this->akick.begin() + index);
+ this->GetAkick(index)->destroy();
+ this->akick->erase(this->akick->begin() + index);
}
/** Clear the whole akick list
*/
void ChannelInfo::ClearAkick()
{
- while (!this->akick.empty())
+ while (!this->akick->empty())
EraseAkick(0);
}
@@ -669,14 +751,14 @@ void ChannelInfo::ClearAkick()
* @param type The type (SINGLE START END)
* @return The badword
*/
-BadWord *ChannelInfo::AddBadWord(const Anope::string &word, BadWordType type)
+BadWord* ChannelInfo::AddBadWord(const Anope::string &word, BadWordType type)
{
- BadWord *bw = new BadWord;
+ BadWord *bw = new BadWord();
bw->ci = this;
bw->word = word;
bw->type = type;
- this->badwords.push_back(bw);
+ this->badwords->push_back(bw);
FOREACH_MOD(I_OnBadWordAdd, OnBadWordAdd(this, bw));
@@ -687,12 +769,14 @@ BadWord *ChannelInfo::AddBadWord(const Anope::string &word, BadWordType type)
* @param index The index
* @return The badword
*/
-BadWord *ChannelInfo::GetBadWord(unsigned index)
+BadWord* ChannelInfo::GetBadWord(unsigned index) const
{
- if (this->badwords.empty() || index >= this->badwords.size())
+ if (this->badwords->empty() || index >= this->badwords->size())
return NULL;
- return this->badwords[index];
+ BadWord *bw = (*this->badwords)[index];
+ bw->QueueUpdate();
+ return bw;
}
/** Get how many badwords are on this channel
@@ -700,7 +784,7 @@ BadWord *ChannelInfo::GetBadWord(unsigned index)
*/
unsigned ChannelInfo::GetBadWordCount() const
{
- return this->badwords.empty() ? 0 : this->badwords.size();
+ return this->badwords->size();
}
/** Remove a badword
@@ -708,20 +792,20 @@ unsigned ChannelInfo::GetBadWordCount() const
*/
void ChannelInfo::EraseBadWord(unsigned index)
{
- if (this->badwords.empty() || index >= this->badwords.size())
+ if (this->badwords->empty() || index >= this->badwords->size())
return;
- FOREACH_MOD(I_OnBadWordDel, OnBadWordDel(this, this->badwords[index]));
+ FOREACH_MOD(I_OnBadWordDel, OnBadWordDel(this, (*this->badwords)[index]));
- delete this->badwords[index];
- this->badwords.erase(this->badwords.begin() + index);
+ delete (*this->badwords)[index];
+ this->badwords->erase(this->badwords->begin() + index);
}
/** Clear all badwords from the channel
*/
void ChannelInfo::ClearBadWords()
{
- while (!this->badwords.empty())
+ while (!this->badwords->empty())
EraseBadWord(0);
}
@@ -732,23 +816,23 @@ void ChannelInfo::ClearBadWords()
*/
bool ChannelInfo::HasMLock(ChannelMode *mode, const Anope::string &param, bool status) const
{
- std::multimap<ChannelModeName, ModeLock>::const_iterator it = this->mode_locks.find(mode->Name);
+ std::multimap<ChannelModeName, ModeLock *>::const_iterator it = this->mode_locks->find(mode->Name);
- if (it != this->mode_locks.end())
+ if (it != this->mode_locks->end())
{
if (mode->Type != MODE_REGULAR)
{
- std::multimap<ChannelModeName, ModeLock>::const_iterator it_end = this->mode_locks.upper_bound(mode->Name);
+ std::multimap<ChannelModeName, ModeLock *>::const_iterator it_end = this->mode_locks->upper_bound(mode->Name);
for (; it != it_end; ++it)
{
- const ModeLock &ml = it->second;
- if (ml.param == param)
+ const ModeLock *ml = it->second;
+ if (ml->param == param)
return true;
}
}
else
- return it->second.set == status;
+ return it->second->set == status;
}
return false;
}
@@ -763,36 +847,46 @@ bool ChannelInfo::SetMLock(ChannelMode *mode, bool status, const Anope::string &
{
if (setter.empty())
setter = this->founder ? this->founder->display : "Unknown";
- std::pair<ChannelModeName, ModeLock> ml = std::make_pair(mode->Name, ModeLock(this, status, mode->Name, param, setter, created));
+ std::pair<ChannelModeName, ModeLock *> ml = std::make_pair(mode->Name, new ModeLock(this, status, mode->Name, param, setter, created));
EventReturn MOD_RESULT;
- FOREACH_RESULT(I_OnMLock, OnMLock(this, &ml.second));
+ FOREACH_RESULT(I_OnMLock, OnMLock(this, ml.second));
if (MOD_RESULT == EVENT_STOP)
return false;
/* First, remove this */
if (mode->Type == MODE_REGULAR || mode->Type == MODE_PARAM)
- this->mode_locks.erase(mode->Name);
+ {
+ ChannelInfo::ModeList::const_iterator it = this->mode_locks->find(mode->Name);
+ if (it != this->mode_locks->end())
+ {
+ ChannelInfo::ModeList::const_iterator it_end = this->mode_locks->upper_bound(mode->Name);
+ for (; it != it_end; ++it)
+ it->second->destroy();
+ }
+ this->mode_locks->erase(mode->Name);
+ }
else
{
// For list or status modes, we must check the parameter
- std::multimap<ChannelModeName, ModeLock>::iterator it = this->mode_locks.find(mode->Name);
- if (it != this->mode_locks.end())
+ ChannelInfo::ModeList::iterator it = this->mode_locks->find(mode->Name);
+ if (it != this->mode_locks->end())
{
- std::multimap<ChannelModeName, ModeLock>::iterator it_end = this->mode_locks.upper_bound(mode->Name);
+ ChannelInfo::ModeList::iterator it_end = this->mode_locks->upper_bound(mode->Name);
for (; it != it_end; ++it)
{
- const ModeLock &modelock = it->second;
- if (modelock.param == param)
+ const ModeLock *modelock = it->second;
+ if (modelock->param == param)
{
- this->mode_locks.erase(it);
+ it->second->destroy();
+ this->mode_locks->erase(it);
break;
}
}
}
}
- this->mode_locks.insert(ml);
+ this->mode_locks->insert(ml);
return true;
}
@@ -807,21 +901,22 @@ bool ChannelInfo::RemoveMLock(ChannelMode *mode, bool status, const Anope::strin
{
if (mode->Type == MODE_REGULAR || mode->Type == MODE_PARAM)
{
- std::multimap<ChannelModeName, ModeLock>::iterator it = this->mode_locks.find(mode->Name), it_end = this->mode_locks.upper_bound(mode->Name), it_next = it;
- if (it != this->mode_locks.end())
+ ChannelInfo::ModeList::iterator it = this->mode_locks->find(mode->Name), it_end = this->mode_locks->upper_bound(mode->Name), it_next = it;
+ if (it != this->mode_locks->end())
for (; it != it_end; it = it_next)
{
- const ModeLock &ml = it->second;
+ const ModeLock *ml = it->second;
++it_next;
- if (status != ml.set)
+ if (status != ml->set)
continue;
EventReturn MOD_RESULT;
- FOREACH_RESULT(I_OnUnMLock, OnUnMLock(this, &it->second));
+ FOREACH_RESULT(I_OnUnMLock, OnUnMLock(this, it->second));
if (MOD_RESULT != EVENT_STOP)
{
- this->mode_locks.erase(it);
+ it->second->destroy();
+ this->mode_locks->erase(it);
return true;
}
}
@@ -830,20 +925,21 @@ bool ChannelInfo::RemoveMLock(ChannelMode *mode, bool status, const Anope::strin
else
{
// For list or status modes, we must check the parameter
- std::multimap<ChannelModeName, ModeLock>::iterator it = this->mode_locks.find(mode->Name);
- if (it != this->mode_locks.end())
+ ChannelInfo::ModeList::iterator it = this->mode_locks->find(mode->Name);
+ if (it != this->mode_locks->end())
{
- std::multimap<ChannelModeName, ModeLock>::iterator it_end = this->mode_locks.upper_bound(mode->Name);
+ ChannelInfo::ModeList::iterator it_end = this->mode_locks->upper_bound(mode->Name);
for (; it != it_end; ++it)
{
- const ModeLock &ml = it->second;
- if (ml.set == status && ml.param == param)
+ const ModeLock *ml = it->second;
+ if (ml->set == status && ml->param == param)
{
EventReturn MOD_RESULT;
- FOREACH_RESULT(I_OnUnMLock, OnUnMLock(this, &it->second));
+ FOREACH_RESULT(I_OnUnMLock, OnUnMLock(this, it->second));
if (MOD_RESULT == EVENT_STOP)
return false;
- this->mode_locks.erase(it);
+ it->second->destroy();
+ this->mode_locks->erase(it);
return true;
}
}
@@ -857,13 +953,13 @@ bool ChannelInfo::RemoveMLock(ChannelMode *mode, bool status, const Anope::strin
*/
void ChannelInfo::ClearMLock()
{
- this->mode_locks.clear();
+ this->mode_locks->clear();
}
/** Get all of the mlocks for this channel
* @return The mlocks
*/
-const std::multimap<ChannelModeName, ModeLock> &ChannelInfo::GetMLock() const
+const ChannelInfo::ModeList &ChannelInfo::GetMLock() const
{
return this->mode_locks;
}
@@ -874,9 +970,9 @@ const std::multimap<ChannelModeName, ModeLock> &ChannelInfo::GetMLock() const
*/
std::pair<ChannelInfo::ModeList::iterator, ChannelInfo::ModeList::iterator> ChannelInfo::GetModeList(ChannelModeName Name)
{
- std::multimap<ChannelModeName, ModeLock>::iterator it = this->mode_locks.find(Name), it_end = it;
- if (it != this->mode_locks.end())
- it_end = this->mode_locks.upper_bound(Name);
+ ChannelInfo::ModeList::iterator it = this->mode_locks->find(Name), it_end = it;
+ if (it != this->mode_locks->end())
+ it_end = this->mode_locks->upper_bound(Name);
return std::make_pair(it, it_end);
}
@@ -885,20 +981,20 @@ std::pair<ChannelInfo::ModeList::iterator, ChannelInfo::ModeList::iterator> Chan
* @param param An optional param to match with
* @return The MLock, if any
*/
-ModeLock *ChannelInfo::GetMLock(ChannelModeName mname, const Anope::string &param)
+const ModeLock *ChannelInfo::GetMLock(ChannelModeName mname, const Anope::string &param)
{
- std::multimap<ChannelModeName, ModeLock>::iterator it = this->mode_locks.find(mname);
- if (it != this->mode_locks.end())
+ ChannelInfo::ModeList::iterator it = this->mode_locks->find(mname);
+ if (it != this->mode_locks->end())
{
if (param.empty())
- return &it->second;
+ return it->second;
else
{
- std::multimap<ChannelModeName, ModeLock>::iterator it_end = this->mode_locks.upper_bound(mname);
+ ChannelInfo::ModeList::iterator it_end = this->mode_locks->upper_bound(mname);
for (; it != it_end; ++it)
{
- if (Anope::Match(param, it->second.param))
- return &it->second;
+ if (Anope::Match(param, it->second->param))
+ return it->second;
}
}
}
@@ -910,20 +1006,20 @@ Anope::string ChannelInfo::GetMLockAsString(bool complete) const
{
Anope::string pos = "+", neg = "-", params;
- for (std::multimap<ChannelModeName, ModeLock>::const_iterator it = this->GetMLock().begin(), it_end = this->GetMLock().end(); it != it_end; ++it)
+ for (ChannelInfo::ModeList::const_iterator it = this->GetMLock().begin(), it_end = this->GetMLock().end(); it != it_end; ++it)
{
- const ModeLock &ml = it->second;
- ChannelMode *cm = ModeManager::FindChannelModeByName(ml.name);
+ const ModeLock *ml = it->second;
+ ChannelMode *cm = ModeManager::FindChannelModeByName(ml->name);
if (!cm || cm->Type == MODE_LIST || cm->Type == MODE_STATUS)
continue;
- if (ml.set)
+ if (ml->set)
pos += cm->ModeChar;
else
neg += cm->ModeChar;
- if (complete && !ml.param.empty() && cm->Type == MODE_PARAM)
- params += " " + ml.param;
+ if (complete && !ml->param.empty() && cm->Type == MODE_PARAM)
+ params += " " + ml->param;
}
if (pos.length() == 1)
@@ -1077,7 +1173,7 @@ void ChannelInfo::RestoreTopic()
}
}
-int16_t ChannelInfo::GetLevel(const Anope::string &priv)
+int16_t ChannelInfo::GetLevel(const Anope::string &priv) const
{
if (PrivilegeManager::FindPrivilege(priv) == NULL)
{
@@ -1085,9 +1181,10 @@ int16_t ChannelInfo::GetLevel(const Anope::string &priv)
return ACCESS_INVALID;
}
- if (this->levels.count(priv) == 0)
- this->levels[priv] = 0;
- return this->levels[priv];
+ std::map<Anope::string, int16_t>::const_iterator it = this->levels.find(priv);
+ if (it == this->levels.end())
+ return 0;
+ return it->second;
}
void ChannelInfo::SetLevel(const Anope::string &priv, int16_t level)
diff --git a/src/serialize.cpp b/src/serialize.cpp
index 3f8df0434..9ff3fca1d 100644
--- a/src/serialize.cpp
+++ b/src/serialize.cpp
@@ -13,16 +13,17 @@
#include "services.h"
#include "anope.h"
#include "serialize.h"
+#include "modules.h"
std::vector<Anope::string> SerializeType::type_order;
Anope::map<SerializeType *> SerializeType::types;
-std::list<Serializable *> *Serializable::serizliable_items;
+std::list<Serializable *> *Serializable::serializable_items;
-stringstream::stringstream() : std::stringstream(), type(Serialize::DT_TEXT), key(false), _max(0)
+stringstream::stringstream() : std::stringstream(), type(Serialize::DT_TEXT), _max(0)
{
}
-stringstream::stringstream(const stringstream &ss) : std::stringstream(ss.str()), type(Serialize::DT_TEXT), key(false), _max(0)
+stringstream::stringstream(const stringstream &ss) : std::stringstream(ss.str()), type(Serialize::DT_TEXT), _max(0)
{
}
@@ -37,26 +38,25 @@ std::istream &stringstream::operator>>(Anope::string &val)
return *this;
}
-stringstream &stringstream::setType(Serialize::DataType t)
+bool stringstream::operator==(const stringstream &other) const
{
- this->type = t;
- return *this;
+ return this->astr() == other.astr();
}
-Serialize::DataType stringstream::getType() const
+bool stringstream::operator!=(const stringstream &other) const
{
- return this->type;
+ return !(*this == other);
}
-stringstream &stringstream::setKey()
+stringstream &stringstream::setType(Serialize::DataType t)
{
- this->key = true;
+ this->type = t;
return *this;
}
-bool stringstream::getKey() const
+Serialize::DataType stringstream::getType() const
{
- return this->key;
+ return this->type;
}
stringstream &stringstream::setMax(unsigned m)
@@ -70,25 +70,30 @@ unsigned stringstream::getMax() const
return this->_max;
}
-Serializable::Serializable()
+Serializable::Serializable() : id(0)
{
- if (serizliable_items == NULL)
- serizliable_items = new std::list<Serializable *>();
- serizliable_items->push_back(this);
- this->s_iter = serizliable_items->end();
+ if (serializable_items == NULL)
+ serializable_items = new std::list<Serializable *>();
+ serializable_items->push_back(this);
+
+ this->s_iter = serializable_items->end();
--this->s_iter;
+
+ FOREACH_MOD(I_OnSerializableConstruct, OnSerializableConstruct(this));
}
-Serializable::Serializable(const Serializable &)
+Serializable::Serializable(const Serializable &) : id(0)
{
- serizliable_items->push_back(this);
- this->s_iter = serizliable_items->end();
+ serializable_items->push_back(this);
+ this->s_iter = serializable_items->end();
--this->s_iter;
+
+ FOREACH_MOD(I_OnSerializableConstruct, OnSerializableConstruct(this));
}
Serializable::~Serializable()
{
- serizliable_items->erase(this->s_iter);
+ serializable_items->erase(this->s_iter);
}
Serializable &Serializable::operator=(const Serializable &)
@@ -96,12 +101,37 @@ Serializable &Serializable::operator=(const Serializable &)
return *this;
}
+void Serializable::destroy()
+{
+ if (!this)
+ return;
+
+ FOREACH_MOD(I_OnSerializableDestruct, OnSerializableDestruct(this));
+
+ delete this;
+}
+
+void Serializable::QueueUpdate()
+{
+ FOREACH_MOD(I_OnSerializableUpdate, OnSerializableUpdate(this));
+}
+
+bool Serializable::IsCached()
+{
+ return this->last_commit == this->serialize();
+}
+
+void Serializable::UpdateCache()
+{
+ this->last_commit = this->serialize();
+}
+
const std::list<Serializable *> &Serializable::GetItems()
{
- return *serizliable_items;
+ return *serializable_items;
}
-SerializeType::SerializeType(const Anope::string &n, unserialize_func f) : name(n), unserialize(f)
+SerializeType::SerializeType(const Anope::string &n, unserialize_func f) : name(n), unserialize(f), timestamp(0)
{
type_order.push_back(this->name);
types[this->name] = this;
@@ -120,9 +150,24 @@ const Anope::string &SerializeType::GetName()
return this->name;
}
-void SerializeType::Create(Serializable::serialized_data &data)
+Serializable *SerializeType::Unserialize(Serializable *obj, Serialize::Data &data)
+{
+ return this->unserialize(obj, data);
+}
+
+void SerializeType::Check()
+{
+ FOREACH_MOD(I_OnSerializeCheck, OnSerializeCheck(this));
+}
+
+time_t SerializeType::GetTimestamp() const
+{
+ return this->timestamp;
+}
+
+void SerializeType::UpdateTimestamp()
{
- this->unserialize(data);
+ this->timestamp = Anope::CurTime;
}
SerializeType *SerializeType::Find(const Anope::string &name)
diff --git a/src/servers.cpp b/src/servers.cpp
index 6ccd4c403..416b35723 100644
--- a/src/servers.cpp
+++ b/src/servers.cpp
@@ -49,7 +49,7 @@ Server::Server(Server *uplink, const Anope::string &name, unsigned hops, const A
if (Me == this->UplinkServer && !this->HasFlag(SERVER_JUPED))
{
/* Now do mode related stuff as we know what modes exist .. */
- for (botinfo_map::iterator it = BotListByNick.begin(), it_end = BotListByNick.end(); it != it_end; ++it)
+ for (botinfo_map::iterator it = BotListByNick->begin(), it_end = BotListByNick->end(); it != it_end; ++it)
{
BotInfo *bi = it->second;
Anope::string modes = !bi->botmodes.empty() ? ("+" + bi->botmodes) : ircd->pseudoclient_mode;
@@ -276,7 +276,7 @@ void Server::Sync(bool SyncLinks)
if (this->GetUplink() && this->GetUplink() == Me)
{
- for (registered_channel_map::iterator it = RegisteredChannelList.begin(), it_end = RegisteredChannelList.end(); it != it_end; ++it)
+ for (registered_channel_map::iterator it = RegisteredChannelList->begin(), it_end = RegisteredChannelList->end(); it != it_end; ++it)
{
ChannelInfo *ci = it->second;
if (ci->HasFlag(CI_PERSIST))
@@ -353,7 +353,7 @@ bool Server::IsULined() const
* @param source The source of the message
* @param message The message
*/
-void Server::Notice(BotInfo *source, const Anope::string &message)
+void Server::Notice(const BotInfo *source, const Anope::string &message)
{
if (Config->NSDefFlags.HasFlag(NI_MSG))
ircdproto->SendGlobalPrivmsg(source, this, message);
diff --git a/src/users.cpp b/src/users.cpp
index aa69f27c7..bbe26a11a 100644
--- a/src/users.cpp
+++ b/src/users.cpp
@@ -41,7 +41,6 @@ User::User(const Anope::string &snick, const Anope::string &sident, const Anope:
/* we used to do this by calloc, no more. */
server = NULL;
- nc = NULL;
invalid_pw_count = invalid_pw_time = lastmemosend = lastnickreg = lastmail = 0;
OnAccess = false;
timestamp = my_signon = Anope::CurTime;
@@ -81,7 +80,7 @@ void User::SetNewNick(const Anope::string &newnick)
UserListByNick[this->nick] = this;
OnAccess = false;
- NickAlias *na = findnick(this->nick);
+ const NickAlias *na = findnick(this->nick);
if (na)
OnAccess = is_on_access(this, na->nc);
}
@@ -225,7 +224,7 @@ User::~User()
Log(LOG_DEBUG_2) << "User::~User() done";
}
-void User::SendMessage(BotInfo *source, const char *fmt, ...)
+void User::SendMessage(const BotInfo *source, const char *fmt, ...)
{
va_list args;
char buf[BUFSIZE] = "";
@@ -240,7 +239,7 @@ void User::SendMessage(BotInfo *source, const char *fmt, ...)
va_end(args);
}
-void User::SendMessage(BotInfo *source, Anope::string msg)
+void User::SendMessage(const BotInfo *source, Anope::string msg)
{
const char *translated_message = translate(this, msg.c_str());
@@ -318,7 +317,7 @@ void User::SendMessage(BotInfo *source, Anope::string msg)
*/
void User::Collide(NickAlias *na)
{
- BotInfo *bi = findbot(Config->NickServ);
+ const BotInfo *bi = findbot(Config->NickServ);
if (!bi)
return;
if (na)
@@ -372,15 +371,15 @@ void User::Identify(NickAlias *na)
this->Login(na->nc);
ircdproto->SendLogin(this);
- NickAlias *this_na = findnick(this->nick);
- if (!Config->NoNicknameOwnership && this_na && this_na->nc == na->nc && na->nc->HasFlag(NI_UNCONFIRMED) == false)
+ const NickAlias *this_na = findnick(this->nick);
+ if (!Config->NoNicknameOwnership && this_na && this_na->nc == *na->nc && na->nc->HasFlag(NI_UNCONFIRMED) == false)
this->SetMode(findbot(Config->NickServ), UMODE_REGISTERED);
FOREACH_MOD(I_OnNickIdentify, OnNickIdentify(this));
if (this->IsServicesOper())
{
- BotInfo *bi = findbot(Config->OperServ);
+ const BotInfo *bi = findbot(Config->OperServ);
if (!this->nc->o->ot->modes.empty())
{
this->SetModes(bi, "%s", this->nc->o->ot->modes.c_str());
@@ -427,7 +426,7 @@ void User::Logout()
/** Get the account the user is logged in using
* @reurn The account or NULL
*/
-NickCore *User::Account()
+NickCore *User::Account() const
{
return this->nc;
}
@@ -436,13 +435,13 @@ NickCore *User::Account()
* @param CheckNick True to check if the user is identified to the nickname they are on too
* @return true or false
*/
-bool User::IsIdentified(bool CheckNick)
+bool User::IsIdentified(bool CheckNick) const
{
if (CheckNick && this->nc)
{
NickAlias *na = findnick(this->nc->display);
- if (na && na->nc == this->nc)
+ if (na && *na->nc == *this->nc)
return true;
return false;
@@ -455,11 +454,11 @@ bool User::IsIdentified(bool CheckNick)
* @param CheckSecure Only returns true if the user has secure off
* @return true or false
*/
-bool User::IsRecognized(bool CheckSecure)
+bool User::IsRecognized(bool CheckSecure) const
{
if (CheckSecure && OnAccess)
{
- NickAlias *na = findnick(this->nick);
+ const NickAlias *na = findnick(this->nick);
if (!na || na->nc->HasFlag(NI_SECURE))
return false;
@@ -589,7 +588,7 @@ void User::RemoveModeInternal(UserMode *um)
* @param um The user mode
* @param Param Optional param for the mode
*/
-void User::SetMode(BotInfo *bi, UserMode *um, const Anope::string &Param)
+void User::SetMode(const BotInfo *bi, UserMode *um, const Anope::string &Param)
{
if (!um || HasMode(um->Name))
return;
@@ -603,7 +602,7 @@ void User::SetMode(BotInfo *bi, UserMode *um, const Anope::string &Param)
* @param Name The mode name
* @param param Optional param for the mode
*/
-void User::SetMode(BotInfo *bi, UserModeName Name, const Anope::string &Param)
+void User::SetMode(const BotInfo *bi, UserModeName Name, const Anope::string &Param)
{
SetMode(bi, ModeManager::FindUserModeByName(Name), Param);
}
@@ -612,7 +611,7 @@ void User::SetMode(BotInfo *bi, UserModeName Name, const Anope::string &Param)
* @param bi The client setting the mode
* @param um The user mode
*/
-void User::RemoveMode(BotInfo *bi, UserMode *um)
+void User::RemoveMode(const BotInfo *bi, UserMode *um)
{
if (!um || !HasMode(um->Name))
return;
@@ -625,7 +624,7 @@ void User::RemoveMode(BotInfo *bi, UserMode *um)
* @param bi The client setting the mode
* @param Name The mode name
*/
-void User::RemoveMode(BotInfo *bi, UserModeName Name)
+void User::RemoveMode(const BotInfo *bi, UserModeName Name)
{
RemoveMode(bi, ModeManager::FindUserModeByName(Name));
}
@@ -634,7 +633,7 @@ void User::RemoveMode(BotInfo *bi, UserModeName Name)
* @param bi The client setting the mode
* @param umodes The modes
*/
-void User::SetModes(BotInfo *bi, const char *umodes, ...)
+void User::SetModes(const BotInfo *bi, const char *umodes, ...)
{
char buf[BUFSIZE] = "";
va_list args;
@@ -761,7 +760,7 @@ Anope::string User::GetModes() const
* @param c The channel
* @return The channel container, or NULL
*/
-ChannelContainer *User::FindChannel(const Channel *c)
+ChannelContainer *User::FindChannel(const Channel *c) const
{
for (UChannelList::const_iterator it = this->chans.begin(), it_end = this->chans.end(); it != it_end; ++it)
if ((*it)->chan == c)