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

* Add child bots, localhub and self depending on cases

Bryan Drewery 16 лет назад
Родитель
Сommit
76af1fad85
2 измененных файлов с 41 добавлено и 19 удалено
  1. 41 16
      src/chanprog.c
  2. 0 3
      src/conf.c

+ 41 - 16
src/chanprog.c

@@ -523,27 +523,42 @@ void load_internal_users()
 
 }
 
-void add_myself_to_userlist() {
-  if (!(conf.bot->u = get_user_by_handle(userlist, conf.bot->nick))) {
+static struct userrec* add_bot_userlist(char* bot) {
+  struct userrec *u = NULL;
+  if (!(u = get_user_by_handle(userlist, bot))) {
     /* I need to be on the userlist... doh. */
-    userlist = adduser(userlist, conf.bot->nick, "none", "-", USER_OP, 1);
-    conf.bot->u = get_user_by_handle(userlist, conf.bot->nick);
-
-    /* Assume hub has a record added from load_internal_users();
-       why would it think it was a hub if it wasn't in the hub list??
-    */
-    if (!conf.bot->hub) {
-      struct bot_addr *bi = (struct bot_addr *) my_calloc(1, sizeof(struct bot_addr));
-      if (conf.bot->net.ip)
-        bi->address = strdup(conf.bot->net.ip);
-      bi->telnet_port = bi->relay_port = 3333;
-      bi->hublevel = 999;
-      bi->uplink = (char *) my_calloc(1, 1);
-      set_user(&USERENTRY_BOTADDR, conf.bot->u, bi);
+    userlist = adduser(userlist, bot, "none", "-", USER_OP, 1);
+    u = get_user_by_handle(userlist, bot);
+
+    struct bot_addr *bi = (struct bot_addr *) my_calloc(1, sizeof(struct bot_addr));
+    bi = (struct bot_addr *) my_calloc(1, sizeof(struct bot_addr));
+    bi->uplink = (char *) my_calloc(1, 1);
+    bi->address = (char *) my_calloc(1, 1);
+    bi->telnet_port = 3333;
+    bi->relay_port = 3333;
+    bi->hublevel = 999;
+    set_user(&USERENTRY_BOTADDR, u, bi);
+  }
+  return u;
+}
+
+void add_myself_to_userlist() {
+  conf.bot->u = add_bot_userlist(conf.bot->nick);
+}
+
+void add_child_bots() {
+  conf_bot* bot = conf.bots->next; //Skip myself
+  if (bot && bot->nick) {
+    for (bot = conf.bots; bot && bot->nick; bot = bot->next) {
+      add_bot_userlist(conf.bot->nick);
     }
   }
 }
 
+void add_localhub() {
+  add_bot_userlist(conf.localhub);
+}
+
 void rehash_ip() {
   /* cache our ip on load instead of every 30 seconds */
   char *ip4 = NULL, *ip6 = NULL;
@@ -624,6 +639,11 @@ void chanprog()
 
   add_myself_to_userlist();
 
+  if (conf.bot->localhub)
+    add_child_bots();
+  else if (!conf.bot->hub)
+    add_localhub();
+
   rehash_ip();
 
   /* set our shell info */
@@ -666,6 +686,11 @@ void reload()
   /* make sure I am added and conf.bot->u is set */
   add_myself_to_userlist();
 
+  if (conf.bot->localhub)
+    add_child_bots();
+  else if (!conf.bot->hub)
+    add_localhub();
+
   /* Make sure no removed users/bots are still connected. */
   check_stale_dcc_users();
 

+ 0 - 3
src/conf.c

@@ -487,9 +487,6 @@ conf_addbot(const char *nick, const char *ip, const char *host, const char *ip6)
     conf.localhub_socket = strdup("/tmp/wraith-test");
   }
 
-  //Add this bot to the userlist
-  if (!bot->u)
-    userlist = adduser(userlist, bot->nick, "none", "-", USER_OP, 1);
   list_append((struct list_type **) &(conf.bots), (struct list_type *) bot);
 }