diff options
Diffstat (limited to 'modules/operserv/os_oper.cpp')
-rw-r--r-- | modules/operserv/os_oper.cpp | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/modules/operserv/os_oper.cpp b/modules/operserv/os_oper.cpp index 3eab14b2a..5a87cd6ba 100644 --- a/modules/operserv/os_oper.cpp +++ b/modules/operserv/os_oper.cpp @@ -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) { } |