diff options
| author | Adam <Adam@anope.org> | 2016-10-09 12:00:15 -0400 |
|---|---|---|
| committer | Adam <Adam@anope.org> | 2016-10-09 12:00:15 -0400 |
| commit | 5fd2d0ee3e136e01926f21edc759a4ab9fd48806 (patch) | |
| tree | 6666be3d14db12fe66a3576e889423f64e5229cc /modules/hostserv | |
| parent | cffbf4e8fd93ae28f1c6d6fde221e72d70015942 (diff) | |
Split vhosts into its own structure
Diffstat (limited to 'modules/hostserv')
| -rw-r--r-- | modules/hostserv/del.cpp | 18 | ||||
| -rw-r--r-- | modules/hostserv/group.cpp | 29 | ||||
| -rw-r--r-- | modules/hostserv/list.cpp | 26 | ||||
| -rw-r--r-- | modules/hostserv/main/hostserv.cpp | 50 | ||||
| -rw-r--r-- | modules/hostserv/main/vhost.cpp | 70 | ||||
| -rw-r--r-- | modules/hostserv/main/vhost.h | 52 | ||||
| -rw-r--r-- | modules/hostserv/main/vhosttype.cpp | 32 | ||||
| -rw-r--r-- | modules/hostserv/main/vhosttype.h | 32 | ||||
| -rw-r--r-- | modules/hostserv/off.cpp | 11 | ||||
| -rw-r--r-- | modules/hostserv/on.cpp | 26 | ||||
| -rw-r--r-- | modules/hostserv/request.cpp | 16 | ||||
| -rw-r--r-- | modules/hostserv/set.cpp | 64 |
12 files changed, 364 insertions, 62 deletions
diff --git a/modules/hostserv/del.cpp b/modules/hostserv/del.cpp index bc9b08533..48a1209fc 100644 --- a/modules/hostserv/del.cpp +++ b/modules/hostserv/del.cpp @@ -42,9 +42,16 @@ class CommandHSDel : public Command return; } + HostServ::VHost *vhost = na->GetVHost(); + if (vhost == nullptr) + { + source.Reply(_("\002{0}\002 doesn't have a vhost."), na->GetNick()); + return; + } + Log(LOG_ADMIN, source, this) << "for user " << na->GetNick(); EventManager::Get()->Dispatch(&Event::DeleteVhost::OnDeleteVhost, na); - na->RemoveVhost(); + vhost->Delete(); source.Reply(_("Vhost for \002{0}\002 has been removed."), na->GetNick()); } @@ -81,7 +88,14 @@ class CommandHSDelAll : public Command NickServ::Account *nc = na->GetAccount(); for (NickServ::Nick *na2 : nc->GetRefs<NickServ::Nick *>()) - na2->RemoveVhost(); + { + HostServ::VHost *vhost = na2->GetVHost(); + if (vhost != nullptr) + { + vhost->Delete(); + } + } + 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()); } diff --git a/modules/hostserv/group.cpp b/modules/hostserv/group.cpp index 8113435fa..a41dc24db 100644 --- a/modules/hostserv/group.cpp +++ b/modules/hostserv/group.cpp @@ -30,13 +30,29 @@ class CommandHSGroup : public Command if (setting) return; - if (!na || !na->HasVhost()) + HostServ::VHost *v = na->GetVHost(); + + if (v == nullptr) return; setting = true; for (NickServ::Nick *nick : na->GetAccount()->GetRefs<NickServ::Nick *>()) { - nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator()); + if (nick == na) + continue; + + HostServ::VHost *vhost = Serialize::New<HostServ::VHost *>(); + if (vhost == nullptr) + continue; + + vhost->SetOwner(nick); + vhost->SetIdent(v->GetIdent()); + vhost->SetHost(v->GetHost()); + vhost->SetCreator(v->GetCreator()); + vhost->SetCreated(Anope::CurTime); + + nick->SetVHost(vhost); + EventManager::Get()->Dispatch(&Event::SetVhost::OnSetVhost, nick); } setting = false; @@ -62,17 +78,18 @@ class CommandHSGroup : public Command return; } - if (!na->HasVhost()) + HostServ::VHost *vhost = na->GetVHost(); + if (vhost == nullptr) { source.Reply(_("There is no vhost assigned to this nickname.")); return; } this->Sync(na); - if (!na->GetVhostIdent().empty()) - source.Reply(_("All vhosts in the group \002{0}\002 have been set to \002{1}\002@\002{2}\002."), source.nc->GetDisplay(), na->GetVhostIdent(), na->GetVhostHost()); + if (!vhost->GetIdent().empty()) + source.Reply(_("All vhosts in the group \002{0}\002 have been set to \002{1}\002@\002{2}\002."), source.nc->GetDisplay(), vhost->GetIdent(), vhost->GetHost()); else - source.Reply(_("All vhosts in the group \002{0}\002 have been set to \002{1}\002."), source.nc->GetDisplay(), na->GetVhostHost()); + source.Reply(_("All vhosts in the group \002{0}\002 have been set to \002{1}\002."), source.nc->GetDisplay(), vhost->GetHost()); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override diff --git a/modules/hostserv/list.cpp b/modules/hostserv/list.cpp index cdaf72a37..5a2b5238a 100644 --- a/modules/hostserv/list.cpp +++ b/modules/hostserv/list.cpp @@ -67,24 +67,26 @@ class CommandHSList : public Command for (NickServ::Nick *na : NickServ::service->GetNickList()) { - if (!na->HasVhost()) + HostServ::VHost *vhost = na->GetVHost(); + + if (vhost == nullptr) continue; if (!key.empty() && key[0] != '#') { - if ((Anope::Match(na->GetNick(), key) || Anope::Match(na->GetVhostHost(), key)) && display_counter < listmax) + if ((Anope::Match(na->GetNick(), key) || Anope::Match(vhost->GetHost(), key)) && display_counter < listmax) { ++display_counter; ListFormatter::ListEntry entry; entry["Number"] = stringify(display_counter); entry["Nick"] = na->GetNick(); - if (!na->GetVhostIdent().empty()) - entry["Vhost"] = na->GetVhostIdent() + "@" + na->GetVhostHost(); + if (!vhost->GetIdent().empty()) + entry["Vhost"] = vhost->GetIdent() + "@" + vhost->GetHost(); else - entry["Vhost"] = na->GetVhostHost(); - entry["Creator"] = na->GetVhostCreator(); - entry["Created"] = Anope::strftime(na->GetVhostCreated(), NULL, true); + entry["Vhost"] = vhost->GetHost(); + entry["Creator"] = vhost->GetCreator(); + entry["Created"] = Anope::strftime(vhost->GetCreated(), NULL, true); list.AddEntry(entry); } } @@ -100,12 +102,12 @@ class CommandHSList : public Command ListFormatter::ListEntry entry; entry["Number"] = stringify(display_counter); entry["Nick"] = na->GetNick(); - if (!na->GetVhostIdent().empty()) - entry["Vhost"] = na->GetVhostIdent() + "@" + na->GetVhostHost(); + if (!vhost->GetIdent().empty()) + entry["Vhost"] = vhost->GetIdent() + "@" + vhost->GetHost(); else - entry["Vhost"] = na->GetVhostHost(); - entry["Creator"] = na->GetVhostCreator(); - entry["Created"] = Anope::strftime(na->GetVhostCreated(), NULL, true); + entry["Vhost"] = vhost->GetHost(); + entry["Creator"] = vhost->GetCreator(); + entry["Created"] = Anope::strftime(vhost->GetCreated(), NULL, true); list.AddEntry(entry); } } 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 *); +}; diff --git a/modules/hostserv/off.cpp b/modules/hostserv/off.cpp index e8c191164..95c27532a 100644 --- a/modules/hostserv/off.cpp +++ b/modules/hostserv/off.cpp @@ -32,16 +32,21 @@ class CommandHSOff : public Command { User *u = source.GetUser(); NickServ::Nick *na = NickServ::FindNick(u->nick); + HostServ::VHost *vhost = nullptr; - if (!na || na->GetAccount() != u->Account() || !na->HasVhost()) - na = NickServ::FindNick(u->Account()->GetDisplay()); + if (na && na->GetAccount() == source.GetAccount()) + vhost = na->GetVHost(); - if (!na || !na->HasVhost() || na->GetAccount() != source.GetAccount()) + if (vhost == nullptr) + vhost = NickServ::FindNick(u->Account()->GetDisplay())->GetVHost(); + + if (vhost == nullptr) { source.Reply(_("There is no vhost assigned to this nickname.")); return; } + // XXX vident? u->vhost.clear(); IRCD->SendVhostDel(u); Log(LOG_COMMAND, source, this) << "to disable their vhost"; diff --git a/modules/hostserv/on.cpp b/modules/hostserv/on.cpp index 1332c7e7a..c911ec206 100644 --- a/modules/hostserv/on.cpp +++ b/modules/hostserv/on.cpp @@ -35,26 +35,30 @@ class CommandHSOn : public Command User *u = source.GetUser(); NickServ::Nick *na = NickServ::FindNick(u->nick); + HostServ::VHost *vhost = nullptr; - if (!na || na->GetAccount() != u->Account() || !na->HasVhost()) - na = NickServ::FindNick(u->Account()->GetDisplay()); + if (na && na->GetAccount() == source.GetAccount()) + vhost = na->GetVHost(); - if (!na || !na->HasVhost() || na->GetAccount() != u->Account()) + if (vhost == nullptr) + vhost = NickServ::FindNick(u->Account()->GetDisplay())->GetVHost(); + + if (vhost == nullptr) { source.Reply(_("There is no vhost assigned to this nickname.")); return; } - if (!na->GetVhostIdent().empty()) - source.Reply(_("Your vhost of \002{0}\002@\002{1}\002 is now activated."), na->GetVhostIdent(), na->GetVhostHost()); + if (!vhost->GetIdent().empty()) + source.Reply(_("Your vhost of \002{0}\002@\002{1}\002 is now activated."), vhost->GetIdent(), vhost->GetHost()); else - source.Reply(_("Your vhost of \002{0}\002 is now activated."), na->GetVhostHost()); + source.Reply(_("Your vhost of \002{0}\002 is now activated."), vhost->GetHost()); - Log(LOG_COMMAND, source, this) << "to enable their vhost of " << (!na->GetVhostIdent().empty() ? na->GetVhostIdent() + "@" : "") << na->GetVhostHost(); - IRCD->SendVhost(u, na->GetVhostIdent(), na->GetVhostHost()); - u->vhost = na->GetVhostHost(); - if (IRCD->CanSetVIdent && !na->GetVhostIdent().empty()) - u->SetVIdent(na->GetVhostIdent()); + Log(LOG_COMMAND, source, this) << "to enable their vhost of " << (!vhost->GetIdent().empty() ? vhost->GetIdent() + "@" : "") << vhost->GetHost(); + IRCD->SendVhost(u, vhost->GetIdent(), vhost->GetHost()); + u->vhost = vhost->GetHost(); + if (IRCD->CanSetVIdent && !vhost->GetIdent().empty()) + u->SetVIdent(vhost->GetIdent()); u->UpdateHost(); } diff --git a/modules/hostserv/request.cpp b/modules/hostserv/request.cpp index 2024ef3b3..2bad26b48 100644 --- a/modules/hostserv/request.cpp +++ b/modules/hostserv/request.cpp @@ -271,7 +271,21 @@ class CommandHSActivate : public Command return; } - na->SetVhost(req->GetIdent(), req->GetHost(), source.GetNick(), req->GetTime()); + HostServ::VHost *vhost = Serialize::New<HostServ::VHost *>(); + if (vhost == nullptr) + { + source.Reply(_("Unable to create vhost, is hostserv enabled?")); + return; + } + + vhost->SetOwner(na); + vhost->SetIdent(req->GetIdent()); + vhost->SetHost(req->GetHost()); + vhost->SetCreator(source.GetNick()); + vhost->SetCreated(req->GetTime()); + + na->SetVHost(vhost); + EventManager::Get()->Dispatch(&Event::SetVhost::OnSetVhost, na); if (Config->GetModule(this->GetOwner())->Get<bool>("memouser") && memoserv) diff --git a/modules/hostserv/set.cpp b/modules/hostserv/set.cpp index 357c0466a..85769e0d2 100644 --- a/modules/hostserv/set.cpp +++ b/modules/hostserv/set.cpp @@ -93,12 +93,26 @@ 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()); + HostServ::VHost *vhost = Serialize::New<HostServ::VHost *>(); + if (vhost == nullptr) + { + source.Reply(_("Unable to create vhost, is hostserv enabled?")); + return; + } + + vhost->SetOwner(na); + vhost->SetIdent(user); + vhost->SetHost(host); + vhost->SetCreator(source.GetNick()); + vhost->SetCreated(Anope::CurTime); + + na->SetVHost(vhost); + 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); + source.Reply(_("Vhost for \002{0}\002 set to \002{1}\002@\002{2}\002."), na->GetNick(), user, host); else - source.Reply(_("Vhost for \002{0}\002 set to \002{0}\002."), nick, host); + source.Reply(_("Vhost for \002{0}\002 set to \002{1}\002."), na->GetNick(), host); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override @@ -112,11 +126,31 @@ class CommandHSSetAll : public Command { void Sync(NickServ::Nick *na) { - if (!na || !na->HasVhost()) + if (!na) + return; + + HostServ::VHost *v = na->GetVHost(); + + if (v == nullptr) return; for (NickServ::Nick *nick : na->GetAccount()->GetRefs<NickServ::Nick *>()) - nick->SetVhost(na->GetVhostIdent(), na->GetVhostHost(), na->GetVhostCreator()); + { + if (nick == na) + continue; + + HostServ::VHost *vhost = Serialize::New<HostServ::VHost *>(); + if (vhost == nullptr) + continue; + + vhost->SetOwner(nick); + vhost->SetIdent(v->GetIdent()); + vhost->SetHost(v->GetHost()); + vhost->SetCreator(v->GetCreator()); + vhost->SetCreated(Anope::CurTime); + + nick->SetVHost(vhost); + } } public: @@ -190,13 +224,27 @@ class CommandHSSetAll : 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()); + HostServ::VHost *vhost = Serialize::New<HostServ::VHost *>(); + if (vhost == nullptr) + { + source.Reply(_("Unable to create vhost, is hostserv enabled?")); + return; + } + + vhost->SetOwner(na); + vhost->SetIdent(user); + vhost->SetHost(host); + vhost->SetCreator(source.GetNick()); + vhost->SetCreated(Anope::CurTime); + + na->SetVHost(vhost); + this->Sync(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()); + source.Reply(_("Vhost for group \002{0}\002 set to \002{1}\002@\002{2}\002."), na->GetAccount()->GetDisplay(), user, host); else - source.Reply(_("host for group \002{0}\002 set to \002{1}\002."), nick.c_str(), host.c_str()); + source.Reply(_("host for group \002{0}\002 set to \002{1}\002."), na->GetAccount()->GetDisplay(), host); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override |
