瀏覽代碼

Merge branch 'maint'

* maint:
  getin_request: Share channel key even if not opped.
  getin_request: No reason to share the WANTED channel key.
  getin_request: Handle some exclusions earlier
Bryan Drewery 7 年之前
父節點
當前提交
e143353d9d
共有 2 個文件被更改,包括 35 次插入28 次删除
  1. 1 0
      doc/UPDATES.md
  2. 34 28
      src/mod/irc.mod/irc.cc

+ 1 - 0
doc/UPDATES.md

@@ -11,6 +11,7 @@
 # maint
 # maint
   * Clear FiSH keys when a client quits.
   * Clear FiSH keys when a client quits.
   * Fix crash when clearing last botset entry for a bot.
   * Fix crash when clearing last botset entry for a bot.
+  * Bots now share channel key to other bots even if not opped.
 
 
 # 1.4.9
 # 1.4.9
   * Fix various compile warnings and spam
   * Fix various compile warnings and spam

+ 34 - 28
src/mod/irc.mod/irc.cc

@@ -786,6 +786,39 @@ getin_request(char *botnick, char *code, char *par)
 
 
     putlog(LOG_GETIN, "*", "opreq from %s/%s on %s - Opped", botnick, nick, chan->dname);
     putlog(LOG_GETIN, "*", "opreq from %s/%s on %s - Opped", botnick, nick, chan->dname);
   } else if (what[0] == 'i') {
   } else if (what[0] == 'i') {
+    if (mem) {
+      putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - %s is already on %s", botnick, nick, chan->dname, nick, chan->dname);
+      return;
+    }
+
+    get_user_flagrec(u, &fr, chan->dname, chan);
+
+    if (unlikely(!chk_op(fr, chan) || chan_kick(fr) || glob_kick(fr))) {
+      putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - %s doesn't have acces for chan.", botnick, nick, chan->dname, botnick);
+      return;
+    }
+
+    char uip[UHOSTLEN] = "";
+    tmp = newsplit(&par);		/* userip */
+    if (tmp[0])
+      simple_snprintf(uip, sizeof uip, "%s!%s", nick, tmp);
+
+    char chankey[128] = "";
+    tmp = newsplit(&par);		/* what the bot thinks the key is */
+    if (tmp[0])
+      simple_snprintf(chankey, sizeof(chankey), "%s", tmp);
+
+    if (chan->channel.mode & CHANKEY && chan->channel.key[0] &&
+        (!chankey[0] || strcmp(chan->channel.key, chankey))) {
+      char *key = chan->channel.key[0] ? chan->channel.key : NULL;
+      size_t siz = strlen(chan->dname) + strlen(key ? key : 0) + 6 + 1;
+      tmp = (char *) calloc(1, siz);
+      simple_snprintf(tmp, siz, "gi K %s %s", chan->dname, key ? key : "");
+      putbot(botnick, tmp);
+      putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - Sent key (%s)", botnick, nick, chan->dname, key ? key : "");
+      free(tmp);
+    }
+
     // Should I respond to this request?
     // 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.
     // 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;
     int eligible_bots = 0;
@@ -807,28 +840,6 @@ getin_request(char *botnick, char *code, char *par)
       return;
       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;
-    }
-
-    get_user_flagrec(u, &fr, chan->dname, chan);
-
-    if (unlikely(!chk_op(fr, chan) || chan_kick(fr) || glob_kick(fr))) {
-      putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - %s doesn't have acces for chan.", botnick, nick, chan->dname, botnick);
-      return;
-    }
-
-    if (chan->channel.mode & CHANKEY) {
-      char *key = chan->channel.key[0] ? chan->channel.key : chan->key_prot;
-      size_t siz = strlen(chan->dname) + strlen(key ? key : 0) + 6 + 1;
-      tmp = (char *) calloc(1, siz);
-      simple_snprintf(tmp, siz, "gi K %s %s", chan->dname, key ? key : "");
-      putbot(botnick, tmp);
-      putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - Sent key (%s)", botnick, nick, chan->dname, key ? key : "");
-      free(tmp);
-    }
-
     if (!me_op(chan)) {
     if (!me_op(chan)) {
       putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - I haven't got ops", botnick, nick, chan->dname);
       putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - I haven't got ops", botnick, nick, chan->dname);
       return;
       return;
@@ -843,11 +854,6 @@ getin_request(char *botnick, char *code, char *par)
       }
       }
     }
     }
 
 
-    char uip[UHOSTLEN] = "";
-    tmp = newsplit(&par);		/* userip */
-    if (tmp[0])
-      simple_snprintf(uip, sizeof uip, "%s!%s", nick, tmp);
-
     struct maskrec **mr = NULL, *tmr = NULL;
     struct maskrec **mr = NULL, *tmr = NULL;
 
 
     /* Check internal global bans */
     /* Check internal global bans */
@@ -1112,7 +1118,7 @@ request_in(struct chanset_t *chan)
     return;
     return;
   }
   }
 
 
-  bd::String request(bd::String::printf("gi i %s %s %s!%s %s", chan->dname, botname, botname, botuserhost, botuserip));
+  bd::String request(bd::String::printf("gi i %s %s %s!%s %s %s", chan->dname, botname, botname, botuserhost, botuserip, chan->channel.key[0] ? chan->channel.key : ""));
   putallbots(request.c_str());
   putallbots(request.c_str());
   putlog(LOG_GETIN, "*", "Requested help to join %s", chan->dname);
   putlog(LOG_GETIN, "*", "Requested help to join %s", chan->dname);
 }
 }