Преглед изворни кода

Merge branch '44-getin-limit' into next

* 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

Conflicts:
	doc/UPDATES
Bryan Drewery пре 14 година
родитељ
комит
f6745d00a1
3 измењених фајлова са 20 додато и 17 уклоњено
  1. 1 0
      doc/UPDATES
  2. 18 16
      src/mod/irc.mod/irc.c
  3. 1 1
      src/mod/irc.mod/irc.h

+ 1 - 0
doc/UPDATES

@@ -6,6 +6,7 @@ next
   * Add chanset 'voice-moderate' which will auto set +m in '+voice' channel and devoice flooding clients instead of kick. (#48)
   * Bots now will enforce devoices made by ops (user +o) and allow any op (user +o) to revoice to disable that enforcement.
     This used to use +m to enforce/allowed revoicing.
+  * Tweak limit range checking such that bot will set limit less often
 
 1.4.0 - http://wraith.botpack.net/milestone/1.4.0
   * Updated server list, 'set -yes servers -' and 'set -yes servers6 -' to get new list.

+ 18 - 16
src/mod/irc.mod/irc.c

@@ -827,7 +827,7 @@ getin_request(char *botnick, char *code, char *par)
     bool sendi = 0;
 
     if (chan->channel.maxmembers) {
-      if (raise_limit(chan)) {
+      if (raise_limit(chan, 5)) {
         putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - Raised limit", botnick, nick, chan->dname);
       }
     }
@@ -1409,7 +1409,7 @@ check_netfight(struct chanset_t *chan)
 }
 
 bool
-raise_limit(struct chanset_t *chan)
+raise_limit(struct chanset_t *chan, int default_limitraise)
 {
   if (!chan || !me_op(chan))
     return false;
@@ -1418,24 +1418,26 @@ raise_limit(struct chanset_t *chan)
   if (chan->mode_mns_prot & CHANLIMIT)
     return false;
 
-  const int nl = (chan->channel.members - chan->channel.splitmembers) + chan->limitraise;	/* new limit */
-  const int limitraise = (chan->limitraise % 2 == 0) ? chan->limitraise : (chan->limitraise + 1);
-  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 */
+  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 false;                     /* 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 true;
+    }
   }
 
   return false;

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

@@ -148,7 +148,7 @@ inline void check_this_mask(const char type, struct chanset_t *chan, char *mask,
 }
 
 void check_this_user(char *, int, char *);
-bool 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 *);