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

* Fix bots never timing out when connecting to servers sometimes.

Bryan Drewery пре 16 година
родитељ
комит
9f6012ff3b
3 измењених фајлова са 15 додато и 14 уклоњено
  1. 2 0
      doc/UPDATES
  2. 5 12
      src/mod/server.mod/server.c
  3. 8 2
      src/mod/server.mod/servmsg.c

+ 2 - 0
doc/UPDATES

@@ -1,3 +1,5 @@
+* Fix bots never timing out when connecting to servers sometimes.
+
 1.3 - http://wraith.botpack.net/milestone/1.3
 * Binary / shell / startup changes
   * Binary error messages are no longer obscure numbers or fake segfaults. (Compile with OBSCURE_ERRORS to re-enable)

+ 5 - 12
src/mod/server.mod/server.c

@@ -82,6 +82,7 @@ static bool waiting_for_awake;	/* set when i unidle myself, cleared when I get t
 time_t server_online = 0;	/* server connection time */
 char botrealname[121] = "A deranged product of evil coders.";	/* realname of bot */
 static interval_t server_timeout = 15;	/* server timeout for connecting */
+static const interval_t stoned_timeout = 500;
 struct server_list *serverlist = NULL;	/* old-style queue, still used by
 					   server list */
 interval_t cycle_time;			/* cycle time till next server connect */
@@ -1015,17 +1016,10 @@ static void server_check_lag()
     dprintf(DP_DUMP, "PING :%li\n", (long)now);
     lastpingtime = now;
     waiting_for_awake = 1;
-  }
-}
-
-static void server_5minutely()
-{
-  if (server_online && waiting_for_awake && ((now - lastpingtime) >= 300)) {
-      /* Uh oh!  Never got pong from last time, five minutes ago!
-       * Server is probably stoned.
-       */
-      disconnect_server(servidx, DO_LOST);
-      putlog(LOG_SERV, "*", "Server got stoned; jumping...");
+  } else if (servidx != -1 && waiting_for_awake && ((now - lastpingtime) >= stoned_timeout)) {
+    // Not checking server_online as this will handle connect timeouts as well where the connect() works, but the server gets stoned afterwards
+    disconnect_server(servidx, DO_LOST);
+    putlog(LOG_SERV, "*", "Server got stoned; jumping...");
   }
 }
 
@@ -1131,6 +1125,5 @@ void server_init()
 
   timer_create_secs(1, "server_secondly", (Function) server_secondly);
   timer_create_secs(30, "server_check_lag", (Function) server_check_lag);
-  timer_create_secs(300, "server_5minutely", (Function) server_5minutely);
 //  timer_create_secs(60, "minutely_checks", (Function) minutely_checks);
 }

+ 8 - 2
src/mod/server.mod/servmsg.c

@@ -216,6 +216,7 @@ static int got001(char *from, char *msg)
 
   fixcolon(msg);
   server_online = now;
+  waiting_for_awake = 0;
   rehash_server(from, msg);
   /* Ok...param #1 of 001 = what server thinks my nick is */
 
@@ -1335,8 +1336,13 @@ static void server_activity(int idx, char *msg, int len)
     serv = dcc[idx].sosck;
     */
     SERVER_SOCKET.timeout_val = 0;
-  }
-  waiting_for_awake = 0;
+
+    // Setup timer for conecting
+    waiting_for_awake = 1;
+    lastpingtime = now - (stoned_timeout + 30); //30 seconds to reach 001
+  } else if (server_online) // Only set once 001 has been received
+    waiting_for_awake = 0;
+
   if (msg[0] == ':') {
     msg++;
     from = newsplit(&msg);