Ver código fonte

Merge branch 'maint'

* maint:
  Leaf bots should set userentry for groups as well
  Track jupenick/nick on restart.
  Rename nick to more appropriate botname
  Remove leftovers from 421caeff6c3e7
  When restarting don't set server_online until after processing socksfile.
  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()
  Comment release expiry
  server_minutely: Only try regaining nicks we think are juped.
  nicks_available: Look for all wanted nicks, not just jupenick.
Bryan Drewery 10 anos atrás
pai
commit
eb2bd9a1ec
6 arquivos alterados com 68 adições e 41 exclusões
  1. 7 0
      doc/UPDATES.md
  2. 27 9
      src/misc.cc
  3. 2 1
      src/mod/server.mod/server.cc
  4. 9 10
      src/mod/server.mod/servmsg.cc
  5. 11 8
      src/set.cc
  6. 12 13
      src/userent.cc

+ 7 - 0
doc/UPDATES.md

@@ -32,6 +32,13 @@
     rather than an obscure Libcrypto error.
   * Restrict 'chanset groups' to owners.
   * 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.
+  * Fix bot forgetting its nick/jupenick during restart and reverting to
+    botnick if restarting in the middle of a server connect or attempted
+    NICK change that fails.
 
 # 1.4.6
   * Disable demo TCL support by default to prevent confusion during build.

+ 27 - 9
src/misc.cc

@@ -655,8 +655,9 @@ readsocks(const char *fname)
   if (!conf.bot->hub)
     restarting = 1;
 
-  char *nick = NULL, *jnick = NULL, *ip4 = NULL, *ip6 = NULL;
-  time_t old_buildts = 0;
+  char *_botname = NULL, *ip4 = NULL, *ip6 = NULL,
+       *_origbotname = NULL, *_jupenick = NULL;
+  time_t old_buildts = 0, _server_online = 0;
 
   bool cached_005 = 0;
   const char salt1[] = SALT1;
@@ -678,7 +679,7 @@ readsocks(const char *fname)
     else if (type == STR("+online_since"))
       online_since = strtol(str.c_str(), NULL, 10);
     else if (type == STR("+server_online"))
-      server_online = strtol(str.c_str(), NULL, 10);
+      _server_online = strtol(str.c_str(), NULL, 10);
     else if (type == STR("+server_floodless"))
       floodless = 1;
     else if (type == STR("+in_deaf"))
@@ -697,7 +698,11 @@ readsocks(const char *fname)
     else if (type == STR("+buildts"))
       old_buildts = strtol(str.c_str(), NULL, 10);
     else if (type == STR("+botname"))
-      nick = str.dup();
+      _botname = str.dup();
+    else if (type == STR("+origbotname"))
+      _origbotname = str.dup();
+    else if (type == STR("+jupenick"))
+      _jupenick = str.dup();
     else if (type == STR("+rolls"))
       rolls = atoi(str.c_str());
     else if (type == STR("+altnick_char"))
@@ -730,6 +735,13 @@ readsocks(const char *fname)
 
   unlink(fname);
 
+  /* server_online is not yet set so these will safely not send NICK. */
+  if (_origbotname) {
+    var_set_by_name(conf.bot->nick, "nick", _origbotname);
+  }
+  if (_jupenick) {
+    var_set_by_name(conf.bot->nick, "jupenick", _jupenick);
+  }
   if (servidx >= 0) {
     char nserv[50] = "";
 
@@ -752,8 +764,10 @@ readsocks(const char *fname)
       curserv = 0;
       keepnick = 0; /* Wait to change nicks until relinking, fixes nick/jupenick switching issues during restart */
       reset_flood();
-      if (!server_online) server_online = now;
-      rehash_server(dcc[servidx].host, nick);
+      if (!_server_online)
+	_server_online = now;
+      server_online = _server_online;
+      rehash_server(dcc[servidx].host, _botname);
       if (cached_005)
         replay_cache(servidx, NULL);
       else
@@ -762,11 +776,11 @@ readsocks(const char *fname)
         reset_chans = 1;
     }
   }
-  delete[] nick;
+  delete[] _botname;
+  delete[] _origbotname;
+  delete[] _jupenick;
   delete[] ip4;
   delete[] ip6;
-  if (jnick)
-    free(jnick);
   if (socksfile)
     free(socksfile);
 }
@@ -817,6 +831,10 @@ restart(int idx)
   if (server_online) {
     if (botname[0])
       stream << bd::String::printf(STR("+botname %s\n"), botname);
+    if (origbotname[0])
+      stream << bd::String::printf(STR("+origbotname %s\n"), origbotname);
+    if (jupenick[0])
+      stream << bd::String::printf(STR("+jupenick %s\n"), jupenick);
     if (rolls)
       stream << bd::String::printf(STR("+rolls %d\n"), rolls);
     if (altnick_char)

+ 2 - 1
src/mod/server.mod/server.cc

@@ -1025,6 +1025,7 @@ static void server_secondly()
     } else if (!keepnick && release_time && ((now - release_time) >= RELEASE_TIME)) {
       release_time = 0;
       keepnick = 1;
+      /* The release time has expired, try to regain the jupenick. */
       nick_available(1, 0);
     }
 
@@ -1108,7 +1109,7 @@ static void server_minutely()
     // Ratbox sets a nick_delay (default:15min) timer when a nick splits off to prevent collisions,
     // We must check periodically to see if the local server has unjuped our wanted nicks.
     if (keepnick && (jnick_juped == 2 || nick_juped == 2)) {
-      nick_available(1, 1);
+      nick_available(jnick_juped == 2, nick_juped == 2);
     }
   }
 }

+ 9 - 10
src/mod/server.mod/servmsg.cc

@@ -1027,17 +1027,14 @@ static int gotpong(char *from, char *msg)
   return 0;
 }
 
-static int nick_which(const char* nick, bool& is_jupe, bool& is_orig) {
-  if (jupenick[0] && !rfc_ncasecmp(nick, jupenick, nick_len)) {
-    is_jupe = 1;
-    // If some stupid reason they have the same jupenick/nick, make sure to mark it as on
-    if (!rfc_ncasecmp(nick, origbotname, nick_len))
-      is_orig = 1;
-    return 1;
-  } else if (!rfc_ncasecmp(nick, origbotname, nick_len)) {
+static void nick_which(const char* nick, bool& is_jupe, bool& is_orig) {
+  if (is_orig == 0 && !rfc_ncasecmp(nick, origbotname, nick_len)) {
     is_orig = 1;
   }
-  return 0;
+  /* It's possible jupenick==nick.  Set both flags. */
+  if (is_jupe == 0 && jupenick[0] && !rfc_ncasecmp(nick, jupenick, nick_len)) {
+    is_jupe = 1;
+  }
 }
 
 static void nick_available(bool is_jupe, bool is_orig) {
@@ -1070,8 +1067,10 @@ void nicks_available(char* buf, char delim, bool buf_contains_available) {
   char *nick = NULL;
   if (delim) {
     while ((nick = newsplit(&buf, delim))[0]) {
-      if (nick_which(nick, is_jupe, is_orig))
+      nick_which(nick, is_jupe, is_orig);
+      if (is_jupe && is_orig) {
         break;
+      }
     }
   } else {
     nick = buf;

+ 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;
 }