Selaa lähdekoodia

Move 'in-bots' logic to getin_request() (#35)

This will give the bot a $in_bots/$opped_bots chance of responding to
the request for invite. This cuts down the bandwidth as bots no longer
need to brute force ask their way into a channel. They can just
broadcast the request and eligible bots will respond.
Bryan Drewery 14 vuotta sitten
vanhempi
commit
ba08582c1e
2 muutettua tiedostoa jossa 22 lisäystä ja 2 poistoa
  1. 1 0
      doc/UPDATES
  2. 21 2
      src/mod/irc.mod/irc.c

+ 1 - 0
doc/UPDATES

@@ -1,5 +1,6 @@
 * Bots now auto-reop other bots that get deopped
 * Bots now ask for ops quicker if another bot is opped
+* Bots now request/join +ilk channels much quicker
 
 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.

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

@@ -598,8 +598,6 @@ getin_request(char *botnick, char *code, char *par)
 
   if (what[0] != 'K') {
     if (!(channel_pending(chan) || channel_active(chan))) {
-      putlog(LOG_GETIN, "*", "%sreq from %s/%s %s %s - I'm not on %s right now.", type, botnick, nick, desc, 
-                             chan->dname, chan->dname);
       return;
     }
   }
@@ -722,6 +720,27 @@ getin_request(char *botnick, char *code, char *par)
       return;
     }
 
+    // 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;
+    for (memberlist* m = chan->channel.member; m && m->nick[0]; m = m->next) {
+      if (chan_hasop(m)) {
+        member_getuser(m, 0);
+        if (m->user && m->user->bot) {
+          ++eligible_bots;
+        }
+      }
+    }
+
+    if (!eligible_bots) {
+      return;
+    }
+
+    if (!((randint(eligible_bots) + 1) <= in_bots)) {
+      // Not my turn
+      return;
+    }
+
     bool sendi = 0;
 
     if (chan->channel.maxmembers) {