Просмотр исходного кода

* Port [3284] [3285] to 1.2.14
* Add ghost-inspired feature: backup bots. Bots marked +B will only join channels marked +backup.
* Check if bot needs to PART channels occasionaly


svn: 3286

Bryan Drewery 19 лет назад
Родитель
Сommit
6861889b6f

+ 1 - 0
doc/UPDATES

@@ -25,6 +25,7 @@ Lines prefixed with '-' were disabled before release and are not finished, or ar
 * Fix cmd_checkchannels not taking slowjoin into account.
 * Fix cmd_swhois returning results after a server jump.
 * Fix bots not connecting to their uplink.
+* Add ghost-inspired feature: backup bots. Bots marked +B will only join channels marked +backup.
 
 1.2.13 - http://wraith.shatow.net/milestone/1.2.13
 * Fix cmd_chanset accepting invalid flags

+ 2 - 0
misc/help.txt

@@ -404,6 +404,7 @@ See also: link
      The following can be set + or - (e.g. .chanset #channel -enforcebans)
         $bautoop$b         Bots that are +y will auto-op all users with 
                        op access to the channel.
+        $bbackup$b         Make backup-bots (+B) join when set.
         $bbitch$b          Only let users with the +o flag have op on the
                        channel?
         $bbotbitch$b       Only let $bbots$b with the +o flag have op on the
@@ -1819,6 +1820,7 @@ See also: whom
       $bx$b = flood-exempt (user is exempt from flood kicks)
  
    Valid bot-only flags:
+      $bB$b = backup-bot (bot will only join chans marked +backup, see '%dhelp chaninfo')
       $bc$b = chat-bot (bot accepts DCC chat on irc)
       $bl$b = limit-bot (bot sets limit in all channels, see '%dhelp chaninfo') [$bCPU INTENSIVE$b]
       $br$b = resolve (bot resolves clients in to match against userlist) [$bCPU INTENSIVE+$b]

+ 2 - 1
src/chan.h

@@ -216,7 +216,7 @@ struct chanset_t {
 #define CHAN_TAKE 	    BIT5	/* When a bot gets opped, take the chan */
 #define CHAN_PROTECTOPS     BIT6	/* re-op any +o people who get deop'd */
 #define CHAN_BOTBITCH       BIT7        /* only let bots be opped? */
-#undef  CHAN_8              /*BIT8	 */
+#define CHAN_BACKUP         BIT8	/* Join the BOT_BACKUP bots when set */
 #define CHAN_SECRET         BIT9	/* don't advertise channel on botnet  */
 #undef  CHAN_10		    /* BIT10        not used */
 #define CHAN_CYCLE          BIT11	/* cycle the channel if possible      */
@@ -255,6 +255,7 @@ struct chanset_t *findchan_by_dname(const char *name);
 #define channel_active(chan)  (chan->status & CHAN_ACTIVE)
 #define channel_joining(chan) (chan->status & CHAN_JOINING)
 #define channel_pending(chan)  (chan->status & CHAN_PEND)
+#define channel_backup(chan) (chan->status & CHAN_BACKUP)
 #define channel_bitch(chan) (chan->status & CHAN_BITCH)
 #define chan_bitch(chan) (chan->status & (CHAN_BITCH|CHAN_BOTBITCH))
 #define channel_botbitch(chan) (chan->status & CHAN_BOTBITCH)

+ 5 - 8
src/chanprog.c

@@ -744,20 +744,17 @@ int shouldjoin(struct chanset_t *chan)
     return 1;
   else if (!strncmp(conf.bot->nick, "wtest", 4)) /* use 5 for all */
     return 0; 
-#ifdef G_BACKUP
-  struct flag_record fr = { FR_CHAN | FR_GLOBAL, 0, 0, 0 };
-  struct userrec *u = NULL;
- 
+
   if (!chan || !chan->dname || !chan->dname[0])
     return 0;
 
+  struct flag_record fr = { FR_CHAN|FR_GLOBAL|FR_BOT, 0, 0, 0 };
+  struct userrec *u = NULL;
+
   if ((u = get_user_by_handle(userlist, conf.bot->nick)))
     get_user_flagrec(u, &fr, chan->dname);
 
-  return (!channel_inactive(chan) && (channel_backup(chan) || !glob_backupbot(fr)));
-#else /* !G_BACKUP */
-  return !channel_inactive(chan);
-#endif /* G_BACKUP */
+  return (!channel_inactive(chan) && (channel_backup(chan) || (!glob_backup(fr) && !chan_backup(fr))));
 }
 
 /* do_chanset() set (options) on (chan)

+ 4 - 1
src/flags.h

@@ -83,13 +83,14 @@ struct flag_record {
 #define USER_CHAN_VALID (flag_t) CHAN_VALID|USER_AUTOOP|USER_MASTER|USER_OWNER
 #define USER_VALID (flag_t) USER_ADMIN|USER_HUBA|USER_CHUBA|USER_PARTY|USER_CHAN_VALID
 
+#define BOT_BACKUP	FLAG[(int) 'B']
 #define BOT_CHANHUB	FLAG[(int) 'c']
 #define BOT_UPDATEHUB	FLAG[(int) 'u']
 #define BOT_DORESOLV	FLAG[(int) 'r']
 #define BOT_DOLIMIT	FLAG[(int) 'l']
 #define BOT_DOVOICE	FLAG[(int) 'y']
 
-#define BOT_CHAN_VALID (flag_t) CHAN_VALID|BOT_CHANHUB|BOT_DOLIMIT|BOT_DOVOICE|BOT_DORESOLV
+#define BOT_CHAN_VALID (flag_t) CHAN_VALID|BOT_CHANHUB|BOT_DOLIMIT|BOT_DOVOICE|BOT_DORESOLV|BOT_BACKUP
 #define BOT_VALID  (flag_t) BOT_CHAN_VALID|BOT_UPDATEHUB
 
 
@@ -134,6 +135,8 @@ struct flag_record {
 #define glob_chanhub(x)                        ((x).global & BOT_CHANHUB)
 #define glob_doresolv(x)                        ((x).global & BOT_DORESOLV)
 #define chan_doresolv(x)                        ((x).chan & BOT_DORESOLV)
+#define glob_backup(x)				((x).global & BOT_BACKUP)
+#define chan_backup(x)				((x).chan & BOT_BACKUP)
 
 void init_flags(void);
 void get_user_flagrec(struct userrec *, struct flag_record *, const char *);

+ 2 - 0
src/mod/channels.mod/channels.c

@@ -869,6 +869,8 @@ void channels_report(int idx, int details)
 */
         if (channel_botbitch(chan))
           i += my_strcpy(s + i, "botbitch ");
+        if (channel_backup(chan))
+          i += my_strcpy(s + i, "backup ");
         if (channel_fastop(chan))
           i += my_strcpy(s + i, "fastop ");
         if (channel_privchan(chan))

+ 1 - 0
src/mod/channels.mod/cmdschan.c

@@ -1200,6 +1200,7 @@ static void cmd_chaninfo(int idx, char *par)
     dprintf(idx, "Channel flags:\n");
     work[0] = 0;
     SHOW_FLAG("autoop",		channel_autoop(chan));
+    SHOW_FLAG("backup",		channel_backup(chan));
     SHOW_FLAG("bitch",		channel_bitch(chan));
     SHOW_FLAG("botbitch",       channel_botbitch(chan));
     SHOW_FLAG("closed",		channel_closed(chan));

+ 7 - 5
src/mod/channels.mod/tclchan.c

@@ -563,16 +563,18 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
  *  else if (!strcmp(item[i], "-temp"))
  *    chan->status &= ~CHAN_TEMP;
  */
-    else if (!strcmp(item[i], "+fastop")) {
+    else if (!strcmp(item[i], "+fastop"))
       chan->status |= CHAN_FASTOP;
-    }
     else if (!strcmp(item[i], "-fastop"))
       chan->status &= ~(CHAN_FASTOP | CHAN_PROTECTOPS);
-    else if (!strcmp(item[i], "+private")) {
+    else if (!strcmp(item[i], "+private"))
       chan->status |= CHAN_PRIVATE;
-    }
     else if (!strcmp(item[i], "-private"))
       chan->status &= ~CHAN_PRIVATE;
+    else if (!strcmp(item[i], "+backup"))
+      chan->status |= CHAN_BACKUP;
+    else if (!strcmp(item[i], "-backup"))
+      chan->status &= ~CHAN_BACKUP;
 
     /* ignore wasoptest, stopnethack and clearbans in chanfile, remove
        this later */
@@ -701,7 +703,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
     chan->status |= CHAN_FASTOP;		// to avoid bots still mass opping from +take from not using cookies
 
   if (!conf.bot->hub) {
-    if ((old_status ^ chan->status) & CHAN_INACTIVE) {
+    if ((old_status ^ chan->status) & (CHAN_INACTIVE | CHAN_BACKUP)) {
       if (!shouldjoin(chan) && (chan->status & (CHAN_ACTIVE | CHAN_PEND)))
         dprintf(DP_SERVER, "PART %s\n", chan->name);
       if (shouldjoin(chan) && !(chan->status & (CHAN_ACTIVE | CHAN_PEND | CHAN_JOINING))) {

+ 2 - 1
src/mod/channels.mod/userchan.c

@@ -735,7 +735,7 @@ exempt-time %lu invite-time %lu voice-non-ident %d \
 %cenforcebans %cdynamicbans %cuserban %cbitch %cprotectops \
 %cprivate %ccycle %cinactive %cdynamicexempts %cuserexempts \
 %cdynamicinvites %cuserinvites %cnodesynch %cclosed %cvoice \
-%cfastop %cautoop %cbotbitch %c%s}\n",
+%cfastop %cautoop %cbotbitch %cbackup %c%s}\n",
 	chan->dname,
 	w,
         chan->added_by,
@@ -785,6 +785,7 @@ exempt-time %lu invite-time %lu voice-non-ident %d \
 	PLSMNS(channel_fastop(chan)),
         PLSMNS(channel_autoop(chan)),
         PLSMNS(channel_botbitch(chan)),
+        PLSMNS(channel_backup(chan)),
 	HAVE_TAKE ? PLSMNS(channel_take(chan)) : 0,
         HAVE_TAKE ? "take " : " "
 /* Chanflag template

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

@@ -2568,10 +2568,8 @@ static int gotpart(char *from, char *msg)
   chan = findchan(chname);
   u = get_user_by_host(from);
   nick = splitnick(&from);
-  if (chan && !shouldjoin(chan)) {
-  /* shouldnt this check for match_my_nick? */
-    if (match_my_nick(nick)) 
-      irc_log(chan, "Parting");    
+  if (chan && !shouldjoin(chan) && match_my_nick(nick)) {
+    irc_log(chan, "Parting");    
     clear_channel(chan, 1);
     chan->status &= ~(CHAN_ACTIVE | CHAN_PEND | CHAN_JOINING);
     return 0;

+ 3 - 1
src/mod/irc.mod/irc.c

@@ -1279,7 +1279,9 @@ raise_limit(struct chanset_t *chan)
 static void
 check_expired_chanstuff(struct chanset_t *chan)
 {
-  if (channel_active(chan)) {
+  if ((channel_active(chan) || channel_pending(chan)) && !shouldjoin(chan)) {
+    dprintf(DP_MODE, "PART %s\n", chan->name[0] ? chan->name : chan->dname);
+  } else if (channel_active(chan)) {
     masklist *b = NULL, *e = NULL;
     memberlist *m = NULL, *n = NULL;
     char s[UHOSTLEN] = "";