Przeglądaj źródła

Merge branch 'set-botset-userentry' into maint

* set-botset-userentry:
  Leaf bots should set userentry for groups as well
  Always share '.set groups' to all bots.
  var_set: Always call var_set_userentry() if there is a target.
  No need to strdup an emptry string.  Follows set_gotshare()
Bryan Drewery 10 lat temu
rodzic
commit
02260e1c3c
3 zmienionych plików z 25 dodań i 21 usunięć
  1. 2 0
      doc/UPDATES.md
  2. 11 8
      src/set.cc
  3. 12 13
      src/userent.cc

+ 2 - 0
doc/UPDATES.md

@@ -31,6 +31,8 @@
   * Stop building the binary as i486.  Let it use modern x86/x86_64.
   * Stop trying to regain jupenick when it is unavailable and main nick is
     temporarily juped (#101).
+  * Fix bots not tracking groups for other bots.  This also fixes slowjoin
+    with groups.
 
 # 1.4.6
   * Disable demo TCL support by default to prevent confusion during build.

+ 11 - 8
src/set.cc

@@ -541,8 +541,17 @@ const char *var_get_gdata(const char *name) {
 
 void var_set(variable_t *var, const char *target, const char *datain)
 {
-  /* Don't set locally if the variable doesn't permit it. */
   if (target) {
+    /*
+     * Setting user entry despite possibly not setting memory due to
+     * historically setting this after var_set() without checking
+     * return value.
+     */
+    if (!parsing_botset) {
+      var_set_userentry(target, var->name, datain);
+    }
+
+    /* Don't set locally if the variable doesn't permit it. */
     if (var->flags & VAR_NOLOC)
       return;
 
@@ -650,7 +659,7 @@ void var_set_userentry(const char *target, const char *name, const char *data)
     struct xtra_key *xk = (struct xtra_key *) calloc(1, sizeof(struct xtra_key));
 
     xk->key = strdup(name);
-    xk->data = data ? strdup(data) : NULL;
+    xk->data = (data && data[0]) ? strdup(data) : NULL;
     set_user(&USERENTRY_SET, u, xk);                //This will send the change to the specified bot
   }
 }
@@ -839,8 +848,6 @@ static int var_add_list(const char *botnick, variable_t *var, const char *elemen
     data = strdup(element);
 
   var_set(var, botnick, data);
-  if (botnick)
-    var_set_userentry(botnick, var->name, data);
   free(data);
   return 1;
 }
@@ -900,8 +907,6 @@ static char *var_rem_list(const char *botnick, variable_t *var, const char *elem
 
   if (num <= i && ret[0]) {
     var_set(var, botnick, data);
-    if (botnick)
-      var_set_userentry(botnick, var->name, data);
   } else
     ret[0] = 0;
  
@@ -1188,8 +1193,6 @@ int cmd_set_real(const char *botnick, int idx, char *par)
       }
 
       var_set(var, botnick, data);
-      if (botnick)
-        var_set_userentry(botnick, name, data);
 
       display_set_value(idx, var, botnick);
 

+ 12 - 13
src/userent.cc

@@ -253,9 +253,15 @@ static bool set_set(struct userrec *u, struct user_entry *e, void *buf)
   }
   
   /* we will possibly free new below, so let's send the information to the botnet now */
-  if (!noshare && !set_noshare)
-    /* only share to pertinent bots */
-    shareout_prot(u, "c %s %s %s %s\n", e->type->name, u->handle, newxk->key, newxk->data ? newxk->data : "");
+  if (!noshare && !set_noshare) {
+    /* Always share groups to all bots. */
+    if (!strcmp(newxk->key, "groups")) {
+      shareout("c %s %s %s %s\n", e->type->name, u->handle, newxk->key, newxk->data ? newxk->data : "");
+    } else {
+      /* only share to pertinent bots */
+      shareout_prot(u, "c %s %s %s %s\n", e->type->name, u->handle, newxk->key, newxk->data ? newxk->data : "");
+    }
+  }
 
   /* unset and bail out if the new data is empty and the old doesn't exist, why'd we even get this change? */
   if (!old && (!newxk->data || !newxk->data[0])) {
@@ -341,18 +347,11 @@ static bool set_gotshare(struct userrec *u, struct user_entry *e, char *buf, int
 
   if (!strcasecmp(u->handle, conf.bot->nick)) {
     set_noshare = 1;
+    /* This will also call set_user(). */
     var_set_by_name(conf.bot->nick, name, buf[0] ? buf : NULL);
     set_noshare = 0;
-  /* var_set_by_name() called set_user(), no need to do it again... */
-  } 
-  /* not else if as the hub might have gotten a botset for itself */
-  if (conf.bot->hub || conf.bot->localhub) {
-  /* only hubs need to bother saving this stuff, leaf bots just store it in vars[] */
-    struct xtra_key *xk = (struct xtra_key *) calloc(1, sizeof(struct xtra_key));
-
-    xk->key = strdup(name);
-    xk->data = (buf && buf[0]) ? strdup(buf) : NULL;
-    set_set(u, e, xk);	/* set the USERENTRY */
+  } else if (conf.bot->hub || conf.bot->localhub || !strcmp(name, "groups")) {
+    var_set_userentry(u->handle, name, buf);
   }
   return 1;
 }