Преглед изворни кода

Merge branch 'restart-origbotname' into maint

* restart-origbotname:
  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.
Bryan Drewery пре 10 година
родитељ
комит
33a6ddbbbb
2 измењених фајлова са 30 додато и 9 уклоњено
  1. 3 0
      doc/UPDATES.md
  2. 27 9
      src/misc.cc

+ 3 - 0
doc/UPDATES.md

@@ -33,6 +33,9 @@
     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)