Prechádzať zdrojové kódy

* Implement +protect

Bryan Drewery 16 rokov pred
rodič
commit
edf5eeae17

+ 4 - 0
src/mod/irc.mod/chan.c

@@ -704,6 +704,8 @@ static bool detect_chan_flood(char *floodnick, char *floodhost, char *from,
         dprintf(DP_MODE, "KICK %s %s :%s%s\n", chan->name, floodnick, kickprefix, response(RES_KICKFLOOD));
 	m->flags |= SENTKICK;
       }
+      if (channel_protect(chan))
+        do_protect(chan, "Mass Kick");
     return 1;
     case FLOOD_DEOP:
       if (me_op(chan) && !chan_sentkick(m)) {
@@ -718,6 +720,8 @@ static bool detect_chan_flood(char *floodnick, char *floodhost, char *from,
         simple_snprintf(s, sizeof(s), "Mass deop on %s by %s", chan->dname, from);
         deflag_user(u, DEFLAG_MDOP, s, chan);
       }
+      if (channel_protect(chan))
+        do_protect(chan, "Mass Deop");
       return 1;
     }
   }

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

@@ -1436,6 +1436,15 @@ check_servers(struct chanset_t *chan)
   }
 }
 
+static void do_protect(struct chanset_t* chan, const char* reason) {
+  // Don't bother with these if already botbitch, already processed it, or it's a hacked bot and +botbitch won't help.
+  if (!channel_botbitch(chan)) {
+    putlog(LOG_MISC, "*", "%s detected in %s: Setting +botbitch/+backup to protect the channel.", reason, chan->dname);
+    do_chanset(NULL, chan, "+botbitch +bitch +backup", DO_LOCAL | DO_NET);
+    enforce_bitch(chan);
+  }
+}
+
 static void
 check_netfight(struct chanset_t *chan)
 {

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

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

+ 21 - 13
src/mod/irc.mod/mode.c

@@ -1085,20 +1085,24 @@ gotmode(char *from, char *msg)
         char tmp[1024] = "";
 
         if (role && u && !u->bot) {
-          if (m && !chan_sentkick(m) && deops >= 3 && chan->mdop) {
-            if (role < 5) {
-              m->flags |= SENTKICK;
-              const size_t len = simple_snprintf(tmp, sizeof(tmp), "KICK %s %s :%s%s\r\n", chan->name, m->nick, kickprefix, response(RES_MASSDEOP));
-              if (role <= 2)
-                tputs(serv, tmp, len);
-              else
-                dprintf(DP_SERVER, "%s", tmp);
-            } else {
-              if (u) {
-                simple_snprintf(tmp, sizeof(tmp), "Mass deop on %s by %s", chan->dname, m->nick);
-                deflag_user(u, DEFLAG_MDOP, tmp, chan);
+          if (m && deops >= 3) {
+            if (chan->mdop) {
+              if (role < 5 && !chan_sentkick(m)) {
+                m->flags |= SENTKICK;
+                const size_t len = simple_snprintf(tmp, sizeof(tmp), "KICK %s %s :%s%s\r\n", chan->name, m->nick, kickprefix, response(RES_MASSDEOP));
+                if (role <= 2)
+                  tputs(serv, tmp, len);
+                else
+                  dprintf(DP_SERVER, "%s", tmp);
+              } else {
+                if (u) {
+                  simple_snprintf(tmp, sizeof(tmp), "Mass deop on %s by %s", chan->dname, m->nick);
+                  deflag_user(u, DEFLAG_MDOP, tmp, chan);
+                }
               }
             }
+            if (channel_protect(chan))
+              do_protect(chan, "Mass Deop");
           }
 
           /* check for mop */
@@ -1119,8 +1123,12 @@ gotmode(char *from, char *msg)
                   }
                 }
               }
-              enforce_bitch(chan);        /* deop quick! */
+              // Don't mass deop if protect is set, it'll happen anyway below
+              if (!channel_protect(chan))
+                enforce_bitch(chan);        /* deop quick! */
             }
+            if (channel_protect(chan))
+              do_protect(chan, "Mass OP");
           }
         }
         if (ops) {