From 85a32077b53a6fa5af76341285758cdaf94b695b Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Thu, 26 Mar 2026 14:26:11 +0000 Subject: [PATCH] Add Data::Load, make the istream operator private. --- include/extensible.h | 6 +- include/serialize.h | 107 ++++++++++++++++++-------- include/services.h | 2 +- modules/botserv/bs_badwords.cpp | 16 +--- modules/botserv/bs_kick.cpp | 44 ++++++----- modules/chanserv/cs_akick.cpp | 48 +++++------- modules/chanserv/cs_entrymsg.cpp | 21 ++--- modules/chanserv/cs_log.cpp | 19 ++--- modules/chanserv/cs_mode.cpp | 16 ++-- modules/chanserv/cs_seen.cpp | 18 ++--- modules/chanserv/cs_set.cpp | 6 +- modules/chanserv/cs_set_misc.cpp | 15 ++-- modules/chanserv/cs_suspend.cpp | 15 ++-- modules/hostserv/hs_offer.cpp | 12 +-- modules/hostserv/hs_request.cpp | 15 ++-- modules/nickserv/ns_ajoin.cpp | 12 +-- modules/nickserv/ns_cert.cpp | 18 ++--- modules/nickserv/ns_set_keepmodes.cpp | 6 +- modules/nickserv/ns_set_misc.cpp | 15 ++-- modules/nickserv/ns_suspend.cpp | 16 ++-- modules/operserv/os_dns.cpp | 26 +++---- modules/operserv/os_forbid.cpp | 14 ++-- modules/operserv/os_ignore.cpp | 8 +- modules/operserv/os_info.cpp | 9 +-- modules/operserv/os_news.cpp | 10 +-- modules/operserv/os_oper.cpp | 11 +-- modules/operserv/os_session.cpp | 13 ++-- modules/operserv/os_stats.cpp | 4 +- src/access.cpp | 26 +++---- src/bots.cpp | 13 +--- src/init.cpp | 2 + src/logger.cpp | 2 + src/memos.cpp | 14 ++-- src/nickalias.cpp | 48 ++++-------- src/nickcore.cpp | 80 ++++++------------- src/regchannel.cpp | 92 ++++++++-------------- src/xline.cpp | 28 ++----- 37 files changed, 345 insertions(+), 482 deletions(-) diff --git a/include/extensible.h b/include/extensible.h index 140ab418d..344481347 100644 --- a/include/extensible.h +++ b/include/extensible.h @@ -185,7 +185,7 @@ public: void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) override { T t; - if (data[this->name] >> t) + if (data.TryLoad(this->name, t)) this->Set(e, t); else this->Unset(e); @@ -205,9 +205,7 @@ public: void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) override { - bool b = false; - data[this->name] >> b; - if (b) + if (data.Load(this->name)) this->Set(e); else this->Unset(e); diff --git a/include/serialize.h b/include/serialize.h index 59c2bc9af..6a2a204ac 100644 --- a/include/serialize.h +++ b/include/serialize.h @@ -40,43 +40,11 @@ namespace Serialize UINT, }; - class CoreExport Data - { - protected: - std::map types; - - public: - virtual ~Data() = default; - - virtual std::iostream &operator[](const Anope::string &key) = 0; - - template - void Store(const Anope::string &key, const T &value) - { - using Type = std::remove_cv_t>; - - if constexpr (std::is_same_v) - SetType(key, DataType::BOOL); - else if constexpr (std::is_floating_point_v) - SetType(key, DataType::FLOAT); - else if constexpr (std::is_integral_v && std::is_signed_v) - SetType(key, DataType::INT); - else if constexpr (std::is_integral_v && std::is_unsigned_v) - SetType(key, DataType::UINT); - - this->operator[](key) << value; - } - - virtual size_t Hash() const { throw CoreException("Not supported"); } - - Serialize::DataType GetType(const Anope::string &key) const; - void SetType(const Anope::string &key, Serialize::DataType dt); - }; - extern void RegisterTypes(); extern void CheckTypes(); extern void CreateTypes(); + class Data; class Type; template class Checker; template class Reference; @@ -141,6 +109,79 @@ public: static const std::list &GetItems(); }; +class CoreExport Serialize::Data +{ +protected: + /** The specified data types of known fields. */ + std::map types; + + Data() = default; + + virtual std::iostream &operator[](const Anope::string &key) = 0; + + /** Sets the data type of the specified field. This is called automatically from \ref Store. + * @param key The field to specify the data type for. + * @param dt The data type of the field. + */ + void SetType(const Anope::string &key, Serialize::DataType dt); + +public: + virtual ~Data() = default; + + /** Retrieves the data type for the specified field. If the field does not have a data type + * specified then it will default to TEXT. + * @param key The field to retrieve the data type for. + */ + Serialize::DataType GetType(const Anope::string &key) const; + + /** Retrieves a unique hash for the data set. */ + virtual size_t Hash() const { throw CoreException("Not supported"); } + + /** Loads the value of a specific field. + * @param key The field to get the value of. + * @param def The default value if none is set. + */ + template + T Load(const Anope::string& key, T def = T()) + { + T out; + if (!TryLoad(key, out)) + out = def; + return out; + } + + /** Stores the value of a specific field, automatically setting its type. + * @param key The field to set the value of. + * @param value The value of the field. + */ + template + void Store(const Anope::string &key, const T &value) + { + using Type = std::remove_cv_t>; + + if constexpr (std::is_same_v) + SetType(key, DataType::BOOL); + else if constexpr (std::is_floating_point_v) + SetType(key, DataType::FLOAT); + else if constexpr (std::is_integral_v && std::is_signed_v) + SetType(key, DataType::INT); + else if constexpr (std::is_integral_v && std::is_unsigned_v) + SetType(key, DataType::UINT); + + this->operator[](key) << value; + } + + /** Tries to load the value of a specific field. + * @param key The field to get the value of. + * @param out The location to store the retrieved value. + */ + template + bool TryLoad(const Anope::string& key, T &out) + { + return static_cast(this->operator[](key) >> out); + } +}; + /* A serializable type. There should be a single instance of a subclass of this * for each subclass of Serializable as this is what is used to serialize and * deserialize data from the database. diff --git a/include/services.h b/include/services.h index 8e16045e9..c075a29a1 100644 --- a/include/services.h +++ b/include/services.h @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/modules/botserv/bs_badwords.cpp b/modules/botserv/bs_badwords.cpp index d939fe053..c5b55ea98 100644 --- a/modules/botserv/bs_badwords.cpp +++ b/modules/botserv/bs_badwords.cpp @@ -172,26 +172,18 @@ BadWordImpl::~BadWordImpl() Serializable *BadWordTypeImpl::Unserialize(Serializable *obj, Serialize::Data &data) const { - Anope::string sci, sword; - - data["ci"] >> sci; - data["word"] >> sword; - - ChannelInfo *ci = ChannelInfo::Find(sci); + auto *ci = ChannelInfo::Find(data.Load("ci")); if (!ci) return NULL; - Anope::string n; - data["type"] >> n; - BadWordImpl *bw; if (obj) bw = anope_dynamic_static_cast(obj); else bw = new BadWordImpl(); - bw->chan = sci; - bw->word = sword; - bw->type = StringToType(n); + bw->chan = ci->name; + bw->word = data.Load("word"); + bw->type = StringToType(data.Load("type")); auto *bws = ci->Require(BOTSERV_BAD_WORDS_EXT); if (!obj) diff --git a/modules/botserv/bs_kick.cpp b/modules/botserv/bs_kick.cpp index 7cbbebb43..db894cbca 100644 --- a/modules/botserv/bs_kick.cpp +++ b/modules/botserv/bs_kick.cpp @@ -88,30 +88,32 @@ struct KickerDataImpl final auto *ci = anope_dynamic_static_cast(e); auto *kd = ci->Require(BOTSERV_KICKER_DATA_EXT); - data["kickerdata:amsgs"] >> kd->amsgs; - data["kickerdata:badwords"] >> kd->badwords; - data["kickerdata:bolds"] >> kd->bolds; - data["kickerdata:caps"] >> kd->caps; - data["kickerdata:colors"] >> kd->colors; - data["kickerdata:flood"] >> kd->flood; - data["kickerdata:italics"] >> kd->italics; - data["kickerdata:repeat"] >> kd->repeat; - data["kickerdata:reverses"] >> kd->reverses; - data["kickerdata:underlines"] >> kd->underlines; + kd->amsgs = data.Load("kickerdata:amsgs"); + kd->badwords = data.Load("kickerdata:badwords"); + kd->bolds = data.Load("kickerdata:bolds"); + kd->caps = data.Load("kickerdata:caps"); + kd->colors = data.Load("kickerdata:colors"); + kd->flood = data.Load("kickerdata:flood"); + kd->italics = data.Load("kickerdata:italics"); + kd->repeat = data.Load("kickerdata:repeat"); + kd->reverses = data.Load("kickerdata:reverses"); + kd->underlines = data.Load("kickerdata:underlines"); - data["capsmin"] >> kd->capsmin; - data["capspercent"] >> kd->capspercent; - data["floodlines"] >> kd->floodlines; - data["floodsecs"] >> kd->floodsecs; - data["repeattimes"] >> kd->repeattimes; - data["dontkickops"] >> kd->dontkickops; - data["dontkickvoices"] >> kd->dontkickvoices; + kd->capsmin = data.Load("capsmin"); + kd->capspercent = data.Load("capspercent"); + kd->floodlines = data.Load("floodlines"); + kd->floodsecs = data.Load("floodsecs"); + kd->repeattimes = data.Load("repeattimes"); + kd->dontkickops = data.Load("dontkickops"); + kd->dontkickvoices = data.Load("dontkickvoices"); - Anope::string ttb, tok; - data["ttb"] >> ttb; - spacesepstream sep(ttb); - for (int i = 0; sep.GetToken(tok) && i < BotServ::TTB_SIZE; ++i) + spacesepstream sep(data.Load("ttb")); + for (size_t i = 0; i < BotServ::TTB_SIZE; ++i) { + Anope::string tok; + if (!sep.GetToken(tok)) + break; + if (auto n = Anope::TryConvert(tok)) kd->ttb[i] = n.value(); } diff --git a/modules/chanserv/cs_akick.cpp b/modules/chanserv/cs_akick.cpp index d754764fa..9296cea0e 100644 --- a/modules/chanserv/cs_akick.cpp +++ b/modules/chanserv/cs_akick.cpp @@ -143,46 +143,34 @@ struct AutoKickType final Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override { - Anope::string sci, snc; - uint64_t sncid = 0; - - data["ci"] >> sci; - data["nc"] >> snc; // Deprecated 2.0 field - data["ncid"] >> sncid; - - ChannelInfo *ci = ChannelInfo::Find(sci); + auto *ci = ChannelInfo::Find(data.Load("ci")); if (!ci) return NULL; + const auto sncid = data.Load("ncid"); + auto *nc = sncid ? NickCore::FindId(sncid) : NickCore::Find(data.Load("nc")); + + const auto screator = data.Load("creator"); + const auto smask = data.Load("mask"); + const auto sreason = data.Load("reason"); + const auto saddtime = data.Load("addtime"); + const auto slastused = data.Load("last_used"); + ChanServ::AutoKick *ak; - auto *nc = sncid ? NickCore::FindId(sncid) : NickCore::Find(snc); if (obj) { ak = anope_dynamic_static_cast(obj); - data["creator"] >> ak->creator; - data["reason"] >> ak->reason; + ak->creator = screator; + ak->reason = sreason; ak->nc = nc; - data["mask"] >> ak->mask; - data["addtime"] >> ak->addtime; - data["last_used"] >> ak->last_used; + ak->mask = smask; + ak->addtime = saddtime; + ak->last_used = slastused; } + else if (nc) + ak = ChanServ::akick_service->AddAKick(ci, screator, nc, sreason, saddtime, slastused); else - { - time_t addtime, lastused; - data["addtime"] >> addtime; - data["last_used"] >> lastused; - - Anope::string screator, sreason, smask; - - data["creator"] >> screator; - data["reason"] >> sreason; - data["mask"] >> smask; - - if (nc) - ak = ChanServ::akick_service->AddAKick(ci, screator, nc, sreason, addtime, lastused); - else - ak = ChanServ::akick_service->AddAKick(ci, screator, smask, sreason, addtime, lastused); - } + ak = ChanServ::akick_service->AddAKick(ci, screator, smask, sreason, saddtime, slastused); return ak; } diff --git a/modules/chanserv/cs_entrymsg.cpp b/modules/chanserv/cs_entrymsg.cpp index de5b62dee..72e6799e9 100644 --- a/modules/chanserv/cs_entrymsg.cpp +++ b/modules/chanserv/cs_entrymsg.cpp @@ -85,31 +85,24 @@ EntryMsgImpl::~EntryMsgImpl() Serializable *EntryMsgTypeImpl::Unserialize(Serializable *obj, Serialize::Data &data) const { - Anope::string sci, screator, smessage; - time_t swhen; - - data["ci"] >> sci; - data["creator"] >> screator; - data["message"] >> smessage; - - ChannelInfo *ci = ChannelInfo::Find(sci); + auto *ci = ChannelInfo::Find(data.Load("ci")); if (!ci) return NULL; + const auto screator = data.Load("creator"); + const auto smessage = data.Load("message"); + const auto swhen = data.Load("when"); if (obj) { auto *msg = anope_dynamic_static_cast(obj); msg->chan = ci->name; - data["creator"] >> msg->creator; - data["message"] >> msg->message; - data["when"] >> msg->when; + msg->creator = screator; + msg->message = smessage; + msg->when = swhen; return msg; } auto *messages = ci->Require(CHANSERV_ENTRY_MESSAGE_EXT); - - data["when"] >> swhen; - auto *m = new EntryMsgImpl(ci, screator, smessage, swhen); (*messages)->push_back(m); return m; diff --git a/modules/chanserv/cs_log.cpp b/modules/chanserv/cs_log.cpp index 9cbb4bb25..cb8e14021 100644 --- a/modules/chanserv/cs_log.cpp +++ b/modules/chanserv/cs_log.cpp @@ -64,10 +64,7 @@ struct LogSettingTypeImpl final Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override { - Anope::string sci; - data["ci"] >> sci; - - ChannelInfo *ci = ChannelInfo::Find(sci); + auto *ci = ChannelInfo::Find(data.Load("ci")); if (ci == NULL) return NULL; @@ -82,13 +79,13 @@ struct LogSettingTypeImpl final } ls->chan = ci->name; - 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->service_name = data.Load("service_name"); + ls->command_service = data.Load("command_service"); + ls->command_name = data.Load("command_name"); + ls->method = data.Load("method"); + ls->extra = data.Load("extra"); + ls->creator = data.Load("creator"); + ls->created = data.Load("created"); return ls; } diff --git a/modules/chanserv/cs_mode.cpp b/modules/chanserv/cs_mode.cpp index 0eafa2d70..574d68317 100644 --- a/modules/chanserv/cs_mode.cpp +++ b/modules/chanserv/cs_mode.cpp @@ -270,11 +270,7 @@ void ModeLockTypeImpl::Serialize(Serializable *obj, Serialize::Data &data) const Serializable *ModeLockTypeImpl::Unserialize(Serializable *obj, Serialize::Data &data) const { - Anope::string sci; - - data["ci"] >> sci; - - ChannelInfo *ci = ChannelInfo::Find(sci); + auto *ci = ChannelInfo::Find(data.Load("ci")); if (!ci) return NULL; @@ -287,11 +283,11 @@ Serializable *ModeLockTypeImpl::Unserialize(Serializable *obj, Serialize::Data & ml->ci = ci->name; } - data["set"] >> ml->set; - data["created"] >> ml->created; - data["setter"] >> ml->setter; - data["name"] >> ml->name; - data["param"] >> ml->param; + ml->set = data.Load("set"); + ml->created = data.Load("created"); + ml->setter = data.Load("setter"); + ml->name = data.Load("name"); + ml->param = data.Load("param"); if (!obj) ci->Require(CHANSERV_MODE_LOCK_EXT)->mlocks->push_back(ml); diff --git a/modules/chanserv/cs_seen.cpp b/modules/chanserv/cs_seen.cpp index dfa858281..ed53218a4 100644 --- a/modules/chanserv/cs_seen.cpp +++ b/modules/chanserv/cs_seen.cpp @@ -111,9 +111,7 @@ struct SeenInfoType final Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override { - Anope::string snick; - - data["nick"] >> snick; + const auto snick = data.Load("nick"); SeenInfo *s; if (obj) @@ -127,14 +125,12 @@ struct SeenInfoType final } s->nick = snick; - data["vhost"] >> s->vhost; - Anope::string n; - data["type"] >> n; - s->type = StringToType(n); - data["nick2"] >> s->nick2; - data["channel"] >> s->channel; - data["message"] >> s->message; - data["last"] >> s->last; + s->vhost = data.Load("vhost"); + s->type = StringToType(data.Load("type")); + s->nick2 = data.Load("nick2"); + s->channel = data.Load("channel"); + s->message = data.Load("message"); + s->last = data.Load("last"); if (!obj) database[s->nick] = s; diff --git a/modules/chanserv/cs_set.cpp b/modules/chanserv/cs_set.cpp index 63d84c85c..6c4b51576 100644 --- a/modules/chanserv/cs_set.cpp +++ b/modules/chanserv/cs_set.cpp @@ -1139,10 +1139,10 @@ class CSSet final return; auto *ci = anope_dynamic_static_cast(s); - Anope::string modes; - data["last_modes"] >> modes; ci->last_modes.clear(); - for (spacesepstream sep(modes); sep.GetToken(modes);) + + spacesepstream sep(data.Load("last_modes")); + for (Anope::string modes; sep.GetToken(modes);) { if (modes[0] == '+') { diff --git a/modules/chanserv/cs_set_misc.cpp b/modules/chanserv/cs_set_misc.cpp index 2b1d7f9e3..0624ffcbf 100644 --- a/modules/chanserv/cs_set_misc.cpp +++ b/modules/chanserv/cs_set_misc.cpp @@ -77,23 +77,20 @@ struct CSMiscDataType Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override { - Anope::string sci, sname, sdata; - - data["ci"] >> sci; - data["name"] >> sname; - data["data"] >> sdata; - - ChannelInfo *ci = ChannelInfo::Find(sci); + auto *ci = ChannelInfo::Find(data.Load("ci")); if (ci == NULL) return NULL; + const auto sname = data.Load("name"); + const auto sdata = data.Load("data"); + CSMiscData *d = NULL; if (obj) { d = anope_dynamic_static_cast(obj); d->object = ci->name; - data["name"] >> d->name; - data["data"] >> d->data; + d->name = sname; + d->data = sdata; } else { diff --git a/modules/chanserv/cs_suspend.cpp b/modules/chanserv/cs_suspend.cpp index 81b086feb..dff454c52 100644 --- a/modules/chanserv/cs_suspend.cpp +++ b/modules/chanserv/cs_suspend.cpp @@ -42,25 +42,22 @@ struct CSSuspendInfoType final Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override { - Anope::string schan; - data["chan"] >> schan; - CSSuspendInfo *si; if (obj) si = anope_dynamic_static_cast(obj); else { - ChannelInfo *ci = ChannelInfo::Find(schan); + auto *ci = ChannelInfo::Find(data.Load("chan")); if (!ci) return NULL; si = ci->Extend("CS_SUSPENDED"); - data["chan"] >> si->what; + si->what = ci->name; } - data["by"] >> si->by; - data["reason"] >> si->reason; - data["time"] >> si->when; - data["expires"] >> si->expires; + si->by = data.Load("by"); + si->reason = data.Load("reason"); + si->when = data.Load("time"); + si->expires = data.Load("expires"); return si; } }; diff --git a/modules/hostserv/hs_offer.cpp b/modules/hostserv/hs_offer.cpp index 266057071..223278e03 100644 --- a/modules/hostserv/hs_offer.cpp +++ b/modules/hostserv/hs_offer.cpp @@ -223,12 +223,12 @@ public: else ho = new HostOffer(); - data["ident"] >> ho->ident; - data["host"] >> ho->host; - data["reason"] >> ho->reason; - data["creator"] >> ho->creator; - data["created"] >> ho->created; - data["expires"] >> ho->expires; + ho->ident = data.Load("ident"); + ho->host = data.Load("host"); + ho->reason = data.Load("reason"); + ho->creator = data.Load("creator"); + ho->created = data.Load("created"); + ho->expires = data.Load("expires"); if (!obj) host_offers->Add(ho); diff --git a/modules/hostserv/hs_request.cpp b/modules/hostserv/hs_request.cpp index 9c95cc664..09ef6227d 100644 --- a/modules/hostserv/hs_request.cpp +++ b/modules/hostserv/hs_request.cpp @@ -75,10 +75,7 @@ struct HostRequestTypeImpl final Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override { - Anope::string snick; - data["nick"] >> snick; - - NickAlias *na = NickAlias::Find(snick); + auto *na = NickAlias::Find(data.Load("nick")); if (na == NULL) return NULL; @@ -90,11 +87,11 @@ struct HostRequestTypeImpl final if (req) { req->nick = na->nick; - data["ident"] >> req->ident; - data["host"] >> req->host; - data["time"] >> req->time; - data["validation_token"] >> req->validation_token; - data["last_validation"] >> req->last_validation; + req->ident = data.Load("ident"); + req->host = data.Load("host"); + req->time = data.Load("time"); + req->validation_token = data.Load("validation_token"); + req->last_validation = data.Load("last_validation"); } return req; diff --git a/modules/nickserv/ns_ajoin.cpp b/modules/nickserv/ns_ajoin.cpp index 996831bca..5c31ac978 100644 --- a/modules/nickserv/ns_ajoin.cpp +++ b/modules/nickserv/ns_ajoin.cpp @@ -65,13 +65,9 @@ struct AJoinEntryType final Serializable *Unserialize(Serializable *obj, Serialize::Data &sd) const override { - Anope::string sowner; - uint64_t sownerid = 0; + const auto sownerid = sd.Load("ownerid"); - sd["owner"] >> sowner; // Deprecated 2.0 field - sd["ownerid"] >> sownerid; - - auto *nc = sownerid ? NickCore::FindId(sownerid) : NickCore::Find(sowner); + auto *nc = sownerid ? NickCore::FindId(sownerid) : NickCore::Find(sd.Load("owner")); if (nc == NULL) return NULL; @@ -84,8 +80,8 @@ struct AJoinEntryType final aj->owner = nc; } - sd["channel"] >> aj->channel; - sd["key"] >> aj->key; + aj->channel = sd.Load("channel"); + aj->key = sd.Load("key"); if (!obj) { diff --git a/modules/nickserv/ns_cert.cpp b/modules/nickserv/ns_cert.cpp index 9f8289e55..ffdecf493 100644 --- a/modules/nickserv/ns_cert.cpp +++ b/modules/nickserv/ns_cert.cpp @@ -219,9 +219,8 @@ public: cl->certs.clear(); // Add the new cert list - Anope::string buf; - data["cert"] >> buf; - for (spacesepstream sep(buf); sep.GetToken(buf); ) + spacesepstream sep(data.Load("cert")); + for (Anope::string buf; sep.GetToken(buf); ) { auto *cert = new NSCertInfo(e); cert->fingerprint = buf; @@ -255,10 +254,7 @@ public: Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override { - uint64_t account = 0; - data["account"] >> account; - - auto *nc = NickCore::FindId(account); + auto *nc = NickCore::FindId(data.Load("account")); if (!nc) return nullptr; // Missing user. @@ -268,10 +264,10 @@ public: else cert = new NSCertInfo(nc); - data["created"] >> cert->created; - data["creator"] >> cert->creator; - data["description"] >> cert->description; - data["fingerprint"] >> cert->fingerprint; + cert->created = data.Load("created"); + cert->creator = data.Load("creator"); + cert->description = data.Load("description"); + cert->fingerprint = data.Load("fingerprint"); if (!obj) { diff --git a/modules/nickserv/ns_set_keepmodes.cpp b/modules/nickserv/ns_set_keepmodes.cpp index 7cb7365de..350091087 100644 --- a/modules/nickserv/ns_set_keepmodes.cpp +++ b/modules/nickserv/ns_set_keepmodes.cpp @@ -156,10 +156,10 @@ private: return; auto *nc = anope_dynamic_static_cast(s); - Anope::string modes; - data["last_modes"] >> modes; nc->last_modes.clear(); - for (spacesepstream sep(modes); sep.GetToken(modes);) + + spacesepstream sep(data.Load("last_modes")); + for (Anope::string modes; sep.GetToken(modes);) { if (modes[0] == '+') { diff --git a/modules/nickserv/ns_set_misc.cpp b/modules/nickserv/ns_set_misc.cpp index 372bfea2f..45144b4ba 100644 --- a/modules/nickserv/ns_set_misc.cpp +++ b/modules/nickserv/ns_set_misc.cpp @@ -79,23 +79,20 @@ struct NSMiscDataType final Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override { - Anope::string snc, sname, sdata; - - data["nc"] >> snc; - data["name"] >> sname; - data["data"] >> sdata; - - NickCore *nc = NickCore::Find(snc); + auto *nc = NickCore::Find(data.Load("nc")); if (nc == NULL) return NULL; + const auto sname = data.Load("name"); + const auto sdata = data.Load("data"); + NSMiscData *d = NULL; if (obj) { d = anope_dynamic_static_cast(obj); d->object = nc->display; - data["name"] >> d->name; - data["data"] >> d->data; + d->name = sname; + d->data = sdata; } else { diff --git a/modules/nickserv/ns_suspend.cpp b/modules/nickserv/ns_suspend.cpp index 0ce02130c..12d0db09d 100644 --- a/modules/nickserv/ns_suspend.cpp +++ b/modules/nickserv/ns_suspend.cpp @@ -43,25 +43,23 @@ struct NSSuspendInfoType final Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override { - Anope::string snick; - data["nick"] >> snick; - NSSuspendInfo *si; if (obj) si = anope_dynamic_static_cast(obj); else { - NickAlias *na = NickAlias::Find(snick); + auto *na = NickAlias::Find(data.Load("nick")); if (!na) return NULL; + si = na->nc->Extend("NS_SUSPENDED"); - data["nick"] >> si->what; + si->what = na->nick; } - data["by"] >> si->by; - data["reason"] >> si->reason; - data["time"] >> si->when; - data["expires"] >> si->expires; + si->by = data.Load("by"); + si->reason = data.Load("reason"); + si->when = data.Load("time"); + si->expires = data.Load("expires"); return si; } }; diff --git a/modules/operserv/os_dns.cpp b/modules/operserv/os_dns.cpp index bd08c75e4..cf9cc6ad6 100644 --- a/modules/operserv/os_dns.cpp +++ b/modules/operserv/os_dns.cpp @@ -79,12 +79,12 @@ struct DNSZoneType final DNSZone *zone; Anope::string zone_name; - data["name"] >> zone_name; + zone_name = data.Load("name"); if (obj) { zone = anope_dynamic_static_cast(obj); - data["name"] >> zone->name; + zone->name = data.Load("name"); } else zone = new DNSZone(zone_name); @@ -92,10 +92,10 @@ struct DNSZoneType final zone->servers.clear(); for (unsigned count = 0; true; ++count) { - Anope::string server_str; - data["server" + Anope::ToString(count)] >> server_str; + const auto server_str = data.Load(Anope::Format("server%u", count)); if (server_str.empty()) break; + zone->servers.insert(server_str); } @@ -195,11 +195,9 @@ struct DNSServerType final Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override { + const auto server_name = data.Load("server_name"); + DNSServer *req; - Anope::string server_name; - - data["server_name"] >> server_name; - if (obj) { req = anope_dynamic_static_cast(obj); @@ -210,23 +208,23 @@ struct DNSServerType final for (unsigned i = 0; true; ++i) { - Anope::string ip_str; - data["ip" + Anope::ToString(i)] >> ip_str; + const auto ip_str = data.Load(Anope::Format("ip%u", i)); if (ip_str.empty()) break; + req->ips.push_back(ip_str); } - data["limit"] >> req->limit; - data["pooled"] >> req->pooled; + req->limit = data.Load("limit"); + req->pooled = data.Load("pooled"); req->zones.clear(); for (unsigned i = 0; true; ++i) { - Anope::string zone_str; - data["zone" + Anope::ToString(i)] >> zone_str; + const auto zone_str = data.Load(Anope::Format("zone%u", i)); if (zone_str.empty()) break; + req->zones.insert(zone_str); } diff --git a/modules/operserv/os_forbid.cpp b/modules/operserv/os_forbid.cpp index fb4e39987..4f4e2f93e 100644 --- a/modules/operserv/os_forbid.cpp +++ b/modules/operserv/os_forbid.cpp @@ -113,14 +113,12 @@ Serializable *ForbidDataTypeImpl::Unserialize(Serializable *obj, Serialize::Data else fb = new ForbidDataImpl(); - data["mask"] >> fb->mask; - data["creator"] >> fb->creator; - data["reason"] >> fb->reason; - data["created"] >> fb->created; - data["expires"] >> fb->expires; - Anope::string t; - data["type"] >> t; - fb->type = StringToType(t); + fb->mask = data.Load("mask"); + fb->creator = data.Load("creator"); + fb->reason = data.Load("reason"); + fb->created = data.Load("created"); + fb->expires = data.Load("expires"); + fb->type = StringToType(data.Load("type")); if (fb->type == OperServ::FT_SIZE) return NULL; diff --git a/modules/operserv/os_ignore.cpp b/modules/operserv/os_ignore.cpp index feb758f9a..a6d5fe74b 100644 --- a/modules/operserv/os_ignore.cpp +++ b/modules/operserv/os_ignore.cpp @@ -66,10 +66,10 @@ Serializable *IgnoreDataTypeImpl::Unserialize(Serializable *obj, Serialize::Data OperServ::ignore_service->AddIgnore(ign); } - data["mask"] >> ign->mask; - data["creator"] >> ign->creator; - data["reason"] >> ign->reason; - data["time"] >> ign->time; + ign->mask = data.Load("mask"); + ign->creator = data.Load("creator"); + ign->reason = data.Load("reason"); + ign->time = data.Load("time"); return ign; } diff --git a/modules/operserv/os_info.cpp b/modules/operserv/os_info.cpp index 20e3247ee..d0c665e8e 100644 --- a/modules/operserv/os_info.cpp +++ b/modules/operserv/os_info.cpp @@ -89,8 +89,7 @@ OperInfoImpl::~OperInfoImpl() Serializable *OperInfoTypeImpl::Unserialize(Serializable *obj, Serialize::Data &data) const { - Anope::string starget; - data["target"] >> starget; + const auto starget = data.Load("target"); Extensible *e = OperInfos::Find(starget); if (!e) @@ -105,9 +104,9 @@ Serializable *OperInfoTypeImpl::Unserialize(Serializable *obj, Serialize::Data & o = new OperInfoImpl(); o->target = starget; } - data["info"] >> o->info; - data["adder"] >> o->adder; - data["created"] >> o->created; + o->info = data.Load("info"); + o->adder = data.Load("adder"); + o->created = data.Load("created"); if (!obj) (*oi)->push_back(o); diff --git a/modules/operserv/os_news.cpp b/modules/operserv/os_news.cpp index e19c8a6f2..9167e1cc9 100644 --- a/modules/operserv/os_news.cpp +++ b/modules/operserv/os_news.cpp @@ -130,12 +130,10 @@ struct NewsItemType final else ni = new OperServ::NewsItem(); - Anope::string t; - data["type"] >> t; - ni->type = StringToType(t); - data["text"] >> ni->text; - data["who"] >> ni->who; - data["time"] >> ni->time; + ni->type = StringToType(data.Load("type")); + ni->text = data.Load("text"); + ni->who = data.Load("who"); + ni->time = data.Load("time"); if (!obj) OperServ::news_service->AddNewsItem(ni); diff --git a/modules/operserv/os_oper.cpp b/modules/operserv/os_oper.cpp index 8a0d894da..1ec4feaeb 100644 --- a/modules/operserv/os_oper.cpp +++ b/modules/operserv/os_oper.cpp @@ -32,15 +32,11 @@ struct OSOperType Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override { - Anope::string stype, sname; - - data["type"] >> stype; - data["name"] >> sname; - - OperType *ot = OperType::Find(stype); + auto *ot = OperType::Find(data.Load("type")); if (ot == NULL) return NULL; - NickCore *nc = NickCore::Find(sname); + + auto *nc = NickCore::Find(data.Load("name")); if (nc == NULL) return NULL; @@ -49,6 +45,7 @@ struct OSOperType myo = anope_dynamic_static_cast(obj); else myo = new OperServ::Oper(nc->display, ot); + nc->o = myo; Log(LOG_NORMAL, "operserv/oper") << "Tied oper " << nc->display << " to type " << ot->GetName(); return myo; diff --git a/modules/operserv/os_session.cpp b/modules/operserv/os_session.cpp index 4ac2bbe99..31aba39d6 100644 --- a/modules/operserv/os_session.cpp +++ b/modules/operserv/os_session.cpp @@ -66,12 +66,13 @@ struct ExceptionType final ex = anope_dynamic_static_cast(obj); else ex = new OperServ::Exception(); - data["mask"] >> ex->mask; - data["limit"] >> ex->limit; - data["who"] >> ex->who; - data["reason"] >> ex->reason; - data["time"] >> ex->time; - data["expires"] >> ex->expires; + + ex->mask = data.Load("mask"); + ex->limit = data.Load("limit"); + ex->who = data.Load("who"); + ex->reason = data.Load("reason"); + ex->time = data.Load("time"); + ex->expires = data.Load("expires"); if (!obj) OperServ::session_service->AddException(ex); diff --git a/modules/operserv/os_stats.cpp b/modules/operserv/os_stats.cpp index 7b067fd0b..9f0a170c6 100644 --- a/modules/operserv/os_stats.cpp +++ b/modules/operserv/os_stats.cpp @@ -43,8 +43,8 @@ struct StatsType final Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override { - data["maxusercnt"] >> MaxUserCount; - data["maxusertime"] >> MaxUserTime; + MaxUserCount = data.Load("maxusercnt"); + MaxUserTime = data.Load("maxusertime"); return Stats::me; } }; diff --git a/src/access.cpp b/src/access.cpp index 93811f8a7..92844d761 100644 --- a/src/access.cpp +++ b/src/access.cpp @@ -184,13 +184,8 @@ void ChanAccess::Type::Serialize(Serializable *obj, Serialize::Data &data) const Serializable *ChanAccess::Type::Unserialize(Serializable *obj, Serialize::Data &data) const { - Anope::string provider, chan; - - data["provider"] >> provider; - data["ci"] >> chan; - - ServiceReference aprovider("AccessProvider", provider); - ChannelInfo *ci = ChannelInfo::Find(chan); + ServiceReference aprovider("AccessProvider", data.Load("provider")); + auto *ci = ChannelInfo::Find(data.Load("ci")); if (!aprovider || !ci) return NULL; @@ -200,17 +195,14 @@ Serializable *ChanAccess::Type::Unserialize(Serializable *obj, Serialize::Data & else access = aprovider->Create(); access->ci = ci; - Anope::string m; - data["mask"] >> m; - access->SetMask(m, ci); - data["creator"] >> access->creator; - data["description"] >> access->description; - data["last_seen"] >> access->last_seen; - data["created"] >> access->created; - Anope::string adata; - data["data"] >> adata; - access->AccessUnserialize(adata); + access->SetMask(data.Load("mask"), ci); + access->creator = data.Load("creator"); + access->description = data.Load("description"); + access->last_seen = data.Load("last_seen"); + access->created = data.Load("created"); + + access->AccessUnserialize(data.Load("data")); if (!obj) ci->AddAccess(access); diff --git a/src/bots.cpp b/src/bots.cpp index 9d6415b07..b7e867132 100644 --- a/src/bots.cpp +++ b/src/bots.cpp @@ -142,21 +142,16 @@ void BotInfo::Type::Serialize(Serializable *obj, Serialize::Data &data) const Serializable *BotInfo::Type::Unserialize(Serializable *obj, Serialize::Data &data) const { - Anope::string nick, user, host, realname, flags; - - data["nick"] >> nick; - data["user"] >> user; - data["host"] >> host; - data["realname"] >> realname; + const auto nick = data.Load("nick"); BotInfo *bi; if (obj) bi = anope_dynamic_static_cast(obj); else if (!(bi = BotInfo::Find(nick, true))) - bi = new BotInfo(nick, user, host, realname); + bi = new BotInfo(nick, data.Load("user"), data.Load("host"), data.Load("realname")); - data["created"] >> bi->created; - data["oper_only"] >> bi->oper_only; + bi->created = data.Load("created"); + bi->oper_only = data.Load("oper_only"); Extensible::ExtensibleUnserialize(bi, bi, data); diff --git a/src/init.cpp b/src/init.cpp index 67481e291..28487875e 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -31,6 +31,8 @@ #include #include #endif + +#include #include Anope::string Anope::ConfigDir = DEFAULT_CONF_DIR; diff --git a/src/logger.cpp b/src/logger.cpp index 909192459..37416414c 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -29,6 +29,8 @@ #include #endif +#include + static Anope::string GetTimeStamp() { char tbuf[256]; diff --git a/src/memos.cpp b/src/memos.cpp index 3b6809613..9fc7e6099 100644 --- a/src/memos.cpp +++ b/src/memos.cpp @@ -56,9 +56,7 @@ void Memo::Type::Serialize(Serializable *obj, Serialize::Data &data) const Serializable *Memo::Type::Unserialize(Serializable *obj, Serialize::Data &data) const { - Anope::string owner; - - data["owner"] >> owner; + const auto owner = data.Load("owner"); bool ischan; MemoInfo *mi = MemoInfo::GetMemoInfo(owner, ischan); @@ -75,11 +73,11 @@ Serializable *Memo::Type::Unserialize(Serializable *obj, Serialize::Data &data) } m->owner = owner; - data["time"] >> m->time; - data["sender"] >> m->sender; - data["text"] >> m->text; - data["unread"] >> m->unread; - data["receipt"] >> m->receipt; + m->time = data.Load("time"); + m->sender = data.Load("sender"); + m->text = data.Load("text"); + m->unread = data.Load("unread"); + m->receipt = data.Load("receipt"); if (obj == NULL) mi->memos->push_back(m); diff --git a/src/nickalias.cpp b/src/nickalias.cpp index 6f954801b..97cea59f0 100644 --- a/src/nickalias.cpp +++ b/src/nickalias.cpp @@ -167,8 +167,8 @@ void NickAlias::Type::Serialize(Serializable *obj, Serialize::Data &data) const data.Store("last_quit", na->last_quit); data.Store("last_userhost", na->last_userhost); data.Store("last_userhost_real", na->last_userhost_real); - data.Store("registered", na->registered); - data.Store("last_seen", na->last_seen); + data.Store("registered", na->registered); + data.Store("last_seen", na->last_seen); data.Store("ncid", na->nc->GetId()); if (na->HasVHost()) @@ -184,14 +184,9 @@ void NickAlias::Type::Serialize(Serializable *obj, Serialize::Data &data) const Serializable *NickAlias::Type::Unserialize(Serializable *obj, Serialize::Data &data) const { - Anope::string snc, snick; - uint64_t sncid = 0; + const auto sncid = data.Load("ncid"); - data["nc"] >> snc; // Deprecated 2.0 field - data["ncid"] >> sncid; - data["nick"] >> snick; - - auto *core = sncid ? NickCore::FindId(sncid) : NickCore::Find(snc); + auto *core = sncid ? NickCore::FindId(sncid) : NickCore::Find(data.Load("nc")); if (core == NULL) return NULL; @@ -199,7 +194,7 @@ Serializable *NickAlias::Type::Unserialize(Serializable *obj, Serialize::Data &d if (obj) na = anope_dynamic_static_cast(obj); else - na = new NickAlias(snick, core); + na = new NickAlias(data.Load("nick"), core); if (na->nc != core) { @@ -216,40 +211,23 @@ Serializable *NickAlias::Type::Unserialize(Serializable *obj, Serialize::Data &d core->aliases->push_back(na); } - data["last_quit"] >> na->last_quit; - data["last_userhost"] >> na->last_userhost; - data["last_userhost_real"] >> na->last_userhost_real; - data["registered"] >> na->registered; - data["last_seen"] >> na->last_seen; + na->last_quit = data.Load("last_quit"); + na->last_userhost = data.Load("last_userhost", data.Load("last_usermask")); + na->last_userhost_real = data.Load("last_userhost_real", data.Load("last_realhost")); + na->registered = data.Load("registered", data.Load("time_registered")); + na->last_seen = data.Load("last_seen"); - Anope::string vhost_ident, vhost_host, vhost_creator; - time_t vhost_time; - - data["vhost_ident"] >> vhost_ident; - data["vhost_host"] >> vhost_host; - data["vhost_creator"] >> vhost_creator; - data["vhost_time"] >> vhost_time; - - na->SetVHost(vhost_ident, vhost_host, vhost_creator, vhost_time); + na->SetVHost(data.Load("vhost_ident"), data.Load("vhost_host"), data.Load("vhost_creator"), + data.Load("vhost_time")); Extensible::ExtensibleUnserialize(na, na, data); // Begin 1.9 compatibility. - bool b; - b = false; - data["extensible:NO_EXPIRE"] >> b; - if (b) + if (data.Load("extensible:NO_EXPIRE")) na->Extend("NS_NO_EXPIRE"); // End 1.9 compatibility. // Begin 2.0 compatibility. - if (na->last_userhost.empty()) - data["last_usermask"] >> na->last_userhost; - if (na->last_userhost_real.empty()) - data["last_realhost"] >> na->last_userhost_real; - - if (na->registered == Anope::CurTime) - data["time_registered"] >> na->registered; if (na->registered < na->nc->registered) na->nc->registered = na->registered; // End 2.0 compatibility. diff --git a/src/nickcore.cpp b/src/nickcore.cpp index 127aea921..386e5e243 100644 --- a/src/nickcore.cpp +++ b/src/nickcore.cpp @@ -82,9 +82,9 @@ void NickCore::Type::Serialize(Serializable *obj, Serialize::Data &data) const data.Store("pass", nc->pass); data.Store("email", nc->email); data.Store("language", nc->language); - data.Store("lastmail", nc->lastmail); - data.Store("registered", nc->registered); - data.Store("memomax", nc->memos.memomax); + data.Store("lastmail", nc->lastmail); + data.Store("registered", nc->registered); + data.Store("memomax", nc->memos.memomax); std::ostringstream oss; for (const auto &ignore : nc->memos.ignores) @@ -97,97 +97,61 @@ void NickCore::Type::Serialize(Serializable *obj, Serialize::Data &data) const Serializable *NickCore::Type::Unserialize(Serializable *obj, Serialize::Data &data) const { NickCore *nc; - - Anope::string sdisplay; - data["display"] >> sdisplay; - - uint64_t sid = 0; - data["uniqueid"] >> sid; - if (obj) nc = anope_dynamic_static_cast(obj); else - nc = new NickCore(sdisplay, sid); + nc = new NickCore(data.Load("display"), data.Load("uniqueid")); - data["pass"] >> nc->pass; - data["email"] >> nc->email; - data["language"] >> nc->language; - data["lastmail"] >> nc->lastmail; - data["registered"] >> nc->registered; - data["memomax"] >> nc->memos.memomax; + nc->pass = data.Load("pass"); + nc->email = data.Load("email"); + nc->language = data.Load("language"); + nc->lastmail = data.Load("lastmail"); + nc->registered = data.Load("registered", data.Load("time_registered")); + nc->memos.memomax = data.Load("memomax"); { - Anope::string buf; - data["memoignores"] >> buf; - spacesepstream sep(buf); nc->memos.ignores.clear(); - while (sep.GetToken(buf)) + spacesepstream sep(data.Load("memoignores")); + for (Anope::string buf; sep.GetToken(buf); ) nc->memos.ignores.insert(buf); } Extensible::ExtensibleUnserialize(nc, nc, data); // Begin 1.9 compatibility. - bool b; - b = false; - data["extensible:PRIVATE"] >> b; - if (b) + if (data.Load("extensible:PRIVATE")) nc->Extend("NS_PRIVATE"); - b = false; - data["extensible:AUTOOP"] >> b; - if (b) + if (data.Load("extensible:AUTOOP")) nc->Extend("AUTOOP"); - b = false; - data["extensible:HIDE_EMAIL"] >> b; - if (b) + if (data.Load("extensible:HIDE_EMAIL")) nc->Extend("HIDE_EMAIL"); - b = false; - data["extensible:HIDE_QUIT"] >> b; - if (b) + if (data.Load("extensible:HIDE_QUIT")) nc->Extend("HIDE_QUIT"); - b = false; - data["extensible:MEMO_RECEIVE"] >> b; - if (b) + if (data.Load("extensible:MEMO_RECEIVE")) nc->Extend("MEMO_RECEIVE"); - b = false; - data["extensible:MEMO_SIGNON"] >> b; - if (b) + if (data.Load("extensible:MEMO_SIGNON")) nc->Extend("MEMO_SIGNON"); - b = false; - data["extensible:KILLPROTECT"] >> b; - if (b) + if (data.Load("extensible:KILLPROTECT")) nc->Extend("PROTECT"); // End 1.9 compatibility - // Begin 2.0 compatibility. - b = false; - data["KILLPROTECT"] >> b; - if (b) + if (data.Load("KILLPROTECT")) { nc->Extend("PROTECT"); nc->Extend("PROTECT_AFTER", Config->GetModule("nickserv").Get("kill", "60s")); } - b = false; - data["KILL_QUICK"] >> b; - if (b) + if (data.Load("KILL_QUICK")) { nc->Extend("PROTECT"); nc->Extend("PROTECT_AFTER", Config->GetModule("nickserv").Get("killquick", "20s")); } - b = false; - data["KILL_IMMED"] >> b; - if (b) + if (data.Load("KILL_IMMED")) { nc->Extend("PROTECT"); nc->Extend("PROTECT_AFTER", 0); } // End 2.0 compatibility. - // Begin 2.1 compatibility. - if (nc->registered == Anope::CurTime) - data["time_registered"] >> nc->registered; - // End 2.1 compatibility. - return nc; } diff --git a/src/regchannel.cpp b/src/regchannel.cpp index 5ddc65900..457378ccc 100644 --- a/src/regchannel.cpp +++ b/src/regchannel.cpp @@ -139,47 +139,41 @@ void ChannelInfo::Type::Serialize(Serializable *obj, Serialize::Data &data) cons Serializable *ChannelInfo::Type::Unserialize(Serializable *obj, Serialize::Data &data) const { - Anope::string sname, sfounder, ssuccessor, slevels, sbi; - uint64_t sfounderid = 0, ssuccessorid = 0; - - data["name"] >> sname; - data["founder"] >> sfounder; // Deprecated 2.0 field - data["founderid"] >> sfounderid; - data["successor"] >> ssuccessor; // Deprecated 2.0 field - data["successorid"] >> ssuccessorid; - data["levels"] >> slevels; - data["bi"] >> sbi; - ChannelInfo *ci; if (obj) ci = anope_dynamic_static_cast(obj); else - ci = new ChannelInfo(sname); + ci = new ChannelInfo(data.Load("name")); - ci->SetFounder(sfounderid ? NickCore::FindId(sfounderid) : NickCore::Find(sfounder)); - ci->SetSuccessor(ssuccessorid ? NickCore::FindId(ssuccessorid) : NickCore::Find(ssuccessor)); + const auto sfounderid = data.Load("founderid"); + ci->SetFounder(sfounderid ? NickCore::FindId(sfounderid) : NickCore::Find(data.Load("founder"))); - data["description"] >> ci->desc; - data["registered"] >> ci->registered; - data["last_used"] >> ci->last_used; - data["last_topic"] >> ci->last_topic; - data["last_topic_setter"] >> ci->last_topic_setter; - data["last_topic_time"] >> ci->last_topic_time; - data["bantype"] >> ci->bantype; + const auto ssuccessorid = data.Load("successorid"); + ci->SetSuccessor(ssuccessorid ? NickCore::FindId(ssuccessorid) : NickCore::Find(data.Load("successor"))); + + ci->desc = data.Load("description"); + ci->registered = data.Load("registered", data.Load("time_registered")); + ci->last_used = data.Load("last_used"); + ci->last_topic = data.Load("last_topic"); + ci->last_topic_setter = data.Load("last_topic_setter"); + ci->last_topic_time = data.Load("last_topic_time"); + ci->bantype = data.Load("bantype"); { std::vector v; - spacesepstream(slevels).GetTokens(v); + spacesepstream(data.Load("levels")).GetTokens(v); for (unsigned i = 0; i + 1 < v.size(); i += 2) { // Begin 2.0 compatibility. if (v[i] == "FANTASIA") v[i] = "FANTASY"; // End 2.0 compatibility. + if (auto level = Anope::TryConvert(v[i + 1])) ci->levels[v[i]] = level.value(); } } - BotInfo *bi = BotInfo::Find(sbi, true); + + auto *bi = BotInfo::Find(data.Load("bi"), true); if (*ci->bi != bi) { if (bi) @@ -187,11 +181,12 @@ Serializable *ChannelInfo::Type::Unserialize(Serializable *obj, Serialize::Data else if (ci->bi) ci->bi->UnAssign(NULL, ci); } - data["banexpire"] >> ci->banexpire; - data["memomax"] >> ci->memos.memomax; + + ci->banexpire = data.Load("banexpire"); + ci->memos.memomax = data.Load("memomax"); { Anope::string buf; - data["memoignores"] >> buf; + buf = data.Load("memoignores"); spacesepstream sep(buf); ci->memos.ignores.clear(); while (sep.GetToken(buf)) @@ -201,53 +196,30 @@ Serializable *ChannelInfo::Type::Unserialize(Serializable *obj, Serialize::Data Extensible::ExtensibleUnserialize(ci, ci, data); // Begin 1.9 compatibility. - bool b; - b = false; - data["extensible:PRIVATE"] >> b; - if (b) + if (data.Load("extensible:PRIVATE")) ci->Extend("CS_PRIVATE"); - b = false; - data["extensible:NO_EXPIRE"] >> b; - if (b) + if (data.Load("extensible:NO_EXPIRE")) ci->Extend("CS_NO_EXPIRE"); - b = false; - data["extensible:FANTASY"] >> b; - if (b) + if (data.Load("extensible:FANTASY")) ci->Extend("BS_FANTASY"); - b = false; - data["extensible:GREET"] >> b; - if (b) + if (data.Load("extensible:GREET")) ci->Extend("BS_GREET"); - b = false; - data["extensible:PEACE"] >> b; - if (b) + if (data.Load("extensible:PEACE")) ci->Extend("PEACE"); - b = false; - data["extensible:SECUREFOUNDER"] >> b; - if (b) + if (data.Load("extensible:SECUREFOUNDER")) ci->Extend("SECUREFOUNDER"); - b = false; - data["extensible:RESTRICTED"] >> b; - if (b) + if (data.Load("extensible:RESTRICTED")) ci->Extend("RESTRICTED"); - b = false; - data["extensible:KEEPTOPIC"] >> b; - if (b) + if (data.Load("extensible:KEEPTOPIC")) ci->Extend("KEEPTOPIC"); - b = false; - data["extensible:SIGNKICK"] >> b; - if (b) + if (data.Load("extensible:SIGNKICK")) ci->Extend("SIGNKICK"); - b = false; - data["extensible:SIGNKICK_LEVEL"] >> b; - if (b) + if (data.Load("extensible:SIGNKICK_LEVEL")) ci->Extend("SIGNKICK_LEVEL"); // End 1.9 compatibility. // Begin 2.0 compatibility. - if (ci->registered == Anope::CurTime) - data["time_registered"] >> ci->registered; - if (ci->registered == 0) + if (!ci->registered) ci->registered = ci->last_used ? ci->last_used : Anope::CurTime; // Probably corrupt database. // End 2.0 compatibility. diff --git a/src/xline.cpp b/src/xline.cpp index a5492f4f6..9fa5339dc 100644 --- a/src/xline.cpp +++ b/src/xline.cpp @@ -187,11 +187,7 @@ void XLine::Type::Serialize(Serializable *obj, Serialize::Data &data) const Serializable *XLine::Type::Unserialize(Serializable *obj, Serialize::Data &data) const { - Anope::string smanager; - - data["manager"] >> smanager; - - ServiceReference xlm("XLineManager", smanager); + ServiceReference xlm("XLineManager", data.Load("manager")); if (!xlm) return NULL; @@ -199,10 +195,10 @@ Serializable *XLine::Type::Unserialize(Serializable *obj, Serialize::Data &data) if (obj) { xl = anope_dynamic_static_cast(obj); - data["mask"] >> xl->mask; - data["by"] >> xl->by; - data["reason"] >> xl->reason; - data["uid"] >> xl->id; + xl->mask = data.Load("mask"); + xl->by = data.Load("by"); + xl->reason = data.Load("reason"); + xl->id = data.Load("uid"); if (xlm != xl->manager) { @@ -212,20 +208,12 @@ Serializable *XLine::Type::Unserialize(Serializable *obj, Serialize::Data &data) } else { - Anope::string smask, sby, sreason, suid; - time_t expires; - - data["mask"] >> smask; - data["by"] >> sby; - data["reason"] >> sreason; - data["uid"] >> suid; - data["expires"] >> expires; - - xl = new XLine(smask, sby, expires, sreason, suid); + xl = new XLine(data.Load("mask"), data.Load("by"), data.Load("expires"), + data.Load("reason"), data.Load("uid")); xlm->AddXLine(xl); } - data["created"] >> xl->created; + xl->created = data.Load("created"); xl->manager = xlm; return xl;