summaryrefslogtreecommitdiff
path: root/modules/operserv
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2016-07-28 21:29:35 -0400
committerAdam <Adam@anope.org>2016-07-28 21:29:35 -0400
commit0e758a2ac23dc4a001e8e126cec14588da9a9769 (patch)
tree45df813323e023c5c89db7279426c4ad0943b4a9 /modules/operserv
parenta3c8afae00c54d5b95c620248b51f90679d7d53f (diff)
Allow serializable fields to use storage in the respective objects.
Split service management code nito a proper servicemanager. Make service references managed instead of lazy lookup. Also made events and serializable use service manager instead of their respective systems for management
Diffstat (limited to 'modules/operserv')
-rw-r--r--modules/operserv/akill.cpp25
-rw-r--r--modules/operserv/chankill.cpp13
-rw-r--r--modules/operserv/defcon.cpp59
-rw-r--r--modules/operserv/dns.cpp187
-rw-r--r--modules/operserv/forbid.cpp49
-rw-r--r--modules/operserv/ignore.cpp28
-rw-r--r--modules/operserv/info.cpp28
-rw-r--r--modules/operserv/login.cpp3
-rw-r--r--modules/operserv/logsearch.cpp2
-rw-r--r--modules/operserv/main/operserv.cpp46
-rw-r--r--modules/operserv/modinfo.cpp15
-rw-r--r--modules/operserv/module.cpp2
-rw-r--r--modules/operserv/news.cpp34
-rw-r--r--modules/operserv/noop.cpp3
-rw-r--r--modules/operserv/oper.cpp2
-rw-r--r--modules/operserv/reload.cpp2
-rw-r--r--modules/operserv/session.cpp67
-rw-r--r--modules/operserv/set.cpp2
-rw-r--r--modules/operserv/stats.cpp108
-rw-r--r--modules/operserv/sxline.cpp30
20 files changed, 418 insertions, 287 deletions
diff --git a/modules/operserv/akill.cpp b/modules/operserv/akill.cpp
index 7f366e0c9..1f62b2f55 100644
--- a/modules/operserv/akill.cpp
+++ b/modules/operserv/akill.cpp
@@ -1,21 +1,18 @@
/* OperServ core functions
*
- * (C) 2003-2014 Anope Team
+ * (C) 2003-2016 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
*
- * Based on the original code of Epona by Lara.
- * Based on the original code of Services by Andy Church.
*/
#include "module.h"
-static ServiceReference<XLineManager> akills("XLineManager", "xlinemanager/sgline");
-
class CommandOSAKill : public Command
{
- private:
+ ServiceReference<XLineManager> akills;
+
void DoAdd(CommandSource &source, const std::vector<Anope::string> &params)
{
Anope::string expiry, mask;
@@ -120,7 +117,12 @@ class CommandOSAKill : public Command
return;
}
- XLine *x = new XLine(mask, source.GetNick(), expires, reason);
+ XLine *x = Serialize::New<XLine *>();
+ x->SetMask(mask);
+ x->SetBy(source.GetNick());
+ x->SetExpires(expires);
+ x->SetReason(reason);
+
if (Config->GetModule("operserv")->Get<bool>("akillids"))
x->SetID(XLineManager::GenerateUID());
@@ -139,7 +141,7 @@ class CommandOSAKill : public Command
}
EventReturn MOD_RESULT;
- MOD_RESULT = Event::OnAddXLine(&Event::AddXLine::OnAddXLine, source, x, akills);
+ MOD_RESULT = EventManager::Get()->Dispatch(&Event::AddXLine::OnAddXLine, source, x, akills);
if (MOD_RESULT == EVENT_STOP)
{
delete x;
@@ -212,7 +214,7 @@ class CommandOSAKill : public Command
do
{
- Event::OnDelXLine(&Event::DelXLine::OnDelXLine, source, x, akills);
+ EventManager::Get()->Dispatch(&Event::DelXLine::OnDelXLine, source, x, akills);
Log(LOG_ADMIN, source, this) << "to remove " << x->GetMask() << " from the list";
source.Reply(_("\002{0}\002 deleted from the akill list."), x->GetMask());
@@ -256,7 +258,7 @@ class CommandOSAKill : public Command
unsigned int i = 0;
for (XLine *x : akills->GetXLines())
{
- if (mask.empty() || mask.equals_ci(x->GetMask()) || mask == x->id || Anope::Match(x->GetMask(), mask, false, true))
+ if (mask.empty() || mask.equals_ci(x->GetMask()) || mask == x->GetID() || Anope::Match(x->GetMask(), mask, false, true))
{
ListFormatter::ListEntry entry;
entry["Number"] = stringify(++i);
@@ -319,7 +321,7 @@ class CommandOSAKill : public Command
{
for (XLine *x : akills->GetXLines())
{
- Event::OnDelXLine(&Event::DelXLine::OnDelXLine, source, x, akills);
+ EventManager::Get()->Dispatch(&Event::DelXLine::OnDelXLine, source, x, akills);
x->Delete();
}
@@ -331,6 +333,7 @@ class CommandOSAKill : public Command
}
public:
CommandOSAKill(Module *creator) : Command(creator, "operserv/akill", 1, 2)
+ , akills("xlinemanager/sgline")
{
this->SetDesc(_("Manipulate the AKILL list"));
this->SetSyntax(_("ADD [+\037expiry\037] \037mask\037 \037reason\037"));
diff --git a/modules/operserv/chankill.cpp b/modules/operserv/chankill.cpp
index 8d3773e9d..81f04583b 100644
--- a/modules/operserv/chankill.cpp
+++ b/modules/operserv/chankill.cpp
@@ -11,12 +11,13 @@
#include "module.h"
-static ServiceReference<XLineManager> akills("XLineManager", "xlinemanager/sgline");
-
class CommandOSChanKill : public Command
{
+ ServiceReference<XLineManager> akills;
+
public:
CommandOSChanKill(Module *creator) : Command(creator, "operserv/chankill", 2, 3)
+ , akills("xlinemanager/sgline")
{
this->SetDesc(_("AKILL all users on a specific channel"));
this->SetSyntax(_("[+\037expiry\037] \037channel\037 \037reason\037"));
@@ -83,7 +84,13 @@ class CommandOSChanKill : public Command
if (uc->user->server == Me || uc->user->HasMode("OPER"))
continue;
- XLine *x = new XLine("*@" + uc->user->host, source.GetNick(), expires, realreason, XLineManager::GenerateUID());
+ XLine *x = Serialize::New<XLine *>();
+ x->SetMask("*@" + uc->user->host);
+ x->SetBy(source.GetNick());
+ x->SetExpires(expires);
+ x->SetReason(realreason);
+ x->SetID(XLineManager::GenerateUID());
+
akills->AddXLine(x);
akills->OnMatch(uc->user, x);
}
diff --git a/modules/operserv/defcon.cpp b/modules/operserv/defcon.cpp
index fc4a096c9..ba081eb06 100644
--- a/modules/operserv/defcon.cpp
+++ b/modules/operserv/defcon.cpp
@@ -107,11 +107,11 @@ static Timer *timeout;
class DefConTimeout : public Timer
{
- EventHandlers<Event::DefconLevel> &eventdefcon;
int level;
+ ServiceReference<Global::GlobalService> global;
public:
- DefConTimeout(EventHandlers<Event::DefconLevel> &ev, Module *mod, int newlevel) : Timer(mod, DConfig.timeout), eventdefcon(ev), level(newlevel)
+ DefConTimeout(Module *mod, int newlevel) : Timer(mod, DConfig.timeout), level(newlevel)
{
timeout = this;
}
@@ -126,18 +126,18 @@ class DefConTimeout : public Timer
if (DConfig.defaultlevel != level)
{
DConfig.defaultlevel = level;
- this->eventdefcon(&Event::DefconLevel::OnDefconLevel, level);
+ EventManager::Get()->Dispatch(&Event::DefconLevel::OnDefconLevel, level);
Log(Config->GetClient("OperServ"), "operserv/defcon") << "Defcon level timeout, returning to level " << level;
- if (DConfig.globalondefcon && Global::service)
+ if (DConfig.globalondefcon && global)
{
if (!DConfig.offmessage.empty())
- Global::service->SendGlobal(NULL, "", DConfig.offmessage);
+ global->SendGlobal(NULL, "", DConfig.offmessage);
else
- Global::service->SendGlobal(NULL, "", Anope::printf(Language::Translate(_("The Defcon level is now at: \002%d\002")), DConfig.defaultlevel));
+ global->SendGlobal(NULL, "", Anope::printf(Language::Translate(_("The Defcon level is now at: \002%d\002")), DConfig.defaultlevel));
if (!DConfig.message.empty())
- Global::service->SendGlobal(NULL, "", DConfig.message);
+ global->SendGlobal(NULL, "", DConfig.message);
}
runDefCon();
@@ -147,6 +147,8 @@ class DefConTimeout : public Timer
class CommandOSDefcon : public Command
{
+ ServiceReference<Global::GlobalService> global;
+
void SendLevels(CommandSource &source)
{
if (DConfig.Check(DEFCON_NO_NEW_CHANNELS))
@@ -171,10 +173,8 @@ class CommandOSDefcon : public Command
source.Reply(_("* No new memos sent"));
}
- EventHandlers<Event::DefconLevel> &ondefconlevel;
-
public:
- CommandOSDefcon(Module *creator, EventHandlers<Event::DefconLevel> &event) : Command(creator, "operserv/defcon", 1, 1), ondefconlevel(event)
+ CommandOSDefcon(Module *creator) : Command(creator, "operserv/defcon", 1, 1)
{
this->SetDesc(_("Manipulate the DefCon system"));
this->SetSyntax(_("[\0021\002|\0022\002|\0023\002|\0024\002|\0025\002]"));
@@ -206,12 +206,12 @@ class CommandOSDefcon : public Command
DConfig.defaultlevel = newLevel;
- this->ondefconlevel(&Event::DefconLevel::OnDefconLevel, newLevel);
+ EventManager::Get()->Dispatch(&Event::DefconLevel::OnDefconLevel, newLevel);
delete timeout;
if (DConfig.timeout)
- timeout = new DefConTimeout(this->ondefconlevel, this->module, 5);
+ timeout = new DefConTimeout(this->module, 5);
source.Reply(_("Services are now at defcon \002{0}\002."), DConfig.defaultlevel);
this->SendLevels(source);
@@ -219,15 +219,15 @@ class CommandOSDefcon : public Command
/* Global notice the user what is happening. Also any Message that
the Admin would like to add. Set in config file. */
- if (DConfig.globalondefcon && Global::service)
+ if (DConfig.globalondefcon && global)
{
if (DConfig.defaultlevel == 5 && !DConfig.offmessage.empty())
- Global::service->SendGlobal(NULL, "", DConfig.offmessage);
+ global->SendGlobal(NULL, "", DConfig.offmessage);
else if (DConfig.defaultlevel != 5)
{
- Global::service->SendGlobal(NULL, "", Anope::printf(_("The defcon level is now at \002%d\002"), DConfig.defaultlevel));
+ global->SendGlobal(NULL, "", Anope::printf(_("The defcon level is now at \002%d\002"), DConfig.defaultlevel));
if (!DConfig.message.empty())
- Global::service->SendGlobal(NULL, "", DConfig.message);
+ global->SendGlobal(NULL, "", DConfig.message);
}
}
@@ -254,7 +254,6 @@ class OSDefcon : public Module
ServiceReference<SessionService> session_service;
ServiceReference<XLineManager> akills;
CommandOSDefcon commandosdefcon;
- EventHandlers<Event::DefconLevel> ondefconlevel;
void ParseModeString()
{
@@ -337,10 +336,14 @@ class OSDefcon : public Module
public:
OSDefcon(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
- , session_service("SessionService", "session")
- , akills("XLineManager", "xlinemanager/sgline")
- , commandosdefcon(this, ondefconlevel)
- , ondefconlevel(this)
+ , EventHook<Event::ChannelModeSet>(this)
+ , EventHook<Event::ChannelModeUnset>(this)
+ , EventHook<Event::PreCommand>(this)
+ , EventHook<Event::UserConnect>(this)
+ , EventHook<Event::ChannelModeAdd>(this)
+ , EventHook<Event::ChannelSync>(this)
+ , akills("xlinemanager/sgline")
+ , commandosdefcon(this)
{
}
@@ -463,7 +466,7 @@ class OSDefcon : public Module
{
return EVENT_STOP;
}
- else if (command->name == "nickserv/register" || command->name == "nickserv/group")
+ else if (command->GetName() == "nickserv/register" || command->GetName() == "nickserv/group")
{
if (DConfig.Check(DEFCON_NO_NEW_NICKS))
{
@@ -471,7 +474,7 @@ class OSDefcon : public Module
return EVENT_STOP;
}
}
- else if (command->name == "chanserv/mode" && params.size() > 1 && params[1].equals_ci("LOCK"))
+ else if (command->GetName() == "chanserv/mode" && params.size() > 1 && params[1].equals_ci("LOCK"))
{
if (DConfig.Check(DEFCON_NO_MLOCK_CHANGE))
{
@@ -479,7 +482,7 @@ class OSDefcon : public Module
return EVENT_STOP;
}
}
- else if (command->name == "chanserv/register")
+ else if (command->GetName() == "chanserv/register")
{
if (DConfig.Check(DEFCON_NO_NEW_CHANNELS))
{
@@ -487,7 +490,7 @@ class OSDefcon : public Module
return EVENT_STOP;
}
}
- else if (command->name == "memoserv/send")
+ else if (command->GetName() == "memoserv/send")
{
if (DConfig.Check(DEFCON_NO_NEW_MEMOS))
{
@@ -508,8 +511,11 @@ class OSDefcon : public Module
if (DConfig.Check(DEFCON_AKILL_NEW_CLIENTS) && akills)
{
Log(OperServ, "operserv/defcon") << "DEFCON: adding akill for *@" << u->host;
+#warning "xline allocated on stack"
+#if 0
XLine x("*@" + u->host, OperServ ? OperServ->nick : "defcon", Anope::CurTime + DConfig.akillexpire, DConfig.akillreason, XLineManager::GenerateUID());
akills->Send(NULL, &x);
+#endif
}
if (DConfig.Check(DEFCON_NO_NEW_CLIENTS) || DConfig.Check(DEFCON_AKILL_NEW_CLIENTS))
@@ -539,9 +545,12 @@ class OSDefcon : public Module
++session->hits;
if (akills && DConfig.max_session_kill && session->hits >= DConfig.max_session_kill)
{
+#warning "xline allocated on stack"
+#if 0
XLine x("*@" + session->addr.mask(), OperServ ? OperServ->nick : "", Anope::CurTime + DConfig.session_autokill_expiry, "Defcon session limit exceeded", XLineManager::GenerateUID());
akills->Send(NULL, &x);
Log(OperServ, "akill/defcon") << "[DEFCON] Added a temporary AKILL for \002*@" << session->addr.mask() << "\002 due to excessive connections";
+#endif
}
else
{
diff --git a/modules/operserv/dns.cpp b/modules/operserv/dns.cpp
index 1d714700d..2cf79d631 100644
--- a/modules/operserv/dns.cpp
+++ b/modules/operserv/dns.cpp
@@ -13,6 +13,10 @@ static std::map<Anope::string, std::list<time_t> > server_quit_times;
class DNSZoneImpl : public DNSZone
{
+ friend class DNSZoneType;
+
+ Anope::string name;
+
public:
DNSZoneImpl(Serialize::TypeBase *type) : DNSZone(type) { }
DNSZoneImpl(Serialize::TypeBase *type, Serialize::ID id) : DNSZone(type, id) { }
@@ -22,7 +26,7 @@ class DNSZoneImpl : public DNSZone
static DNSZone *Find(const Anope::string &name)
{
- for (DNSZone *zone : Serialize::GetObjects<DNSZone *>(dnszone))
+ for (DNSZone *zone : Serialize::GetObjects<DNSZone *>())
if (zone->GetName().equals_ci(name))
return zone;
return nullptr;
@@ -34,8 +38,8 @@ class DNSZoneType : public Serialize::Type<DNSZoneImpl>
public:
Serialize::Field<DNSZoneImpl, Anope::string> name;
- DNSZoneType(Module *creator) : Serialize::Type<DNSZoneImpl>(creator, "DNSZone")
- , name(this, "name")
+ DNSZoneType(Module *creator) : Serialize::Type<DNSZoneImpl>(creator)
+ , name(this, "name", &DNSZoneImpl::name)
{
}
};
@@ -52,6 +56,15 @@ void DNSZoneImpl::SetName(const Anope::string &name)
class DNSServerImpl : public DNSServer
{
+ friend class DNSServerType;
+
+ ServiceReference<DNS::Manager> manager;
+
+ DNSZone *zone = nullptr;
+ Anope::string name;
+ unsigned int limit = 0;
+ bool pooled = false;
+
/* is actually in the pool */
bool active = false;
@@ -85,17 +98,17 @@ class DNSServerImpl : public DNSServer
this->SetPool(p);
active = p;
- if (DNS::manager)
+ if (manager)
{
- DNS::manager->UpdateSerial();
+ manager->UpdateSerial();
for (std::set<Anope::string, ci::less>::iterator it = zones.begin(), it_end = zones.end(); it != it_end; ++it)
- DNS::manager->Notify(*it);
+ manager->Notify(*it);
}
}
static DNSServerImpl *Find(const Anope::string &s)
{
- for (DNSServerImpl *server : Serialize::GetObjects<DNSServerImpl *>(dnsserver))
+ for (DNSServerImpl *server : Serialize::GetObjects<DNSServerImpl *>())
if (server->GetName().equals_ci(s))
return server;
return nullptr;
@@ -110,11 +123,11 @@ class DNSServerType : public Serialize::Type<DNSServerImpl>
Serialize::Field<DNSServerImpl, unsigned int> limit;
Serialize::Field<DNSServerImpl, bool> pooled;
- DNSServerType(Module *creator) : Serialize::Type<DNSServerImpl>(creator, "DNSServer")
- , zone(this, "zone")
- , name(this, "name")
- , limit(this, "limit")
- , pooled(this, "pooled")
+ DNSServerType(Module *creator) : Serialize::Type<DNSServerImpl>(creator)
+ , zone(this, "zone", &DNSServerImpl::zone)
+ , name(this, "name", &DNSServerImpl::name)
+ , limit(this, "limit", &DNSServerImpl::limit)
+ , pooled(this, "pooled", &DNSServerImpl::pooled)
{
}
};
@@ -161,6 +174,11 @@ void DNSServerImpl::SetPool(const bool &p)
class DNSZoneMembershipImpl : public DNSZoneMembership
{
+ friend class DNSZoneMembershipType;
+
+ DNSServer *server = nullptr;
+ DNSZone *zone = nullptr;
+
public:
DNSZoneMembershipImpl(Serialize::TypeBase *type) : DNSZoneMembership(type) { }
DNSZoneMembershipImpl(Serialize::TypeBase *type, Serialize::ID id) : DNSZoneMembership(type, id) { }
@@ -173,7 +191,7 @@ class DNSZoneMembershipImpl : public DNSZoneMembership
static DNSZoneMembership *Find(DNSServer *server, DNSZone *zone)
{
- for (DNSZoneMembership *mem : Serialize::GetObjects<DNSZoneMembership *>(dnszonemembership))
+ for (DNSZoneMembership *mem : Serialize::GetObjects<DNSZoneMembership *>())
if (mem->GetServer() == server && mem->GetZone() == zone)
return mem;
return nullptr;
@@ -186,9 +204,9 @@ class DNSZoneMembershipType : public Serialize::Type<DNSZoneMembershipImpl>
Serialize::ObjectField<DNSZoneMembershipImpl, DNSServer *> server;
Serialize::ObjectField<DNSZoneMembershipImpl, DNSZone *> zone;
- DNSZoneMembershipType(Module *creator) : Serialize::Type<DNSZoneMembershipImpl>(creator, "DNSZoneMembership")
- , server(this, "server")
- , zone(this, "zone")
+ DNSZoneMembershipType(Module *creator) : Serialize::Type<DNSZoneMembershipImpl>(creator)
+ , server(this, "server", &DNSZoneMembershipImpl::server)
+ , zone(this, "zone", &DNSZoneMembershipImpl::zone)
{
}
};
@@ -215,6 +233,11 @@ void DNSZoneMembershipImpl::SetZone(DNSZone *z)
class DNSIPImpl : public DNSIP
{
+ friend class DNSIPType;
+
+ DNSServer *server = nullptr;
+ Anope::string ip;
+
public:
DNSIPImpl(Serialize::TypeBase *type) : DNSIP(type) { }
DNSIPImpl(Serialize::TypeBase *type, Serialize::ID id) : DNSIP(type, id) { }
@@ -229,12 +252,12 @@ class DNSIPImpl : public DNSIP
class DNSIPType : public Serialize::Type<DNSIPImpl>
{
public:
- Serialize::ObjectField<DNSServerImpl, DNSServer *> server;
- Serialize::Field<DNSServerImpl, Anope::string> ip;
+ Serialize::ObjectField<DNSIPImpl, DNSServer *> server;
+ Serialize::Field<DNSIPImpl, Anope::string> ip;
- DNSIPType(Module *creator) : Serialize::Type<DNSIPImpl>(creator, "DNSIP")
- , server(this, "server")
- , ip(this, "ip")
+ DNSIPType(Module *creator) : Serialize::Type<DNSIPImpl>(creator)
+ , server(this, "server", &DNSIPImpl::server)
+ , ip(this, "ip", &DNSIPImpl::ip)
{
}
};
@@ -261,9 +284,11 @@ void DNSIPImpl::SetIP(const Anope::string &ip)
class CommandOSDNS : public Command
{
+ ServiceReference<DNS::Manager> manager;
+
void DisplayPoolState(CommandSource &source)
{
- std::vector<DNSServerImpl *> servers = Serialize::GetObjects<DNSServerImpl *>(dnsserver);
+ std::vector<DNSServerImpl *> servers = Serialize::GetObjects<DNSServerImpl *>();
if (servers.empty())
{
@@ -282,7 +307,7 @@ class CommandOSDNS : public Command
entry["Limit"] = s->GetLimit() ? stringify(s->GetLimit()) : Language::Translate(source.GetAccount(), _("None"));
Anope::string ip_str;
- for (DNSIP *ip : s->GetRefs<DNSIP *>(dnsip))
+ for (DNSIP *ip : s->GetRefs<DNSIP *>())
ip_str += ip->GetIP() + " ";
ip_str.trim();
if (ip_str.empty())
@@ -305,7 +330,7 @@ class CommandOSDNS : public Command
std::vector<Anope::string> replies;
lf.Process(replies);
- std::vector<DNSZone *> zones = Serialize::GetObjects<DNSZone *>(dnszone);
+ std::vector<DNSZone *> zones = Serialize::GetObjects<DNSZone *>();
if (!zones.empty())
{
ListFormatter lf2(source.GetAccount());
@@ -317,7 +342,7 @@ class CommandOSDNS : public Command
entry["Zone"] = z->GetName();
Anope::string server_str;
- for (DNSServer *s : z->GetRefs<DNSServer *>(dnsserver))
+ for (DNSServer *s : z->GetRefs<DNSServer *>())
server_str += s->GetName() + " ";
server_str.trim();
@@ -351,7 +376,7 @@ class CommandOSDNS : public Command
Log(LOG_ADMIN, source, this) << "to add zone " << zone;
- DNSZone *z = dnszone.Create();
+ DNSZone *z = Serialize::New<DNSZone *>();
z->SetName(zone);
source.Reply(_("Added zone \002{0}\002."), zone);
}
@@ -372,13 +397,13 @@ class CommandOSDNS : public Command
Log(LOG_ADMIN, source, this) << "to delete zone " << z->GetName();
- for (DNSZoneMembership *mem : z->GetRefs<DNSZoneMembership *>(dnszonemembership))
+ for (DNSZoneMembership *mem : z->GetRefs<DNSZoneMembership *>())
mem->Delete();
- if (DNS::manager)
+ if (manager)
{
- DNS::manager->UpdateSerial();
- DNS::manager->Notify(z->GetName());
+ manager->UpdateSerial();
+ manager->Notify(z->GetName());
}
source.Reply(_("Zone \002{0}\002 removed."), z->GetName());
@@ -415,14 +440,14 @@ class CommandOSDNS : public Command
if (Anope::ReadOnly)
source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
- mem = dnszonemembership.Create();
+ mem = Serialize::New<DNSZoneMembership *>();
mem->SetZone(z);
mem->SetServer(s);
- if (DNS::manager)
+ if (manager)
{
- DNS::manager->UpdateSerial();
- DNS::manager->Notify(zone);
+ manager->UpdateSerial();
+ manager->Notify(zone);
}
Log(LOG_ADMIN, source, this) << "to add server " << s->GetName() << " to zone " << z->GetName();
@@ -440,7 +465,7 @@ class CommandOSDNS : public Command
return;
}
- s = dnsserver.Create();
+ s = Serialize::New<DNSServer *>();
s->SetName(params[1]);
if (zone.empty())
{
@@ -465,14 +490,14 @@ class CommandOSDNS : public Command
Log(LOG_ADMIN, source, this) << "to add server " << s->GetName() << " to zone " << zone;
- DNSZoneMembership *mem = dnszonemembership.Create();
+ DNSZoneMembership *mem = Serialize::New<DNSZoneMembership *>();
mem->SetServer(s);
mem->SetZone(z);
- if (DNS::manager)
+ if (manager)
{
- DNS::manager->UpdateSerial();
- DNS::manager->Notify(z->GetName());
+ manager->UpdateSerial();
+ manager->Notify(z->GetName());
}
}
}
@@ -509,10 +534,10 @@ class CommandOSDNS : public Command
Log(LOG_ADMIN, source, this) << "to remove server " << s->GetName() << " from zone " << z->GetName();
- if (DNS::manager)
+ if (manager)
{
- DNS::manager->UpdateSerial();
- DNS::manager->Notify(z->GetName());
+ manager->UpdateSerial();
+ manager->Notify(z->GetName());
}
mem->Delete();
@@ -526,14 +551,14 @@ class CommandOSDNS : public Command
return;
}
- for (DNSZoneMembership *mem : s->GetRefs<DNSZoneMembership *>(dnszonemembership))
+ for (DNSZoneMembership *mem : s->GetRefs<DNSZoneMembership *>())
mem->Delete();
if (Anope::ReadOnly)
source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
- if (DNS::manager)
- DNS::manager->UpdateSerial();
+ if (manager)
+ manager->UpdateSerial();
Log(LOG_ADMIN, source, this) << "to delete server " << s->GetName();
source.Reply(_("Removed server \002{0}\002."), s->GetName());
@@ -550,7 +575,7 @@ class CommandOSDNS : public Command
return;
}
- for (DNSIP *ip : s->GetRefs<DNSIP *>(dnsip))
+ for (DNSIP *ip : s->GetRefs<DNSIP *>())
if (params[2].equals_ci(ip->GetIP()))
{
source.Reply(_("IP \002{0}\002 already exists for \002{1}\002."), ip->GetIP(), s->GetName());
@@ -567,18 +592,18 @@ class CommandOSDNS : public Command
if (Anope::ReadOnly)
source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
- DNSIP *ip = dnsip.Create();
+ DNSIP *ip = Serialize::New<DNSIP *>();
ip->SetServer(s);
ip->SetIP(params[2]);
source.Reply(_("Added IP \002{0}\002 to \002{1}\002."), params[2], s->GetName());
Log(LOG_ADMIN, source, this) << "to add IP " << params[2] << " to " << s->GetName();
- if (s->Active() && DNS::manager)
+ if (s->Active() && manager)
{
- DNS::manager->UpdateSerial();
- for (DNSZone *zone : s->GetRefs<DNSZone *>(dnszone))
- DNS::manager->Notify(zone->GetName());
+ manager->UpdateSerial();
+ for (DNSZone *zone : s->GetRefs<DNSZone *>())
+ manager->Notify(zone->GetName());
}
}
@@ -595,7 +620,7 @@ class CommandOSDNS : public Command
if (Anope::ReadOnly)
source.Reply(_("Services are in read-only mode. Any changes made may not persist."));
- for (DNSIP *ip : s->GetRefs<DNSIP *>(dnsip))
+ for (DNSIP *ip : s->GetRefs<DNSIP *>())
if (params[2].equals_ci(ip->GetIP()))
{
ip->Delete();
@@ -603,17 +628,17 @@ class CommandOSDNS : public Command
source.Reply(_("Removed IP \002{0}\002 from \002{1}\002."), params[2], s->GetName());
Log(LOG_ADMIN, source, this) << "to remove IP " << params[2] << " from " << s->GetName();
- if (s->GetRefs<DNSIP *>(dnsip).empty())
+ if (s->GetRefs<DNSIP *>().empty())
{
s->repool = 0;
s->SetPool(false);
}
- if (s->Active() && DNS::manager)
+ if (s->Active() && manager)
{
- DNS::manager->UpdateSerial();
- for (DNSZone *zone : s->GetRefs<DNSZone *>(dnszone))
- DNS::manager->Notify(zone->GetName());
+ manager->UpdateSerial();
+ for (DNSZone *zone : s->GetRefs<DNSZone *>())
+ manager->Notify(zone->GetName());
}
return;
@@ -677,7 +702,7 @@ class CommandOSDNS : public Command
return;
}
- if (s->GetRefs<DNSIP *>(dnsip).empty())
+ if (s->GetRefs<DNSIP *>().empty())
{
source.Reply(_("Server \002{0}\002 has no configured IPs."), s->GetName());
return;
@@ -791,32 +816,34 @@ class ModuleDNS : public Module
DNSIPType iptype;
CommandOSDNS commandosdns;
- time_t ttl;
- int user_drop_mark;
- time_t user_drop_time;
- time_t user_drop_readd_time;
- bool remove_split_servers;
- bool readd_connected_servers;
+ time_t ttl = 0;
+ int user_drop_mark = 0;
+ time_t user_drop_time = 0;
+ time_t user_drop_readd_time = 0;
+ bool remove_split_servers = 0;
+ bool readd_connected_servers = 0;
- time_t last_warn;
+ time_t last_warn = 0;
public:
ModuleDNS(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, EXTRA | VENDOR)
+ , EventHook<Event::NewServer>(this)
+ , EventHook<Event::ServerQuit>(this)
+ , EventHook<Event::UserConnect>(this)
+ , EventHook<Event::PreUserLogoff>(this)
+ , EventHook<Event::DnsRequest>(this)
, zonetype(this)
, servertype(this)
, zonemembtype(this)
, iptype(this)
, commandosdns(this)
- , last_warn(0)
{
-#if 0
- for (unsigned j = 0; j < dns_servers->size(); ++j)
- {
- DNSServer *s = dns_servers->at(j);
- if (s->Pooled() && Server::Find(s->GetName(), true))
+ /* enable active flag for linked servers */
+ std::vector<DNSServerImpl *> servers = Serialize::GetObjects<DNSServerImpl *>();
+
+ for (DNSServerImpl *s : servers)
+ if (s->GetPooled() && Server::Find(s->GetName(), true))
s->SetActive(true);
- }
-#endif
}
~ModuleDNS()
@@ -841,7 +868,7 @@ class ModuleDNS : public Module
if (!Me->IsSynced() || this->readd_connected_servers)
{
DNSServerImpl *dns = DNSServerImpl::Find(s->GetName());
- if (dns && dns->GetPooled() && !dns->Active() && !dns->GetRefs<DNSIP *>(dnsip).empty())
+ if (dns && dns->GetPooled() && !dns->Active() && !dns->GetRefs<DNSIP *>().empty())
{
dns->SetActive(true);
Log(this) << "Pooling server " << s->GetName();
@@ -934,12 +961,12 @@ class ModuleDNS : public Module
size_t answer_size = packet->answers.size();
if (zone)
{
- for (DNSServerImpl *s : zone->GetRefs<DNSServerImpl *>(dnsserver))
+ for (DNSServerImpl *s : zone->GetRefs<DNSServerImpl *>())
{
if (!s->Active())
continue;
- for (DNSIP *ip : s->GetRefs<DNSIP *>(dnsip))
+ for (DNSIP *ip : s->GetRefs<DNSIP *>())
{
DNS::QueryType q_type = ip->GetIP().find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A;
@@ -957,12 +984,12 @@ class ModuleDNS : public Module
if (packet->answers.size() == answer_size)
{
/* Default zone */
- for (DNSServerImpl *s : Serialize::GetObjects<DNSServerImpl *>(dnsserver))
+ for (DNSServerImpl *s : Serialize::GetObjects<DNSServerImpl *>())
{
if (!s->Active())
continue;
- for (DNSIP *ip : s->GetRefs<DNSIP *>(dnsip))
+ for (DNSIP *ip : s->GetRefs<DNSIP *>())
{
DNS::QueryType q_type = ip->GetIP().find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A;
@@ -986,8 +1013,8 @@ class ModuleDNS : public Module
}
/* Something messed up, just return them all and hope one is available */
- for (DNSServer *s : Serialize::GetObjects<DNSServer *>(dnsserver))
- for (DNSIP *ip : s->GetRefs<DNSIP *>(dnsip))
+ for (DNSServer *s : Serialize::GetObjects<DNSServer *>())
+ for (DNSIP *ip : s->GetRefs<DNSIP *>())
{
DNS::QueryType q_type = ip->GetIP().find(':') != Anope::string::npos ? DNS::QUERY_AAAA : DNS::QUERY_A;
diff --git a/modules/operserv/forbid.cpp b/modules/operserv/forbid.cpp
index 2375eddcd..6fb0172cf 100644
--- a/modules/operserv/forbid.cpp
+++ b/modules/operserv/forbid.cpp
@@ -16,6 +16,12 @@
class ForbidDataImpl : public ForbidData
{
+ friend class ForbidDataType;
+
+ Anope::string mask, creator, reason;
+ time_t created = 0, expires = 0;
+ ForbidType type = static_cast<ForbidType>(0);
+
public:
ForbidDataImpl(Serialize::TypeBase *type) : ForbidData(type) { }
ForbidDataImpl(Serialize::TypeBase *type, Serialize::ID id) : ForbidData(type, id) { }
@@ -46,13 +52,13 @@ class ForbidDataType : public Serialize::Type<ForbidDataImpl>
Serialize::Field<ForbidDataImpl, time_t> created, expires;
Serialize::Field<ForbidDataImpl, ForbidType> type;
- ForbidDataType(Module *me) : Serialize::Type<ForbidDataImpl>(me, "ForbidData")
- , mask(this, "mask")
- , creator(this, "creator")
- , reason(this, "reason")
- , created(this, "created")
- , expires(this, "expires")
- , type(this, "type")
+ ForbidDataType(Module *me) : Serialize::Type<ForbidDataImpl>(me)
+ , mask(this, "mask", &ForbidDataImpl::mask)
+ , creator(this, "creator", &ForbidDataImpl::creator)
+ , reason(this, "reason", &ForbidDataImpl::reason)
+ , created(this, "created", &ForbidDataImpl::created)
+ , expires(this, "expires", &ForbidDataImpl::expires)
+ , type(this, "type", &ForbidDataImpl::type)
{
}
};
@@ -134,7 +140,7 @@ class MyForbidService : public ForbidService
std::vector<ForbidData *> GetForbids() override
{
- for (ForbidData *d : Serialize::GetObjects<ForbidData *>(forbiddata))
+ for (ForbidData *d : Serialize::GetObjects<ForbidData *>())
if (d->GetExpires() && !Anope::NoExpire && Anope::CurTime >= d->GetExpires())
{
Anope::string ftype = "none";
@@ -148,15 +154,16 @@ class MyForbidService : public ForbidService
Log(LOG_NORMAL, "expire/forbid", Config->GetClient("OperServ")) << "Expiring forbid for " << d->GetMask() << " type " << ftype;
d->Delete();
}
- return Serialize::GetObjects<ForbidData *>(forbiddata);
+ return Serialize::GetObjects<ForbidData *>();
}
};
cl