ソースを参照

* Fix aliases not properly indicating bad command on leaf bots (fixes #297)

Bryan Drewery 17 年 前
コミット
ae0b2ac496
4 ファイル変更24 行追加19 行削除
  1. 1 0
      doc/UPDATES
  2. 1 8
      src/cmds.c
  3. 2 1
      src/cmds.h
  4. 20 10
      src/core_binds.c

+ 1 - 0
doc/UPDATES

@@ -35,6 +35,7 @@
 * Fix problem of upgrading with uninitialized binaries causing corruption (will kick in on future upgrades)
 * Fix botcmd to make sure that results are delivered only to the requester (fixes #208)
 * Fix issues with server-port not being updated to the current server list (fixes #176)
+* Fix aliases not properly indicating bad command on leaf bots (fixes #297)
 
 1.2.16 - http://wraith.botpack.net/milestone/1.2.16
 * Add 'set altchars' so that alternative characters used for nicks can be changed. (fixes #418)

+ 1 - 8
src/cmds.c

@@ -77,7 +77,6 @@ int    			 cmdi = 0;
 
 static char		 *btos(unsigned long);
 
-static help_t *findcmd(const char *, bool);
 char s1_10[3] = "",s1_4[3] = "",s1_12[3] = "";
 
 static void tell_who(int idx, int chan)
@@ -612,7 +611,7 @@ static int comp_help_t(const void *m1, const void *m2) {
   return egg_strcasecmp(mi1->cmd, mi2->cmd);
 }
 
-static help_t *
+help_t *
 findcmd(const char *lookup, bool care_about_type)
 {
   help_t key;
@@ -624,12 +623,6 @@ findcmd(const char *lookup, bool care_about_type)
   return NULL;
 }
 
-help_t *
-findhelp(const char *cmd)
-{
-  return findcmd(cmd, 1);
-}
-
 static void cmd_help(int idx, char *par)
 {
   char flg[100] = "", *fcats = NULL, temp[100] = "", buf[2046] = "", match[20] = "";

+ 2 - 1
src/cmds.h

@@ -43,7 +43,8 @@ typedef struct cmd_pass {
 extern mycmds 		cmdlist[]; 
 extern int		cmdi;
 
-help_t* findhelp(const char *);
+#define findhelp(x) findcmd(x, 1)
+help_t *findcmd(const char *lookup, bool care_about_type);
 int check_dcc_attrs(struct userrec *, flag_t);
 int check_dcc_chanattrs(struct userrec *, char *, flag_t, flag_t);
 int stripmodes(char *);

+ 20 - 10
src/core_binds.c

@@ -38,6 +38,7 @@
 #include "misc.h"
 #include "binds.h"
 #include "dcc.h"
+#include "cmds.h"
 
 extern cmd_t 		C_dcc[];
 
@@ -98,15 +99,23 @@ bool check_aliases(int idx, const char *cmd, const char *args)
           break;
         }
       }
-      /* FIXME: see cmt */
-      /* If the cmd wasnt found in the binds list, it's probably an alias, or invalid cmd? */
+
       if (!find) {
-        dprintf(idx, "'%s' is an invalid alias: references alias '%s'.\n", cmd, p);
-        putlog(LOG_ERROR, "*", "Invalid alias '%s' attempted: references alias '%s'.", cmd, p);
-        if (argsp)
-          free(argsp);
-        free(aliasp);
-        return 1; /* Alias was found -- just not accepted */
+        /* Does the cmd exist though? (Hub-only cmd from a leaf or a leaf-only cmd from a hub, or restricted cmd) */
+        if (findcmd(cmd, 0)) {
+          if (argsp)
+            free(argsp);
+          free(aliasp);
+          return 0; /* Show bad cmd */
+        } else {
+          /* nope, show alias error */
+          dprintf(idx, "'%s' is an invalid alias: references alias '%s'.\n", cmd, p);
+          putlog(LOG_ERROR, "*", "Invalid alias '%s' attempted: references alias '%s'.", cmd, p);
+          if (argsp)
+            free(argsp);
+          free(aliasp);
+          return 1; /* Alias was found -- just not accepted */
+        }
       }
 
       char *myargs = NULL, *pass = NULL;
@@ -237,9 +246,10 @@ void real_check_bind_dcc(const char *cmd, int idx, const char *text, Auth *auth)
     log_bad = 1;
 
   if (hits == 0) {
-    if (!check_aliases(idx, cmd, args)) 
+    if (!check_aliases(idx, cmd, args)) {
+      log_bad = 1;
       dprintf(idx, "What?  You need '%shelp'\n", (dcc[idx].u.chat->channel >= 0) ? settings.dcc_prefix : "");
-    else
+    } else
       log_bad = 0;
   } else if (hits > 1)
     dprintf(idx, "Ambiguous command.\n");