1
0
mirror of https://github.com/anope/anope.git synced 2026-07-07 00:03:13 +02:00

Add CFLAG_ALLOW_UNREGISTERED, commands without this flag will now not run for unregistered users.

git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@2065 5417fbe8-f217-4b02-8779-1006273d7864
This commit is contained in:
rburchell
2009-02-15 15:23:03 +00:00
parent 02452a0375
commit d121c4bd37
5 changed files with 70 additions and 10 deletions
+2 -2
View File
@@ -81,12 +81,12 @@ class NickCore : public Extensible
* @param cmdstr The string to check, e.g. botserv/set/private.
* @return True if this opertype may run the specified command, false otherwise.
*/
bool HasCommand(const std::string &cmdstr);
bool HasCommand(const std::string &cmdstr) const;
/** Check whether this opertype has access to the given special permission.
* @param privstr The priv to check for, e.g. users/auspex.
* @return True if this opertype has the specified priv, false otherwise.
*/
bool HasPriv(const std::string &privstr);
bool HasPriv(const std::string &privstr) const;
};
+21 -1
View File
@@ -146,10 +146,16 @@ struct ModuleLang_ {
char **argv;
};
enum CommandFlags
{
CFLAG_ALLOW_UNREGISTERED
};
/** Every services command is a class, inheriting from Command.
*/
class Command
{
int flags;
public:
size_t MaxParams;
size_t MinParams;
@@ -181,7 +187,21 @@ class Command
*/
virtual void OnSyntaxError(User *u);
int (*has_priv)(User *u); /* Returns 1 if user may use command, else 0 */
/** Set a certain flag on this command.
* @param flag The CommandFlag to set on this command.
*/
void SetFlag(CommandFlags flag);
/** Remove a certain flag from this command.
* @param flag The CommandFlag to unset.
*/
void UnsetFlag(CommandFlags flag);
/** Check whether a certain flag is set on this command.
* @param flag The CommandFlag to check.
* @return bool True if the flag is set, false else.
*/
bool HasFlag(CommandFlags flag) const;
char *help_param1;
char *help_param2;
+26 -2
View File
@@ -3,7 +3,7 @@
Command::Command(const std::string &sname, size_t min_params, size_t max_params) : MaxParams(max_params), MinParams(min_params), name(sname)
{
this->has_priv = NULL;
this->flags = 0;
this->help_param1 = NULL;
this->help_param2 = NULL;
this->help_param3 = NULL;
@@ -21,7 +21,6 @@ Command::Command(const std::string &sname, size_t min_params, size_t max_params)
Command::~Command()
{
this->has_priv = NULL;
if (this->mod_name) {
delete [] this->mod_name;
}
@@ -47,3 +46,28 @@ bool Command::OnHelp(User *u, const std::string &subcommand) { return false; }
* @param u The user executing the command.
*/
void Command::OnSyntaxError(User *u) { }
/** Set a certain flag on this command.
* @param flag The CommandFlag to set on this command.
*/
void Command::SetFlag(CommandFlags flag)
{
this->flags |= flag;
}
/** Remove a certain flag from this command.
* @param flag The CommandFlag to unset.
*/
void Command::UnsetFlag(CommandFlags flag)
{
this->flags &= ~flag;
}
/** Check whether a certain flag is set on this command.
* @param flag The CommandFlag to check.
* @return bool True if the flag is set, false else.
*/
bool Command::HasFlag(CommandFlags flag) const
{
return this->flags & flag;
}
+21 -4
View File
@@ -72,13 +72,28 @@ void mod_run_cmd(char *service, User * u, CommandHash * cmdTable[], const char *
}
}
if (!c->HasFlag(CFLAG_ALLOW_UNREGISTERED))
{
// Command requires registered users only
if (!u->na || !u->na->nc)
{
// XXX: we should have a new string for this
notice_lang(service, u, ACCESS_DENIED);
alog("Access denied for unregistered user %s with service %s and command %s", u->nick, service, cmd);
return;
}
}
/*
XXX: priv checking
if (c->has_priv != NULL && !c->has_priv(u))
{
notice_lang(service, u, ACCESS_DENIED);
alog("Access denied for %s with service %s and command %s", u->nick, service, cmd);
return;
}
*/
std::vector<std::string> params;
std::string curparam;
char *s = NULL;
@@ -131,7 +146,7 @@ void mod_run_cmd(char *service, User * u, CommandHash * cmdTable[], const char *
* @param u User Struct
* @param c Command Struct
* @return void
*/
*
void do_help_limited(char *service, User * u, Command * c)
{
if (c->has_priv == is_services_oper)
@@ -147,6 +162,7 @@ void do_help_limited(char *service, User * u, Command * c)
else if (c->has_priv == is_host_remover)
notice_lang(service, u, HELP_LIMIT_HOST_REMOVER);
}
*/
/*************************************************************************/
@@ -177,9 +193,10 @@ void mod_help_cmd(char *service, User * u, CommandHash * cmdTable[],
}
if (has_had_help == false) {
notice_lang(service, u, NO_HELP_AVAILABLE, cmd);
} else {
do_help_limited(service, u, c);
}
//else {
// do_help_limited(service, u, c);
//}
}
/*************************************************************************/
-1
View File
@@ -31,7 +31,6 @@ class CommandCSGetPass : public Command
public:
CommandCSGetPass() : Command("GETPASS", 1, 1)
{
this->has_priv = is_services_admin;
}
CommandReturn Execute(User *u, std::vector<std::string> &params)