summaryrefslogtreecommitdiff
path: root/modules/hostserv
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/hostserv
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/hostserv')
-rw-r--r--modules/hostserv/del.cpp20
-rw-r--r--modules/hostserv/group.cpp6
-rw-r--r--modules/hostserv/list.cpp2
-rw-r--r--modules/hostserv/main/hostserv.cpp5
-rw-r--r--modules/hostserv/request.cpp99
-rw-r--r--modules/hostserv/set.cpp6
6 files changed, 74 insertions, 64 deletions
diff --git a/modules/hostserv/del.cpp b/modules/hostserv/del.cpp
index 0830cd5b5..37823b1b7 100644
--- a/modules/hostserv/del.cpp
+++ b/modules/hostserv/del.cpp
@@ -14,10 +14,8 @@
class CommandHSDel : public Command
{
- EventHandlers<Event::DeleteVhost> &OnDeleteVhost;
-
public:
- CommandHSDel(Module *creator, EventHandlers<Event::DeleteVhost> &onDeleteVhost) : Command(creator, "hostserv/del", 1, 1), OnDeleteVhost(onDeleteVhost)
+ CommandHSDel(Module *creator) : Command(creator, "hostserv/del", 1, 1)
{
this->SetDesc(_("Delete the vhost of another user"));
this->SetSyntax(_("\037user\037"));
@@ -37,7 +35,7 @@ class CommandHSDel : public Command
}
Log(LOG_ADMIN, source, this) << "for user " << na->GetNick();
- this->OnDeleteVhost(&Event::DeleteVhost::OnDeleteVhost, na);
+ EventManager::Get()->Dispatch(&Event::DeleteVhost::OnDeleteVhost, na);
na->RemoveVhost();
source.Reply(_("Vhost for \002{0}\002 has been removed."), na->GetNick());
}
@@ -51,10 +49,8 @@ class CommandHSDel : public Command
class CommandHSDelAll : public Command
{
- EventHandlers<Event::DeleteVhost> &ondeletevhost;
-
public:
- CommandHSDelAll(Module *creator, EventHandlers<Event::DeleteVhost> &event) : Command(creator, "hostserv/delall", 1, 1), ondeletevhost(event)
+ CommandHSDelAll(Module *creator) : Command(creator, "hostserv/delall", 1, 1)
{
this->SetDesc(_("Delete the vhost for all nicks in a group"));
this->SetSyntax(_("\037group\037"));
@@ -73,10 +69,10 @@ class CommandHSDelAll : public Command
return;
}
- this->ondeletevhost(&Event::DeleteVhost::OnDeleteVhost, na);
+ EventManager::Get()->Dispatch(&Event::DeleteVhost::OnDeleteVhost, na);
NickServ::Account *nc = na->GetAccount();
- for (NickServ::Nick *na2 : nc->GetRefs<NickServ::Nick *>(NickServ::nick))
+ for (NickServ::Nick *na2 : nc->GetRefs<NickServ::Nick *>())
na2->RemoveVhost();
Log(LOG_ADMIN, source, this) << "for all nicks in group " << nc->GetDisplay();
source.Reply(_("Vhosts for group \002{0}\002 have been removed."), nc->GetDisplay());
@@ -93,13 +89,11 @@ class HSDel : public Module
{
CommandHSDel commandhsdel;
CommandHSDelAll commandhsdelall;
- EventHandlers<Event::DeleteVhost> ondeletevhost;
public:
HSDel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
- , commandhsdel(this, ondeletevhost)
- , commandhsdelall(this, ondeletevhost)
- , ondeletevhost(this)
+ , commandhsdel(this)
+ , commandhsdelall(this)
{
if (!IRCD || !IRCD->CanSetVHost)
throw ModuleException("Your IRCd does not support vhosts");
diff --git a/modules/hostserv/group.cpp b/modules/hostserv/group.cpp
index 3aff66e27..01e8ad722 100644
--- a/modules/hostserv/group.cpp
+++ b/modules/hostserv/group.cpp
@@ -26,10 +26,10 @@ class CommandHSGroup : public Command
return;
setting = true;
- for (NickServ::Nick *nick : na->GetAccount()->GetRefs<NickServ::Nick *>(NickServ::nick))
+ for (NickServ::Nick *nick : na->GetAccount()->GetRefs<NickServ::Nick *>())
{
nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator());
- Event::OnSetVhost(&Event::SetVhost::OnSetVhost, nick);
+ EventManager::Get()->Dispatch(&Event::SetVhost::OnSetVhost, nick);
}
setting = false;
}
@@ -84,6 +84,8 @@ class HSGroup : public Module
public:
HSGroup(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR)
+ , EventHook<Event::SetVhost>(this)
+ , EventHook<Event::NickGroup>(this)
, commandhsgroup(this)
{
if (!IRCD || !IRCD->CanSetVHost)
diff --git a/modules/hostserv/list.cpp b/modules/hostserv/list.cpp
index 738f9f1bd..e77d8d9fa 100644
--- a/modules/hostserv/list.cpp
+++ b/modules/hostserv/list.cpp
@@ -53,7 +53,7 @@ class CommandHSList : public Command
}
}
- unsigned display_counter = 0, listmax = Config->GetModule(this->owner)->Get<unsigned>("listmax", "50");
+ unsigned display_counter = 0, listmax = Config->GetModule(this->GetOwner())->Get<unsigned>("listmax", "50");
ListFormatter list(source.GetAccount());
list.AddColumn(_("Number")).AddColumn(_("Nick")).AddColumn(_("Vhost")).AddColumn(_("Creator")).AddColumn(_("Created"));
diff --git a/modules/hostserv/main/hostserv.cpp b/modules/hostserv/main/hostserv.cpp
index 8fdfa560e..345d2cf97 100644
--- a/modules/hostserv/main/hostserv.cpp
+++ b/modules/hostserv/main/hostserv.cpp
@@ -25,6 +25,11 @@ class HostServCore : public Module
public:
HostServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR)
+ , EventHook<Event::UserLogin>(this)
+ , EventHook<Event::NickUpdate>(this)
+ , EventHook<Event::Help>(this)
+ , EventHook<Event::SetVhost>(this)
+ , EventHook<Event::DeleteVhost>(this)
{
if (!IRCD || !IRCD->CanSetVHost)
throw ModuleException("Your IRCd does not support vhosts");
diff --git a/modules/hostserv/request.cpp b/modules/hostserv/request.cpp
index 8a064a84c..25f3de12b 100644
--- a/modules/hostserv/request.cpp
+++ b/modules/hostserv/request.cpp
@@ -1,7 +1,7 @@
/*
*
*
- * (C) 2003-2014 Anope Team
+ * (C) 2003-2016 Anope Team
* Contact us at team@anope.org
*
* Please read COPYING and README for further details.
@@ -11,11 +11,17 @@
#include "module.h"
#include "modules/memoserv.h"
-static void req_send_memos(Module *me, CommandSource &source, const Anope::string &vIdent, const Anope::string &vHost);
-
class HostRequest : public Serialize::Object
{
+ friend class HostRequestType;
+
+ NickServ::Nick *na = nullptr;
+ Anope::string ident, host;
+ time_t time = 0;
+
public:
+ static constexpr const char *const NAME = "hostrequest";
+
HostRequest(Serialize::TypeBase *type) : Serialize::Object(type) { }
HostRequest(Serialize::TypeBase *type, Serialize::ID id) : Serialize::Object(type, id) { }
@@ -39,11 +45,11 @@ class HostRequestType : public Serialize::Type<HostRequest>
Serialize::Field<HostRequest, Anope::string> ident, host;
Serialize::Field<HostRequest, time_t> time;
- HostRequestType(Module *me) : Serialize::Type<HostRequest>(me, "HostRequest")
- , na(this, "na", true)
- , ident(this, "ident")
- , host(this, "host")
- , time(this, "time")
+ HostRequestType(Module *me) : Serialize::Type<HostRequest>(me)
+ , na(this, "na", &HostRequest::na, true)
+ , ident(this, "ident", &HostRequest::ident)
+ , host(this, "host", &HostRequest::host)
+ , time(this, "time", &HostRequest::time)
{
}
};
@@ -88,10 +94,32 @@ void HostRequest::SetTime(const time_t &t)
Set(&HostRequestType::time, t);
}
-static Serialize::TypeReference<HostRequest> hostrequest("HostRequest");
-
class CommandHSRequest : public Command
{
+ ServiceReference<MemoServ::MemoServService> memoserv;
+
+ void SendMemos(CommandSource &source, const Anope::string &vIdent, const Anope::string &vHost)
+ {
+ Anope::string host;
+
+ if (!vIdent.empty())
+ host = vIdent + "@" + vHost;
+ else
+ host = vHost;
+
+ if (Config->GetModule(GetOwner())->Get<bool>("memooper") && memoserv)
+ for (Oper *o : Serialize::GetObjects<Oper *>())
+ {
+ NickServ::Nick *na = NickServ::FindNick(o->GetName());
+ if (!na)
+ continue;
+
+ Anope::string message = Anope::printf(_("[auto memo] vHost \002%s\002 has been requested by %s."), host.c_str(), source.GetNick().c_str());
+
+ memoserv->Send(source.service->nick, na->GetNick(), message, true);
+ }
+ }
+
public:
CommandHSRequest(Module *creator) : Command(creator, "hostserv/request", 1, 1)
{
@@ -174,21 +202,21 @@ class CommandHSRequest : public Command
}
time_t send_delay = Config->GetModule("memoserv")->Get<time_t>("senddelay");
- if (Config->GetModule(this->owner)->Get<bool>("memooper") && send_delay > 0 && u && u->lastmemosend + send_delay > Anope::CurTime)
+ if (Config->GetModule(this->GetOwner())->Get<bool>("memooper") && send_delay > 0 && u && u->lastmemosend + send_delay > Anope::CurTime)
{
source.Reply(_("Please wait %d seconds before requesting a new vHost."), send_delay);
u->lastmemosend = Anope::CurTime;
return;
}
- HostRequest *req = hostrequest.Create();
+ HostRequest *req = Serialize::New<HostRequest *>();
req->SetNick(na);
req->SetIdent(user);
req->SetHost(host);
req->SetTime(Anope::CurTime);
source.Reply(_("Your vhost has been requested."));
- req_send_memos(owner, source, user, host);
+ this->SendMemos(source, user, host);
Log(LOG_COMMAND, source, this) << "to request new vhost " << (!user.empty() ? user + "@" : "") << host;
}
@@ -201,6 +229,8 @@ class CommandHSRequest : public Command
class CommandHSActivate : public Command
{
+ ServiceReference<MemoServ::MemoServService> memoserv;
+
public:
CommandHSActivate(Module *creator) : Command(creator, "hostserv/activate", 1, 1)
{
@@ -233,10 +263,10 @@ class CommandHSActivate : public Command
}
na->SetVhost(req->GetIdent(), req->GetHost(), source.GetNick(), req->GetTime());
- Event::OnSetVhost(&Event::SetVhost::OnSetVhost, na);
+ EventManager::Get()->Dispatch(&Event::SetVhost::OnSetVhost, na);
- if (Config->GetModule(this->owner)->Get<bool>("memouser") && MemoServ::service)
- MemoServ::service->Send(source.service->nick, na->GetNick(), _("[auto memo] Your requested vHost has been approved."), true);
+ if (Config->GetModule(this->GetOwner())->Get<bool>("memouser") && memoserv)
+ memoserv->Send(source.service->nick, na->GetNick(), _("[auto memo] Your requested vHost has been approved."), true);
source.Reply(_("Vhost for \002{0}\002 has been activated."), na->GetNick());
Log(LOG_COMMAND, source, this) << "for " << na->GetNick() << " for vhost " << (!req->GetIdent().empty() ? req->GetIdent() + "@" : "") << req->GetHost();
@@ -246,7 +276,7 @@ class CommandHSActivate : public Command
bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
source.Reply(_("Activate the requested vhost for the given user."));
- if (Config->GetModule(this->owner)->Get<bool>("memouser"))
+ if (Config->GetModule(this->GetOwner())->Get<bool>("memouser"))
source.Reply(_("A memo informing the user will also be sent."));
return true;
@@ -255,6 +285,8 @@ class CommandHSActivate : public Command
class CommandHSReject : public Command
{
+ ServiceReference<MemoServ::MemoServService> memoserv;
+
public:
CommandHSReject(Module *creator) : Command(creator, "hostserv/reject", 1, 2)
{
@@ -289,7 +321,7 @@ class CommandHSReject : public Command
req->Delete();
- if (Config->GetModule(this->owner)->Get<bool>("memouser") && MemoServ::service)
+ if (Config->GetModule(this->GetOwner())->Get<bool>("memouser") && memoserv)
{
Anope::string message;
if (!reason.empty())
@@ -297,7 +329,7 @@ class CommandHSReject : public Command
else
message = _("[auto memo] Your requested vHost has been rejected.");
- MemoServ::service->Send(source.service->nick, nick, Language::Translate(source.GetAccount(), message.c_str()), true);
+ memoserv->Send(source.service->nick, nick, Language::Translate(source.GetAccount(), message.c_str()), true);
}
source.Reply(_("Vhost for \002{0}\002 has been rejected."), na->GetNick());
@@ -307,7 +339,7 @@ class CommandHSReject : public Command
bool OnHelp(CommandSource &source, const Anope::string &subcommand) override
{
source.Reply(_("Reject the requested vhost for the given user."));
- if (Config->GetModule(this->owner)->Get<bool>("memouser"))
+ if (Config->GetModule(this->GetOwner())->Get<bool>("memouser"))
source.Reply(_("A memo informing the user will also be sent, which includes the reason for the rejection if supplied."));
return true;
@@ -325,12 +357,12 @@ class CommandHSWaiting : public Command
void Execute(CommandSource &source, const std::vector<Anope::string> &params) override
{
unsigned counter = 0;
- unsigned display_counter = 0, listmax = Config->GetModule(this->owner)->Get<unsigned>("listmax");
+ unsigned display_counter = 0, listmax = Config->GetModule(this->GetOwner())->Get<unsigned>("listmax");
ListFormatter list(source.GetAccount());
list.AddColumn(_("Number")).AddColumn(_("Nick")).AddColumn(_("Vhost")).AddColumn(_("Created"));
- for (HostRequest *hr : Serialize::GetObjects<HostRequest *>(hostrequest))
+ for (HostRequest *hr : Serialize::GetObjects<HostRequest *>())
{
if (!listmax || display_counter < listmax)
{
@@ -388,27 +420,4 @@ class HSRequest : public Module
}
};
-static void req_send_memos(Module *me, CommandSource &source, const Anope::string &vIdent, const Anope::string &vHost)
-{
- Anope::string host;
- std::list<std::pair<Anope::string, Anope::string> >::iterator it, it_end;
-
- if (!vIdent.empty())
- host = vIdent + "@" + vHost;
- else
- host = vHost;
-
- if (Config->GetModule(me)->Get<bool>("memooper") && MemoServ::service)
- for (Oper *o : Serialize::GetObjects<Oper *>(operblock))
- {
- NickServ::Nick *na = NickServ::FindNick(o->GetName());
- if (!na)
- continue;
-
- Anope::string message = Anope::printf(_("[auto memo] vHost \002%s\002 has been requested by %s."), host.c_str(), source.GetNick().c_str());
-
- MemoServ::service->Send(source.service->nick, na->GetNick(), message, true);
- }
-}
-
MODULE_INIT(HSRequest)
diff --git a/modules/hostserv/set.cpp b/modules/hostserv/set.cpp
index a86afead4..e7f42e630 100644
--- a/modules/hostserv/set.cpp
+++ b/modules/hostserv/set.cpp
@@ -86,7 +86,7 @@ class CommandHSSet : public Command
Log(LOG_ADMIN, source, this) << "to set the vhost of " << na->GetNick() << " to " << (!user.empty() ? user + "@" : "") << host;
na->SetVhost(user, host, source.GetNick());
- Event::OnSetVhost(&Event::SetVhost::OnSetVhost, na);
+ EventManager::Get()->Dispatch(&Event::SetVhost::OnSetVhost, na);
if (!user.empty())
source.Reply(_("Vhost for \002{0}\002 set to \002{0}\002@\002{1}\002."), nick, user, host);
else
@@ -107,7 +107,7 @@ class CommandHSSetAll : public Command
if (!na || !na->HasVhost())
return;
- for (NickServ::Nick *nick : na->GetAccount()->GetRefs<NickServ::Nick *>(NickServ::nick))
+ for (NickServ::Nick *nick : na->GetAccount()->GetRefs<NickServ::Nick *>())
nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator());
}
@@ -184,7 +184,7 @@ class CommandHSSetAll : public Command
na->SetVhost(user, host, source.GetNick());
this->Sync(na);
- Event::OnSetVhost(&Event::SetVhost::OnSetVhost, na);
+ EventManager::Get()->Dispatch(&Event::SetVhost::OnSetVhost, na);
if (!user.empty())
source.Reply(_("Vhost for group \002{0}\002 set to \002{1}\002@\002{2}\002."), nick.c_str(), user.c_str(), host.c_str());
else