mirror of
https://github.com/anope/anope.git
synced 2026-07-07 22:43:12 +02:00
Move serialization from Serializable to a Serialize::Type child.
This commit is contained in:
@@ -12,6 +12,47 @@
|
||||
#include "module.h"
|
||||
#include "modules/operserv/oper.h"
|
||||
|
||||
struct OSOperType
|
||||
: Serialize::Type
|
||||
{
|
||||
OSOperType()
|
||||
: Serialize::Type("Oper")
|
||||
{
|
||||
}
|
||||
|
||||
void Serialize(const Serializable *obj, Serialize::Data &data) const override
|
||||
{
|
||||
const auto *myo = static_cast<const MyOper *>(obj);
|
||||
data.Store("name", myo->name);
|
||||
data.Store("type", myo->ot->GetName());
|
||||
}
|
||||
|
||||
Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override
|
||||
{
|
||||
Anope::string stype, sname;
|
||||
|
||||
data["type"] >> stype;
|
||||
data["name"] >> sname;
|
||||
|
||||
OperType *ot = OperType::Find(stype);
|
||||
if (ot == NULL)
|
||||
return NULL;
|
||||
NickCore *nc = NickCore::Find(sname);
|
||||
if (nc == NULL)
|
||||
return NULL;
|
||||
|
||||
MyOper *myo;
|
||||
if (obj)
|
||||
myo = anope_dynamic_static_cast<MyOper *>(obj);
|
||||
else
|
||||
myo = new MyOper(nc->display, ot);
|
||||
nc->o = myo;
|
||||
Log(LOG_NORMAL, "operserv/oper") << "Tied oper " << nc->display << " to type " << ot->GetName();
|
||||
return myo;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
class CommandOSOper final
|
||||
: public Command
|
||||
{
|
||||
@@ -222,12 +263,13 @@ public:
|
||||
class OSOper final
|
||||
: public Module
|
||||
{
|
||||
Serialize::Type myoper_type;
|
||||
OSOperType myoper_type;
|
||||
CommandOSOper commandosoper;
|
||||
|
||||
public:
|
||||
OSOper(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
|
||||
myoper_type("Oper", MyOper::Unserialize), commandosoper(this)
|
||||
OSOper(const Anope::string &modname, const Anope::string &creator)
|
||||
: Module(modname, creator, VENDOR)
|
||||
, commandosoper(this)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user