summaryrefslogtreecommitdiff
path: root/src/commands.c
diff options
context:
space:
mode:
authorrburchell <rburchell@5417fbe8-f217-4b02-8779-1006273d7864>2009-02-09 21:01:05 +0000
committerrburchell <rburchell@5417fbe8-f217-4b02-8779-1006273d7864>2009-02-09 21:01:05 +0000
commitd7d01bdc5c667a1fafd95241282b58e03b4caa5b (patch)
treef1482d8734da609923c6d8af6bc8fcb0fc187534 /src/commands.c
parentd49b3a25fda5f597491e73640dd1e76babc240eb (diff)
Squashed commit: merge next (1.9.1) back to trunk.
SVN users, NOTE: THIS WILL NOT BUILD, NOR SHOULD YOU RUN IT YET. git-svn-id: http://anope.svn.sourceforge.net/svnroot/anope/trunk@1953 5417fbe8-f217-4b02-8779-1006273d7864
Diffstat (limited to 'src/commands.c')
-rw-r--r--src/commands.c132
1 files changed, 58 insertions, 74 deletions
diff --git a/src/commands.c b/src/commands.c
index 52b74b488..17b6629b3 100644
--- a/src/commands.c
+++ b/src/commands.c
@@ -29,8 +29,8 @@ Command *lookup_cmd(Command * list, char *cmd)
{
Command *c;
- for (c = list; c->name; c++) {
- if (stricmp(c->name, cmd) == 0) {
+ for (c = list; ; c++) {
+ if (stricmp(c->name.c_str(), cmd) == 0) {
return c;
}
}
@@ -48,39 +48,66 @@ Command *lookup_cmd(Command * list, char *cmd)
* @param cmd Command
* @return void
*/
-void mod_run_cmd(char *service, User * u, CommandHash * cmdTable[],
- const char *cmd)
+void mod_run_cmd(char *service, User * u, CommandHash * cmdTable[], const char *cmd)
{
Command *c = findCommand(cmdTable, cmd);
int retVal = 0;
Command *current;
- if (c && c->routine) {
- if ((checkDefCon(DEFCON_OPER_ONLY)
- || checkDefCon(DEFCON_SILENT_OPER_ONLY)) && !is_oper(u)) {
- if (!checkDefCon(DEFCON_SILENT_OPER_ONLY)) {
- notice_lang(service, u, OPER_DEFCON_DENIED);
- }
- } else {
- if ((c->has_priv == NULL) || c->has_priv(u)) {
- retVal = c->routine(u);
- if (retVal == MOD_CONT) {
- current = c->next;
- while (current && retVal == MOD_CONT) {
- retVal = current->routine(u);
- current = current->next;
- }
- }
- } else {
- notice_lang(service, u, ACCESS_DENIED);
- alog("Access denied for %s with service %s and command %s",
- u->nick, service, cmd);
- }
- }
- } else {
- if ((!checkDefCon(DEFCON_SILENT_OPER_ONLY)) || is_oper(u)) {
+ if (!c)
+ {
+ if ((!checkDefCon(DEFCON_SILENT_OPER_ONLY)) || is_oper(u))
+ {
notice_lang(service, u, UNKNOWN_COMMAND_HELP, cmd, service);
}
+ return;
+ }
+
+ if ((checkDefCon(DEFCON_OPER_ONLY) || checkDefCon(DEFCON_SILENT_OPER_ONLY)) && !is_oper(u))
+ {
+ if (!checkDefCon(DEFCON_SILENT_OPER_ONLY))
+ {
+ notice_lang(service, u, OPER_DEFCON_DENIED);
+ return;
+ }
+ }
+
+ 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;
+ while ((s = strtok(NULL, " ")))
+ {
+ if (params.size() < c->MaxParams)
+ params.push_back(s);
+ else
+ curparam += s;
+ }
+
+ if (!curparam.empty())
+ params.push_back(curparam);
+
+ if (params.size() < c->MinParams)
+ {
+ c->OnBadSyntax(u);
+ return;
+ }
+
+ retVal = c->Execute(u, params);
+ if (retVal == MOD_CONT)
+ {
+ current = c->next;
+ while (current && retVal == MOD_CONT)
+ {
+ retVal = current->Execute(u, params);
+ current = current->next;
+ }
}
}
@@ -124,7 +151,7 @@ void mod_help_cmd(char *service, User * u, CommandHash * cmdTable[],
{
Command *c = findCommand(cmdTable, cmd);
Command *current;
- int has_had_help = 0;
+ bool has_had_help = false;
int cont = MOD_CONT;
const char *p1 = NULL, *p2 = NULL, *p3 = NULL, *p4 = NULL;
@@ -134,52 +161,9 @@ void mod_help_cmd(char *service, User * u, CommandHash * cmdTable[],
p2 = current->help_param2;
p3 = current->help_param3;
p4 = current->help_param4;
- if (current->helpmsg_all >= 0) {
- notice_help(service, u, current->helpmsg_all, p1, p2, p3, p4);
- has_had_help = 1;
- } else if (current->all_help) {
- cont = current->all_help(u);
- has_had_help = 1;
- }
- if (is_services_root(u)) {
- if (current->helpmsg_root >= 0) {
- notice_help(service, u, current->helpmsg_root, p1, p2, p3,
- p4);
- has_had_help = 1;
- } else if (current->root_help) {
- cont = current->root_help(u);
- has_had_help = 1;
- }
- } else if (is_services_admin(u)) {
- if (current->helpmsg_admin >= 0) {
- notice_help(service, u, current->helpmsg_admin, p1, p2, p3,
- p4);
- has_had_help = 1;
- } else if (current->admin_help) {
- cont = current->admin_help(u);
- has_had_help = 1;
- }
- } else if (is_services_oper(u)) {
- if (current->helpmsg_oper >= 0) {
- notice_help(service, u, current->helpmsg_oper, p1, p2, p3,
- p4);
- has_had_help = 1;
- } else if (current->oper_help) {
- cont = current->oper_help(u);
- has_had_help = 1;
- }
- } else {
- if (current->helpmsg_reg >= 0) {
- notice_help(service, u, current->helpmsg_reg, p1, p2, p3,
- p4);
- has_had_help = 1;
- } else if (current->regular_help) {
- cont = current->regular_help(u);
- has_had_help = 1;
- }
- }
+ has_had_help = current->OnHelp(u, ""); // XXX: this needs finishing to actually pass a subcommand
}
- if (has_had_help == 0) {
+ if (has_had_help == false) {
notice_lang(service, u, NO_HELP_AVAILABLE, cmd);
} else {
do_help_limited(service, u, c);