diff options
author | Adam <Adam@anope.org> | 2016-10-09 19:51:39 -0400 |
---|---|---|
committer | Adam <Adam@anope.org> | 2016-10-09 19:51:39 -0400 |
commit | e7dd7159b1e1ab5b3edabc44ece5338672f8fbb4 (patch) | |
tree | 9517f02ca1c29fa247f6914398f35a44052c22ff /modules/hostserv/del.cpp | |
parent | 8ceca4fd3f9cb82bc93801d5eb682d27b2ad2f54 (diff) |
Make vhosts assignable to accounts, not nicks. Allow multiple vhosts per account.
Diffstat (limited to 'modules/hostserv/del.cpp')
-rw-r--r-- | modules/hostserv/del.cpp | 77 |
1 files changed, 26 insertions, 51 deletions
diff --git a/modules/hostserv/del.cpp b/modules/hostserv/del.cpp index 48a1209fc..4d754ac1b 100644 --- a/modules/hostserv/del.cpp +++ b/modules/hostserv/del.cpp @@ -23,10 +23,10 @@ class CommandHSDel : public Command { public: - CommandHSDel(Module *creator) : Command(creator, "hostserv/del", 1, 1) + CommandHSDel(Module *creator) : Command(creator, "hostserv/del", 1, 2) { - this->SetDesc(_("Delete the vhost of another user")); - this->SetSyntax(_("\037user\037")); + this->SetDesc(_("Delete the vhost of a user")); + this->SetSyntax(_("\037user\037 [\037vhost\037]")); } void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override @@ -35,6 +35,8 @@ class CommandHSDel : public Command source.Reply(_("Services are in read-only mode. Any changes made may not persist.")); const Anope::string &nick = params[0]; + const Anope::string &host = params.size() > 1 ? params[1] : ""; + NickServ::Nick *na = NickServ::FindNick(nick); if (!na) { @@ -42,67 +44,42 @@ class CommandHSDel : public Command return; } - HostServ::VHost *vhost = na->GetVHost(); - if (vhost == nullptr) + if (!host.empty()) { - source.Reply(_("\002{0}\002 doesn't have a vhost."), na->GetNick()); - return; - } + HostServ::VHost *vhost = HostServ::FindVHost(na->GetAccount(), host); - Log(LOG_ADMIN, source, this) << "for user " << na->GetNick(); - EventManager::Get()->Dispatch(&Event::DeleteVhost::OnDeleteVhost, na); - vhost->Delete(); - source.Reply(_("Vhost for \002{0}\002 has been removed."), na->GetNick()); - } - - bool OnHelp(CommandSource &source, const Anope::string &subcommand) override - { - source.Reply(_("Removes the vhost of \037user\037.")); - return true; - } -}; - -class CommandHSDelAll : public Command -{ - public: - CommandHSDelAll(Module *creator) : Command(creator, "hostserv/delall", 1, 1) - { - this->SetDesc(_("Delete the vhost for all nicks in a group")); - this->SetSyntax(_("\037group\037")); - } + if (vhost == nullptr) + { + source.Reply(_("\002{0}\002 doesn't have vhost \002{1}\002."), na->GetAccount()->GetDisplay(), host); + return; + } - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override - { - if (Anope::ReadOnly) - source.Reply(_("Services are in read-only mode. Any changes made may not persist.")); + Log(LOG_ADMIN, source, this) << "on " << na->GetAccount()->GetDisplay() << " to remove vhost " << vhost->Mask(); + source.Reply(_("Vhost \002{0}\002 for \002{1}\002 has been removed."), vhost->Mask(), na->GetAccount()->GetDisplay()); + vhost->Delete(); + return; + } - const Anope::string &nick = params[0]; - NickServ::Nick *na = NickServ::FindNick(nick); - if (!na) + std::vector<HostServ::VHost *> vhosts = na->GetAccount()->GetRefs<HostServ::VHost *>(); + if (vhosts.empty()) { - source.Reply(_("\002{0}\002 isn't registered."), nick); + source.Reply(_("\002{0}\002 doesn't have a vhost."), na->GetAccount()->GetDisplay()); return; } + Log(LOG_ADMIN, source, this) << "on " << na->GetAccount()->GetDisplay(); +#warning "send account" EventManager::Get()->Dispatch(&Event::DeleteVhost::OnDeleteVhost, na); - NickServ::Account *nc = na->GetAccount(); - for (NickServ::Nick *na2 : nc->GetRefs<NickServ::Nick *>()) - { - HostServ::VHost *vhost = na2->GetVHost(); - if (vhost != nullptr) - { - vhost->Delete(); - } - } + for (HostServ::VHost *v : vhosts) + v->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()); + source.Reply(_("Vhost(s) for \002{0}\002 has been removed."), na->GetAccount()->GetDisplay()); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override { - source.Reply(_("Removes the vhost of all nicks in the group \037group\037.")); + source.Reply(_("Removes the vhost of \037user\037.")); return true; } }; @@ -110,12 +87,10 @@ class CommandHSDelAll : public Command class HSDel : public Module { CommandHSDel commandhsdel; - CommandHSDelAll commandhsdelall; public: HSDel(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, VENDOR) , commandhsdel(this) - , commandhsdelall(this) { if (!IRCD || !IRCD->CanSetVHost) throw ModuleException("Your IRCd does not support vhosts"); |