瀏覽代碼

* Save hubs to binary when saving userfile

Bryan Drewery 14 年之前
父節點
當前提交
d7c7646c80
共有 3 個文件被更改,包括 32 次插入1 次删除
  1. 24 0
      src/conf.c
  2. 1 0
      src/conf.h
  3. 7 1
      src/userrec.c

+ 24 - 0
src/conf.c

@@ -1018,6 +1018,30 @@ bin_to_conf(bool error)
   tellconf();
 }
 
+void conf_update_hubs(struct userrec* list) {
+  bd::Array<bd::String> hubUsers;
+
+  // Count how many hubs there are
+  for (struct userrec *u = list; u; u = u->next) {
+    if (bot_hublevel(u) < 999) {
+      hubUsers << u->handle;
+    }
+  }
+
+  conf.hubs.clear();
+  conf.hubs.Reserve(hubUsers.length());
+  for (size_t idx = 0; idx < hubUsers.length(); ++idx) {
+    struct userrec *u = get_user_by_handle(list, const_cast<char*>(static_cast<bd::String>(hubUsers[idx]).c_str()));
+    struct bot_addr *bi = (struct bot_addr *) get_user(&USERENTRY_BOTADDR, u);
+    conf.hubs << bd::String::printf("%s %s %d %d", u->handle, bi->address, bi->telnet_port, bi->hublevel);
+  }
+
+  if (conf.bot->hub || conf.bot->localhub) {
+    /* rewrite our binary */
+    conf_to_bin(&conf, 0, -1);
+  }
+}
+
 void conf_add_userlist_bots()
 {
   conf_bot *bot = NULL;

+ 1 - 0
src/conf.h

@@ -75,5 +75,6 @@ void deluser_removed_bots(conf_bot *, conf_bot *);
 conf_bot *conf_getlocalhub(conf_bot *);
 void conf_setmypid(pid_t);
 void conf_bot_dup(conf_bot *dest, conf_bot *src);
+void conf_update_hubs(struct userrec* list);
 
 #endif /* !_CONF_H */

+ 7 - 1
src/userrec.c

@@ -476,7 +476,13 @@ void stream_writeuserfile(bd::Stream& stream, const struct userrec *bu, bool old
  */
 int write_userfile(int idx)
 {
-  if (userlist == NULL || !conf.bot->hub)
+  if (!userlist) {
+    return 1;
+  }
+
+  conf_update_hubs(userlist);
+
+  if (!conf.bot->hub)
     return 1;			/* No point in saving userfile */
 
   if (idx >= 0)