Explorar o código

Merge branch 'flood-improvements'

* flood-improvements:
  * Remove unfinished flood control code
  * When in +f, automatically remove -D
  * Don't bother with server_send_ison() timer if not using ISON
  * Display floodbots (+f) in cmd_userlist
Bryan Drewery %!s(int64=16) %!d(string=hai) anos
pai
achega
117c0e50e1

+ 4 - 0
doc/UPDATES

@@ -1,3 +1,7 @@
+* Floodbots (+f) are now listed in cmd_userlist
+* Floodbots (+f) will automatically unDEAF themselves to they can monitor the channel for floods (namely flood-chan).
+  Note that this is done about 10 seconds after adding +f to a bot. Removing +f will set DEAF again.
+
 1.3 - http://wraith.botpack.net/milestone/1.3
 * Binary / shell / startup changes
   * Binary error messages are no longer obscure numbers or fake segfaults. (Compile with OBSCURE_ERRORS to re-enable)

+ 1 - 0
src/cmds.c

@@ -874,6 +874,7 @@ static void cmd_userlist(int idx, char *par)
   PRINT_USERS(1, BOT_CHANHUB, 0, "Chatbots");
   PRINT_USERS(1, BOT_DOVOICE, 0, "Voicebots");
   PRINT_USERS(1, BOT_DOLIMIT, 0, "Limitbots");
+  PRINT_USERS(1, BOT_FLOODBOT, 0, "Floodbots");
   tt = 0;
   PRINT_USERS(0, USER_ADMIN, 0, "Admins");
   PRINT_USERS(0, USER_OWNER, USER_ADMIN, "Owners");

+ 3 - 4
src/flags.c

@@ -513,12 +513,11 @@ dovoice(struct chanset_t *chan)
 int
 doflood(struct chanset_t *chan)
 {
-  if (!chan)
-    return 0;
-
   struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_BOT, 0, 0, 0 };
+  if (!chan)
+    fr.match |= FR_ANYWH;
 
-  get_user_flagrec(conf.bot->u, &fr, chan->dname);
+  get_user_flagrec(conf.bot->u, &fr, chan ? chan->dname : NULL);
   if (glob_doflood(fr) || chan_doflood(fr))
     return 1;
   return 0;

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

@@ -3191,8 +3191,10 @@ static int gotmsg(char *from, char *msg)
     int botmatch = 0;
     char *my_msg = NULL, *my_ptr = NULL, *fword = NULL;
 
-    if (me_op(chan) && doflood(chan) && 0)
+#ifdef unfinished
+    if (me_op(chan) && doflood(chan))
       detect_offense(m, chan, msg);
+#endif
 
     /* Check even if we're ignoring the host. (modified by Eule 17.7.99) */
     detect_chan_flood(nick, uhost, from, chan, FLOOD_PRIVMSG, NULL);

+ 2 - 0
src/mod/irc.mod/irc.c

@@ -109,6 +109,7 @@ voice_ok(memberlist *m, struct chanset_t *chan)
 #include "cmdsirc.c"
 #include "msgcmds.c"
 
+#ifdef unfinished
 static void
 detect_offense(memberlist* m, struct chanset_t *chan, char *msg)
 {
@@ -140,6 +141,7 @@ dprintf(DP_HELP, "PRIVMSG %s :cap flood.\n", chan->dname);
   }
 */
 }
