Selaa lähdekoodia

getin_request: Share channel key even if not opped.

Only do this if the bot doesn't already know the proper key.
Bryan Drewery 7 vuotta sitten
vanhempi
commit
ee3dd49a57
2 muutettua tiedostoa jossa 23 lisäystä ja 16 poistoa
  1. 1 0
      doc/UPDATES.md
  2. 22 16
      src/mod/irc.mod/irc.cc

+ 1 - 0
doc/UPDATES.md

@@ -1,6 +1,7 @@
 # maint
   * Clear FiSH keys when a client quits.
   * 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
   * Fix various compile warnings and spam

+ 22 - 16
src/mod/irc.mod/irc.cc

@@ -798,6 +798,27 @@ getin_request(char *botnick, char *code, char *par)
       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?
     // 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;
@@ -819,16 +840,6 @@ getin_request(char *botnick, char *code, char *par)
       return;
     }
 
-    if (chan->channel.mode & 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);
-    }
-
     if (!me_op(chan)) {
       putlog(LOG_GETIN, "*", "inreq from %s/%s for %s - I haven't got ops", botnick, nick, chan->dname);
       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;
 
     /* Check internal global bans */
@@ -1112,7 +1118,7 @@ request_in(struct chanset_t *chan)
     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());
   putlog(LOG_GETIN, "*", "Requested help to join %s", chan->dname);
 }