summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAdam <Adam@anope.org>2011-08-04 21:59:01 -0400
committerAdam <Adam@anope.org>2011-08-04 21:59:01 -0400
commit9ec18a3b020932eee6242c878149c484f49b13cb (patch)
tree6f0470e27bf4f3ced0f6833db00134f4b29a79a9 /src
parent773a1f3075fa12700d41598c0b8a8dd7caf9011e (diff)
Added a command:permission setting
Diffstat (limited to 'src')
-rw-r--r--src/bots.cpp35
-rw-r--r--src/command.cpp7
-rw-r--r--src/config.cpp11
3 files changed, 37 insertions, 16 deletions
diff --git a/src/bots.cpp b/src/bots.cpp
index 13947c0bb..bff2adac8 100644
--- a/src/bots.cpp
+++ b/src/bots.cpp
@@ -203,7 +203,7 @@ void BotInfo::OnMessage(User *u, const Anope::string &message)
{
std::vector<Anope::string> params = BuildStringVector(message);
- command_map::iterator it = this->commands.end();
+ BotInfo::command_map::iterator it = this->commands.end();
unsigned count = 0;
for (unsigned max = params.size(); it == this->commands.end() && max > 0; --max)
{
@@ -222,11 +222,12 @@ void BotInfo::OnMessage(User *u, const Anope::string &message)
return;
}
- service_reference<Command> c(it->second);
+ CommandInfo &info = it->second;
+ service_reference<Command> c(info.name);
if (!c)
{
u->SendMessage(this, _("Unknown command \002%s\002. \"%s%s HELP\" for help."), message.c_str(), Config->UseStrictPrivMsgString.c_str(), this->nick.c_str());
- Log(this) << "Command " << it->first << " exists on me, but its service " << it->second << " was not found!";
+ Log(this) << "Command " << it->first << " exists on me, but its service " << info.name << " was not found!";
return;
}
@@ -253,6 +254,7 @@ void BotInfo::OnMessage(User *u, const Anope::string &message)
source.owner = this;
source.service = this;
source.command = it->first;
+ source.permission = info.permission;
EventReturn MOD_RESULT;
FOREACH_RESULT(I_OnPreCommand, OnPreCommand(source, c, params));
@@ -271,7 +273,7 @@ void BotInfo::OnMessage(User *u, const Anope::string &message)
}
// If the command requires a permission, and they aren't registered or don't have the required perm, DENIED
- if (!c->permission.empty() && !u->HasCommand(c->permission))
+ if (!info.permission.empty() && !u->HasCommand(info.permission))
{
u->SendMessage(this, ACCESS_DENIED);
Log(LOG_COMMAND, "denied", this) << "Access denied for user " << u->GetMask() << " with command " << c->name;
@@ -289,3 +291,28 @@ void BotInfo::OnMessage(User *u, const Anope::string &message)
}
}
+/** Link a command name to a command in services
+ * @param cname The command name
+ * @param sname The service name
+ * @param permission Permission required to execute the command, if any
+ */
+void BotInfo::SetCommand(const Anope::string &cname, const Anope::string &sname, const Anope::string &permission)
+{
+ CommandInfo ci;
+ ci.name = sname;
+ ci.permission = permission;
+ this->commands[cname] = ci;
+}
+
+/** Get command info for a command
+ * @param cname The command name
+ * @return A struct containing service name and permission
+ */
+CommandInfo *BotInfo::GetCommand(const Anope::string &cname)
+{
+ command_map::iterator it = this->commands.find(cname);
+ if (it != this->commands.end())
+ return &it->second;
+ return NULL;
+}
+
diff --git a/src/command.cpp b/src/command.cpp
index 0663ec2fa..041551bd4 100644
--- a/src/command.cpp
+++ b/src/command.cpp
@@ -56,7 +56,7 @@ void CommandSource::DoReply()
}
}
-Command::Command(Module *o, const Anope::string &sname, size_t min_params, size_t max_params, const Anope::string &spermission) : Service(o, sname), Flags<CommandFlag>(CommandFlagStrings), MaxParams(max_params), MinParams(min_params), permission(spermission), module(owner)
+Command::Command(Module *o, const Anope::string &sname, size_t min_params, size_t max_params) : Service(o, sname), Flags<CommandFlag>(CommandFlagStrings), MaxParams(max_params), MinParams(min_params), module(owner)
{
}
@@ -113,8 +113,3 @@ void Command::OnSyntaxError(CommandSource &source, const Anope::string &subcomma
source.Reply(MORE_INFO, Config->UseStrictPrivMsgString.c_str(), source.owner->nick.c_str(), source.command.c_str());
}
-void Command::SetPermission(const Anope::string &reststr)
-{
- this->permission = reststr;
-}
-
diff --git a/src/config.cpp b/src/config.cpp
index ae27d7273..c59188bd7 100644
--- a/src/config.cpp
+++ b/src/config.cpp
@@ -871,6 +871,7 @@ static bool DoCommands(ServerConfig *config, const Anope::string &, const Anope:
Anope::string service = values[0].GetValue();
Anope::string name = values[1].GetValue();
Anope::string command = values[2].GetValue();
+ Anope::string permission = values[3].GetValue();
ValueItem vi(service);
if (!ValidateNotEmpty(config, "command", "service", vi))
@@ -891,7 +892,7 @@ static bool DoCommands(ServerConfig *config, const Anope::string &, const Anope:
if (bi->commands.count(name))
throw ConfigException("Command name " + name + " already exists on " + bi->nick);
- bi->commands[name] = command;
+ bi->SetCommand(name, command, permission);
return true;
}
@@ -1127,7 +1128,6 @@ ConfigItems::ConfigItems(ServerConfig *conf)
{"nickserv", "releasetimeout", "0", new ValueContainerTime(&conf->NSReleaseTimeout), DT_TIME, ValidateNotZero},
{"nickserv", "allowkillimmed", "no", new ValueContainerBool(&conf->NSAllowKillImmed), DT_BOOLEAN | DT_NORELOAD, NoValidation},
{"nickserv", "nogroupchange", "no", new ValueContainerBool(&conf->NSNoGroupChange), DT_BOOLEAN, NoValidation},
- {"nickserv", "listopersonly", "no", new ValueContainerBool(&conf->NSListOpersOnly), DT_BOOLEAN, NoValidation},
{"nickserv", "listmax", "0", new ValueContainerUInt(&conf->NSListMax), DT_UINTEGER, ValidateNotZero},
{"nickserv", "guestnickprefix", "", new ValueContainerString(&conf->NSGuestNickPrefix), DT_STRING, ValidateGuestPrefix},
{"nickserv", "secureadmins", "no", new ValueContainerBool(&conf->NSSecureAdmins), DT_BOOLEAN, NoValidation},
@@ -1154,7 +1154,6 @@ ConfigItems::ConfigItems(ServerConfig *conf)
{"chanserv", "autokickmax", "0", new ValueContainerUInt(&conf->CSAutokickMax), DT_UINTEGER, ValidateChanServ},
{"chanserv", "autokickreason", "User has been banned from the channel", new ValueContainerString(&conf->CSAutokickReason), DT_STRING, ValidateChanServ},
{"chanserv", "inhabit", "0", new ValueContainerTime(&conf->CSInhabit), DT_TIME, ValidateChanServ},
- {"chanserv", "listopersonly", "no", new ValueContainerBool(&conf->CSListOpersOnly), DT_BOOLEAN, ValidateChanServ},
{"chanserv", "listmax", "0", new ValueContainerUInt(&conf->CSListMax), DT_UINTEGER, ValidateChanServ},
{"chanserv", "opersonly", "no", new ValueContainerBool(&conf->CSOpersOnly), DT_BOOLEAN, ValidateChanServ},
{"memoserv", "name", "", new ValueContainerString(&conf->MemoServ), DT_STRING, NoValidation},
@@ -1242,9 +1241,9 @@ ConfigItems::ConfigItems(ServerConfig *conf)
{DT_STRING, DT_STRING, DT_INTEGER, DT_BOOLEAN, DT_STRING, DT_STRING, DT_STRING, DT_STRING, DT_STRING, DT_STRING, DT_STRING, DT_BOOLEAN, DT_BOOLEAN},
InitLogs, DoLogs, DoneLogs},
{"command",
- {"service", "name", "command", ""},
- {"", "", "", ""},
- {DT_STRING, DT_STRING, DT_STRING},
+ {"service", "name", "command", "permission", ""},
+ {"", "", "", "", ""},
+ {DT_STRING, DT_STRING, DT_STRING, DT_STRING},
InitCommands, DoCommands, DoneCommands},
{"",
{""},