mirror of
https://github.com/anope/anope.git
synced 2026-06-12 15:44:46 +02:00
Add Data::Load, make the istream operator private.
This commit is contained in:
@@ -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<bool>(this->name))
|
||||
this->Set(e);
|
||||
else
|
||||
this->Unset(e);
|
||||
|
||||
+74
-33
@@ -40,43 +40,11 @@ namespace Serialize
|
||||
UINT,
|
||||
};
|
||||
|
||||
class CoreExport Data
|
||||
{
|
||||
protected:
|
||||
std::map<Anope::string, Serialize::DataType> types;
|
||||
|
||||
public:
|
||||
virtual ~Data() = default;
|
||||
|
||||
virtual std::iostream &operator[](const Anope::string &key) = 0;
|
||||
|
||||
template <typename T>
|
||||
void Store(const Anope::string &key, const T &value)
|
||||
{
|
||||
using Type = std::remove_cv_t<std::remove_reference_t<T>>;
|
||||
|
||||
if constexpr (std::is_same_v<Type, bool>)
|
||||
SetType(key, DataType::BOOL);
|
||||
else if constexpr (std::is_floating_point_v<Type>)
|
||||
SetType(key, DataType::FLOAT);
|
||||
else if constexpr (std::is_integral_v<Type> && std::is_signed_v<Type>)
|
||||
SetType(key, DataType::INT);
|
||||
else if constexpr (std::is_integral_v<Type> && std::is_unsigned_v<Type>)
|
||||
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<typename T> class Checker;
|
||||
template<typename T> class Reference;
|
||||
@@ -141,6 +109,79 @@ public:
|
||||
static const std::list<Serializable *> &GetItems();
|
||||
};
|
||||
|
||||
class CoreExport Serialize::Data
|
||||
{
|
||||
protected:
|
||||
/** The specified data types of known fields. */
|
||||
std::map<Anope::string, Serialize::DataType> 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 <typename T = Anope::string>
|
||||
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 <typename T>
|
||||
void Store(const Anope::string &key, const T &value)
|
||||
{
|
||||
using Type = std::remove_cv_t<std::remove_reference_t<T>>;
|
||||
|
||||
if constexpr (std::is_same_v<Type, bool>)
|
||||
SetType(key, DataType::BOOL);
|
||||
else if constexpr (std::is_floating_point_v<Type>)
|
||||
SetType(key, DataType::FLOAT);
|
||||
else if constexpr (std::is_integral_v<Type> && std::is_signed_v<Type>)
|
||||
SetType(key, DataType::INT);
|
||||
else if constexpr (std::is_integral_v<Type> && std::is_unsigned_v<Type>)
|
||||
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 <typename T = Anope::string>
|
||||
bool TryLoad(const Anope::string& key, T &out)
|
||||
{
|
||||
return static_cast<bool>(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.
|
||||
|
||||
+1
-1
@@ -27,7 +27,7 @@
|
||||
#include <exception>
|
||||
#include <fstream>
|
||||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <istream>
|
||||
#include <list>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
@@ -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<BadWordImpl *>(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<BadWordsImpl>(BOTSERV_BAD_WORDS_EXT);
|
||||
if (!obj)
|
||||
|
||||
+23
-21
@@ -88,30 +88,32 @@ struct KickerDataImpl final
|
||||
auto *ci = anope_dynamic_static_cast<ChannelInfo *>(e);
|
||||
auto *kd = ci->Require<BotServ::KickerData>(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<bool>("kickerdata:amsgs");
|
||||
kd->badwords = data.Load<bool>("kickerdata:badwords");
|
||||
kd->bolds = data.Load<bool>("kickerdata:bolds");
|
||||
kd->caps = data.Load<bool>("kickerdata:caps");
|
||||
kd->colors = data.Load<bool>("kickerdata:colors");
|
||||
kd->flood = data.Load<bool>("kickerdata:flood");
|
||||
kd->italics = data.Load<bool>("kickerdata:italics");
|
||||
kd->repeat = data.Load<bool>("kickerdata:repeat");
|
||||
kd->reverses = data.Load<bool>("kickerdata:reverses");
|
||||
kd->underlines = data.Load<bool>("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<int16_t>("capsmin");
|
||||
kd->capspercent = data.Load<int16_t>("capspercent");
|
||||
kd->floodlines = data.Load<int16_t>("floodlines");
|
||||
kd->floodsecs = data.Load<int16_t>("floodsecs");
|
||||
kd->repeattimes = data.Load<int16_t>("repeattimes");
|
||||
kd->dontkickops = data.Load<bool>("dontkickops");
|
||||
kd->dontkickvoices = data.Load<bool>("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<int16_t>(tok))
|
||||
kd->ttb[i] = n.value();
|
||||
}
|
||||
|
||||
@@ -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<uint64_t>("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<time_t>("addtime");
|
||||
const auto slastused = data.Load<time_t>("last_used");
|
||||
|
||||
ChanServ::AutoKick *ak;
|
||||
auto *nc = sncid ? NickCore::FindId(sncid) : NickCore::Find(snc);
|
||||
if (obj)
|
||||
{
|
||||
ak = anope_dynamic_static_cast<ChanServ::AutoKick *>(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;
|
||||
}
|
||||
|
||||
@@ -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<time_t>("when");
|
||||
if (obj)
|
||||
{
|
||||
auto *msg = anope_dynamic_static_cast<EntryMsgImpl *>(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::EntryMessageList>(CHANSERV_ENTRY_MESSAGE_EXT);
|
||||
|
||||
data["when"] >> swhen;
|
||||
|
||||
auto *m = new EntryMsgImpl(ci, screator, smessage, swhen);
|
||||
(*messages)->push_back(m);
|
||||
return m;
|
||||
|
||||
@@ -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<time_t>("created");
|
||||
|
||||
return ls;
|
||||
}
|
||||
|
||||
@@ -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<bool>("set");
|
||||
ml->created = data.Load<time_t>("created");
|
||||
ml->setter = data.Load("setter");
|
||||
ml->name = data.Load("name");
|
||||
ml->param = data.Load("param");
|
||||
|
||||
if (!obj)
|
||||
ci->Require<ModeLocksImpl>(CHANSERV_MODE_LOCK_EXT)->mlocks->push_back(ml);
|
||||
|
||||
@@ -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<time_t>("last");
|
||||
|
||||
if (!obj)
|
||||
database[s->nick] = s;
|
||||
|
||||
@@ -1139,10 +1139,10 @@ class CSSet final
|
||||
return;
|
||||
|
||||
auto *ci = anope_dynamic_static_cast<ChannelInfo *>(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] == '+')
|
||||
{
|
||||
|
||||
@@ -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<CSMiscData *>(obj);
|
||||
d->object = ci->name;
|
||||
data["name"] >> d->name;
|
||||
data["data"] >> d->data;
|
||||
d->name = sname;
|
||||
d->data = sdata;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -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<CSSuspendInfo *>(obj);
|
||||
else
|
||||
{
|
||||
ChannelInfo *ci = ChannelInfo::Find(schan);
|
||||
auto *ci = ChannelInfo::Find(data.Load("chan"));
|
||||
if (!ci)
|
||||
return NULL;
|
||||
si = ci->Extend<CSSuspendInfo>("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_t>("time");
|
||||
si->expires = data.Load<time_t>("expires");
|
||||
return si;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -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<time_t>("created");
|
||||
ho->expires = data.Load<time_t>("expires");
|
||||
|
||||
if (!obj)
|
||||
host_offers->Add(ho);
|
||||
|
||||
@@ -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_t>("time");
|
||||
req->validation_token = data.Load("validation_token");
|
||||
req->last_validation = data.Load<time_t>("last_validation");
|
||||
}
|
||||
|
||||
return req;
|
||||
|
||||
@@ -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<uint64_t>("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)
|
||||
{
|
||||
|
||||
@@ -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<uint64_t>("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<time_t>("created");
|
||||
cert->creator = data.Load("creator");
|
||||
cert->description = data.Load("description");
|
||||
cert->fingerprint = data.Load("fingerprint");
|
||||
|
||||
if (!obj)
|
||||
{
|
||||
|
||||
@@ -156,10 +156,10 @@ private:
|
||||
return;
|
||||
|
||||
auto *nc = anope_dynamic_static_cast<NickCore *>(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] == '+')
|
||||
{
|
||||
|
||||
@@ -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<NSMiscData *>(obj);
|
||||
d->object = nc->display;
|
||||
data["name"] >> d->name;
|
||||
data["data"] >> d->data;
|
||||
d->name = sname;
|
||||
d->data = sdata;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -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<NSSuspendInfo *>(obj);
|
||||
else
|
||||
{
|
||||
NickAlias *na = NickAlias::Find(snick);
|
||||
auto *na = NickAlias::Find(data.Load("nick"));
|
||||
if (!na)
|
||||
return NULL;
|
||||
|
||||
si = na->nc->Extend<NSSuspendInfo>("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_t>("time");
|
||||
si->expires = data.Load<time_t>("expires");
|
||||
return si;
|
||||
}
|
||||
};
|
||||
|
||||
+12
-14
@@ -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<DNSZone *>(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<DNSServer *>(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<unsigned>("limit");
|
||||
req->pooled = data.Load<bool>("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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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<time_t>("created");
|
||||
fb->expires = data.Load<time_t>("expires");
|
||||
fb->type = StringToType(data.Load("type"));
|
||||
|
||||
if (fb->type == OperServ::FT_SIZE)
|
||||
return NULL;
|
||||
|
||||
@@ -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_t>("time");
|
||||
|
||||
return ign;
|
||||
}
|
||||
|
||||
@@ -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<time_t>("created");
|
||||
|
||||
if (!obj)
|
||||
(*oi)->push_back(o);
|
||||
|
||||
@@ -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_t>("time");
|
||||
|
||||
if (!obj)
|
||||
OperServ::news_service->AddNewsItem(ni);
|
||||
|
||||
@@ -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<OperServ::Oper *>(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;
|
||||
|
||||
@@ -66,12 +66,13 @@ struct ExceptionType final
|
||||
ex = anope_dynamic_static_cast<OperServ::Exception *>(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<unsigned>("limit");
|
||||
ex->who = data.Load("who");
|
||||
ex->reason = data.Load("reason");
|
||||
ex->time = data.Load<time_t>("time");
|
||||
ex->expires = data.Load<time_t>("expires");
|
||||
|
||||
if (!obj)
|
||||
OperServ::session_service->AddException(ex);
|
||||
|
||||
@@ -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<size_t>("maxusercnt");
|
||||
MaxUserTime = data.Load<time_t>("maxusertime");
|
||||
return Stats::me;
|
||||
}
|
||||
};
|
||||
|
||||
+9
-17
@@ -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<AccessProvider> aprovider("AccessProvider", provider);
|
||||
ChannelInfo *ci = ChannelInfo::Find(chan);
|
||||
ServiceReference<AccessProvider> 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<time_t>("last_seen");
|
||||
access->created = data.Load<time_t>("created");
|
||||
|
||||
access->AccessUnserialize(data.Load("data"));
|
||||
|
||||
if (!obj)
|
||||
ci->AddAccess(access);
|
||||
|
||||
+4
-9
@@ -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<BotInfo *>(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<time_t>("created");
|
||||
bi->oper_only = data.Load<bool>("oper_only");
|
||||
|
||||
Extensible::ExtensibleUnserialize(bi, bi, data);
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@
|
||||
#include <pwd.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <thread>
|
||||
|
||||
Anope::string Anope::ConfigDir = DEFAULT_CONF_DIR;
|
||||
|
||||
@@ -29,6 +29,8 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
|
||||
static Anope::string GetTimeStamp()
|
||||
{
|
||||
char tbuf[256];
|
||||
|
||||
+6
-8
@@ -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_t>("time");
|
||||
m->sender = data.Load("sender");
|
||||
m->text = data.Load("text");
|
||||
m->unread = data.Load<bool>("unread");
|
||||
m->receipt = data.Load<bool>("receipt");
|
||||
|
||||
if (obj == NULL)
|
||||
mi->memos->push_back(m);
|
||||
|
||||
+13
-35
@@ -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<time_t>("registered", na->registered);
|
||||
data.Store<time_t>("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<uint64_t>("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<NickAlias *>(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<time_t>("registered", data.Load<time_t>("time_registered"));
|
||||
na->last_seen = data.Load<time_t>("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<time_t>("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<bool>("extensible:NO_EXPIRE"))
|
||||
na->Extend<bool>("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.
|
||||
|
||||
+22
-58
@@ -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<time_t>("lastmail", nc->lastmail);
|
||||
data.Store<time_t>("registered", nc->registered);
|
||||
data.Store<int16_t>("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<NickCore *>(obj);
|
||||
else
|
||||
nc = new NickCore(sdisplay, sid);
|
||||
nc = new NickCore(data.Load("display"), data.Load<uint64_t>("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<time_t>("lastmail");
|
||||
nc->registered = data.Load<time_t>("registered", data.Load<time_t>("time_registered"));
|
||||
nc->memos.memomax = data.Load<int16_t>("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<bool>("extensible:PRIVATE"))
|
||||
nc->Extend<bool>("NS_PRIVATE");
|
||||
b = false;
|
||||
data["extensible:AUTOOP"] >> b;
|
||||
if (b)
|
||||
if (data.Load<bool>("extensible:AUTOOP"))
|
||||
nc->Extend<bool>("AUTOOP");
|
||||
b = false;
|
||||
data["extensible:HIDE_EMAIL"] >> b;
|
||||
if (b)
|
||||
if (data.Load<bool>("extensible:HIDE_EMAIL"))
|
||||
nc->Extend<bool>("HIDE_EMAIL");
|
||||
b = false;
|
||||
data["extensible:HIDE_QUIT"] >> b;
|
||||
if (b)
|
||||
if (data.Load<bool>("extensible:HIDE_QUIT"))
|
||||
nc->Extend<bool>("HIDE_QUIT");
|
||||
b = false;
|
||||
data["extensible:MEMO_RECEIVE"] >> b;
|
||||
if (b)
|
||||
if (data.Load<bool>("extensible:MEMO_RECEIVE"))
|
||||
nc->Extend<bool>("MEMO_RECEIVE");
|
||||
b = false;
|
||||
data["extensible:MEMO_SIGNON"] >> b;
|
||||
if (b)
|
||||
if (data.Load<bool>("extensible:MEMO_SIGNON"))
|
||||
nc->Extend<bool>("MEMO_SIGNON");
|
||||
b = false;
|
||||
data["extensible:KILLPROTECT"] >> b;
|
||||
if (b)
|
||||
if (data.Load<bool>("extensible:KILLPROTECT"))
|
||||
nc->Extend<bool>("PROTECT");
|
||||
// End 1.9 compatibility
|
||||
|
||||
|
||||
// Begin 2.0 compatibility.
|
||||
b = false;
|
||||
data["KILLPROTECT"] >> b;
|
||||
if (b)
|
||||
if (data.Load<bool>("KILLPROTECT"))
|
||||
{
|
||||
nc->Extend<bool>("PROTECT");
|
||||
nc->Extend("PROTECT_AFTER", Config->GetModule("nickserv").Get<time_t>("kill", "60s"));
|
||||
}
|
||||
b = false;
|
||||
data["KILL_QUICK"] >> b;
|
||||
if (b)
|
||||
if (data.Load<bool>("KILL_QUICK"))
|
||||
{
|
||||
nc->Extend<bool>("PROTECT");
|
||||
nc->Extend("PROTECT_AFTER", Config->GetModule("nickserv").Get<time_t>("killquick", "20s"));
|
||||
}
|
||||
b = false;
|
||||
data["KILL_IMMED"] >> b;
|
||||
if (b)
|
||||
if (data.Load<bool>("KILL_IMMED"))
|
||||
{
|
||||
nc->Extend<bool>("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;
|
||||
}
|
||||
|
||||
|
||||
+32
-60
@@ -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<ChannelInfo *>(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<uint64_t>("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<uint64_t>("successorid");
|
||||
ci->SetSuccessor(ssuccessorid ? NickCore::FindId(ssuccessorid) : NickCore::Find(data.Load("successor")));
|
||||
|
||||
ci->desc = data.Load("description");
|
||||
ci->registered = data.Load<time_t>("registered", data.Load<time_t>("time_registered"));
|
||||
ci->last_used = data.Load<time_t>("last_used");
|
||||
ci->last_topic = data.Load("last_topic");
|
||||
ci->last_topic_setter = data.Load("last_topic_setter");
|
||||
ci->last_topic_time = data.Load<time_t>("last_topic_time");
|
||||
ci->bantype = data.Load<int16_t>("bantype");
|
||||
{
|
||||
std::vector<Anope::string> 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<int16_t>(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<time_t>("banexpire");
|
||||
ci->memos.memomax = data.Load<int16_t>("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<bool>("extensible:PRIVATE"))
|
||||
ci->Extend<bool>("CS_PRIVATE");
|
||||
b = false;
|
||||
data["extensible:NO_EXPIRE"] >> b;
|
||||
if (b)
|
||||
if (data.Load<bool>("extensible:NO_EXPIRE"))
|
||||
ci->Extend<bool>("CS_NO_EXPIRE");
|
||||
b = false;
|
||||
data["extensible:FANTASY"] >> b;
|
||||
if (b)
|
||||
if (data.Load<bool>("extensible:FANTASY"))
|
||||
ci->Extend<bool>("BS_FANTASY");
|
||||
b = false;
|
||||
data["extensible:GREET"] >> b;
|
||||
if (b)
|
||||
if (data.Load<bool>("extensible:GREET"))
|
||||
ci->Extend<bool>("BS_GREET");
|
||||
b = false;
|
||||
data["extensible:PEACE"] >> b;
|
||||
if (b)
|
||||
if (data.Load<bool>("extensible:PEACE"))
|
||||
ci->Extend<bool>("PEACE");
|
||||
b = false;
|
||||
data["extensible:SECUREFOUNDER"] >> b;
|
||||
if (b)
|
||||
if (data.Load<bool>("extensible:SECUREFOUNDER"))
|
||||
ci->Extend<bool>("SECUREFOUNDER");
|
||||
b = false;
|
||||
data["extensible:RESTRICTED"] >> b;
|
||||
if (b)
|
||||
if (data.Load<bool>("extensible:RESTRICTED"))
|
||||
ci->Extend<bool>("RESTRICTED");
|
||||
b = false;
|
||||
data["extensible:KEEPTOPIC"] >> b;
|
||||
if (b)
|
||||
if (data.Load<bool>("extensible:KEEPTOPIC"))
|
||||
ci->Extend<bool>("KEEPTOPIC");
|
||||
b = false;
|
||||
data["extensible:SIGNKICK"] >> b;
|
||||
if (b)
|
||||
if (data.Load<bool>("extensible:SIGNKICK"))
|
||||
ci->Extend<bool>("SIGNKICK");
|
||||
b = false;
|
||||
data["extensible:SIGNKICK_LEVEL"] >> b;
|
||||
if (b)
|
||||
if (data.Load<bool>("extensible:SIGNKICK_LEVEL"))
|
||||
ci->Extend<bool>("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.
|
||||
|
||||
|
||||
+8
-20
@@ -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<XLineManager> xlm("XLineManager", smanager);
|
||||
ServiceReference<XLineManager> 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<XLine *>(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<time_t>("expires"),
|
||||
data.Load("reason"), data.Load("uid"));
|
||||
xlm->AddXLine(xl);
|
||||
}
|
||||
|
||||
data["created"] >> xl->created;
|
||||
xl->created = data.Load<time_t>("created");
|
||||
xl->manager = xlm;
|
||||
|
||||
return xl;
|
||||
|
||||
Reference in New Issue
Block a user