Просмотр исходного кода

* Port [3146] to 1.2.13
* cmd_[bot]set now accepts wildcards (*) for listing variables. (not for setting)


svn: 3147

Bryan Drewery 19 лет назад
Родитель
Сommit
12eea17dc8
3 измененных файлов с 42 добавлено и 22 удалено
  1. 1 0
      doc/UPDATES
  2. 7 1
      misc/help.txt
  3. 34 21
      src/set.c

+ 1 - 0
doc/UPDATES

@@ -11,6 +11,7 @@ Lines prefixed with '-' were disabled before release and are not finished, or ar
 * Fix security hole in all shell cmds. (fixes #321)
 * Make ./binary -E default to displaying every error. (fixes #322)
 * Fix a possible memory leak with DNS. (fixes #296)
+* cmd_[bot]set now accepts wildcards (*) for listing variables. (not for setting)
 
 1.2.12 - http://wraith.shatow.net/milestone/1.2.12
 * Clearing a variable via 'set var -' now resets that variable to default settings. (implements #111)

+ 7 - 1
misc/help.txt

@@ -319,7 +319,10 @@ See also: netserver, servers%{+n}, set%{-}
    If there is a botset entry for 'name' and a set entry for 'name', 
    the bot will use the 'botset' entry. Otherwise, the 'set' entry
    will be used for all options.
- 
+
+   The <var> may have wildcards. Wildcards will only be used for listing
+   variable, not for setting.
+
    See 'set' for a full help listing.
  
 See also: set
@@ -1474,6 +1477,9 @@ See also: reload, backup
 ###  $bset$b [<+/->list] [<var> [data|-]]
    Sets various options. Type alone to see all set entries. To set
    an entry do '%dset name VALUE'. Use '-' as a value to clear an entry.
+
+   The <var> may have wildcards. Wildcards will only be used for listing
+   variable, not for setting.
  
    The '+' may be used to add 1 element to a comma separated list. (ie, servers)
    The '-' may be used to remove 1 element from a comma separated list. (ie, servers)

+ 34 - 21
src/set.c

@@ -9,6 +9,7 @@
 #include "shell.h"
 #include "botmsg.h"
 #include "chanprog.h"
+#include "match.h"
 #include "misc.h"
 #include "src/mod/server.mod/server.h"
 #include "src/mod/channels.mod/channels.h"
@@ -784,7 +785,7 @@ int cmd_set_real(const char *botnick, int idx, char *par)
   char *name = NULL;
   const char *data = NULL, *botdata = NULL;
   int list = 0, i = 0;
-  bool notyes = 1;
+  bool notyes = 1, wildcard = 0;
 
   if (par[0] && !egg_strncasecmp(par, "-yes", 4)) {
     notyes = 0;
@@ -819,26 +820,34 @@ int cmd_set_real(const char *botnick, int idx, char *par)
       name = newsplit(&par);
     }
   }
+  
+  if (name && strchr(name, '*'))
+    wildcard = 1;
 
-  if (!list || (list && list != LIST_SHOW)) {
-    if (par[0])
-      data = (const char *) par;
-    else if (!par[0] && list) {
-      dprintf(idx, "A value must be specified!\n");
-      return 0;
+  if (wildcard && par[0]) {
+    dprintf(idx, "Wildcards may only be used for listing matching variables.\n");
+    return 0;
+  } else if (!wildcard) {
+    if (!list || (list && list != LIST_SHOW)) {
+      if (par[0])
+        data = (const char *) par;
+      else if (!par[0] && list) {
+        dprintf(idx, "A value must be specified!\n");
+        return 0;
+      }
+    } else if (par[0] && list && list == LIST_SHOW) {
+      dprintf(idx, "Data value ignored for listing.\n");
     }
-  } else if (par[0] && list && list == LIST_SHOW) {
-    dprintf(idx, "Data value ignored for listing.\n");
-  }
 
-  if (name && !(var = var_get_var_by_name(name))) {
-    dprintf(idx, "No such variable: %s\n", name);
-    return 0;
-  }
+    if (name && !(var = var_get_var_by_name(name))) {
+      dprintf(idx, "No such variable: %s\n", name);
+      return 0;
+    }
 
-  if (list && !(var->flags & VAR_LIST)) {
-    dprintf(idx, "That variable is not a list!\n");
-    return 0;
+    if (list && !(var->flags & VAR_LIST)) {
+      dprintf(idx, "That variable is not a list!\n");
+      return 0;
+    }
   }
   
   struct userrec *botu = NULL;
@@ -851,13 +860,17 @@ int cmd_set_real(const char *botnick, int idx, char *par)
     ishub = bot_hublevel(botu) == 999 ? 0 : 1;
   }
 
-
   if (!data) {
     while (vars[i].name) {
       botdata = NULL;
-      if (!name)	//not looping all, provided with one...
+      if (!name || wildcard)	//not looping all, provided with one...
         if (vars[i].name)
           var = &vars[i]; 
+
+      if (wildcard && !wild_match(name, var->name)) {
+        ++i;
+        continue;
+      }
       
       if (!(var->flags & VAR_HIDE) && !((var->flags & VAR_PERM) && !isowner(dcc[idx].nick)) && 
           !(botnick && ((var->flags & VAR_NOLOC) || (ishub && (var->flags & VAR_NOLHUB))))
@@ -880,9 +893,9 @@ int cmd_set_real(const char *botnick, int idx, char *par)
           dumplots(idx, buf, data ? (char *) data : (char *) "(not set)");
         }
       }
-      if (name)
+      if (name && !wildcard)
         break;
-      i++;
+      ++i;
     }
   } else { // need to set it!
     if (!list && var->flags & VAR_LIST) {