summaryrefslogtreecommitdiff
path: root/modules/operserv
diff options
context:
space:
mode:
Diffstat (limited to 'modules/operserv')
-rw-r--r--modules/operserv/os_dns.cpp102
-rw-r--r--modules/operserv/os_forbid.cpp40
-rw-r--r--modules/operserv/os_ignore.cpp35
-rw-r--r--modules/operserv/os_info.cpp33
-rw-r--r--modules/operserv/os_news.cpp39
-rw-r--r--modules/operserv/os_oper.cpp48
-rw-r--r--modules/operserv/os_session.cpp51
-rw-r--r--modules/operserv/os_stats.cpp23
8 files changed, 267 insertions, 104 deletions
diff --git a/modules/operserv/os_dns.cpp b/modules/operserv/os_dns.cpp
index 147e29eaa..d1b02affe 100644
--- a/modules/operserv/os_dns.cpp
+++ b/modules/operserv/os_dns.cpp
@@ -37,15 +37,38 @@ struct DNSZone final
zones->erase(it);
}
- void Serialize(Serialize::Data &data) const override
+ static DNSZone *Find(const Anope::string &name)
+ {
+ for (auto *zone : *zones)
+ {
+ if (zone->name.equals_ci(name))
+ {
+ zone->QueueUpdate();
+ return zone;
+ }
+ }
+ return NULL;
+ }
+};
+
+struct DNSZoneType final
+ : Serialize::Type
+{
+ DNSZoneType()
+ : Serialize::Type("DNSZone")
{
- data.Store("name", name);
+ }
+
+ void Serialize(const Serializable *obj, Serialize::Data &data) const override
+ {
+ const auto *zone = static_cast<const DNSZone *>(obj);
+ data.Store("name", zone->name);
unsigned count = 0;
- for (const auto &server : servers)
+ for (const auto &server : zone->servers)
data.Store("server" + Anope::ToString(count++), server);
}
- static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
+ Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override
{
DNSZone *zone;
Anope::string zone_name;
@@ -72,19 +95,6 @@ struct DNSZone final
return zone;
}
-
- static DNSZone *Find(const Anope::string &name)
- {
- for (auto *zone : *zones)
- {
- if (zone->name.equals_ci(name))
- {
- zone->QueueUpdate();
- return zone;
- }
- }
- return NULL;
- }
};
class DNSServer final
@@ -99,6 +109,8 @@ class DNSServer final
bool active = false;
public:
+ friend class DNSServerType;
+
std::set<Anope::string, ci::less> zones;
time_t repool = 0;
@@ -142,19 +154,40 @@ public:
}
}
- void Serialize(Serialize::Data &data) const override
+ static DNSServer *Find(const Anope::string &s)
+ {
+ for (auto *serv : *dns_servers)
+ if (serv->GetName().equals_ci(s))
+ {
+ serv->QueueUpdate();
+ return serv;
+ }
+ return NULL;
+ }
+};
+
+struct DNSServerType final
+ : Serialize::Type
+{
+ DNSServerType()
+ : Serialize::Type("DNSServer")
{
- data.Store("server_name", server_name);
- for (unsigned i = 0; i < ips.size(); ++i)
- data.Store("ip" + Anope::ToString(i), ips[i]);
- data.Store("limit", limit);
- data.Store("pooled", pooled);
+ }
+
+ void Serialize(const Serializable *obj, Serialize::Data &data) const override
+ {
+ const auto *req = static_cast<const DNSServer *>(obj);
+ data.Store("server_name", req->server_name);
+ for (unsigned i = 0; i < req->ips.size(); ++i)
+ data.Store("ip" + Anope::ToString(i), req->ips[i]);
+ data.Store("limit", req->limit);
+ data.Store("pooled", req->pooled);
unsigned count = 0;
- for (const auto &zone : zones)
+ for (const auto &zone : req->zones)
data.Store("zone" + Anope::ToString(count++), zone);
}
- static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
+ Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override
{
DNSServer *req;
Anope::string server_name;
@@ -193,17 +226,6 @@ public:
return req;
}
-
- static DNSServer *Find(const Anope::string &s)
- {
- for (auto *serv : *dns_servers)
- if (serv->GetName().equals_ci(s))
- {
- serv->QueueUpdate();
- return serv;
- }
- return NULL;
- }
};
class CommandOSDNS final
@@ -721,7 +743,8 @@ public:
class ModuleDNS final
: public Module
{
- Serialize::Type zone_type, dns_type;
+ DNSZoneType zone_type;
+ DNSServerType dns_type;
CommandOSDNS commandosdns;
time_t ttl;
@@ -734,8 +757,9 @@ class ModuleDNS final
time_t last_warn = 0;
public:
- ModuleDNS(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR),
- zone_type("DNSZone", DNSZone::Unserialize), dns_type("DNSServer", DNSServer::Unserialize), commandosdns(this)
+ ModuleDNS(const Anope::string &modname, const Anope::string &creator)
+ : Module(modname, creator, EXTRA | VENDOR)
+ , commandosdns(this)
{
for (auto *s : *dns_servers)
{
diff --git a/modules/operserv/os_forbid.cpp b/modules/operserv/os_forbid.cpp
index 36bddb998..6c34cb0e7 100644
--- a/modules/operserv/os_forbid.cpp
+++ b/modules/operserv/os_forbid.cpp
@@ -19,21 +19,32 @@ struct ForbidDataImpl final
, Serializable
{
ForbidDataImpl() : Serializable("ForbidData") { }
- void Serialize(Serialize::Data &data) const override;
- static Serializable *Unserialize(Serializable *obj, Serialize::Data &data);
};
-void ForbidDataImpl::Serialize(Serialize::Data &data) const
+struct ForbidDataTypeImpl final
+ : Serialize::Type
{
- data.Store("mask", this->mask);
- data.Store("creator", this->creator);
- data.Store("reason", this->reason);
- data.Store("created", this->created);
- data.Store("expires", this->expires);
- data.Store("type", this->type);
+ ForbidDataTypeImpl()
+ : Serialize::Type("ForbidData")
+ {
+ }
+
+ void Serialize(const Serializable *obj, Serialize::Data &data) const override;
+ Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override;
+};
+
+void ForbidDataTypeImpl::Serialize(const Serializable *obj, Serialize::Data &data) const
+{
+ const auto *fb = static_cast<const ForbidDataImpl *>(obj);
+ data.Store("mask", fb->mask);
+ data.Store("creator", fb->creator);
+ data.Store("reason", fb->reason);
+ data.Store("created", fb->created);
+ data.Store("expires", fb->expires);
+ data.Store("type", fb->type);
}
-Serializable *ForbidDataImpl::Unserialize(Serializable *obj, Serialize::Data &data)
+Serializable *ForbidDataTypeImpl::Unserialize(Serializable *obj, Serialize::Data &data) const
{
if (!forbid_service)
return NULL;
@@ -465,14 +476,15 @@ class OSForbid final
: public Module
{
MyForbidService forbidService;
- Serialize::Type forbiddata_type;
+ ForbidDataTypeImpl forbiddata_type;
CommandOSForbid commandosforbid;
public:
- OSForbid(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
- forbidService(this), forbiddata_type("ForbidData", ForbidDataImpl::Unserialize), commandosforbid(this)
+ OSForbid(const Anope::string &modname, const Anope::string &creator)
+ : Module(modname, creator, VENDOR)
+ , forbidService(this)
+ , commandosforbid(this)
{
-
}
void OnUserConnect(User *u, bool &exempt) override
diff --git a/modules/operserv/os_ignore.cpp b/modules/operserv/os_ignore.cpp
index e0c8eeb2c..41b7ae858 100644
--- a/modules/operserv/os_ignore.cpp
+++ b/modules/operserv/os_ignore.cpp
@@ -18,8 +18,6 @@ struct IgnoreDataImpl final
{
IgnoreDataImpl() : Serializable("IgnoreData") { }
~IgnoreDataImpl() override;
- void Serialize(Serialize::Data &data) const override;
- static Serializable *Unserialize(Serializable *obj, Serialize::Data &data);
};
IgnoreDataImpl::~IgnoreDataImpl()
@@ -28,15 +26,27 @@ IgnoreDataImpl::~IgnoreDataImpl()
ignore_service->DelIgnore(this);
}
-void IgnoreDataImpl::Serialize(Serialize::Data &data) const
+struct IgnoreDataTypeImpl final
+ : public Serialize::Type
{
- data.Store("mask", this->mask);
- data.Store("creator", this->creator);
- data.Store("reason", this->reason);
- data.Store("time", this->time);
+ IgnoreDataTypeImpl()
+ : Serialize::Type("IgnoreData")
+ {
+ }
+ void Serialize(const Serializable *obj, Serialize::Data &data) const override;
+ Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override;
+};
+
+void IgnoreDataTypeImpl::Serialize(const Serializable *obj, Serialize::Data &data) const
+{
+ const auto *ign = static_cast<const IgnoreDataImpl *>(obj);
+ data.Store("mask", ign->mask);
+ data.Store("creator", ign->creator);
+ data.Store("reason", ign->reason);
+ data.Store("time", ign->time);
}
-Serializable *IgnoreDataImpl::Unserialize(Serializable *obj, Serialize::Data &data)
+Serializable *IgnoreDataTypeImpl::Unserialize(Serializable *obj, Serialize::Data &data) const
{
if (!ignore_service)
return NULL;
@@ -398,15 +408,16 @@ public:
class OSIgnore final
: public Module
{
- Serialize::Type ignoredata_type;
+ IgnoreDataTypeImpl ignoredata_type;
OSIgnoreService osignoreservice;
CommandOSIgnore commandosignore;
public:
- OSIgnore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
- ignoredata_type("IgnoreData", IgnoreDataImpl::Unserialize), osignoreservice(this), commandosignore(this)
+ OSIgnore(const Anope::string &modname, const Anope::string &creator)
+ : Module(modname, creator, VENDOR)
+ , osignoreservice(this)
+ , commandosignore(this)
{
-
}
void Prioritize() override
diff --git a/modules/operserv/os_info.cpp b/modules/operserv/os_info.cpp
index ed111a3cd..05ff6af07 100644
--- a/modules/operserv/os_info.cpp
+++ b/modules/operserv/os_info.cpp
@@ -25,16 +25,26 @@ struct OperInfoImpl final
}
~OperInfoImpl() override;
+};
+
+struct OperInfoTypeImpl
+ : Serialize::Type
+{
+ OperInfoTypeImpl()
+ : Serialize::Type("OperInfo")
+ {
+ }
- void Serialize(Serialize::Data &data) const override
+ void Serialize(const Serializable *obj, Serialize::Data &data) const override
{
- data.Store("target", target);
- data.Store("info", info);
- data.Store("adder", adder);
- data.Store("created", created);
+ const auto *oi = static_cast<const OperInfoImpl *>(obj);
+ data.Store("target", oi->target);
+ data.Store("info", oi->info);
+ data.Store("adder", oi->adder);
+ data.Store("created", oi->created);
}
- static Serializable *Unserialize(Serializable *obj, Serialize::Data &data);
+ Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override;
};
struct OperInfos final
@@ -71,7 +81,7 @@ OperInfoImpl::~OperInfoImpl()
}
}
-Serializable *OperInfoImpl::Unserialize(Serializable *obj, Serialize::Data &data)
+Serializable *OperInfoTypeImpl::Unserialize(Serializable *obj, Serialize::Data &data) const
{
Anope::string starget;
data["target"] >> starget;
@@ -256,7 +266,7 @@ class OSInfo final
{
CommandOSInfo commandosinfo;
ExtensibleItem<OperInfos> oinfo;
- Serialize::Type oinfo_type;
+ OperInfoTypeImpl oinfo_type;
void OnInfo(CommandSource &source, Extensible *e, InfoFormatter &info)
{
@@ -274,10 +284,11 @@ class OSInfo final
}
public:
- OSInfo(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
- commandosinfo(this), oinfo(this, "operinfo"), oinfo_type("OperInfo", OperInfoImpl::Unserialize)
+ OSInfo(const Anope::string &modname, const Anope::string &creator)
+ : Module(modname, creator, VENDOR)
+ , commandosinfo(this)
+ , oinfo(this, "operinfo")
{
-
}
void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) override
diff --git a/modules/operserv/os_news.cpp b/modules/operserv/os_news.cpp
index 031e6f5d5..e5b6b057c 100644
--- a/modules/operserv/os_news.cpp
+++ b/modules/operserv/os_news.cpp
@@ -64,18 +64,24 @@ struct NewsMessages msgarray[] = {
}
};
-struct MyNewsItem final
- : NewsItem
+struct NewsItemType final
+ : Serialize::Type
{
- void Serialize(Serialize::Data &data) const override
+ NewsItemType()
+ : Serialize::Type("NewsItem")
{
- data.Store("type", this->type);
- data.Store("text", this->text);
- data.Store("who", this->who);
- data.Store("time", this->time);
}
- static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
+ void Serialize(const Serializable *obj, Serialize::Data &data) const override
+ {
+ const auto *ni = static_cast<const NewsItem *>(obj);
+ data.Store("type", ni->type);
+ data.Store("text", ni->text);
+ data.Store("who", ni->who);
+ data.Store("time", ni->time);
+ }
+
+ Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override
{
if (!news_service)
return NULL;
@@ -84,7 +90,7 @@ struct MyNewsItem final
if (obj)
ni = anope_dynamic_static_cast<NewsItem *>(obj);
else
- ni = new MyNewsItem();
+ ni = new NewsItem();
unsigned int t;
data["type"] >> t;
@@ -117,7 +123,7 @@ public:
NewsItem *CreateNewsItem() override
{
- return new MyNewsItem();
+ return new NewsItem();
}
void AddNewsItem(NewsItem *n) override
@@ -200,7 +206,7 @@ protected:
if (Anope::ReadOnly)
source.Reply(READ_ONLY_MODE);
- NewsItem *news = new MyNewsItem();
+ NewsItem *news = new NewsItem();
news->type = ntype;
news->text = text;
news->time = Anope::CurTime;
@@ -382,7 +388,7 @@ class OSNews final
: public Module
{
MyNewsService newsservice;
- Serialize::Type newsitem_type;
+ NewsItemType newsitem_type;
CommandOSLogonNews commandoslogonnews;
CommandOSOperNews commandosopernews;
@@ -442,9 +448,12 @@ class OSNews final
}
public:
- OSNews(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
- newsservice(this), newsitem_type("NewsItem", MyNewsItem::Unserialize),
- commandoslogonnews(this), commandosopernews(this), commandosrandomnews(this)
+ OSNews(const Anope::string &modname, const Anope::string &creator)
+ : Module(modname, creator, VENDOR)
+ , newsservice(this)
+ , commandoslogonnews(this)
+ , commandosopernews(this)
+ , commandosrandomnews(this)
{
}
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)
{
}
diff --git a/modules/operserv/os_session.cpp b/modules/operserv/os_session.cpp
index 3d78340a7..e6111827f 100644
--- a/modules/operserv/os_session.cpp
+++ b/modules/operserv/os_session.cpp
@@ -35,6 +35,47 @@ namespace
unsigned ipv6_cidr;
}
+struct ExceptionType final
+ : public Serialize::Type
+{
+ ExceptionType()
+ : Serialize::Type("Exception")
+ {
+ }
+
+ void Serialize(const Serializable *obj, Serialize::Data &data) const override
+ {
+ const auto *ex = static_cast<const Exception *>(obj);
+ data.Store("mask", ex->mask);
+ data.Store("limit", ex->limit);
+ data.Store("who", ex->who);
+ data.Store("reason", ex->reason);
+ data.Store("time", ex->time);
+ }
+
+ Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override
+ {
+ if (!session_service)
+ return NULL;
+
+ Exception *ex;
+ if (obj)
+ ex = anope_dynamic_static_cast<Exception *>(obj);
+ else
+ ex = new 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;
+
+ if (!obj)
+ session_service->AddException(ex);
+ return ex;
+ }
+};
+
class MySessionService final
: public SessionService
{
@@ -573,15 +614,19 @@ public:
class OSSession final
: public Module
{
- Serialize::Type exception_type;
+ ExceptionType exception_type;
MySessionService ss;
CommandOSSession commandossession;
CommandOSException commandosexception;
ServiceReference<XLineManager> akills;
public:
- OSSession(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
- exception_type("Exception", Exception::Unserialize), ss(this), commandossession(this), commandosexception(this), akills("XLineManager", "xlinemanager/sgline")
+ OSSession(const Anope::string &modname, const Anope::string &creator)
+ : Module(modname, creator, VENDOR)
+ , ss(this)
+ , commandossession(this)
+ , commandosexception(this)
+ , akills("XLineManager", "xlinemanager/sgline")
{
this->SetPermanent(true);
}
diff --git a/modules/operserv/os_stats.cpp b/modules/operserv/os_stats.cpp
index 14055971b..4b94a8f46 100644
--- a/modules/operserv/os_stats.cpp
+++ b/modules/operserv/os_stats.cpp
@@ -21,18 +21,27 @@ struct Stats final
{
me = this;
}
+};
+
+struct StatsType final
+ : Serialize::Type
+{
+ StatsType()
+ : Serialize::Type("Stats")
+ {
+ }
- void Serialize(Serialize::Data &data) const override
+ void Serialize(const Serializable *obj, Serialize::Data &data) const override
{
data.Store("maxusercnt", MaxUserCount);
data.Store("maxusertime", MaxUserTime);
}
- static Serializable *Unserialize(Serializable *obj, Serialize::Data &data)
+ Serializable *Unserialize(Serializable *obj, Serialize::Data &data) const override
{
data["maxusercnt"] >> MaxUserCount;
data["maxusertime"] >> MaxUserTime;
- return me;
+ return obj;
}
};
@@ -316,14 +325,14 @@ class OSStats final
: public Module
{
CommandOSStats commandosstats;
- Serialize::Type stats_type;
+ StatsType stats_type;
Stats stats_saver;
public:
- OSStats(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR),
- commandosstats(this), stats_type("Stats", Stats::Unserialize)
+ OSStats(const Anope::string &modname, const Anope::string &creator)
+ : Module(modname, creator, VENDOR)
+ , commandosstats(this)
{
-
}
void OnUserConnect(User *u, bool &exempt) override