ソースを参照

Merge branch '127-roles-bugs'

* 127-roles-bugs:
  Fix role assigned to self
  Fix roles to consider if a bot is linked.
Bryan Drewery 6 年 前
コミット
6273e44440
6 ファイル変更33 行追加17 行削除
  1. 5 0
      src/botnet.cc
  2. 1 0
      src/botnet.h
  3. 1 1
      src/chan.h
  4. 1 1
      src/mod/channels.mod/chanmisc.cc
  5. 6 6
      src/mod/irc.mod/chan.cc
  6. 19 9
      src/mod/irc.mod/irc.cc

+ 5 - 0
src/botnet.cc

@@ -60,6 +60,7 @@ tand_t			*tandbot = NULL;		/* Keep track of tandem bots on the
 							   botnet */
 party_t			*party = NULL;			/* Keep track of people on the botnet */
 int			tands = 0;			/* Number of bots on the botnet */
+unsigned long		tand_updates = 0;
 
 static int 		maxparty = 50;			/* Maximum space for party line members
 							   currently */
@@ -122,6 +123,8 @@ void addbot(char *who, char *from, char *next, char flag, int vlocalhub, time_t
   else
     ptr2->uplink = findbot(next);
   tands++;
+  if (!ptr2->hub)
+    tand_updates++;
 
   counter_clear(who);
 }
@@ -334,6 +337,8 @@ void rembot(const char *whoin)
 
   ptr2 = *ptr;
   *ptr = ptr2->next;
+  if (!ptr2->hub)
+    tand_updates++;
   free(ptr2);
   tands--;
 

+ 1 - 0
src/botnet.h

@@ -14,6 +14,7 @@ namespace bd {
 extern tand_t		*tandbot;
 extern party_t		*party;
 extern int		tands;
+extern unsigned long	tand_updates;
 
 #define lower_bot_linked(idx) do {} while (0)
 void answer_local_whom(int, int);

+ 1 - 1
src/chan.h

@@ -312,7 +312,7 @@ struct chanset_t {
   // My role bitmask
   int role;
 
-  int needs_role_rebalance;
+  unsigned long role_rebalance_cookie;
 };
 
 /* behavior modes for the channel */

+ 1 - 1
src/mod/channels.mod/chanmisc.cc

@@ -993,7 +993,7 @@ static void init_channel(struct chanset_t *chan, bool reset)
     chan->role_bots = new bd::HashTable<short, bd::Array<bd::String> >;
     chan->role = 0;
   }
-  chan->needs_role_rebalance = 1;
+  chan->role_rebalance_cookie = 0;
 }
 
 static void clear_masklist(masklist *m)

+ 6 - 6
src/mod/irc.mod/chan.cc

@@ -1307,7 +1307,7 @@ void check_this_user(char *hand, int del, char *host)
         /* Newly discovered bot, or deleted bot which fullfilled a role,
          * need to rebalance. */
         if (!del || (del && (*chan->bot_roles)[u->handle] != 0)) {
-          chan->needs_role_rebalance = 1;
+          chan->role_rebalance_cookie = 0;
         }
       }
       if (m->user && !had_user) // If a member is newly recognized, act on it
@@ -2750,7 +2750,7 @@ static int gotjoin(char *from, char *chname)
 	m->flags = (chan_hasop(m) ? WASOP : 0);
         /* New bot available for roles, rebalance. */
         if (is_bot(m->user)) {
-          chan->needs_role_rebalance = 1;
+          chan->role_rebalance_cookie = 0;
         }
 	set_handle_laston(chan->dname, m->user, now);
 //	m->flags |= STOPWHO;
@@ -2815,7 +2815,7 @@ static int gotjoin(char *from, char *chname)
           detect_chan_flood(m, from, chan, FLOOD_JOIN);
           /* New bot available for roles, rebalance. */
           if (is_bot(m->user)) {
-            chan->needs_role_rebalance = 1;
+            chan->role_rebalance_cookie = 0;
           }
 	  set_handle_laston(chan->dname, m->user, now);
 	}
@@ -2969,7 +2969,7 @@ static int gotpart(char *from, char *msg)
     }
     /* This bot fullfilled a role, need to rebalance. */
     if (u && u->bot && (*chan->bot_roles)[u->handle] != 0) {
-      chan->needs_role_rebalance = 1;
+      chan->role_rebalance_cookie = 0;
     }
     set_handle_laston(chan->dname, u, now);
 
@@ -3062,7 +3062,7 @@ static int gotkick(char *from, char *origmsg)
       set_handle_laston(chan->dname, mv->user, now);
       /* This bot fullfilled a role, need to rebalance. */
       if (mv->user->bot && (*chan->bot_roles)[mv->user->handle] != 0) {
-        chan->needs_role_rebalance = 1;
+        chan->role_rebalance_cookie = 0;
       }
     }
     irc_log(chan, "%s!%s was kicked by %s (%s)", mv->nick, mv->userhost, from, msg);
@@ -3240,7 +3240,7 @@ static int gotquit(char *from, char *msg)
           counter_clear(u->handle);
           /* This bot fullfilled a role, need to rebalance. */
           if ((*chan->bot_roles)[u->handle] != 0) {
-            chan->needs_role_rebalance = 1;
+            chan->role_rebalance_cookie = 0;
           }
         }
         set_handle_laston(chan->dname, u, now); /* If you remove this, the bot will crash when the user record in question

+ 19 - 9
src/mod/irc.mod/irc.cc

@@ -1766,14 +1766,8 @@ static void bot_release_nick (char *botnick, char *code, char *par) {
 
 static void rebalance_roles_chan(struct chanset_t* chan)
 {
-  bd::Array<bd::String> bots;
-  int *bot_bits;
-  short role;
-  size_t botcount, mappedbot, omappedbot, botidx, roleidx, rolecount;
-  struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
-  memberlist *m;
-
-  if (chan->needs_role_rebalance == 0) {
+  /* Compare to tand_updates which ensures a trigger on unlink/link. */
+  if (chan->role_rebalance_cookie == tand_updates) {
     return;
   }
 
@@ -1782,6 +1776,13 @@ static void rebalance_roles_chan(struct chanset_t* chan)
     return;
   }
 
+  bd::Array<bd::String> bots;
+  int *bot_bits;
+  short role;
+  size_t botcount, mappedbot, omappedbot, botidx, roleidx, rolecount;
+  struct flag_record fr = {FR_GLOBAL | FR_CHAN, 0, 0, 0 };
+  memberlist *m;
+
   /* Gather list of all bots in the channel. */
   /* XXX: Keep this known in chan->bots */
   for (m = chan->channel.member; m && m->nick[0]; m = m->next) {
@@ -1799,6 +1800,14 @@ static void rebalance_roles_chan(struct chanset_t* chan)
     if (!(m->user->fflags & FEATURE_ROLES)) {
       continue;
     }
+    /*
+     * By requiring a linked bot it avoids descyning to the point
+     * of a bot assigning a role to a +d bot. This also allows
+     * botnet splits to balance between themselves.
+     */
+    if (!in_chain(m->user->handle))
+      continue;
+
     bots << m->user->handle;
   }
   botcount = bots.length();
@@ -1859,7 +1868,8 @@ static void rebalance_roles_chan(struct chanset_t* chan)
   /* Set my own roles */
   chan->role = (*chan->bot_roles)[conf.bot->nick];
   free(bot_bits);
-  chan->needs_role_rebalance = 0;
+  /* Reset to tand_updates which ensures a trigger on unlink/link. */
+  chan->role_rebalance_cookie = tand_updates;
 }
 
 static void rebalance_roles()