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

Consolidate user pointer cache clearing

Bryan Drewery 10 лет назад
Родитель
Сommit
beed6c880b
3 измененных файлов с 22 добавлено и 28 удалено
  1. 1 16
      src/mod/share.mod/share.cc
  2. 20 12
      src/userrec.cc
  3. 1 0
      src/userrec.h

+ 1 - 16
src/mod/share.mod/share.cc

@@ -1373,22 +1373,7 @@ static void share_read_stream(int idx, bd::Stream& stream) {
   //userlist = (struct userrec *) -1;       /* Do this to prevent .user messups     */
   userlist = NULL;
 
-  /* Bot user pointers are updated to point to the new list, all others
-   * are set to NULL. If our userfile will be overriden, just set _all_
-   * to NULL directly.
-   */
-  for (i = 0; i < dcc_total; i++)
-    if (dcc[i].type)
-      dcc[i].user = NULL;
-
-  for (tand_t* bot = tandbot; bot; bot = bot->next)
-    bot->u = NULL;
-
-  if (!conf.bot->hub) {
-    Auth::NullUsers();
-  }
-
-  conf.bot->u = NULL;
+  clear_cached_users();
 
   struct cmd_pass *old_cmdpass = cmdpass;
   cmdpass = NULL;

+ 20 - 12
src/userrec.cc

@@ -172,6 +172,25 @@ void clear_masks(maskrec *m)
 
 static void freeuser(struct userrec *);
 
+void clear_cached_users()
+{
+  for (int i = 0; i < dcc_total; i++) {
+    if (dcc[i].type) {
+      dcc[i].user = NULL;
+    }
+  }
+
+  conf.bot->u = NULL;
+
+  for (tand_t* bot = tandbot; bot; bot = bot->next) {
+    bot->u = NULL;
+  }
+
+  if (!conf.bot->hub) {
+    Auth::NullUsers();
+  }
+}
+
 void clear_userlist(struct userrec *bu)
 {
   struct userrec *v = NULL;
@@ -183,18 +202,7 @@ void clear_userlist(struct userrec *bu)
   if (userlist == bu) {
     struct chanset_t *cst = NULL;
 
-    for (int i = 0; i < dcc_total; i++)
-      if (dcc[i].type)
-        dcc[i].user = NULL;
-
-    conf.bot->u = NULL;
-
-    for (tand_t* bot = tandbot; bot; bot = bot->next)
-      bot->u = NULL;
-
-    if (!conf.bot->hub) {
-      Auth::NullUsers();
-    }
+    clear_cached_users();
 
     clear_chanlist();
     lastuser = NULL;

+ 1 - 0
src/userrec.h

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