diff options
Diffstat (limited to 'modules/commands/ns_set.cpp')
-rw-r--r-- | modules/commands/ns_set.cpp | 202 |
1 files changed, 101 insertions, 101 deletions
diff --git a/modules/commands/ns_set.cpp b/modules/commands/ns_set.cpp index 62dd51180..b18bb9cff 100644 --- a/modules/commands/ns_set.cpp +++ b/modules/commands/ns_set.cpp @@ -20,13 +20,13 @@ class CommandNSSet : public Command this->SetSyntax(_("\037option\037 \037parameters\037")); } - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { this->OnSyntaxError(source, ""); return; } - bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override { this->SendSyntax(source); source.Reply(" "); @@ -35,11 +35,8 @@ class CommandNSSet : public Command Anope::string this_name = source.command; bool hide_privileged_commands = Config->GetBlock("options")->Get<bool>("hideprivilegedcommands"), hide_registered_commands = Config->GetBlock("options")->Get<bool>("hideregisteredcommands"); - for (CommandInfo::map::const_iterator it = source.service->commands.begin(), it_end = source.service->commands.end(); it != it_end; ++it) + for (const auto &[c_name, info] : source.service->commands) { - const Anope::string &c_name = it->first; - const CommandInfo &info = it->second; - if (c_name.find_ci(this_name + " ") == 0) { if (info.hide) @@ -75,24 +72,21 @@ class CommandNSSASet : public Command this->SetSyntax(_("\037option\037 \037nickname\037 \037parameters\037")); } - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { this->OnSyntaxError(source, ""); return; } - bool OnHelp(CommandSource &source, const Anope::string &subcommand) anope_override + bool OnHelp(CommandSource &source, const Anope::string &subcommand) override { this->SendSyntax(source); source.Reply(" "); source.Reply(_("Sets various nickname options. \037option\037 can be one of:")); Anope::string this_name = source.command; - for (CommandInfo::map::const_iterator it = source.service->commands.begin(), it_end = source.service->commands.end(); it != it_end; ++it) + for (const auto &[c_name, info] : source.service->commands) { - const Anope::string &c_name = it->first; - const CommandInfo &info = it->second; - if (c_name.find_ci(this_name + " ") == 0) { ServiceReference<Command> command("Command", info.name); @@ -120,7 +114,7 @@ class CommandNSSetPassword : public Command this->SetSyntax(_("\037new-password\037")); } - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { const Anope::string ¶m = params[0]; unsigned len = param.length(); @@ -131,30 +125,33 @@ class CommandNSSetPassword : public Command return; } - if (source.GetNick().equals_ci(param) || (Config->GetBlock("options")->Get<bool>("strictpasswords") && len < 5)) + if (source.GetNick().equals_ci(param)) { source.Reply(MORE_OBSCURE_PASSWORD); return; } - unsigned int passlen = Config->GetModule("nickserv")->Get<unsigned>("passlen", "32"); - if (len > passlen) + unsigned int minpasslen = Config->GetModule("nickserv")->Get<unsigned>("minpasslen", "8"); + if (len < minpasslen) { - source.Reply(PASSWORD_TOO_LONG, passlen); + source.Reply(PASSWORD_TOO_SHORT, minpasslen); + return; + } + + unsigned int maxpasslen = Config->GetModule("nickserv")->Get<unsigned>("maxpasslen", "32"); + if (len > maxpasslen) + { + source.Reply(PASSWORD_TOO_LONG, maxpasslen); return; } Log(LOG_COMMAND, source, this) << "to change their password"; Anope::Encrypt(param, source.nc->pass); - Anope::string tmp_pass; - if (Anope::Decrypt(source.nc->pass, tmp_pass) == 1) - source.Reply(_("Password for \002%s\002 changed to \002%s\002."), source.nc->display.c_str(), tmp_pass.c_str()); - else - source.Reply(_("Password for \002%s\002 changed."), source.nc->display.c_str()); + source.Reply(_("Password for \002%s\002 changed."), source.nc->display.c_str()); } - bool OnHelp(CommandSource &source, const Anope::string &) anope_override + bool OnHelp(CommandSource &source, const Anope::string &) override { this->SendSyntax(source); source.Reply(" "); @@ -173,7 +170,7 @@ class CommandNSSASetPassword : public Command this->SetSyntax(_("\037nickname\037 \037new-password\037")); } - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { if (Anope::ReadOnly) { @@ -197,16 +194,23 @@ class CommandNSSASetPassword : public Command return; } - if (nc->display.equals_ci(params[1]) || (Config->GetBlock("options")->Get<bool>("strictpasswords") && len < 5)) + if (nc->display.equals_ci(params[1])) { source.Reply(MORE_OBSCURE_PASSWORD); return; } - unsigned int passlen = Config->GetModule("nickserv")->Get<unsigned>("passlen", "32"); - if (len > passlen) + unsigned int minpasslen = Config->GetModule("nickserv")->Get<unsigned>("minpasslen", "8"); + if (len < minpasslen) + { + source.Reply(PASSWORD_TOO_SHORT, minpasslen); + return; + } + + unsigned int maxpasslen = Config->GetModule("nickserv")->Get<unsigned>("maxpasslen", "32"); + if (len > maxpasslen) { - source.Reply(PASSWORD_TOO_LONG, passlen); + source.Reply(PASSWORD_TOO_LONG, maxpasslen); return; } @@ -214,13 +218,10 @@ class CommandNSSASetPassword : public Command Anope::Encrypt(params[1], nc->pass); Anope::string tmp_pass; - if (Anope::Decrypt(nc->pass, tmp_pass) == 1) - source.Reply(_("Password for \002%s\002 changed to \002%s\002."), nc->display.c_str(), tmp_pass.c_str()); - else - source.Reply(_("Password for \002%s\002 changed."), nc->display.c_str()); + source.Reply(_("Password for \002%s\002 changed."), nc->display.c_str()); } - bool OnHelp(CommandSource &source, const Anope::string &) anope_override + bool OnHelp(CommandSource &source, const Anope::string &) override { this->SendSyntax(source); source.Reply(" "); @@ -275,12 +276,12 @@ class CommandNSSetAutoOp : public Command this->OnSyntaxError(source, "AUTOOP"); } - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { this->Run(source, source.nc->display, params[0]); } - bool OnHelp(CommandSource &source, const Anope::string &) anope_override + bool OnHelp(CommandSource &source, const Anope::string &) override { BotInfo *bi = Config->GetClient("ChanServ"); this->SendSyntax(source); @@ -302,12 +303,12 @@ class CommandNSSASetAutoOp : public CommandNSSetAutoOp this->SetSyntax(_("\037nickname\037 {ON | OFF}")); } - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { this->Run(source, params[0], params[1]); } - bool OnHelp(CommandSource &source, const Anope::string &) anope_override + bool OnHelp(CommandSource &source, const Anope::string &) override { BotInfo *bi = Config->GetClient("ChanServ"); this->SendSyntax(source); @@ -375,12 +376,12 @@ class CommandNSSetDisplay : public Command source.Reply(NICK_SET_DISPLAY_CHANGED, user_na->nc->display.c_str()); } - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { this->Run(source, source.nc->display, params[0]); } - bool OnHelp(CommandSource &source, const Anope::string &) anope_override + bool OnHelp(CommandSource &source, const Anope::string &) override { this->SendSyntax(source); source.Reply(" "); @@ -399,12 +400,12 @@ class CommandNSSASetDisplay : public CommandNSSetDisplay this->SetSyntax(_("\037nickname\037 \037new-display\037")); } - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { this->Run(source, params[0], params[1]); } - bool OnHelp(CommandSource &source, const Anope::string &) anope_override + bool OnHelp(CommandSource &source, const Anope::string &) override { this->SendSyntax(source); source.Reply(" "); @@ -521,12 +522,12 @@ class CommandNSSetEmail : public Command } } - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { this->Run(source, source.nc->display, params.size() ? params[0] : ""); } - bool OnHelp(CommandSource &source, const Anope::string &) anope_override + bool OnHelp(CommandSource &source, const Anope::string &) override { this->SendSyntax(source); source.Reply(" "); @@ -546,12 +547,12 @@ class CommandNSSASetEmail : public CommandNSSetEmail this->SetSyntax(_("\037nickname\037 \037address\037")); } - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { this->Run(source, params[0], params.size() > 1 ? params[1] : ""); } - bool OnHelp(CommandSource &source, const Anope::string &) anope_override + bool OnHelp(CommandSource &source, const Anope::string &) override { this->SendSyntax(source); source.Reply(" "); @@ -606,12 +607,12 @@ class CommandNSSetKeepModes : public Command this->OnSyntaxError(source, ""); } - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { this->Run(source, source.nc->display, params[0]); } - bool OnHelp(CommandSource &source, const Anope::string &) anope_override + bool OnHelp(CommandSource &source, const Anope::string &) override { this->SendSyntax(source); source.Reply(" "); @@ -631,12 +632,12 @@ class CommandNSSASetKeepModes : public CommandNSSetKeepModes this->SetSyntax(_("\037nickname\037 {ON | OFF}")); } - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { this->Run(source, params[0], params[1]); } - bool OnHelp(CommandSource &source, const Anope::string &) anope_override + bool OnHelp(CommandSource &source, const Anope::string &) override { this->SendSyntax(source); source.Reply(" "); @@ -726,12 +727,12 @@ class CommandNSSetKill : public Command return; } - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { this->Run(source, source.nc->display, params[0]); } - bool OnHelp(CommandSource &source, const Anope::string &) anope_override + bool OnHelp(CommandSource &source, const Anope::string &) override { this->SendSyntax(source); source.Reply(" "); @@ -760,12 +761,12 @@ class CommandNSSASetKill : public CommandNSSetKill this->SetSyntax(_("\037nickname\037 {ON | QUICK | IMMED | OFF}")); } - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { this->Run(source, params[0], params[1]); } - bool OnHelp(CommandSource &source, const Anope::string &) anope_override + bool OnHelp(CommandSource &source, const Anope::string &) override { this->SendSyntax(source); source.Reply(" "); @@ -790,7 +791,7 @@ class CommandNSSetLanguage : public Command public: CommandNSSetLanguage(Module *creator, const Anope::string &sname = "nickserv/set/language", size_t min = 1) : Command(creator, sname, min, min + 1) { - this->SetDesc(_("Set the language Services will use when messaging you")); + this->SetDesc(_("Set the language services will use when messaging you")); this->SetSyntax(_("\037language\037")); } @@ -836,27 +837,27 @@ class CommandNSSetLanguage : public Command source.Reply(_("Language for \002%s\002 changed to \002%s\002."), nc->display.c_str(), Language::Translate(param.c_str(), _("English"))); } - void Execute(CommandSource &source, const std::vector<Anope::string> ¶m) anope_override + void Execute(CommandSource &source, const std::vector<Anope::string> ¶m) override { this->Run(source, source.nc->display, param[0]); } - bool OnHelp(CommandSource &source, const Anope::string &) anope_override + bool OnHelp(CommandSource &source, const Anope::string &) override { this->SendSyntax(source); source.Reply(" "); - source.Reply(_("Changes the language Services uses when sending messages to\n" + source.Reply(_("Changes the language services uses when sending messages to\n" "you (for example, when responding to a command you send).\n" "\037language\037 should be chosen from the following list of\n" "supported languages:")); source.Reply(" en_US (English)"); - for (unsigned j = 0; j < Language::Languages.size(); ++j) + for (const auto &language : Language::Languages) { - const Anope::string &langname = Language::Translate(Language::Languages[j].c_str(), _("English")); + const Anope::string &langname = Language::Translate(language.c_str(), _("English")); if (langname == "English") continue; - source.Reply(" %s (%s)", Language::Languages[j].c_str(), langname.c_str()); + source.Reply(" %s (%s)", language.c_str(), langname.c_str()); } return true; @@ -872,26 +873,26 @@ class CommandNSSASetLanguage : public CommandNSSetLanguage this->SetSyntax(_("\037nickname\037 \037language\037")); } - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { this->Run(source, params[0], params[1]); } - bool OnHelp(CommandSource &source, const Anope::string &) anope_override + bool OnHelp(CommandSource &source, const Anope::string &) override { this->SendSyntax(source); source.Reply(" "); - source.Reply(_("Changes the language Services uses when sending messages to\n" + source.Reply(_("Changes the language services uses when sending messages to\n" "the given user (for example, when responding to a command they send).\n" "\037language\037 should be chosen from the following list of\n" "supported languages:")); source.Reply(" en (English)"); - for (unsigned j = 0; j < Language::Languages.size(); ++j) + for (const auto &language : Language::Languages) { - const Anope::string &langname = Language::Translate(Language::Languages[j].c_str(), _("English")); + const Anope::string &langname = Language::Translate(language.c_str(), _("English")); if (langname == "English") continue; - source.Reply(" %s (%s)", Language::Languages[j].c_str(), langname.c_str()); + source.Reply(" %s (%s)", language.c_str(), langname.c_str()); } return true; } @@ -902,7 +903,7 @@ class CommandNSSetMessage : public Command public: CommandNSSetMessage(Module *creator, const Anope::string &sname = "nickserv/set/message", size_t min = 1) : Command(creator, sname, min, min + 1) { - this->SetDesc(_("Change the communication method of Services")); + this->SetDesc(_("Change the communication method of services")); this->SetSyntax("{ON | OFF}"); } @@ -949,12 +950,12 @@ class CommandNSSetMessage : public Command this->OnSyntaxError(source, "MSG"); } - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { this->Run(source, source.nc->display, params[0]); } - bool OnHelp(CommandSource &source, const Anope::string &) anope_override + bool OnHelp(CommandSource &source, const Anope::string &) override { Anope::string cmd = source.command; size_t i = cmd.find_last_of(' '); @@ -963,13 +964,13 @@ class CommandNSSetMessage : public Command this->SendSyntax(source); source.Reply(" "); - source.Reply(_("Allows you to choose the way Services are communicating with\n" - "you. With \002%s\002 set, Services will use messages, else they'll\n" + source.Reply(_("Allows you to choose the way services are communicating with\n" + "you. With \002%s\002 set, services will use messages, else they'll\n" "use notices."), cmd.upper().c_str()); return true; } - void OnServHelp(CommandSource &source) anope_override + void OnServHelp(CommandSource &source) override { if (Config->GetBlock("options")->Get<bool>("useprivmsg")) Command::OnServHelp(source); @@ -985,17 +986,17 @@ class CommandNSSASetMessage : public CommandNSSetMessage this->SetSyntax(_("\037nickname\037 {ON | OFF}")); } - bool OnHelp(CommandSource &source, const Anope::string &) anope_override + bool OnHelp(CommandSource &source, const Anope::string &) override { this->SendSyntax(source); source.Reply(" "); - source.Reply(_("Allows you to choose the way Services are communicating with\n" - "the given user. With \002MSG\002 set, Services will use messages,\n" + source.Reply(_("Allows you to choose the way services are communicating with\n" + "the given user. With \002MSG\002 set, services will use messages,\n" "else they'll use notices.")); return true; } - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { this->Run(source, params[0], params[1]); } @@ -1047,12 +1048,12 @@ class CommandNSSetSecure : public Command this->OnSyntaxError(source, "SECURE"); } - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { this->Run(source, source.nc->display, params[0]); } - bool OnHelp(CommandSource &source, const Anope::string &) anope_override + bool OnHelp(CommandSource &source, const Anope::string &) override { this->SendSyntax(source); source.Reply(" "); @@ -1076,12 +1077,12 @@ class CommandNSSASetSecure : public CommandNSSetSecure this->SetSyntax(_("\037nickname\037 {ON | OFF}")); } - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { this->Run(source, params[0], params[1]); } - bool OnHelp(CommandSource &source, const Anope::string &) anope_override + bool OnHelp(CommandSource &source, const Anope::string &) override { this->SendSyntax(source); source.Reply(" "); @@ -1105,7 +1106,7 @@ class CommandNSSASetNoexpire : public Command this->SetSyntax(_("\037nickname\037 {ON | OFF}")); } - void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) anope_override + void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms) override { if (Anope::ReadOnly) { @@ -1138,7 +1139,7 @@ class CommandNSSASetNoexpire : public Command this->OnSyntaxError(source, "NOEXPIRE"); } - bool OnHelp(CommandSource &source, const Anope::string &) anope_override + bool OnHelp(CommandSource &source, const Anope::string &) override { this->SendSyntax(source); source.Reply(" "); @@ -1189,7 +1190,7 @@ class NSSet : public Module { KeepModes(Module *m, const Anope::string &n) : SerializableExtensibleItem<bool>(m, n) { } - void ExtensibleSerialize(const Extensible *e, const Serializable *s, Serialize::Data &data) const anope_override + void ExtensibleSerialize(const Extensible *e, const Serializable *s, Serialize::Data &data) const override { SerializableExtensibleItem<bool>::ExtensibleSerialize(e, s, data); @@ -1198,18 +1199,18 @@ class NSSet : public Module const NickCore *nc = anope_dynamic_static_cast<const NickCore *>(s); Anope::string modes; - for (User::ModeList::const_iterator it = nc->last_modes.begin(); it != nc->last_modes.end(); ++it) + for (const auto &[last_mode, last_value] : nc->last_modes) { if (!modes.empty()) modes += " "; - modes += it->first; - if (!it->second.empty()) - modes += "," + it->second; + modes += last_mode; + if (!last_value.empty()) + modes += "," + last_value; } data["last_modes"] << modes; } - void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) anope_override + void ExtensibleUnserialize(Extensible *e, Serializable *s, Serialize::Data &data) override { SerializableExtensibleItem<bool>::ExtensibleUnserialize(e, s, data); @@ -1224,9 +1225,9 @@ class NSSet : public Module { size_t c = modes.find(','); if (c == Anope::string::npos) - nc->last_modes.insert(std::make_pair(modes, "")); + nc->last_modes.emplace(modes, ""); else - nc->last_modes.insert(std::make_pair(modes.substr(0, c), modes.substr(c + 1))); + nc->last_modes.emplace(modes.substr(0, c), modes.substr(c + 1)); } } } keep_modes; @@ -1258,7 +1259,7 @@ class NSSet : public Module } - EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> ¶ms) anope_override + EventReturn OnPreCommand(CommandSource &source, Command *command, std::vector<Anope::string> ¶ms) override { NickCore *uac = source.nc; @@ -1281,7 +1282,7 @@ class NSSet : public Module return EVENT_CONTINUE; } - void OnSetCorrectModes(User *user, Channel *chan, AccessGroup &access, bool &give_modes, bool &take_modes) anope_override + void OnSetCorrectModes(User *user, Channel *chan, AccessGroup &access, bool &give_modes, bool &take_modes) override { if (chan->ci) { @@ -1290,13 +1291,13 @@ class NSSet : public Module } } - void OnPreNickExpire(NickAlias *na, bool &expire) anope_override + void OnPreNickExpire(NickAlias *na, bool &expire) override { if (noexpire.HasExt(na)) expire = false; } - void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) anope_override + void OnNickInfo(CommandSource &source, NickAlias *na, InfoFormatter &info, bool show_hidden) override { if (!show_hidden) return; @@ -1319,29 +1320,28 @@ class NSSet : public Module info.AddOption(_("Keep modes")); } - void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) anope_override + void OnUserModeSet(const MessageSource &setter, User *u, const Anope::string &mname) override { if (u->Account() && setter.GetUser() == u) u->Account()->last_modes = u->GetModeList(); } - void OnUserModeUnset(const MessageSource &setter, User *u, const Anope::string &mname) anope_override + void OnUserModeUnset(const MessageSource &setter, User *u, const Anope::string &mname) override { if (u->Account() && setter.GetUser() == u) u->Account()->last_modes = u->GetModeList(); } - void OnUserLogin(User *u) anope_override + void OnUserLogin(User *u) override { if (keep_modes.HasExt(u->Account())) { - User::ModeList modes = u->Account()->last_modes; - for (User::ModeList::iterator it = modes.begin(); it != modes.end(); ++it) + for (const auto &[last_mode, last_value] : u->Account()->last_modes) { - UserMode *um = ModeManager::FindUserModeByName(it->first); + UserMode *um = ModeManager::FindUserModeByName(last_mode); /* if the null user can set the mode, then it's probably safe */ if (um && um->CanSet(NULL)) - u->SetMode(NULL, it->first, it->second); + u->SetMode(NULL, last_mode, last_value); } } } |