From bb94f286f5ffdc86240cadbe713ede22966d6a18 Mon Sep 17 00:00:00 2001 From: Sadie Powell Date: Thu, 7 Mar 2024 21:18:06 +0000 Subject: [PATCH] Also use drop confirmation codes for nicknames. --- include/language.h | 1 + modules/chanserv/cs_drop.cpp | 7 +++--- modules/nickserv/ns_drop.cpp | 47 +++++++++++++++++++++++++++--------- 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/include/language.h b/include/language.h index a0ca020d9..8dfd004c1 100644 --- a/include/language.h +++ b/include/language.h @@ -65,6 +65,7 @@ namespace Language } // namespace Language /* Commonly used language strings */ +#define CONFIRM_DROP _("Please confirm that you want to drop \002%s\002 with \002DROP %s %s\002") #define MORE_INFO _("\002%s%s HELP %s\002 for more information.") #define BAD_USERHOST_MASK _("Mask must be in the form \037user\037@\037host\037.") #define BAD_EXPIRY_TIME _("Invalid expiry time.") diff --git a/modules/chanserv/cs_drop.cpp b/modules/chanserv/cs_drop.cpp index eada1c23b..cfeeddbdb 100644 --- a/modules/chanserv/cs_drop.cpp +++ b/modules/chanserv/cs_drop.cpp @@ -20,7 +20,7 @@ private: public: CommandCSDrop(Module *creator) : Command(creator, "chanserv/drop", 1, 2) - , dropcode(creator, "dropcode") + , dropcode(creator, "channel-dropcode") { this->SetDesc(_("Cancel the registration of a channel")); this->SetSyntax(_("\037channel\037 [\037code\037]")); @@ -54,12 +54,11 @@ public: { if (!code) { - code = ci->Extend("dropcode"); + code = ci->Extend("channel-dropcode"); *code = Anope::Random(15); } - source.Reply(_("Please confirm that you want to drop \002%s\002 with \002DROP %s %s\002"), - chan.c_str(), chan.c_str(), code->c_str()); + source.Reply(CONFIRM_DROP, ci->name.c_str(), ci->name.c_str(), code->c_str()); return; } diff --git a/modules/nickserv/ns_drop.cpp b/modules/nickserv/ns_drop.cpp index dbdbe09be..a315deab5 100644 --- a/modules/nickserv/ns_drop.cpp +++ b/modules/nickserv/ns_drop.cpp @@ -14,10 +14,15 @@ class CommandNSDrop final : public Command { +private: + PrimitiveExtensibleItem dropcode; + public: - CommandNSDrop(Module *creator) : Command(creator, "nickserv/drop", 1, 1) + CommandNSDrop(Module *creator) + : Command(creator, "nickserv/drop", 1, 2) + , dropcode(creator, "nickname-dropcode") { - this->SetSyntax(_("\037nickname\037")); + this->SetSyntax(_("\037nickname\037 [\037code\037]")); this->SetDesc(_("Cancel the registration of a nickname")); } @@ -41,18 +46,36 @@ public: bool is_mine = source.GetAccount() == na->nc; if (!is_mine && !source.HasPriv("nickserv/drop")) - source.Reply(ACCESS_DENIED); - else if (Config->GetModule("nickserv")->Get("secureadmins", "yes") && !is_mine && na->nc->IsServicesOper()) - source.Reply(_("You may not drop other Services Operators' nicknames.")); - else { - FOREACH_MOD(OnNickDrop, (source, na)); - - Log(!is_mine ? LOG_ADMIN : LOG_COMMAND, source, this) << "to drop nickname " << na->nick << " (group: " << na->nc->display << ") (email: " << (!na->nc->email.empty() ? na->nc->email : "none") << ")"; - delete na; - - source.Reply(_("Nickname \002%s\002 has been dropped."), nick.c_str()); + source.Reply(ACCESS_DENIED); + return; } + + if (Config->GetModule("nickserv")->Get("secureadmins", "yes") && !is_mine && na->nc->IsServicesOper()) + { + source.Reply(_("You may not drop other Services Operators' nicknames.")); + return; + } + + auto *code = dropcode.Get(na); + if (params.size() < 2 || !code || !code->equals_ci(params[1])) + { + if (!code) + { + code = na->Extend("nickname-dropcode"); + *code = Anope::Random(15); + } + + source.Reply(CONFIRM_DROP, na->nick.c_str(), na->nick.c_str(), code->c_str()); + return; + } + + FOREACH_MOD(OnNickDrop, (source, na)); + + Log(!is_mine ? LOG_ADMIN : LOG_COMMAND, source, this) << "to drop nickname " << na->nick << " (group: " << na->nc->display << ") (email: " << (!na->nc->email.empty() ? na->nc->email : "none") << ")"; + delete na; + + source.Reply(_("Nickname \002%s\002 has been dropped."), nick.c_str()); } bool OnHelp(CommandSource &source, const Anope::string &subcommand) override