Bladeren bron

* Added dcc alias support, see 'help set' (only perm owner may set aliases as loops are easy and fatal)
-Added aliases: bl, bc. See 'set list alias' for more info.


svn: 2163

Bryan Drewery 21 jaren geleden
bovenliggende
commit
6119aeff39
5 gewijzigde bestanden met toevoegingen van 49 en 7 verwijderingen
  1. 2 0
      doc/UPDATES
  2. 0 1
      src/cmds.c
  3. 44 3
      src/core_binds.c
  4. 2 2
      src/set.c
  5. 1 1
      src/set.h

+ 2 - 0
doc/UPDATES

@@ -17,6 +17,8 @@ Lines prefixed with '-' were disabled before release and are not finished, or ar
 1.2.3
 * HUB/LEAF binaries have been combined into 1 binary named 'wraith'
 * Rewrote config/botconfig from scratch as [bot]set with list support. See 'help set'.
+* Added dcc alias support, see 'help set' (only perm owner may set aliases as loops are easy and fatal)
+  -Added aliases: bl, bc. See 'set list alias' for more info.
 * Read in '.resolv.conf' before '/etc/resolv.conf'
 * Fixed binary getting an excess of 1-15 bytes during write. 
 * Binary writing is now a bit faster as the hash is calculated on the fly now.

+ 0 - 1
src/cmds.c

@@ -4226,7 +4226,6 @@ cmd_t C_dcc[] =
   {"encrypt",		"",	(Function) cmd_encrypt,		NULL, AUTH_ALL},
   {"decrypt",		"",	(Function) cmd_decrypt,		NULL, AUTH_ALL},
   {"botcmd",		"i",	(Function) cmd_botcmd, 		NULL, HUB},
-  {"bc",		"i",	(Function) cmd_botcmd, 		NULL, HUB},
   {"hublevel", 		"a", 	(Function) cmd_hublevel, 	NULL, HUB},
   {"lagged", 		"m", 	(Function) cmd_lagged, 		NULL, HUB},
   {"uplink", 		"a", 	(Function) cmd_uplink, 		NULL, HUB},

+ 44 - 3
src/core_binds.c

@@ -13,6 +13,7 @@
 #include "userrec.h"
 #include "main.h"
 #include "settings.h"
+#include "set.h"
 #include "users.h"
 #include "misc.h"
 #include "tclhash.h"
@@ -38,6 +39,45 @@ void core_binds_init()
 	BT_time = bind_table_add("time", 5, "iiiii", MATCH_MASK, BIND_STACKABLE);
 }
 
+bool check_aliases(int idx, const char *cmd, const char *args)
+{
+  char *a = NULL, *p = NULL, *aliasp = NULL, *aliasdup = NULL;
+  bool found = 0;
+
+  aliasp = aliasdup = strdup(alias);
+
+  while ((a = strsep(&aliasdup, ","))) {
+    p = newsplit(&a);
+    if (!egg_strcasecmp(p, cmd)) {
+      p = newsplit(&a);
+
+      if (!egg_strcasecmp(cmd, p)) {
+        putlog(LOG_WARN, "*", "Loop detected in alias '%s'", p);
+        return 0;
+      }
+
+      char *myargs = NULL;
+      size_t size = 0;
+
+      found = 1;
+
+      size = strlen(a) + 1 + strlen(args) + 1;
+      myargs = (char *) calloc(1, size);
+      simple_snprintf(myargs, size, "%s %s", a, args);        
+      check_bind_dcc(p, idx, myargs);
+
+      if (myargs)
+        free(myargs);
+      break;
+    }
+  }
+
+
+  free(aliasp);
+
+  return found;
+}
+
 void check_bind_dcc(const char *cmd, int idx, const char *text)
 {
   real_check_bind_dcc(cmd, idx, text, NULL);
@@ -101,9 +141,10 @@ void real_check_bind_dcc(const char *cmd, int idx, const char *text, Auth *auth)
   if (hits != 1)
     putlog(LOG_CMDS, "*", "! #%s# %s %s", dcc[idx].nick, cmd, args);
 
-  if (hits == 0)
-    dprintf(idx, "What?  You need '%shelp'\n", settings.dcc_prefix);
-  else if (hits > 1)
+  if (hits == 0) {
+    if (!check_aliases(idx, cmd, args)) 
+      dprintf(idx, "What?  You need '%shelp'\n", settings.dcc_prefix);
+  } else if (hits > 1)
     dprintf(idx, "Ambiguous command.\n");
 
   free(args);

+ 2 - 2
src/set.c

@@ -20,7 +20,7 @@
 
 int set_noshare = 0;
 
-//char alias[1024] = "";
+char alias[1024] = "bc botcmd,bl botcmd ?";
 char auth_key[51] = "";
 char auth_prefix[2] = "";
 int badprocess = DET_IGNORE;
@@ -47,7 +47,7 @@ int promisc = DET_WARN;
 int trace = DET_WARN;
 
 static variable_t vars[] = {
-// {"alias",		alias,			sizeof(alias),			VAR_STRING|VAR_LIST|VAR_NOLOC, NULL, NULL},
+ {"alias",		alias,			sizeof(alias),			VAR_STRING|VAR_LIST|VAR_NOLOC|VAR_PERM, NULL, NULL},
  {"auth-key",		auth_key,		sizeof(auth_key),		VAR_STRING|VAR_PERM, NULL, NULL},
  {"auth-prefix",	auth_prefix,		sizeof(auth_prefix),		VAR_STRING|VAR_NOLHUB|VAR_PERM, NULL, NULL},
  {"bad-process",	&badprocess,		0,				VAR_INT|VAR_DETECTED, NULL, NULL},

+ 1 - 1
src/set.h

@@ -51,7 +51,7 @@ typedef struct rate_b {
  time_t time;
 } rate_t;
 
-extern char		auth_key[], auth_prefix[2], motd[], *def_chanset,
+extern char		auth_key[], auth_prefix[2], motd[], *def_chanset, alias[],
 			msgident[], msginvite[], msgop[], msgpass[], process_list[];
 extern bool		dccauth;
 extern int		cloak_script, fight_threshold, fork_interval, in_bots, set_noshare,