Prechádzať zdrojové kódy

Merge branch '35-speedup-request' into next

* 35-speedup-request:
  Move 'in-bots' logic to getin_request() (#35)
  Request help to join from all bots (#35)
  Update functions to accept consts
  Remove unneeded revenge code

Conflicts:
	doc/UPDATES
Bryan Drewery 14 rokov pred
rodič
commit
d73a9c20b6
7 zmenil súbory, kde vykonal 52 pridanie a 42 odobranie
  1. 1 0
      doc/UPDATES
  2. 1 1
      src/botmsg.c
  3. 1 1
      src/botmsg.h
  4. 9 9
      src/flags.c
  5. 9 9
      src/flags.h
  6. 29 22
      src/mod/irc.mod/irc.c
  7. 2 0
      src/mod/irc.mod/mode.c

+ 1 - 0
doc/UPDATES

@@ -5,6 +5,7 @@ next
   * Add chanset 'closed-exempt' which will allow exempting non-users (who are opped or voice) from being kicked. (fixes #171)
   * Add chanset 'closed-exempt' which will allow exempting non-users (who are opped or voice) from being kicked. (fixes #171)
   * Bots now auto-reop other bots that get deopped
   * Bots now auto-reop other bots that get deopped
   * Bots now ask for ops quicker if another bot is opped
   * 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
 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.
   * Updated server list, 'set -yes servers -' and 'set -yes servers6 -' to get new list.

+ 1 - 1
src/botmsg.c

@@ -299,7 +299,7 @@ void putallbots(const char *par)
   return;
   return;
 }
 }
 
 
-void putbot(const char *bot, char *par)
+void putbot(const char *bot, const char *par)
 {
 {
   if (!bot || !par || !bot[0] || !par[0])
   if (!bot || !par || !bot[0] || !par[0])
     return;
     return;

+ 1 - 1
src/botmsg.h

@@ -10,7 +10,7 @@
 
 
 void botnet_send_var(int idx, variable_t *);
 void botnet_send_var(int idx, variable_t *);
 void botnet_send_var_broad(int idx, variable_t *);
 void botnet_send_var_broad(int idx, variable_t *);
-void putbot(const char *, char *);
+void putbot(const char *, const char *);
 void putallbots(const char *);
 void putallbots(const char *);
 int add_note(char *, char *, char *, int, int);
 int add_note(char *, char *, char *, int, int);
 
 

+ 9 - 9
src/flags.c

@@ -380,7 +380,7 @@ set_user_flagrec(struct userrec *u, struct flag_record *fr, const char *chname)
 /* Always pass the dname (display name) to this function for chname <cybah>
 /* Always pass the dname (display name) to this function for chname <cybah>
  */
  */
 void
 void
-get_user_flagrec(struct userrec *u, struct flag_record *fr, const char *chname, const struct chanset_t* chan)
+get_user_flagrec(const struct userrec *u, struct flag_record *fr, const char *chname, const struct chanset_t* chan)
 {
 {
   fr->bot = 0;
   fr->bot = 0;
   if (!u) {
   if (!u) {
@@ -427,7 +427,7 @@ get_user_flagrec(struct userrec *u, struct flag_record *fr, const char *chname,
  * restricted by +private for the channel
  * restricted by +private for the channel
  */
  */
 int
 int
-privchan(struct flag_record fr, struct chanset_t *chan, int type)
+privchan(const struct flag_record fr, const struct chanset_t *chan, int type)
 {
 {
   if (!chan || !channel_privchan(chan) || glob_bot(fr) || glob_owner(fr))
   if (!chan || !channel_privchan(chan) || glob_bot(fr) || glob_owner(fr))
     return 0;                   /* user is implicitly not restricted by +private, they may however be lacking other flags */
     return 0;                   /* user is implicitly not restricted by +private, they may however be lacking other flags */
@@ -444,7 +444,7 @@ privchan(struct flag_record fr, struct chanset_t *chan, int type)
 }
 }
 
 
 int
 int
-real_chk_op(struct flag_record fr, struct chanset_t *chan, bool botbitch)
+real_chk_op(const struct flag_record fr, const struct chanset_t *chan, bool botbitch)
 {
 {
   if (!chan && glob_op(fr))
   if (!chan && glob_op(fr))
     return 1;
     return 1;
@@ -459,7 +459,7 @@ real_chk_op(struct flag_record fr, struct chanset_t *chan, bool botbitch)
 }
 }
 
 
 int
 int
-chk_autoop(struct flag_record fr, struct chanset_t *chan)
+chk_autoop(const struct flag_record fr, const struct chanset_t *chan)
 {
 {
   if (glob_bot(fr))
   if (glob_bot(fr))
     return 0;
     return 0;
@@ -471,7 +471,7 @@ chk_autoop(struct flag_record fr, struct chanset_t *chan)
 }
 }
 
 
 int
 int
-real_chk_deop(struct flag_record fr, struct chanset_t *chan, bool botbitch)
+real_chk_deop(const struct flag_record fr, const struct chanset_t *chan, bool botbitch)
 {
 {
   if (chan && botbitch && channel_botbitch(chan) && !glob_bot(fr))
   if (chan && botbitch && channel_botbitch(chan) && !glob_bot(fr))
     return 1;
     return 1;
@@ -483,7 +483,7 @@ real_chk_deop(struct flag_record fr, struct chanset_t *chan, bool botbitch)
 }
 }
 
 
 int
 int
-doresolv(struct chanset_t *chan)
+doresolv(const struct chanset_t *chan)
 {
 {
   if (!chan)
   if (!chan)
     return 0;
     return 0;
@@ -497,7 +497,7 @@ doresolv(struct chanset_t *chan)
 }
 }
 
 
 int
 int
-dovoice(struct chanset_t *chan)
+dovoice(const struct chanset_t *chan)
 {
 {
   if (!chan)
   if (!chan)
     return 0;
     return 0;
@@ -511,7 +511,7 @@ dovoice(struct chanset_t *chan)
 }
 }
 
 
 int
 int
-doflood(struct chanset_t *chan)
+doflood(const struct chanset_t *chan)
 {
 {
   struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_BOT, 0, 0, 0 };
   struct flag_record fr = { FR_GLOBAL | FR_CHAN | FR_BOT, 0, 0, 0 };
   if (!chan)
   if (!chan)
@@ -524,7 +524,7 @@ doflood(struct chanset_t *chan)
 }
 }
 
 
 int
 int
-dolimit(struct chanset_t *chan)
+dolimit(const struct chanset_t *chan)
 {
 {
   if (!chan)
   if (!chan)
     return 0;
     return 0;

+ 9 - 9
src/flags.h

@@ -142,7 +142,7 @@ struct flag_record {
 #define chan_doflood(x)				((x).chan & BOT_FLOODBOT)
 #define chan_doflood(x)				((x).chan & BOT_FLOODBOT)
 
 
 void init_flags(void);
 void init_flags(void);
-void get_user_flagrec(struct userrec *, struct flag_record *, const char *, const struct chanset_t* = NULL);
+void get_user_flagrec(const struct userrec *, struct flag_record *, const char *, const struct chanset_t* = NULL);
 void set_user_flagrec(struct userrec *, struct flag_record *, const char *);
 void set_user_flagrec(struct userrec *, struct flag_record *, const char *);
 void break_down_flags(const char *, struct flag_record *, struct flag_record *);
 void break_down_flags(const char *, struct flag_record *, struct flag_record *);
 int build_flags(char *, struct flag_record *, struct flag_record *);
 int build_flags(char *, struct flag_record *, struct flag_record *);
@@ -151,12 +151,12 @@ int flagrec_ok(struct flag_record *, struct flag_record *);
 flag_t sanity_check(flag_t, int);
 flag_t sanity_check(flag_t, int);
 flag_t chan_sanity_check(flag_t, int);
 flag_t chan_sanity_check(flag_t, int);
 char geticon(int);
 char geticon(int);
-int privchan(struct flag_record, struct chanset_t *, int);
+int privchan(const struct flag_record, const struct chanset_t *, int);
 #define chk_op(fr, chan) real_chk_op(fr, chan, 1)
 #define chk_op(fr, chan) real_chk_op(fr, chan, 1)
-int real_chk_op(struct flag_record, struct chanset_t *, bool);
-int chk_autoop(struct flag_record, struct chanset_t *);
+int real_chk_op(const struct flag_record, const struct chanset_t *, bool);
+int chk_autoop(const struct flag_record, const struct chanset_t *);
 #define chk_deop(fr, chan) real_chk_deop(fr, chan, 1)
 #define chk_deop(fr, chan) real_chk_deop(fr, chan, 1)
-int real_chk_deop(struct flag_record, struct chanset_t *, bool);
+int real_chk_deop(const struct flag_record, const struct chanset_t *, bool);
 #define chk_voice(fr, chan) (\
 #define chk_voice(fr, chan) (\
     (\
     (\
      (!chan || (!privchan(fr, chan, PRIV_VOICE) && !chk_devoice(fr))) \
      (!chan || (!privchan(fr, chan, PRIV_VOICE) && !chk_devoice(fr))) \
@@ -166,10 +166,10 @@ int real_chk_deop(struct flag_record, struct chanset_t *, bool);
 #define chk_devoice(fr) ((chan_quiet(fr) || (glob_quiet(fr) && !chan_voice(fr))) ? 1 : 0)
 #define chk_devoice(fr) ((chan_quiet(fr) || (glob_quiet(fr) && !chan_voice(fr))) ? 1 : 0)
 #define isupdatehub() ((conf.bot->hub && conf.bot->u && (conf.bot->u->flags & BOT_UPDATEHUB)) ? 1 : 0)
 #define isupdatehub() ((conf.bot->hub && conf.bot->u && (conf.bot->u->flags & BOT_UPDATEHUB)) ? 1 : 0)
 #define ischanhub() ((!conf.bot->hub && conf.bot->u && (conf.bot->u->flags & BOT_CHANHUB)) ? 1 : 0)
 #define ischanhub() ((!conf.bot->hub && conf.bot->u && (conf.bot->u->flags & BOT_CHANHUB)) ? 1 : 0)
-int doresolv(struct chanset_t *);
-int dovoice(struct chanset_t *);
-int doflood(struct chanset_t *);
-int dolimit(struct chanset_t *);
+int doresolv(const struct chanset_t *);
+int dovoice(const struct chanset_t *);
+int doflood(const struct chanset_t *);
+int dolimit(const struct chanset_t *);
 int whois_access(struct userrec *, struct userrec *);
 int whois_access(struct userrec *, struct userrec *);
 void deflag_user(struct userrec *, int, char *, struct chanset_t *);
 void deflag_user(struct userrec *, int, char *, struct chanset_t *);
 int deflag_translate(const char *);
 int deflag_translate(const char *);

+ 29 - 22
src/mod/irc.mod/irc.c

@@ -598,8 +598,6 @@ getin_request(char *botnick, char *code, char *par)
 
 
   if (what[0] != 'K') {
   if (what[0] != 'K') {
     if (!(channel_pending(chan) || channel_active(chan))) {
     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;
       return;
     }
     }
   }
   }
@@ -722,6 +720,27 @@ getin_request(char *botnick, char *code, char *par)
       return;
       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;
     bool sendi = 0;
 
 
     if (chan->channel.maxmembers) {
     if (chan->channel.maxmembers) {
@@ -987,15 +1006,17 @@ request_in(struct chanset_t *chan)
   }
   }
 
 
   int foundBots = 0;
   int foundBots = 0;
-  char* botops[MAX_BOTS];
+//  char* botops[MAX_BOTS];
 
 
   for (tand_t* bot = tandbot; bot && (foundBots < MAX_BOTS); bot = bot->next) {
   for (tand_t* bot = tandbot; bot && (foundBots < MAX_BOTS); bot = bot->next) {
     if (bot->hub || !bot->u)
     if (bot->hub || !bot->u)
       continue;
       continue;
 
 
     get_user_flagrec(bot->u, &fr, chan->dname, chan);
     get_user_flagrec(bot->u, &fr, chan->dname, chan);
-    if (bot_shouldjoin(bot->u, &fr, chan) && chk_op(fr, chan))
-      botops[foundBots++] = bot->bot;
+    if (bot_shouldjoin(bot->u, &fr, chan) && chk_op(fr, chan)) {
+      ++foundBots;
+//      botops[foundBots++] = bot->bot;
+    }
   }
   }
 
 
   if (!foundBots) {
   if (!foundBots) {
@@ -1003,23 +1024,9 @@ request_in(struct chanset_t *chan)
     return;
     return;
   }
   }
 
 
-  int cnt = foundBots < in_bots ? foundBots : in_bots;
-  char s[255] = "";
-  char l[1024] = "";
-  size_t len = 0;
-
-  simple_snprintf(s, sizeof(s), "gi i %s %s %s!%s %s", chan->dname, botname, botname, botuserhost, botuserip);
-
-  shuffleArray(botops, foundBots);
-  for (int n = 0; n < cnt; ++n) {
-    putbot(botops[n], s);
-
-    if (l[0])
-      len += strlcpy(l + len, ", ", sizeof(l) - len);
-    len += strlcpy(l + len, botops[n], sizeof(l) - len);
-  }
-  l[len] = 0;
-  putlog(LOG_GETIN, "*", "Requested help to join %s from %s", chan->dname, l);
+  bd::String request(bd::String::printf("gi i %s %s %s!%s %s", chan->dname, botname, botname, botuserhost, botuserip));
+  putallbots(request.c_str());
+  putlog(LOG_GETIN, "*", "Requested help to join %s", chan->dname);
 }
 }
 
 
 
 

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

@@ -720,12 +720,14 @@ got_deop(struct chanset_t *chan, memberlist *m, memberlist *mv, char *isserver)
     if (!m)
     if (!m)
       putlog(LOG_MODES, chan->dname, "TS resync deopped me on %s :(", chan->dname);
       putlog(LOG_MODES, chan->dname, "TS resync deopped me on %s :(", chan->dname);
   }
   }
+#ifdef revenge
   if (m) {
   if (m) {
     char s[UHOSTLEN] = "";
     char s[UHOSTLEN] = "";
 
 
     simple_snprintf(s, sizeof(s), "%s!%s", mv->nick, mv->userhost);
     simple_snprintf(s, sizeof(s), "%s!%s", mv->nick, mv->userhost);
 //    maybe_revenge(chan, s1, s, REVENGE_DEOP);
 //    maybe_revenge(chan, s1, s, REVENGE_DEOP);
   }
   }
+#endif
 }
 }
 
 
 static void
 static void