Explorar el Código

Merge branch '44-getin-limit'

* 44-getin-limit:
  Tweak limit range checking such that bot will set limit less often
  Raise limit by 5 if 'limit 0' is set for getin_request
  Only raise limit if needed, and use proper even value
  Avoid rounding errors by adding 1 to make limit even (#44)
  Ignore all getin requests unless eligible (#44)
  Only raise limit when inviting a bot if needed (#44)
Bryan Drewery hace 14 años
padre
commit
26b72e921d
Se han modificado 3 ficheros con 48 adiciones y 45 borrados
  1. 1 0
      doc/UPDATES
  2. 46 44
      src/mod/irc.mod/irc.c
  3. 1 1
      src/mod/irc.mod/irc.h

+ 1 - 0
doc/UPDATES

@@ -46,6 +46,7 @@
   * Add chanset 'caps-limit' to handle % of message that can be in caps before kick (#8)
   * Add chanset 'color-limit' to handle how many color codes are allowed in a message before kick (#8)
   * Add chanset 'closed-exempt' which will allow exempting non-users (who are opped or voice) from being kicked. (fixes #171)
+  * Tweak limit range checking such that bot will set limit less often
 
 1.3.4 - http://wraith.botpack.net/milestone/1.3.4
   * Fix various compile warnings with newer GCC

+ 46 - 44
src/mod/irc.mod/irc.c

@@ -756,6 +756,27 @@ getin_request(char *botnick, char *code, char *par)
 
     putlog(LOG_GETIN, "*", "opreq from %s/%s on %s - Opped", botnick, nick, chan->dname);
   } else if (what[0] == 'i') {
+    // Should I respond to this request?
+    // If there's 18 eligible bots in the channel, and in-bots is 2, I have a 2/18 chance of replying.
+    int eligible_bots = 0;
+    for (memberlist* m = chan->channel.member; m && m->nick[0]; m = m->next) {
+      if (chan_hasop(m)) {
+        member_getuser(m, 0);
+        if (m->user && m->user->bot) {
+          ++eligible_bots;
+        }
+      }
+    }
+
+    if (!eligible_bots) {
+      return;
+    }
+
+    if (!((randint(eligible_bots) + 1) <= static_cast<unsigned int>(in_bots))) {
+      // Not my turn
+      return;
+    }
+
     if (mem) {
       putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - %s is already on %s", botnick, nick, chan->dname, nick, chan->dname);
       return;
@@ -783,38 +804,12 @@ getin_request(char *botnick, char *code, char *par)
       return;
     }
 
-    // Should I respond to this request?
-    // If there's 18 eligible bots in the channel, and in-bots is 2, I have a 2/18 chance of replying.
-    int eligible_bots = 0;
-    for (memberlist* m = chan->channel.member; m && m->nick[0]; m = m->next) {
-      if (chan_hasop(m)) {
-        member_getuser(m, 0);
-        if (m->user && m->user->bot) {
-          ++eligible_bots;
-        }
-      }
-    }
-
-    if (!eligible_bots) {
-      return;
-    }
-
-    if (!((randint(eligible_bots) + 1) <= static_cast<unsigned int>(in_bots))) {
-      // Not my turn
-      return;
-    }
 
     bool sendi = 0;
 
     if (chan->channel.maxmembers) {
-      int lim = (chan->channel.members - chan->channel.splitmembers) + 5, curlim = chan->channel.maxmembers;
-      if (curlim < lim) {
-        char s2[6] = "";
-
-        sendi = 1;
-        simple_snprintf(s2, sizeof(s2), "%d", lim);
-        add_mode(chan, '+', 'l', s2);
-        putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - Raised limit to %d", botnick, nick, chan->dname, lim);
+      if (raise_limit(chan, 5)) {
+        putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - Raised limit", botnick, nick, chan->dname);
       }
     }
 
@@ -1394,32 +1389,39 @@ check_netfight(struct chanset_t *chan)
   chan->channel.fighting = 0;   /* we put this here because we need to clear it once per min */
 }
 
-void
-raise_limit(struct chanset_t *chan)
+bool
+raise_limit(struct chanset_t *chan, int default_limitraise)
 {
   if (!chan || !me_op(chan))
-    return;
+    return false;
 
   /* Don't bother setting limit if the user has set a protect -l */
   if (chan->mode_mns_prot & CHANLIMIT)
-    return;
-
-  int nl = (chan->channel.members - chan->channel.splitmembers) + chan->limitraise;	/* new limit */
-  int i = chan->limitraise >> 2;			/* DIV 4 */
-  /* if the newlimit will be in the range made by these vars, dont change. */
-  int ul = nl + i;					/* upper limit */
-  int ll = nl - i;					/* lower limit */
+    return false;
+
+  const int limitraise = (chan->limitraise ? ((chan->limitraise % 2 == 0) ? chan->limitraise : (chan->limitraise + 1)) : default_limitraise);
+  if (limitraise) {
+    const int nl = (chan->channel.members - chan->channel.splitmembers) + limitraise;	/* new limit */
+    const int i = limitraise >> 2;			/* DIV 4 */
+    /* if the newlimit will be in the range made by these vars, dont change. */
+    const int ul = nl + i;					/* upper limit */
+    const int ll = nl - i;					/* lower limit */
+
+    if ((chan->channel.maxmembers >= ll) && (chan->channel.maxmembers <= ul)) {
+      return false;                     /* the current limit is in the range, so leave it. */
+    }
 
-  if ((chan->channel.maxmembers > ll) && (chan->channel.maxmembers < ul))
-    return;                     /* the current limit is in the range, so leave it. */
+    if (nl != chan->channel.maxmembers) {
+      char s[6] = "";
 
-  if (nl != chan->channel.maxmembers) {
-    char s[6] = "";
+      simple_snprintf(s, sizeof(s), "%d", nl);
+      add_mode(chan, '+', 'l', s);
 
-    simple_snprintf(s, sizeof(s), "%d", nl);
-    add_mode(chan, '+', 'l', s);
+      return true;
+    }
   }
 
+  return false;
 }
 
 void check_shouldjoin(struct chanset_t* chan)

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

@@ -146,7 +146,7 @@ inline void check_this_mask(const char type, struct chanset_t *chan, char *mask,
 }
 
 void check_this_user(char *, int, char *);
-void raise_limit(struct chanset_t *);
+bool raise_limit(struct chanset_t *, int default_limitraise = 0);
 void enforce_closed(struct chanset_t *);
 void recheck_channel(struct chanset_t *, int);
 void recheck_channel_modes(struct chanset_t *);