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

Consolidate user cache filling

Bryan Drewery 10 лет назад
Родитель
Сommit
c622ae8f33
4 измененных файлов с 27 добавлено и 24 удалено
  1. 2 4
      src/chanprog.cc
  2. 3 20
      src/mod/share.mod/share.cc
  3. 21 0
      src/userrec.cc
  4. 1 0
      src/userrec.h

+ 2 - 4
src/chanprog.cc

@@ -668,15 +668,13 @@ void reload()
   else if (!conf.bot->hub)
     add_localhub();
 
+  cache_users();
+
   /* Make sure no removed users/bots are still connected. */
   check_stale_dcc_users();
 
-  for (tand_t* bot = tandbot; bot; bot = bot->next)
-    bot->u = get_user_by_handle(userlist, bot->bot);
-
   /* I don't think these will ever be called anyway. */
   if (!conf.bot->hub) {
-    Auth::FillUsers();
     check_hostmask();
   }
 

+ 3 - 20
src/mod/share.mod/share.cc

@@ -1342,7 +1342,6 @@ finish_share(int idx)
 static void share_read_stream(int idx, bd::Stream& stream) {
   struct userrec *u = NULL, *ou = NULL;
   struct chanset_t *chan = NULL;
-  int i;
 
   /*
    * This is where we remove all global and channel bans/exempts/invites and
@@ -1392,20 +1391,11 @@ static void share_read_stream(int idx, bd::Stream& stream) {
     clear_userlist(u);          /* Clear new, obsolete, user list.      */
     clear_chanlist();           /* Remove all user references from the
                                  * channel lists.                       */
-    for (i = 0; i < dcc_total; i++)
-      if (dcc[i].type)
-        dcc[i].user = get_user_by_handle(ou, dcc[i].nick);
-
-    for (tand_t* bot = tandbot; bot; bot = bot->next)
-      bot->u = get_user_by_handle(ou, bot->bot);
-
-    conf.bot->u = get_user_by_handle(ou, conf.bot->nick);
 
     userlist = ou;              /* Revert to old user list.             */
     lastuser = NULL;            /* Reset last accessed user ptr.        */
 
-    Auth::FillUsers();
-
+    cache_users();
     cmdpass = old_cmdpass;
 
     checkchans(2);              /* un-flag the channels, we are keeping them.. */
@@ -1445,18 +1435,11 @@ static void share_read_stream(int idx, bd::Stream& stream) {
   if (conf.bot->localhub)
     add_child_bots();
 
+  cache_users();
+
   /* Make sure no removed users/bots are still connected. */
   check_stale_dcc_users();
 
-  /* Refill tand list with cached user entries */
-  for (tand_t* bot = tandbot; bot; bot = bot->next)
-    bot->u = get_user_by_handle(userlist, bot->bot);
-
-  if (!conf.bot->hub) {  
-    /* copy over any auth users */
-    Auth::FillUsers();
-  }
-
   write_userfile(-1);
 
   cmdpass_free(old_cmdpass);

+ 21 - 0
src/userrec.cc

@@ -191,6 +191,27 @@ void clear_cached_users()
   }
 }
 
+void cache_users()
+{
+  for (int i = 0; i < dcc_total; i++) {
+    if (dcc[i].type) {
+      dcc[i].user = get_user_by_handle(userlist, dcc[i].nick);
+    }
+  }
+
+  if (conf.bot->u == NULL) {
+    conf.bot->u = get_user_by_handle(userlist, conf.bot->nick);
+  }
+
+  for (tand_t* bot = tandbot; bot; bot = bot->next) {
+    bot->u = get_user_by_handle(userlist, bot->bot);
+  }
+
+  if (!conf.bot->hub) {
+    Auth::FillUsers();
+  }
+}
+
 void clear_userlist(struct userrec *bu)
 {
   struct userrec *v = NULL;

+ 1 - 0
src/userrec.h

@@ -9,6 +9,7 @@ struct userrec *adduser(struct userrec *, const char *, char *, char *, flag_t,
 void addhost_by_handle(char *, char *);
 void clear_masks(struct maskrec *);
 void clear_cached_users();
+void cache_users();
 void clear_userlist(struct userrec *);
 int u_pass_match(struct userrec *, const char *);
 int delhost_by_handle(char *, char *);