소스 검색

Rebalance roles on only after channel resets

Bryan Drewery 12 년 전
부모
커밋
2221dccb29
4개의 변경된 파일16개의 추가작업 그리고 5개의 파일을 삭제
  1. 2 0
      src/chan.h
  2. 2 0
      src/mod/channels.mod/chanmisc.c
  3. 11 5
      src/mod/irc.mod/irc.c
  4. 1 0
      src/mod/irc.mod/irc.h

+ 2 - 0
src/chan.h

@@ -266,6 +266,8 @@ struct chanset_t {
 
   // My role bitmask
   int role;
+
+  int needs_role_rebalance;
 };
 
 /* behavior modes for the channel */

+ 2 - 0
src/mod/channels.mod/chanmisc.c

@@ -969,6 +969,8 @@ static void init_channel(struct chanset_t *chan, bool reset)
   chan->channel.floodtime = new bd::HashTable<bd::String, bd::HashTable<flood_t, time_t> >;
   chan->channel.floodnum  = new bd::HashTable<bd::String, bd::HashTable<flood_t, int> >;
   chan->channel.cached_members = new bd::HashTable<bd::String, memberlist*>;
+  chan->role = 0;
+  chan->needs_role_rebalance = 1;
 }
 
 static void clear_masklist(masklist *m)

+ 11 - 5
src/mod/irc.mod/irc.c

@@ -1313,6 +1313,7 @@ reset_chan_info(struct chanset_t *chan)
     send_chan_who(DP_MODE, chan, 1);
     /* clear_channel nuked the data...so */
     dprintf(DP_HELP, "TOPIC %s\n", chan->name);//Topic is very low priority
+    rebalance_roles_chan(chan);
   }
 }
 
@@ -1753,7 +1754,7 @@ static void bot_release_nick (char *botnick, char *code, char *par) {
   release_nick(par);
 }
 
-static void rebalance_roles_chans(struct chanset_t* chan)
+static void rebalance_roles_chan(struct chanset_t* chan)
 {
   bd::Array<bd::String> bots;
   int *bot_bits;
@@ -1761,9 +1762,9 @@ static void rebalance_roles_chans(struct chanset_t* chan)
   size_t botcount, mappedbot, omappedbot, botidx, roleidx, rolecount;
   memberlist *m;
 
-  /* Reset current bits */
-  chan->bot_roles->clear();
-  chan->role_bots->clear();
+  if (chan->needs_role_rebalance == 0) {
+    return;
+  }
 
   /* Gather list of all bots in the channel. */
   /* XXX: Keep this known in chan->bots */
@@ -1806,6 +1807,10 @@ static void rebalance_roles_chans(struct chanset_t* chan)
     }
   }
 
+  /* Reset current bits */
+  chan->bot_roles->clear();
+  chan->role_bots->clear();
+
   /* Take bitmask of assigned roles and apply to bots. */
   for (botidx = 0; botidx < botcount; botidx++) {
     if (bot_bits[botidx] != 0) {
@@ -1827,6 +1832,7 @@ static void rebalance_roles_chans(struct chanset_t* chan)
   /* Set my own roles */
   chan->role = (*chan->bot_roles)[botname];
   free(bot_bits);
+  chan->needs_role_rebalance = 0;
 }
 
 static void rebalance_roles()
@@ -1837,7 +1843,7 @@ static void rebalance_roles()
     if (channel_pending(chan) || !channel_active(chan) ||
         !shouldjoin(chan) || (chan->channel.mode & CHANANON))
       continue;
-    rebalance_roles_chans(chan);
+    rebalance_roles_chan(chan);
   }
 }
 

+ 1 - 0
src/mod/irc.mod/irc.h

@@ -75,6 +75,7 @@ static char *getchanmode(struct chanset_t *);
 static void flush_mode(struct chanset_t *, int);
 static bool member_getuser(memberlist* m, bool act_on_lookup = 0);
 static void do_protect(struct chanset_t* chan, const char* reason);
+static void rebalance_roles_chan(struct chanset_t* chan);
 
 /* reset(bans|exempts|invites) are now just macros that call resetmasks
  * in order to reduce the code duplication. <cybah>