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 | |
parent | cffbf4e8fd93ae28f1c6d6fde221e72d70015942 (diff) |
Split vhosts into its own structure
25 files changed, 458 insertions, 182 deletions
diff --git a/include/modules/hostserv.h b/include/modules/hostserv.h new file mode 100644 index 000000000..4e6661faa --- /dev/null +++ b/include/modules/hostserv.h @@ -0,0 +1,50 @@ +/* + * 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 "serialize.h" + +namespace HostServ +{ + class VHost : public Serialize::Object + { + protected: + using Serialize::Object::Object; + + public: + static constexpr const char *const NAME = "vhost"; + + virtual Serialize::Object *GetOwner() anope_abstract; + virtual void SetOwner(Serialize::Object *) anope_abstract; + + virtual Anope::string GetIdent() anope_abstract; + virtual void SetIdent(const Anope::string &) anope_abstract; + + virtual Anope::string GetHost() anope_abstract; + virtual void SetHost(const Anope::string &) anope_abstract; + + virtual Anope::string GetCreator() anope_abstract; + virtual void SetCreator(const Anope::string &) anope_abstract; + + virtual time_t GetCreated() anope_abstract; + virtual void SetCreated(time_t) anope_abstract; + }; +} + diff --git a/include/modules/nickserv.h b/include/modules/nickserv.h index 43e2a21ce..1ecb2a933 100644 --- a/include/modules/nickserv.h +++ b/include/modules/nickserv.h @@ -22,6 +22,7 @@ #include "event.h" #include "service.h" #include "serialize.h" +#include "hostserv.h" namespace NickServ { @@ -169,27 +170,8 @@ namespace NickServ virtual Account *GetAccount() anope_abstract; virtual void SetAccount(Account *acc) anope_abstract; - /** Set a vhost for the user - * @param ident The ident - * @param host The host - * @param creator Who created the vhost - * @param time When the vhost was craated - */ - virtual void SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created = Anope::CurTime) anope_abstract; - virtual void RemoveVhost() anope_abstract; - virtual bool HasVhost() anope_abstract; - - virtual Anope::string GetVhostIdent() anope_abstract; - virtual void SetVhostIdent(const Anope::string &) anope_abstract; - - virtual Anope::string GetVhostHost() anope_abstract; - virtual void SetVhostHost(const Anope::string &) anope_abstract; - - virtual Anope::string GetVhostCreator() anope_abstract; - virtual void SetVhostCreator(const Anope::string &) anope_abstract; - - virtual time_t GetVhostCreated() anope_abstract; - virtual void SetVhostCreated(const time_t &) anope_abstract; + virtual HostServ::VHost *GetVHost() anope_abstract; + virtual void SetVHost(HostServ::VHost *) anope_abstract; }; /* A registered account. Each account must have a Nick with the same nick as the diff --git a/modules/database/old.cpp b/modules/database/old.cpp index 1a00b5c17..dad711cdb 100644 --- a/modules/database/old.cpp +++ b/modules/database/old.cpp @@ -738,7 +738,17 @@ static void LoadVHosts() continue; } - na->SetVhost(ident, host, creator, vtime); + HostServ::VHost *vhost = Serialize::New<HostServ::VHost *>(); + if (vhost == nullptr) + continue; + + vhost->SetOwner(na); + vhost->SetIdent(ident); + vhost->SetHost(host); + vhost->SetCreator(creator); + vhost->SetCreated(vtime); + + na->SetVHost(vhost); Log() << "Loaded vhost for " << na->GetNick(); } 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 diff --git a/modules/memoserv/main/memo.cpp b/modules/memoserv/main/memo.cpp index e148040f4..e55ce1cfb 100644 --- a/modules/memoserv/main/memo.cpp +++ b/modules/memoserv/main/memo.cpp @@ -19,10 +19,6 @@ #include "memotype.h" -MemoImpl::~MemoImpl() -{ -} - MemoServ::MemoInfo *MemoImpl::GetMemoInfo() { return Get(&MemoType::mi); diff --git a/modules/memoserv/main/memo.h b/modules/memoserv/main/memo.h index 5eac706db..7f34f90dd 100644 --- a/modules/memoserv/main/memo.h +++ b/modules/memoserv/main/memo.h @@ -31,7 +31,6 @@ class MemoImpl : public MemoServ::Memo public: MemoImpl(Serialize::TypeBase *type) : MemoServ::Memo(type) { } MemoImpl(Serialize::TypeBase *type, Serialize::ID id) : MemoServ::Memo(type, id) { } - ~MemoImpl(); MemoServ::MemoInfo *GetMemoInfo() override; void SetMemoInfo(MemoServ::MemoInfo *) override; diff --git a/modules/nickserv/info.cpp b/modules/nickserv/info.cpp index 593cfa116..e782edbaa 100644 --- a/modules/nickserv/info.cpp +++ b/modules/nickserv/info.cpp @@ -109,12 +109,13 @@ class CommandNSInfo : public Command if (show_hidden) { - if (na->HasVhost()) + HostServ::VHost *vhost = na->GetVHost(); + if (vhost != nullptr) { - if (IRCD->CanSetVIdent && !na->GetVhostIdent().empty()) - info[_("VHost")] = na->GetVhostIdent() + "@" + na->GetVhostHost(); + if (IRCD->CanSetVIdent && !vhost->GetIdent().empty()) + info[_("VHost")] = vhost->GetIdent() + "@" + vhost->GetHost(); else - info[_("VHost")] = na->GetVhostHost(); + info[_("VHost")] = vhost->GetHost(); } } diff --git a/modules/nickserv/main/nick.cpp b/modules/nickserv/main/nick.cpp index 3fc1e6b05..88f618855 100644 --- a/modules/nickserv/main/nick.cpp +++ b/modules/nickserv/main/nick.cpp @@ -136,64 +136,12 @@ void NickImpl::SetAccount(NickServ::Account *acc) Set(&NickType::nc, acc); } -void NickImpl::SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created) +HostServ::VHost *NickImpl::GetVHost() { - Set(&NickType::vhost_ident, ident); - Set(&NickType::vhost_host, host); - Set(&NickType::vhost_creator, creator); - Set(&NickType::vhost_created, created); + return Get(&NickType::vhost); } -void NickImpl::RemoveVhost() +void NickImpl::SetVHost(HostServ::VHost *vhost) { - Anope::string e; - Set(&NickType::vhost_ident, e); - Set(&NickType::vhost_host, e); - Set(&NickType::vhost_creator, e); - Set(&NickType::vhost_created, 0); -} - -bool NickImpl::HasVhost() -{ - return !GetVhostHost().empty(); -} - -Anope::string NickImpl::GetVhostIdent() -{ - return Get(&NickType::vhost_ident); -} - -void NickImpl::SetVhostIdent(const Anope::string &i) -{ - Set(&NickType::vhost_ident, i); -} - -Anope::string NickImpl::GetVhostHost() -{ - return Get(&NickType::vhost_host); -} - -void NickImpl::SetVhostHost(const Anope::string &h) -{ - Set(&NickType::vhost_host, h); -} - -Anope::string NickImpl::GetVhostCreator() -{ - return Get(&NickType::vhost_creator); -} - -void NickImpl::SetVhostCreator(const Anope::string &c) -{ - Set(&NickType::vhost_creator, c); -} - -time_t NickImpl::GetVhostCreated() -{ - return Get(&NickType::vhost_created); -} - -void NickImpl::SetVhostCreated(const time_t &cr) -{ - Set(&NickType::vhost_created, cr); -} + Set(&NickType::vhost, vhost); +}
\ No newline at end of file diff --git a/modules/nickserv/main/nick.h b/modules/nickserv/main/nick.h index ce0111b59..6c174739a 100644 --- a/modules/nickserv/main/nick.h +++ b/modules/nickserv/main/nick.h @@ -24,8 +24,7 @@ class NickImpl : public NickServ::Nick NickServ::Account *account = nullptr; Anope::string nick, last_quit, last_realname, last_usermask, last_realhost; time_t time_registered = 0, last_seen = 0; - Anope::string vhost_ident, vhost_host, vhost_creator; - time_t vhost_created = 0; + HostServ::VHost *vhost = nullptr; public: NickImpl(Serialize::TypeBase *type) : NickServ::Nick(type) { } @@ -57,16 +56,6 @@ class NickImpl : public NickServ::Nick NickServ::Account *GetAccount() override; void SetAccount(NickServ::Account *acc) override; - void SetVhost(const Anope::string &ident, const Anope::string &host, const Anope::string &creator, time_t created = Anope::CurTime) override; - void RemoveVhost() override; - bool HasVhost() override; - - Anope::string GetVhostIdent() override; - void SetVhostIdent(const Anope::string &) override; - Anope::string GetVhostHost() override; - void SetVhostHost(const Anope::string &) override; - Anope::string GetVhostCreator() override; - void SetVhostCreator(const Anope::string &) override; - time_t GetVhostCreated() override; - void SetVhostCreated(const time_t &) override; + HostServ::VHost *GetVHost() override; + void SetVHost(HostServ::VHost *) override; }; diff --git a/modules/nickserv/main/nicktype.cpp b/modules/nickserv/main/nicktype.cpp index 465cf2062..f27d27e18 100644 --- a/modules/nickserv/main/nicktype.cpp +++ b/modules/nickserv/main/nicktype.cpp @@ -28,11 +28,8 @@ NickType::NickType(Module *me) : Serialize::Type<NickImpl>(me) , last_realhost(this, "last_realhost", &NickImpl::last_realhost) , time_registered(this, "time_registered", &NickImpl::time_registered) , last_seen(this, "last_seen", &NickImpl::last_seen) - , vhost_ident(this, "vhost_ident", &NickImpl::vhost_ident) - , vhost_host(this, "vhost_host", &NickImpl::vhost_host) - , vhost_creator(this, "vhost_creator", &NickImpl::vhost_creator) - , vhost_created(this, "vhost_created", &NickImpl::vhost_created) , nc(this, "nc", &NickImpl::account) + , vhost(this, "vhost", &NickImpl::vhost) { } diff --git a/modules/nickserv/main/nicktype.h b/modules/nickserv/main/nicktype.h index cd875953a..08e556b0a 100644 --- a/modules/nickserv/main/nicktype.h +++ b/modules/nickserv/main/nicktype.h @@ -37,14 +37,11 @@ class NickType : public Serialize::Type<NickImpl> Serialize::Field<NickImpl, time_t> time_registered; Serialize::Field<NickImpl, time_t> last_seen; - Serialize::Field<NickImpl, Anope::string> vhost_ident; - Serialize::Field<NickImpl, Anope::string> vhost_host; - Serialize::Field<NickImpl, Anope::string> vhost_creator; - Serialize::Field<NickImpl, time_t> vhost_created; - /* Account this nick is tied to. Multiple nicks can be tied to a single account. */ Serialize::ObjectField<NickImpl, NickServ::Account *> nc; + Serialize::ObjectField<NickImpl, HostServ::VHost *> vhost; + NickType(Module *); NickServ::Nick *FindNick(const Anope::string &nick); diff --git a/modules/sasl.cpp b/modules/sasl.cpp index f07026b9e..0cc81d235 100644 --- a/modules/sasl.cpp +++ b/modules/sasl.cpp @@ -245,7 +245,8 @@ class SASLService : public SASL::Service, public Timer } else { - IRCD->SendSVSLogin(session->uid, nc->GetDisplay(), na->GetVhostIdent(), na->GetVhostHost()); + HostServ::VHost *vhost = na->GetVHost(); + IRCD->SendSVSLogin(session->uid, nc->GetDisplay(), vhost ? vhost->GetIdent() : "", vhost ? vhost->GetHost() : ""); } this->SendMessage(session, "D", "S"); } diff --git a/modules/webcpanel/pages/hostserv/request.cpp b/modules/webcpanel/pages/hostserv/request.cpp index 0230ba8fa..dc782361c 100644 --- a/modules/webcpanel/pages/hostserv/request.cpp +++ b/modules/webcpanel/pages/hostserv/request.cpp @@ -33,12 +33,13 @@ bool WebCPanel::HostServ::Request::OnRequest(HTTPProvider *server, const Anope:: WebPanel::RunCommand(na->GetAccount()->GetDisplay(), na->GetAccount(), "HostServ", "hostserv/request", params, replacements, "CMDR"); } - if (na->HasVhost()) + ::HostServ::VHost *vhost = na->GetVHost(); + if (vhost != nullptr) { - if (na->GetVhostIdent().empty() == false) - replacements["VHOST"] = na->GetVhostIdent() + "@" + na->GetVhostHost(); + if (vhost->GetIdent().empty() == false) + replacements["VHOST"] = vhost->GetIdent() + "@" + vhost->GetHost(); else - replacements["VHOST"] = na->GetVhostHost(); + replacements["VHOST"] = vhost->GetHost(); } if (ServiceReference<Command>("hostserv/request")) replacements["CAN_REQUEST"] = "YES"; diff --git a/modules/webcpanel/pages/nickserv/info.cpp b/modules/webcpanel/pages/nickserv/info.cpp index f3c353044..7b0f5d64f 100644 --- a/modules/webcpanel/pages/nickserv/info.cpp +++ b/modules/webcpanel/pages/nickserv/info.cpp @@ -100,13 +100,16 @@ bool WebCPanel::NickServ::Info::OnRequest(HTTPProvider *server, const Anope::str if (na->GetAccount()->GetEmail().empty() == false) replacements["EMAIL"] = HTTPUtils::Escape(na->GetAccount()->GetEmail()); replacements["TIME_REGISTERED"] = Anope::strftime(na->GetTimeRegistered(), na->GetAccount()); - if (na->HasVhost()) + + ::HostServ::VHost *vhost = na->GetVHost(); + if (vhost != nullptr) { - if (na->GetVhostIdent().empty() == false) - replacements["VHOST"] = na->GetVhostIdent() + "@" + na->GetVhostHost(); + if (vhost->GetIdent().empty() == false) + replacements["VHOST"] = vhost->GetIdent() + "@" + vhost->GetHost(); else - replacements["VHOST"] = na->GetVhostHost(); + replacements["VHOST"] = vhost->GetHost(); } + Anope::string *greet = na->GetAccount()->GetExt<Anope::string>("greet"); if (greet) replacements["GREET"] = HTTPUtils::Escape(*greet); |