summaryrefslogtreecommitdiff
path: root/modules/hostserv/main
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2016-10-09 12:00:15 -0400
committerAdam <Adam@anope.org>2016-10-09 12:00:15 -0400
commit5fd2d0ee3e136e01926f21edc759a4ab9fd48806 (patch)
tree6666be3d14db12fe66a3576e889423f64e5229cc /modules/hostserv/main
parentcffbf4e8fd93ae28f1c6d6fde221e72d70015942 (diff)
Split vhosts into its own structure
Diffstat (limited to 'modules/hostserv/main')
-rw-r--r--modules/hostserv/main/hostserv.cpp50
-rw-r--r--modules/hostserv/main/vhost.cpp70
-rw-r--r--modules/hostserv/main/vhost.h52
-rw-r--r--modules/hostserv/main/vhosttype.cpp32
-rw-r--r--modules/hostserv/main/vhosttype.h32
5 files changed, 217 insertions, 19 deletions
diff --git a/modules/hostserv/main/hostserv.cpp b/modules/hostserv/main/hostserv.cpp
index c1c9408e4..ab1617a85 100644
--- a/modules/hostserv/main/hostserv.cpp
+++ b/modules/hostserv/main/hostserv.cpp
@@ -21,6 +21,7 @@
#include "modules/nickserv/update.h"
#include "modules/hostserv/del.h"
#include "modules/help.h"
+#include "vhosttype.h"
class HostServCore : public Module
, public EventHook<Event::UserLogin>
@@ -31,6 +32,8 @@ class HostServCore : public Module
{
Reference<ServiceBot> HostServ;
+ VHostType vhost_type;
+
public:
HostServCore(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, PSEUDOCLIENT | VENDOR)
, EventHook<Event::UserLogin>(this)
@@ -38,6 +41,7 @@ class HostServCore : public Module
, EventHook<Event::Help>(this)
, EventHook<Event::SetVhost>(this)
, EventHook<Event::DeleteVhost>(this)
+ , vhost_type(this)
{
if (!IRCD || !IRCD->CanSetVHost)
throw ModuleException("Your IRCd does not support vhosts");
@@ -63,27 +67,33 @@ class HostServCore : public Module
return;
NickServ::Nick *na = NickServ::FindNick(u->nick);
- if (!na || na->GetAccount() != u->Account() || !na->HasVhost())
- na = NickServ::FindNick(u->Account()->GetDisplay());
- if (!na || !na->HasVhost())
+ HostServ::VHost *vhost = nullptr;
+
+ if (na && na->GetAccount() == u->Account())
+ vhost = na->GetVHost();
+
+ if (vhost == nullptr)
+ vhost = NickServ::FindNick(u->Account()->GetDisplay())->GetVHost();
+
+ if (vhost == nullptr)
return;
- if (u->vhost.empty() || !u->vhost.equals_cs(na->GetVhostHost()) || (!na->GetVhostIdent().empty() && !u->GetVIdent().equals_cs(na->GetVhostIdent())))
+ if (u->vhost.empty() || !u->vhost.equals_cs(vhost->GetHost()) || (!vhost->GetIdent().empty() && !u->GetVIdent().equals_cs(vhost->GetIdent())))
{
- IRCD->SendVhost(u, na->GetVhostIdent(), na->GetVhostHost());
+ IRCD->SendVhost(u, vhost->GetIdent(), vhost->GetHost());
- u->vhost = na->GetVhostHost();
+ u->vhost = vhost->GetHost();
u->UpdateHost();
- if (IRCD->CanSetVIdent && !na->GetVhostIdent().empty())
- u->SetVIdent(na->GetVhostIdent());
+ if (IRCD->CanSetVIdent && !vhost->GetIdent().empty())
+ u->SetVIdent(vhost->GetIdent());
if (HostServ)
{
- if (!na->GetVhostIdent().empty())
- u->SendMessage(*HostServ, _("Your vhost of \002%s\002@\002%s\002 is now activated."), na->GetVhostIdent().c_str(), na->GetVhostHost().c_str());
+ if (!vhost->GetIdent().empty())
+ u->SendMessage(*HostServ, _("Your vhost of \002{0}\002@\002{1}\002 is now activated."), vhost->GetIdent(), vhost->GetHost());
else
- u->SendMessage(*HostServ, _("Your vhost of \002%s\002 is now activated."), na->GetVhostHost().c_str());
+ u->SendMessage(*HostServ, _("Your vhost of \002{0}\002 is now activated."), vhost->GetHost());
}
}
}
@@ -97,7 +107,7 @@ class HostServCore : public Module
{
if (!params.empty() || source.c || source.service != *HostServ)
return EVENT_CONTINUE;
- source.Reply(_("%s commands:"), HostServ->nick.c_str());
+ source.Reply(_("{0} commands:"), HostServ->nick);
return EVENT_CONTINUE;
}
@@ -113,20 +123,22 @@ class HostServCore : public Module
if (u && u->Account() == na->GetAccount())
{
- IRCD->SendVhost(u, na->GetVhostIdent(), na->GetVhostHost());
+ HostServ::VHost *vhost = na->GetVHost();
+
+ IRCD->SendVhost(u, vhost->GetIdent(), vhost->GetHost());
- u->vhost = na->GetVhostHost();
+ u->vhost = vhost->GetHost();
u->UpdateHost();
- if (IRCD->CanSetVIdent && !na->GetVhostIdent().empty())
- u->SetVIdent(na->GetVhostIdent());
+ if (IRCD->CanSetVIdent && !vhost->GetIdent().empty())
+ u->SetVIdent(vhost->GetIdent());
if (HostServ)
{
- if (!na->GetVhostIdent().empty())
- u->SendMessage(*HostServ, _("Your vhost of \002%s\002@\002%s\002 is now activated."), na->GetVhostIdent().c_str(), na->GetVhostHost().c_str());
+ if (!vhost->GetIdent().empty())
+ u->SendMessage(*HostServ, _("Your vhost of \002{0}\002@\002{1}\002 is now activated."), vhost->GetIdent(), vhost->GetHost());
else
- u->SendMessage(*HostServ, _("Your vhost of \002%s\002 is now activated."), na->GetVhostHost().c_str());
+ u->SendMessage(*HostServ, _("Your vhost of \002{0}\002 is now activated."), vhost->GetHost());
}
}
}
diff --git a/modules/hostserv/main/vhost.cpp b/modules/hostserv/main/vhost.cpp
new file mode 100644
index 000000000..f7878d53c
--- /dev/null
+++ b/modules/hostserv/main/vhost.cpp
@@ -0,0 +1,70 @@
+/*
+ * Anope IRC Services
+ *
+ * Copyright (C) 2015-2016 Anope Team <team@anope.org>
+ *
+ * This file is part of Anope. Anope is free software; you can
+ * redistribute it and/or modify it under the terms of the GNU
+ * General Public License as published by the Free Software
+ * Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see see <http://www.gnu.org/licenses/>.
+ */
+
+#include "vhosttype.h"
+
+Serialize::Object *VHostImpl::GetOwner()
+{
+ return Get(&VHostType::owner);
+}
+
+void VHostImpl::SetOwner(Serialize::Object *owner)
+{
+ Set(&VHostType::owner, owner);
+}
+
+Anope::string VHostImpl::GetIdent()
+{
+ return Get(&VHostType::vident);
+}
+
+void VHostImpl::SetIdent(const Anope::string &vident)
+{
+ Set(&VHostType::vident, vident);
+}
+
+Anope::string VHostImpl::GetHost()
+{
+ return Get(&VHostType::vhost);
+}
+
+void VHostImpl::SetHost(const Anope::string &vhost)
+{
+ Set(&VHostType::vhost, vhost);
+}
+
+Anope::string VHostImpl::GetCreator()
+{
+ return Get(&VHostType::creator);
+}
+
+void VHostImpl::SetCreator(const Anope::string &creator)
+{
+ Set(&VHostType::creator, creator);
+}
+
+time_t VHostImpl::GetCreated()
+{
+ return Get(&VHostType::created);
+}
+
+void VHostImpl::SetCreated(time_t created)
+{
+ Set(&VHostType::created, created);
+} \ No newline at end of file
diff --git a/modules/hostserv/main/vhost.h b/modules/hostserv/main/vhost.h
new file mode 100644
index 000000000..e0b751899
--- /dev/null
+++ b/modules/hostserv/main/vhost.h
@@ -0,0 +1,52 @@
+/*
+ * Anope IRC Services
+ *
+ * Copyright (C) 2016 Anope Team <team@anope.org>
+ *
+ * This file is part of Anope. Anope is free software; you can
+ * redistribute it and/or modify it under the terms of the GNU
+ * General Public License as published by the Free Software
+ * Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see see <http://www.gnu.org/licenses/>.
+ */
+
+#pragma once
+
+#include "modules/hostserv.h"
+
+class VHostImpl : public HostServ::VHost
+{
+ friend class VHostType;
+
+ Serialize::Object *owner = nullptr;
+ Anope::string vident;
+ Anope::string vhost;
+ Anope::string creator;
+ time_t created = 0;
+
+ public:
+ using HostServ::VHost::VHost;
+
+ Serialize::Object *GetOwner() override;
+ void SetOwner(Serialize::Object *) override;
+
+ Anope::string GetIdent() override;
+ void SetIdent(const Anope::string &) override;
+
+ Anope::string GetHost() override;
+ void SetHost(const Anope::string &) override;
+
+ Anope::string GetCreator() override;
+ void SetCreator(const Anope::string &) override;
+
+ time_t GetCreated() override;
+ void SetCreated(time_t) override;
+};
+
diff --git a/modules/hostserv/main/vhosttype.cpp b/modules/hostserv/main/vhosttype.cpp
new file mode 100644
index 000000000..3eae8eec3
--- /dev/null
+++ b/modules/hostserv/main/vhosttype.cpp
@@ -0,0 +1,32 @@
+/*
+ * Anope IRC Services
+ *
+ * Copyright (C) 2015-2016 Anope Team <team@anope.org>
+ *
+ * This file is part of Anope. Anope is free software; you can
+ * redistribute it and/or modify it under the terms of the GNU
+ * General Public License as published by the Free Software
+ * Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see see <http://www.gnu.org/licenses/>.
+ */
+
+#include "module.h"
+#include "vhosttype.h"
+
+VHostType::VHostType(Module *me) : Serialize::Type<VHostImpl>(me)
+ , owner(this, "owner", &VHostImpl::owner, true)
+ , vident(this, "vident", &VHostImpl::vident)
+ , vhost(this, "vhost", &VHostImpl::vhost)
+ , creator(this, "creator", &VHostImpl::creator)
+ , created(this, "created", &VHostImpl::created)
+{
+
+}
+
diff --git a/modules/hostserv/main/vhosttype.h b/modules/hostserv/main/vhosttype.h
new file mode 100644
index 000000000..8306cae27
--- /dev/null
+++ b/modules/hostserv/main/vhosttype.h
@@ -0,0 +1,32 @@
+/*
+ * Anope IRC Services
+ *
+ * Copyright (C) 2015-2016 Anope Team <team@anope.org>
+ *
+ * This file is part of Anope. Anope is free software; you can
+ * redistribute it and/or modify it under the terms of the GNU
+ * General Public License as published by the Free Software
+ * Foundation, version 2.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see see <http://www.gnu.org/licenses/>.
+ */
+
+#include "vhost.h"
+
+class VHostType : public Serialize::Type<VHostImpl>
+{
+ public:
+ Serialize::ObjectField<VHostImpl, Serialize::Object *> owner;
+ Serialize::Field<VHostImpl, Anope::string> vident;
+ Serialize::Field<VHostImpl, Anope::string> vhost;
+ Serialize::Field<VHostImpl, Anope::string> creator;
+ Serialize::Field<VHostImpl, time_t> created;
+
+ VHostType(Module *);
+};