mirror of
https://github.com/anope/anope.git
synced 2026-07-05 06:13:13 +02:00
Rewrote how commands are handled within Anope.
This allows naming commands and having spaces within command names.
This commit is contained in:
+50
-133
@@ -12,165 +12,91 @@
|
||||
/*************************************************************************/
|
||||
|
||||
#include "module.h"
|
||||
#include "nickserv.h"
|
||||
|
||||
class CommandNSSet : public Command
|
||||
{
|
||||
typedef std::map<Anope::string, Command *, std::less<ci::string> > subcommand_map;
|
||||
subcommand_map subcommands;
|
||||
|
||||
public:
|
||||
CommandNSSet() : Command("SET", 1, 3)
|
||||
CommandNSSet(Module *creator) : Command(creator, "nickserv/set", 1, 3)
|
||||
{
|
||||
this->SetDesc(_("Set options, including kill protection"));
|
||||
this->SetSyntax(_("\037option\037 \037parameters\037"));
|
||||
}
|
||||
|
||||
~CommandNSSet()
|
||||
void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms)
|
||||
{
|
||||
this->subcommands.clear();
|
||||
}
|
||||
|
||||
CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms)
|
||||
{
|
||||
User *u = source.u;
|
||||
|
||||
if (readonly)
|
||||
{
|
||||
source.Reply(_(NICK_SET_DISABLED));
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
if (u->Account()->HasFlag(NI_SUSPENDED))
|
||||
{
|
||||
source.Reply(_(NICK_X_SUSPENDED), u->Account()->display.c_str());
|
||||
return MOD_CONT;
|
||||
}
|
||||
|
||||
Command *c = this->FindCommand(params[0]);
|
||||
|
||||
if (c)
|
||||
{
|
||||
Anope::string cmdparams = u->Account()->display;
|
||||
for (std::vector<Anope::string>::const_iterator it = params.begin() + 1, it_end = params.end(); it != it_end; ++it)
|
||||
cmdparams += " " + *it;
|
||||
/* Don't log the whole message for set password */
|
||||
if (c->name != "PASSWORD")
|
||||
Log(LOG_COMMAND, u, this) << params[0] << " " << cmdparams;
|
||||
else
|
||||
Log(LOG_COMMAND, u, this) << params[0];
|
||||
mod_run_cmd(nickserv->Bot(), u, NULL, c, params[0], cmdparams);
|
||||
}
|
||||
else
|
||||
source.Reply(_(NICK_SET_UNKNOWN_OPTION), Config->UseStrictPrivMsgString.c_str(), params[0].c_str());
|
||||
|
||||
return MOD_CONT;
|
||||
this->OnSyntaxError(source, "");
|
||||
return;
|
||||
}
|
||||
|
||||
bool OnHelp(CommandSource &source, const Anope::string &subcommand)
|
||||
{
|
||||
if (subcommand.empty())
|
||||
this->SendSyntax(source);
|
||||
source.Reply(" ");
|
||||
source.Reply(_("Sets various nickname options. \037option\037 can be one of:"));
|
||||
Anope::string this_name = source.command;
|
||||
for (command_map::iterator it = source.owner->commands.begin(), it_end = source.owner->commands.end(); it != it_end; ++it)
|
||||
{
|
||||
source.Reply(_("Syntax: \002SET \037option\037 \037parameters\037\002\n"
|
||||
" \n"
|
||||
"Sets various nickname options. \037option\037 can be one of:"));
|
||||
for (subcommand_map::iterator it = this->subcommands.begin(), it_end = this->subcommands.end(); it != it_end; ++it)
|
||||
it->second->OnServHelp(source);
|
||||
source.Reply(_("In order to use this command, you must first identify\n"
|
||||
"with your password (\002%s%s HELP IDENTIFY\002 for more\n"
|
||||
"information).\n"
|
||||
" \n"
|
||||
"Type \002%s%s HELP SET \037option\037\002 for more information\n"
|
||||
"on a specific option."), Config->UseStrictPrivMsgString.c_str(), Config->s_NickServ.c_str(), (Config->UseStrictPrivMsg ? "/msg " : "/"), Config->s_NickServ.c_str());
|
||||
return true;
|
||||
if (it->first.find_ci(this_name + " ") == 0)
|
||||
{
|
||||
service_reference<Command> command(it->second);
|
||||
if (command)
|
||||
{
|
||||
source.command = it->first;
|
||||
command->OnServHelp(source);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Command *c = this->FindCommand(subcommand);
|
||||
|
||||
if (c)
|
||||
return c->OnHelp(source, subcommand);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void OnSyntaxError(CommandSource &source, const Anope::string &subcommand)
|
||||
{
|
||||
SyntaxError(source, "SET", _(NICK_SET_SYNTAX));
|
||||
}
|
||||
|
||||
bool AddSubcommand(Module *creator, Command *c)
|
||||
{
|
||||
c->module = creator;
|
||||
c->service = this->service;
|
||||
return this->subcommands.insert(std::make_pair(c->name, c)).second;
|
||||
}
|
||||
|
||||
bool DelSubcommand(const Anope::string &command)
|
||||
{
|
||||
return this->subcommands.erase(command);
|
||||
}
|
||||
|
||||
Command *FindCommand(const Anope::string &subcommand)
|
||||
{
|
||||
subcommand_map::const_iterator it = this->subcommands.find(subcommand);
|
||||
|
||||
if (it != this->subcommands.end())
|
||||
return it->second;
|
||||
|
||||
return NULL;
|
||||
source.Reply(_("Type \002%s%s HELP %s \037option\037\002 for more information\n"
|
||||
"on a specific option."), Config->UseStrictPrivMsgString.c_str(), source.owner->nick.c_str(), source.command.c_str());
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
class CommandNSSetDisplay : public Command
|
||||
{
|
||||
public:
|
||||
CommandNSSetDisplay() : Command("DISPLAY", 2)
|
||||
CommandNSSetDisplay(Module *creator) : Command(creator, "nickserv/set/display", 1)
|
||||
{
|
||||
this->SetDesc(_("Set the display of your group in Services"));
|
||||
this->SetSyntax(_("\037new-display\037"));
|
||||
}
|
||||
|
||||
CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms)
|
||||
void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms)
|
||||
{
|
||||
User *u = source.u;
|
||||
NickAlias *na = findnick(params[1]);
|
||||
|
||||
if (!na || na->nc != u->Account())
|
||||
{
|
||||
source.Reply(_(NICK_SASET_DISPLAY_INVALID), u->Account()->display.c_str());
|
||||
return MOD_CONT;
|
||||
source.Reply(_("The new display MUST be a nickname of your nickname group!"));
|
||||
return;
|
||||
}
|
||||
|
||||
change_core_display(u->Account(), params[1]);
|
||||
source.Reply(_(NICK_SET_DISPLAY_CHANGED), u->Account()->display.c_str());
|
||||
return MOD_CONT;
|
||||
source.Reply(NICK_SET_DISPLAY_CHANGED, u->Account()->display.c_str());
|
||||
return;
|
||||
}
|
||||
|
||||
bool OnHelp(CommandSource &source, const Anope::string &)
|
||||
{
|
||||
source.Reply(_("Syntax: \002SET DISPLAY \037new-display\037\002\n"
|
||||
" \n"
|
||||
"Changes the display used to refer to your nickname group in \n"
|
||||
this->SendSyntax(source);
|
||||
source.Reply(" ");
|
||||
source.Reply(_("Changes the display used to refer to your nickname group in \n"
|
||||
"Services. The new display MUST be a nick of your group."));
|
||||
return true;
|
||||
}
|
||||
|
||||
void OnSyntaxError(CommandSource &source, const Anope::string &)
|
||||
{
|
||||
// XXX
|
||||
SyntaxError(source, "SET", _(NICK_SET_SYNTAX));
|
||||
}
|
||||
};
|
||||
|
||||
class CommandNSSetPassword : public Command
|
||||
{
|
||||
public:
|
||||
CommandNSSetPassword() : Command("PASSWORD", 2)
|
||||
CommandNSSetPassword(Module *creator) : Command(creator, "nickserv/set/password", 1)
|
||||
{
|
||||
this->SetDesc(_("Set your nickname password"));
|
||||
this->SetSyntax(_("\037new-password\037"));
|
||||
}
|
||||
|
||||
CommandReturn Execute(CommandSource &source, const std::vector<Anope::string> ¶ms)
|
||||
void Execute(CommandSource &source, const std::vector<Anope::string> ¶ms)
|
||||
{
|
||||
User *u = source.u;
|
||||
|
||||
@@ -179,39 +105,33 @@ class CommandNSSetPassword : public Command
|
||||
|
||||
if (u->Account()->display.equals_ci(param) || (Config->StrictPasswords && len < 5))
|
||||
{
|
||||
source.Reply(_(MORE_OBSCURE_PASSWORD));
|
||||
return MOD_CONT;
|
||||
source.Reply(MORE_OBSCURE_PASSWORD);
|
||||
return;
|
||||
}
|
||||
else if (len > Config->PassLen)
|
||||
{
|
||||
source.Reply(_(PASSWORD_TOO_LONG));
|
||||
return MOD_CONT;
|
||||
source.Reply(PASSWORD_TOO_LONG);
|
||||
return;
|
||||
}
|
||||
|
||||
enc_encrypt(param, u->Account()->pass);
|
||||
Anope::string tmp_pass;
|
||||
if (enc_decrypt(u->Account()->pass, tmp_pass) == 1)
|
||||
source.Reply(_(NICK_SASET_PASSWORD_CHANGED_TO), u->Account()->display.c_str(), tmp_pass.c_str());
|
||||
source.Reply(_("Password for \002%s\002 changed to \002%s\002."), u->Account()->display.c_str(), tmp_pass.c_str());
|
||||
else
|
||||
source.Reply(_(NICK_SASET_PASSWORD_CHANGED), u->Account()->display.c_str());
|
||||
source.Reply(_("Password for \002%s\002 changed."), u->Account()->display.c_str());
|
||||
|
||||
return MOD_CONT;
|
||||
return;
|
||||
}
|
||||
|
||||
bool OnHelp(CommandSource &source, const Anope::string &)
|
||||
{
|
||||
source.Reply(_("Syntax: \002SET PASSWORD \037new-password\037\002\n"
|
||||
" \n"
|
||||
"Changes the password used to identify you as the nick's\n"
|
||||
this->SendSyntax(source);
|
||||
source.Reply(" ");
|
||||
source.Reply(_("Changes the password used to identify you as the nick's\n"
|
||||
"owner."));
|
||||
return true;
|
||||
}
|
||||
|
||||
void OnSyntaxError(CommandSource &source, const Anope::string &)
|
||||
{
|
||||
// XXX
|
||||
SyntaxError(source, "SET", _(NICK_SET_SYNTAX));
|
||||
}
|
||||
};
|
||||
|
||||
class NSSet : public Module
|
||||
@@ -221,17 +141,14 @@ class NSSet : public Module
|
||||
CommandNSSetPassword commandnssetpassword;
|
||||
|
||||
public:
|
||||
NSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE)
|
||||
NSSet(const Anope::string &modname, const Anope::string &creator) : Module(modname, creator, CORE),
|
||||
commandnsset(this), commandnssetdisplay(this), commandnssetpassword(this)
|
||||
{
|
||||
this->SetAuthor("Anope");
|
||||
|
||||
if (!nickserv)
|
||||
throw ModuleException("NickServ is not loaded!");
|
||||
|
||||
this->AddCommand(nickserv->Bot(), &commandnsset);
|
||||
|
||||
commandnsset.AddSubcommand(this, &commandnssetdisplay);
|
||||
commandnsset.AddSubcommand(this, &commandnssetpassword);
|
||||
ModuleManager::RegisterService(&commandnsset);
|
||||
ModuleManager::RegisterService(&commandnssetdisplay);
|
||||
ModuleManager::RegisterService(&commandnssetpassword);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user