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

Merge branch 'change-server-keeps-old' into next

* change-server-keeps-old:
  * Check for removed server after .set as well
  * Check for removed server after userfile load, to avoid parsing twice (local vs global)
Bryan Drewery 16 лет назад
Родитель
Сommit
bfe3786a53
6 измененных файлов с 37 добавлено и 22 удалено
  1. 26 0
      src/chanprog.c
  2. 1 0
      src/chanprog.h
  3. 1 1
      src/mod/server.mod/server.c
  4. 2 0
      src/mod/share.mod/share.c
  5. 5 21
      src/set.c
  6. 2 0
      src/userent.c

+ 26 - 0
src/chanprog.c

@@ -978,3 +978,29 @@ void notice(const char* target, const char* msg, int idx) {
   else
     dprintf(idx, "NOTICE %s :%s\n", target, msg);
 }
+
+
+void check_removed_server() {
+  if (server_online) {
+    bool found_server = 0;
+
+    for (struct server_list *n = serverlist; n; n = n->next) {
+      if (((n->port && n->port == curservport) || (!n->port && default_port == curservport)) &&
+          !strcmp(n->name, cursrvname)) {
+        found_server = 1;
+        break;
+      }
+    }
+
+    if (!found_server) {
+      // Current server not found in new list, jump!
+      putlog(LOG_SERV, "*", "Server removed from list, jumping!");
+      nuke_server("server removed");
+      cycle_time = 0;
+    } else {
+      // Update current server in list.
+      curserv = -1;
+      next_server(&curserv, cursrvname, &curservport, NULL);
+    }
+  }
+}

+ 1 - 0
src/chanprog.h

@@ -34,6 +34,7 @@ void load_internal_users();
 void setup_HQ(int);
 void privmsg(const char* target, const char* msg, int idx);
 void notice(const char* target, const char* msg, int idx);
+void check_removed_server();
 
 extern struct chanset_t		*chanset, *chanset_default;
 extern char			admin[], origbotnick[HANDLEN + 1], origbotname[NICKLEN], jupenick[NICKLEN], botname[NICKLEN], *def_chanset;

+ 1 - 1
src/mod/server.mod/server.c

@@ -794,7 +794,7 @@ void clearq(struct server_list *xx)
 
 /* Set botserver to the next available server.
  *
- * -> if (*ptr == -1) then jump to that particular server
+ * -> if (*ptr == -1) then add that particular server
  */
 void next_server(int *ptr, char *servname, port_t *port, char *pass)
 {

+ 2 - 0
src/mod/share.mod/share.c

@@ -1425,6 +1425,8 @@ static void share_read_stream(int idx, bd::Stream& stream) {
    */
   clear_userlist(ou);
 
+  check_removed_server();
+
   /* The userfile we received may just be bogus or missing important users */
   load_internal_users();
   add_myself_to_userlist();

+ 5 - 21
src/set.c

@@ -390,28 +390,8 @@ sdprintf("var (mem): %s -> %s", var->name, datain ? datain : "(NULL)");
 
     if (data)
       add_server(data);
-    
-    if (server_online) {
-      bool found_server = 0;
-
-      for (struct server_list *n = (*(struct server_list **)var->mem); n; n = n->next) {
-        if (((n->port && n->port == curservport) || (!n->port && default_port == curservport)) &&
-            !strcmp(n->name, cursrvname)) {
-          found_server = 1;
-          break;
-        }
-      }
 
-      if (!found_server) {
-        // Current server not found in new list, jump!
-        nuke_server("server removed");
-        cycle_time = 0;
-      } else {
-        // Update current server in list.
-        curserv = -1;
-        next_server(&curserv, cursrvname, &curservport, NULL);
-      }
-    }
+    curserv = 999; /* Will get updated after userfile is loaded */
   }
 
   if (datap)
@@ -675,6 +655,7 @@ void init_vars()
 }
 
 /* This is used to parse (GLOBAL) userfile var lines and changes via .set from a remote hub */
+// per-bot is set in userent.c: set_gotshare
 void var_userfile_share_line(char *line, int idx, bool share)
 {
   char *name = newsplit(&line);
@@ -691,6 +672,9 @@ void var_userfile_share_line(char *line, int idx, bool share)
   if (share && (conf.bot->hub || conf.bot->localhub))
     botnet_send_var_broad(idx, var);
   set_noshare = 0;
+
+  if (!conf.bot->hub && !strncmp(var->name, "servers", 7))
+    check_removed_server();
 }
 
 static const char *var_get_bot_data(struct userrec *u, const char *name)

+ 2 - 0
src/userent.c

@@ -351,6 +351,8 @@ static bool set_gotshare(struct userrec *u, struct user_entry *e, char *buf, int
     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... */
+    if (!conf.bot->hub && !strncmp(name, "servers", 7))
+      check_removed_server();
   } 
   /* not else if as the hub might have gotten a botset for itself */
   if (conf.bot->hub || conf.bot->localhub) {