+#endif
 
 void unlock_chan(struct chanset_t *chan)
 {

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

@@ -78,7 +78,7 @@ static void flush_mode(struct chanset_t *, int);
 #define resetexempts(chan)  resetmasks((chan), (chan)->channel.exempt, (chan)->exempts, global_exempts, 'e')
 #define resetinvites(chan)  resetmasks((chan), (chan)->channel.invite, (chan)->invites, global_invites, 'I')
 
-static void detect_offense(memberlist*, struct chanset_t *, char *);
+//static void detect_offense(memberlist*, struct chanset_t *, char *);
 /* static int target_priority(struct chanset_t *, memberlist *, int); */
 static bool do_op(char *, struct chanset_t *, bool, bool);
 static void request_op(struct chanset_t *);

+ 32 - 10
src/mod/server.mod/server.c

@@ -98,6 +98,7 @@ static bool use_penalties = 0;
 static int use_fastdeq;
 size_t nick_len = 9;			/* Maximal nick length allowed on the network. */
 char deaf_char = 0;
+bool deaf_set = 0;
 char callerid_char = 0;
 
 static bool double_mode = 0;		/* allow a msgs to be twice in a queue? */
@@ -990,18 +991,39 @@ static void server_secondly()
   if (!resolvserv && serv < 0 && !trying_server)
     connect_server();
 
-  if (!conf.bot->hub) {
-    static int ison_cnt = 0;
+  if (server_online) {
+    if (keepnick && !use_monitor) {
+      static int ison_cnt = 0;
+
+      if (ison_time == 0) //If someone sets this to 0, all hell will break loose!
+        ison_time = 10;
+      if (ison_cnt >= ison_time) {
+        server_send_ison();
+        ison_cnt = 0;
+      } else
+        ++ison_cnt;
+    }
 
-    if (ison_time == 0) //If someone sets this to 0, all hell will break loose!
-      ison_time = 10;
-    if (ison_cnt >= ison_time) {
-      server_send_ison();
-      ison_cnt = 0;
-    } else
-      ++ison_cnt;
-  }
+    if (!loading) {
+      static int cnt_10 = 0;
 
+      // Every 10 seconds
+      if (cnt_10 == 9) {
+        // Ensure that +D/+f are not conflicting
+
+        // In +D but am +f, need to -D
+        if (deaf_set && doflood(NULL)) {
+          dprintf(DP_SERVER, "MODE %s -%c\n", botname, deaf_char);
+        } else if (!deaf_set && use_deaf && deaf_char) {
+          // Not +D but should be, probably had +f removed.
+          dprintf(DP_SERVER, "MODE %s +%c\n", botname, deaf_char);
+        }
+
+        cnt_10 = 0;
+      } else
+        ++cnt_10;
+    }
+  }
 }
 
 static void server_check_lag()

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

@@ -46,7 +46,7 @@ enum {
 
 extern bind_table_t	*BT_ctcp, *BT_ctcr, *BT_msgc;
 extern size_t		nick_len;
-extern bool		trigger_on_ignore, floodless, keepnick;
+extern bool		trigger_on_ignore, floodless, keepnick, deaf_set;
 extern int 		servidx, ctcp_mode, answer_ctcp, serv, curserv, default_alines;
 extern unsigned int     rolls;
 extern port_t		default_port, newserverport, curservport;

+ 12 - 11
src/mod/server.mod/servmsg.c

@@ -314,8 +314,10 @@ got005(char *from, char *msg)
       use_354 = 1;
     else if (!strcasecmp(tmp, "DEAF")) {
       deaf_char = p ? p[0] : 'D';
-      if (use_deaf)
+      if (use_deaf) {
         dprintf(DP_SERVER, "MODE %s +%c\n", botname, deaf_char);
+        deaf_set = 1;
+      }
     } else if (!strcasecmp(tmp, "CALLERID")) {
       callerid_char = p ? p[0] : 'g';
       if (use_callerid)
@@ -790,16 +792,14 @@ static int gotwall(char *from, char *msg)
 
 void server_send_ison()
 {
-  if (server_online && keepnick && !use_monitor) {
-    // Only check if we're not on jupenick, or there is no jupenick and we're not on the preferred nick
-    bool have_jupenick = jupenick[0] ? match_my_nick(jupenick) : 0;
-    if (!have_jupenick) {
-      /* See if my nickname is in use and if if my nick is right.  */
-      if (jupenick[0] && !have_jupenick)
-        dprintf(DP_SERVER, "ISON %s %s\n", origbotname, jupenick);
-      else if (!match_my_nick(origbotname)) 
-        dprintf(DP_SERVER, "ISON %s\n", origbotname);
-    }
+  // Only check if we're not on jupenick, or there is no jupenick and we're not on the preferred nick
+  bool have_jupenick = jupenick[0] ? match_my_nick(jupenick) : 0;
+  if (!have_jupenick) {
+    /* See if my nickname is in use and if if my nick is right.  */
+    if (jupenick[0] && !have_jupenick)
+      dprintf(DP_SERVER, "ISON %s %s\n", origbotname, jupenick);
+    else if (!match_my_nick(origbotname))
+      dprintf(DP_SERVER, "ISON %s\n", origbotname);
   }
 }
 /* Called once a minute... but if we're the only one on the
@@ -1181,6 +1181,7 @@ static void disconnect_server(int idx, int dolost)
   use_penalties = 0;
   use_354 = 0;
   deaf_char = 0;
+  deaf_set = 0;
   callerid_char = 0;
   in_callerid = 0;
   use_exempts = 0;

+ 2 - 0
src/set.c

@@ -285,6 +285,8 @@ sdprintf("var (mem): %s -> %s", var->name, datain ? datain : "(NULL)");
           which = '-';
         if (which) {
           char mode_char = strcmp(var->name, "deaf") == 0 ? deaf_char : callerid_char;
+          if (mode_char == deaf_char)
+            deaf_set = num;
           dprintf(DP_SERVER, "MODE %s %c%c\n", botname, which, mode_char);
         }
       }