Ver código fonte

* Port [3421] to 1.2.14
* Cleaned up some bugs in the 'getin' system.
* Cache user record in tandem list for bots
* Keep track if bots are hubs in tandem list
* Add bot_shouldjoin() which predicts whether the specified bot should join the given channel (based on +inactive and +backup)



svn: 3422

Bryan Drewery 19 anos atrás
pai
commit
78614222e2
8 arquivos alterados com 107 adições e 78 exclusões
  1. 1 0
      doc/UPDATES
  2. 8 6
      src/botnet.c
  3. 42 17
      src/chanprog.c
  4. 3 1
      src/chanprog.h
  5. 2 18
      src/conf.c
  6. 35 35
      src/mod/irc.mod/irc.c
  7. 14 1
      src/mod/share.mod/share.c
  8. 2 0
      src/tandem.h

+ 1 - 0
doc/UPDATES

@@ -43,6 +43,7 @@ Lines prefixed with '-' were disabled before release and are not finished, or ar
 * Fix chanset flag 'userbans' not being saved correctly. (may cause warnings on upgrade)
 * Fix authing on non-chathubs (fixes #356)
 * Fix segfault with cmd_set and adding to empty lists.
+* Cleaned up some bugs in the 'getin' system.
 
 1.2.13 - http://wraith.shatow.net/milestone/1.2.13
 * Fix cmd_chanset accepting invalid flags

+ 8 - 6
src/botnet.c

@@ -46,9 +46,7 @@ void init_party()
 
 tand_t *findbot(char *who)
 {
-  tand_t *ptr = NULL;
-
-  for (ptr = tandbot; ptr; ptr = ptr->next)
+  for (tand_t* ptr = tandbot; ptr; ptr = ptr->next)
     if (!egg_strcasecmp(ptr->bot, who))
       return ptr;
   return NULL;
@@ -66,7 +64,7 @@ void addbot(char *who, char *from, char *next, char flag, int vlocalhub, time_t
     ptr = &((*ptr)->next);
   }
   ptr2 = (tand_t *) my_calloc(1, sizeof(tand_t));
-  strncpy(ptr2->bot, who, HANDLEN);
+  strlcpy(ptr2->bot, who, HANDLEN + 1);
   ptr2->bot[HANDLEN] = 0;
   ptr2->share = flag;
   ptr2->localhub = vlocalhub;
@@ -77,6 +75,10 @@ void addbot(char *who, char *from, char *next, char flag, int vlocalhub, time_t
   *ptr = ptr2;
   /* May be via itself */
   ptr2->via = findbot(from);
+  /* Look up the bot in internal users */
+  ptr2->hub = is_hub(who);
+  /* Cache user record */
+  ptr2->u = userlist ? get_user_by_handle(userlist, who) : NULL;
   if (!egg_strcasecmp(next, conf.bot->nick))
     ptr2->uplink = (tand_t *) 1;
   else
@@ -804,10 +806,10 @@ void dump_links(int z)
 
 int in_chain(char *who)
 {
-  if (findbot(who))
-    return 1;
   if (!egg_strcasecmp(who, conf.bot->nick))
     return 1;
+  if (findbot(who))
+    return 1;
   return 0;
 }
 

+ 42 - 17
src/chanprog.c

@@ -375,6 +375,24 @@ void reaffirm_owners()
   }
 }
 
+bool is_hub(const char* nick) {
+  char *p = settings.hubs, *p2 = NULL, hubbuf[HANDLEN + 1] ="";
+  size_t len = 0;
+
+  while (p && *p) {
+    if ((p2 = strchr(p, ' '))) {
+
+      len = p2 - p;
+      simple_snprintf(hubbuf, len + 1, "%s", p);
+      if (!egg_strncasecmp(nick, hubbuf, HANDLEN))
+        return 1;
+    }
+    if ((p = strchr(p, ',')))
+      p++;
+  }
+  return 0;
+}
+
 void load_internal_users()
 {
   char *p = NULL, *ln = NULL, *hand = NULL, *ip = NULL, *port = NULL, *pass = NULL, *q = NULL;
@@ -630,7 +648,10 @@ void reload()
 
   /* 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();
@@ -738,26 +759,30 @@ chans_delbot(const char *bot, struct chanset_t *chan)
 }
 */
 
-int shouldjoin(struct chanset_t *chan)
+bool bot_shouldjoin(struct userrec* u, struct flag_record* fr, struct chanset_t* chan)
 {
   /* If the bot is restarting (and hasn't finished getting the userfile for the first time) DO NOT JOIN channels - breaks +B/+backup */
-  if (restarting) return 0;
-
-  if (!strncmp(conf.bot->nick, "wtest", 5) && (!strcmp(chan->dname, "#skynet") || !strcmp(chan->dname, "#bryan") || !strcmp(chan->dname, "#wraith")))
-    return 1;
-  else if (!strncmp(conf.bot->nick, "wtest", 4)) /* use 5 for all */
-    return 0; 
+  if (restarting || loading) return 0;
 
-  if (!chan || !chan->dname || !chan->dname[0])
-    return 0;
-
-  struct flag_record fr = { FR_CHAN|FR_GLOBAL|FR_BOT, 0, 0, 0 };
-  struct userrec *u = NULL;
-
-  if ((u = get_user_by_handle(userlist, conf.bot->nick)))
-    get_user_flagrec(u, &fr, chan->dname);
+  if (!strncmp(u->handle, "wtest", 5)) {
+    if (!strcmp(chan->dname, "#skynet") || 
+        !strcmp(chan->dname, "#bryan") || 
+        !strcmp(chan->dname, "#wraith"))
+      return 1;
+    else
+      return 0;
+  }
+  return (!channel_inactive(chan) && (channel_backup(chan) || (!glob_backup(*fr) && !chan_backup(*fr))));
+}
 
-  return (!channel_inactive(chan) && (channel_backup(chan) || (!glob_backup(fr) && !chan_backup(fr))));
+bool shouldjoin(struct chanset_t *chan)
+{
+  if (conf.bot->u) {
+    struct flag_record fr = { FR_CHAN|FR_GLOBAL|FR_BOT, 0, 0, 0 };
+    get_user_flagrec(conf.bot->u, &fr, chan->dname);
+    return bot_shouldjoin(conf.bot->u, &fr, chan);
+  }
+  return 0;
 }
 
 /* do_chanset() set (options) on (chan)

+ 3 - 1
src/chanprog.h

@@ -23,9 +23,11 @@ void set_chanlist(const char *host, struct userrec *rec);
 void clear_chanlist(void);
 void clear_chanlist_member(const char *nick);
 int botshouldjoin(struct userrec *u, struct chanset_t *);
-int shouldjoin(struct chanset_t *);
+bool bot_shouldjoin(struct userrec* , struct flag_record *, struct chanset_t *);
+bool shouldjoin(struct chanset_t *);
 char *samechans(const char *, const char *);
 void add_myself_to_userlist();
+bool is_hub(const char*);
 void load_internal_users();
 
 extern struct chanset_t		*chanset;

+ 2 - 18
src/conf.c

@@ -565,24 +565,8 @@ conf_addbot(char *nick, char *ip, char *host, char *ip6)
 
 //  bot->pid = checkpid(nick, bot);
 
-  if (settings.hubs) {
-    char *p = settings.hubs, *p2 = NULL, hubbuf[HANDLEN + 1] ="";
-    size_t len = 0;
-
-    while (p && *p) {
-      if ((p2 = strchr(p, ' '))) {
-
-        len = p2 - p;
-        simple_snprintf(hubbuf, len + 1, "%s", p);
-        if (!egg_strncasecmp(bot->nick, hubbuf, HANDLEN)) {
-          bot->hub = 1;
-          break;
-        }
-      }
-      if ((p = strchr(p, ',')))
-        p++;
-    }
-  }
+  if (settings.hubs && is_hub(bot->nick))
+    bot->hub = 1;
 
   /* not a hub 
    AND

+ 35 - 35
src/mod/irc.mod/irc.c

@@ -720,18 +720,19 @@ request_op(struct chanset_t *chan)
     return;
   }
 
-  int i = 0, my_exp = 0, first = 100;
-  time_t n = now;
-  struct flag_record myfr = { FR_GLOBAL | FR_CHAN | FR_BOT, 0, 0, 0 };
+  struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_BOT, 0, 0, 0 };
 
-  get_user_flagrec(conf.bot->u, &myfr, chan->dname);
+  get_user_flagrec(conf.bot->u, &fr, chan->dname);
 
-  if (!chk_op(myfr, chan) || glob_kick(myfr) || chan_kick(myfr)) {
+  if (!chk_op(fr, chan) || glob_kick(fr) || chan_kick(fr)) {
     putlog(LOG_GETIN, "*", "Not requesting op for %s - I do not have access to that channel.", chan->dname);
     chan->channel.no_op = now + 10;
     return;
   }
 
+  int i = 0, my_exp = 0, first = 100;
+  time_t n = now;
+
   /* max OPREQ_COUNT requests per OPREQ_SECONDS sec */
   while (i < 5) {
     if (n - chan->opreqtime[i] > op_requests.time) {
@@ -748,32 +749,33 @@ request_op(struct chanset_t *chan)
     chan->channel.no_op = now + op_requests.time + 1;
     return;
   }
-  int cnt = op_bots, i2;
-  memberlist *ml = NULL;
-  memberlist *botops[MAX_BOTS];
-  struct flag_record fr = { FR_GLOBAL | FR_CHAN, 0, 0, 0 };
+
+  int cnt = op_bots, i2 = 0;
+  memberlist *ml = NULL, *botops[MAX_BOTS];
   char s[UHOSTLEN] = "";
 
   for (i = 0, ml = chan->channel.member; (i < MAX_BOTS) && ml && ml->nick[0]; ml = ml->next) {
-    /* If bot, linked, global op & !split & chanop & (chan is reserver | bot isn't +a) -> 
-     * add to temp list */
+    if (!chan_hasop(ml) || chan_issplit(ml))
+      continue;
+
     if (!ml->user && !ml->tried_getuser) {
       simple_sprintf(s, "%s!%s", ml->nick, ml->userhost);
       ml->user = get_user_by_host(s);
       ml->tried_getuser = 1;
     }
-    if ((i < MAX_BOTS) && ml->user && ml->user->bot && 
-        findbot(ml->user->handle) && chan_hasop(ml) && !chan_issplit(ml)) {
 
-      get_user_flagrec(ml->user, &fr, NULL);
-      if (chk_op(fr, chan))
-        botops[i++] = ml;
-    }
+    if (!ml->user || !ml->user->bot)
+      continue;
+
+    /* Is the bot linked? */
+    if (findbot(ml->user->handle))
+      botops[i++] = ml;
+
   }
   if (!i) {
     if (channel_active(chan) && !channel_pending(chan)) {
       chan->channel.no_op = now + op_requests.time;
-      putlog(LOG_GETIN, "*", "No one to ask for ops on %s - Delaying requests for %d seconds.", chan->dname, op_requests.time);
+      putlog(LOG_GETIN, "*", "No one to ask for ops on %s - Delaying requests for %lu seconds.", chan->dname, op_requests.time);
     }
     return;
   }
@@ -834,30 +836,28 @@ request_in(struct chanset_t *chan)
   if (!shouldjoin(chan))
     return;
 
-  struct flag_record myfr = { FR_GLOBAL | FR_CHAN | FR_BOT, 0, 0, 0 };
+  struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_BOT, 0, 0, 0 };
 
-  get_user_flagrec(conf.bot->u, &myfr, NULL);
+  get_user_flagrec(conf.bot->u, &fr, NULL);
 
-  if (!chk_op(myfr, chan) || glob_kick(myfr) || chan_kick(myfr)) {
+  if (!chk_op(fr, chan) || glob_kick(fr) || chan_kick(fr)) {
     putlog(LOG_GETIN, "*", "Not requesting help to join %s - I do not have access to that channel.", chan->dname);
     return;
   }
 
-  int i = 0;
+  int foundBots = 0;
   struct userrec *botops[MAX_BOTS];
-  struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0 };
 
-  for (struct userrec *u = userlist; u && (i < MAX_BOTS); u = u->next) {
-    get_user_flagrec(u, &fr, NULL);
-    if (bot_hublevel(u) == 999 && glob_bot(fr) && chk_op(fr, chan)
-#ifdef G_BACKUP
-        && (!glob_backupbot(fr) || channel_backup(chan))
-#endif
-        /* G_BACKUP */
-        && nextbot(u->handle) >= 0)
-      botops[i++] = u;
+  for (tand_t* bot = tandbot; bot && (foundBots < MAX_BOTS); bot = bot->next) {
+    if (bot->hub || !bot->u)
+      continue;
+
+    get_user_flagrec(bot->u, &fr, chan->dname);
+    if (bot_shouldjoin(bot->u, &fr, chan) && chk_op(fr, chan))
+      botops[foundBots++] = bot->u;
   }
-  if (!i) {
+
+  if (!foundBots) {
     putlog(LOG_GETIN, "*", "No bots linked, can't request help to join %s", chan->dname);
     return;
   }
@@ -867,7 +867,7 @@ request_in(struct chanset_t *chan)
 
   simple_sprintf(s, "gi i %s %s %s!%s %s", chan->dname, botname, botname, botuserhost, botuserip);
   while (cnt) {
-    n = randint(i);
+    n = randint(foundBots);
     if (botops[n]) {
       putbot(botops[n]->handle, s);
       if (l[0]) {
@@ -879,7 +879,7 @@ request_in(struct chanset_t *chan)
       botops[n] = NULL;
       cnt--;
     } else {
-      if (i < in_bots)
+      if (foundBots < in_bots)
         cnt--;
     }
   }

+ 14 - 1
src/mod/share.mod/share.c

@@ -1266,7 +1266,13 @@ finish_share(int idx)
   for (i = 0; i < dcc_total; i++)
     if (dcc[i].type)
       dcc[i].user = NULL;
-  Auth::NullUsers();
+
+  for (tand_t* bot = tandbot; bot; bot = bot->next)
+    bot->u = NULL;
+
+  if (!conf.bot->hub) {
+    Auth::NullUsers();
+  }
 
   if (conf.bot->u)
     conf.bot->u = NULL;
@@ -1295,6 +1301,9 @@ finish_share(int idx)
       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.             */
@@ -1346,6 +1355,10 @@ finish_share(int idx)
   /* 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) {  
     /* Our hostmask may have been updated on connect, but the new userfile may not have it. */
     check_hostmask();

+ 2 - 0
src/tandem.h

@@ -13,10 +13,12 @@ typedef struct tand_t_struct {
   struct tand_t_struct *next;
   time_t buildts;
   int localhub;
+  struct userrec* u;
   char *not_chans;
   char bot[HANDLEN + 1];
   char version[121];
   char share;
+  bool hub;
 } tand_t;
 
 /* Keep track of party-line members */