Bläddra i källkod

Lockdown channel (+im) if banlist becomes full (#37)

Bryan Drewery 14 år sedan
förälder
incheckning
a3a6a68110
4 ändrade filer med 40 tillägg och 4 borttagningar
  1. 1 0
      doc/UPDATES
  2. 33 1
      src/mod/irc.mod/chan.c
  3. 3 1
      src/mod/irc.mod/irc.c
  4. 3 2
      src/mod/irc.mod/irc.h

+ 1 - 0
doc/UPDATES

@@ -1,5 +1,6 @@
 * Fix flood kicking not properly tracking multiple clients at once (#43)
 * Add chanset 'flood-bytes' to count how many bytes:second a user sends before getting kicked for flood. (#42)
+* Bot will now lockdown channel (+im) if banlist becomes full (#37)
 
 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.

+ 33 - 1
src/mod/irc.mod/chan.c

@@ -2446,6 +2446,37 @@ static int got475(char *from, char *msg)
   return 0;
 }
 
+/* got 478: Channel ban list is full
+ * [@] irc.blessed.net 478 wtest #wraith-devel *!*@host.com :Channel ban list is full
+ */
+static int got478(char *from, char *msg)
+{
+  char *chname = NULL;
+  struct chanset_t *chan = NULL;
+
+  newsplit(&msg);
+  chname = newsplit(&msg);
+
+  /* !channel short names (also referred to as 'description names'
+   * can be received by skipping over the unique ID.
+   */
+  if ((chname[0] == '!') && (strlen(chname) > CHANNEL_ID_LEN)) {
+    chname += CHANNEL_ID_LEN;
+    chname[0] = '!';
+  }
+  /* We use dname because name is first set on JOIN and we might not
+   * have joined the channel yet.
+   */
+  chan = findchan_by_dname(chname);
+  if (chan && shouldjoin(chan)) {
+    // Only lockdown if not already locked down
+    if (!chan->channel.drone_set_mode) {
+      lockdown_chan(chan, FLOOD_BANLIST);
+    }
+  }
+  return 0;
+}
+
 /* got invitation
  */
 static int gotinvite(char *from, char *msg)
@@ -2714,7 +2745,7 @@ static int gotjoin(char *from, char *chname)
           chan->channel.drone_jointime = now;
 
           if (!chan->channel.drone_set_mode && chan->channel.drone_joins >= chan->flood_mjoin_thr) {  //flood from dronenet, let's attempt to set +im
-            detected_drone_flood(chan, m, FLOOD_DRONE);
+            lockdown_chan(chan, FLOOD_DRONE);
           }
         }
 
@@ -3411,6 +3442,7 @@ static cmd_t irc_raw[] =
   {"473",	"",	(Function) got473,	"irc:473", LEAF},
   {"474",	"",	(Function) got474,	"irc:474", LEAF},
   {"475",	"",	(Function) got475,	"irc:475", LEAF},
+  {"478",	"",	(Function) got478,	"irc:478", LEAF},
   {"INVITE",	"",	(Function) gotinvite,	"irc:invite", LEAF},
   {"TOPIC",	"",	(Function) gottopic,	"irc:topic", LEAF},
   {"331",	"",	(Function) got331,	"irc:331", LEAF},

+ 3 - 1
src/mod/irc.mod/irc.c

@@ -160,7 +160,7 @@ void unlock_chan(struct chanset_t *chan)
   chan->channel.drone_set_mode = 0;
 }
 
-void detected_drone_flood(struct chanset_t* chan, memberlist* m, flood_reason_t reason) {
+void lockdown_chan(struct chanset_t* chan, flood_reason_t reason) {
   egg_timeval_t howlong;
 
   chan->channel.drone_set_mode = 0;
@@ -188,6 +188,8 @@ void detected_drone_flood(struct chanset_t* chan, memberlist* m, flood_reason_t
 
     if (reason == FLOOD_DRONE) {
       putlog(LOG_MISC, "*", "Flood detected in %s! Locking for %d seconds.", chan->dname, chan->flood_lock_time);
+    } else if (reason == FLOOD_BANLIST) {
+      putlog(LOG_MISC, "*", "Banlist full in %s! Locking for %d seconds.", chan->dname, chan->flood_lock_time);
     }
   }
 }

+ 3 - 2
src/mod/irc.mod/irc.h

@@ -25,7 +25,8 @@ namespace bd {
 }
 
 enum flood_reason_t {
-  FLOOD_DRONE
+  FLOOD_DRONE,
+  FLOOD_BANLIST
 };
 
 #ifdef CACHE
@@ -94,7 +95,7 @@ static bool killmember(struct chanset_t *chan, char *nick);
 static void check_lonely_channel(struct chanset_t *chan);
 static int gotmode(char *, char *);
 void unset_im(struct chanset_t* chan);
-void detected_drone_flood(struct chanset_t* chan, memberlist*, flood_reason_t reason);
+void lockdown_chan(struct chanset_t* chan, flood_reason_t reason);
 static void send_chan_who(int queue, struct chanset_t* chan, bool chain = 0);
 #define newban(chan, mask, who)         new_mask((chan)->channel.ban, mask, who)
 #define newexempt(chan, mask, who)      new_mask((chan)->channel.exempt, mask, who)