Explorar o código

Merge branch '21-botgroups' into next

* 21-botgroups:
  * Optimize channel groups by storing as an array in memory
  * Handle accidental commas in list
  * Default channel groups to 'main'
  * Add chanset 'groups'
  * Only join if the bot's group matches
  * Add 'groups' set var

Conflicts:
	doc/UPDATES
	doc/help.txt
Bryan Drewery %!s(int64=14) %!d(string=hai) anos
pai
achega
e60d459fa2

+ 2 - 0
doc/UPDATES

@@ -5,6 +5,8 @@ next
   * Hubs can now be overridden inside the botconfig (-C)
   * Optimize userfile writing by doing it asynchronously
   * Fix bot getting confusd when changing to long nicks
+  * Add [bot]set var 'groups' to configure what groups bots are in
+  * Add chanset 'groups' to take a list of groups that should join. 'chanset #chan groups { main backup }'
 
 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.

+ 7 - 3
doc/help.txt

@@ -359,8 +359,12 @@ See also: link%{+a}, newhub%{-}
 ###  $bchaninfo$b <channel>
    This lists all the settings for the bot on the given channel.
    It shows any of the following:
-        $bchanmode$b   These modes are enforced on the channel. Both + and -
-                   modes can be enforced.
+        $bchanmode$b         These modes are enforced on the channel.
+                          Both + and - modes can be enforced. Use {} to
+                          add a key. '%dchanset #chan chanmode { +nt key }'
+        $bgroups$b            List of groups that should join the channel.
+                          Use {} to add multiple groups. See also '%dhelp set'
+                          '%dchanset #chan groups { main alt }'
 %{+m|m}
         $bauto-delay$b        Amount of seconds to wait before auto opping,
                               or auto voicing a client based on flags or
@@ -1672,7 +1676,7 @@ See also: reload, backup
 [N]  $bmsgburst$b        How many messages to burst at once to server. (Too high will excess flood)
 [N]  $bmsgrate$b         How often (msecs) to dequeue msgs to the server. Only used on
                            non-ratbox servers. Too small a value can result in Excess Flood.
- 
+[L]  $bgroups$b          List of groups that the affected bots are a part of.
 [L]  $brbl-servers$b     Servers to use for RBL checking in channels that are +rbl.
  
 [S]  $brealname$b        The bot's "real name" when connecting. (supports '$n' expansion)

+ 4 - 0
src/chan.h

@@ -8,6 +8,9 @@
 #ifndef _EGG_CHAN_H
 #define _EGG_CHAN_H
 
+#include <lib/bdlib/src/Array.h>
+#include <lib/bdlib/src/String.h>
+
 typedef struct memstruct {
   struct memstruct *next;
   struct userrec *user;
@@ -210,6 +213,7 @@ struct chanset_t {
   char pls[21];			/* positive mode changes		*/
   char mns[21];			/* negative mode changes		*/
   char key_prot[121];		/* desired password			*/
+  bd::Array<bd::String> *groups;/* groups that should join */
 /* Chanchar template
  *char temp[121];
  */

+ 22 - 4
src/chanprog.c

@@ -54,8 +54,10 @@
 #endif
 #endif
 #include <sys/utsname.h>
+#include <bdlib/src/Array.h>
+#include <bdlib/src/String.h>
 
-char *def_chanset = "+enforcebans +dynamicbans +userbans -bitch +cycle -inactive +userexempts -dynamicexempts +userinvites -dynamicinvites -nodesynch -closed -take -voice -private -fastop +meankicks ban-type 3 protect-backup 1";
+char *def_chanset = "+enforcebans +dynamicbans +userbans -bitch +cycle -inactive +userexempts -dynamicexempts +userinvites -dynamicinvites -nodesynch -closed -take -voice -private -fastop +meankicks ban-type 3 protect-backup 1 groups { main }";
 struct chanset_t 	*chanset = NULL;	/* Channel list			*/
 struct chanset_t	*chanset_default = NULL;	/* Default channel list */
 char 			admin[121] = "";	/* Admin info			*/
@@ -824,10 +826,26 @@ bool bot_shouldjoin(struct userrec* u, struct flag_record* fr, struct chanset_t*
       return 0;
   }
 #endif
+
+  // Am I in the groups that this channel has?
+  bd::Array<bd::String> my_groupsArray(bd::String(groups).split(','));
+  bool group_match = 0;
+
+  if (chan->groups && chan->groups->length()) {
+    for (size_t i = 0; i < my_groupsArray.length(); ++i) {
+      if (chan->groups->find(my_groupsArray[i]) != chan->groups->npos) {
+        group_match = 1;
+        break;
+      }
+    }
+  }
+
   // Ignore +inactive during cmd_slowjoin to ensure that +backup bots join
-  return (!glob_kick(*fr) && !chan_kick(*fr) &&
-      ((ignore_inactive || !channel_inactive(chan)) &&
-       (channel_backup(chan) || (!glob_backup(*fr) && !chan_backup(*fr)))));
+  return (!glob_kick(*fr) && !chan_kick(*fr) && // Not being kicked
+      ((ignore_inactive || !channel_inactive(chan)) && // Not inactive
+      ((channel_backup(chan) && (glob_backup(*fr) || chan_backup(*fr))) || (!channel_backup(chan) && !glob_backup(*fr) && !chan_backup(*fr)))) && // Is +backup and I'm B|B, or is -backup and I am not B|B
+      group_match // My group should join
+      );
 }
 
 bool shouldjoin(struct chanset_t *chan)

+ 15 - 0
src/mod/channels.mod/chanmisc.c

@@ -336,6 +336,19 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
       }
       strlcpy(s, item[i], sizeof(s));
       set_mode_protect(chan, s);
+    } else if (!strcmp(item[i], "groups")) {
+      i++;
+      if (i >= items) {
+	if (result)
+	  strlcpy(result, "channel groups needs argument", RESULT_LEN);
+	return ERROR;
+      }
+      // Get string into right format
+      bd::String changroups(item[i]);
+      // Replace commas with spaces to be in proper format
+      changroups.sub(",", " ");
+      changroups.trim();
+      *(chan->groups) = changroups.split(" ");
     } else if (!strcmp(item[i], "topic")) {
       char *p = NULL;
 
@@ -995,6 +1008,8 @@ int channel_add(char *result, const char *newname, char *options, bool isdefault
 /* Chanint template
  *  chan->temp = 0;
  */
+    chan->groups = new bd::Array<bd::String>;
+    *(chan->groups) << "main";
     chan->protect_backup = 1;
     chan->knock_flags = 0;
     chan->flood_lock_time = 120;

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

@@ -723,6 +723,9 @@ void remove_channel(struct chanset_t *chan)
      free(chan->key);
    if (chan->rmkey)
      free(chan->rmkey);
+   if (chan->groups) {
+     delete(chan->groups);
+   }
    free(chan);
 }
 

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

@@ -1228,6 +1228,7 @@ static void cmd_chaninfo(int idx, char *par)
 /* FIXME: SHOW_CHAR() here */
     get_mode_protect(chan, work, sizeof(work));
     dprintf(idx, "Protect modes (chanmode): %s\n", work[0] ? work : "None");
+    dprintf(idx, "Groups: %s\n", chan->groups && chan->groups->length() ? static_cast<bd::String>(chan->groups->join(" ")).c_str() : "None");
 //    dprintf(idx, "Protect topic (topic)   : %s\n", chan->topic[0] ? chan->topic : "");
 /* Chanchar template
  *  dprintf(idx, "String temp: %s\n", chan->temp[0] ? chan->temp : "NULL");

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

@@ -717,7 +717,7 @@ bd::String channel_to_string(struct chanset_t* chan, bool force_inactive) {
 
   get_mode_protect(chan, w, sizeof(w));
   return bd::String::printf("\
-chanmode { %s } bad-cookie %d manop %d mdop %d mop %d limit %d ban-type %d \
+chanmode { %s } groups { %s } bad-cookie %d manop %d mdop %d mop %d limit %d ban-type %d \
 flood-chan %d:%d flood-ctcp %d:%d flood-join %d:%d \
 flood-kick %d:%d flood-deop %d:%d flood-nick %d:%d flood-mjoin %d:%d \
 closed-ban %d closed-invite %d closed-private %d ban-time %d \
@@ -732,6 +732,7 @@ flood-exempt %d flood-lock-time %d knock %d \
  *      temp,
  * also include temp %s in dprintf.
  */
+        chan->groups && chan->groups->length() ? static_cast<bd::String>(chan->groups->join(" ")).c_str() : "",
 	chan->bad_cookie,
 	chan->manop,
 	chan->mdop,

+ 2 - 0
src/set.c

@@ -30,6 +30,7 @@ static bool parsing_botset = 0;
 char altchars[50] = "";
 char alias[1024] = "";
 char rbl_servers[1024] = "";
+char groups[1024] = "";
 bool auth_chan;
 char auth_key[51] = "";
 char auth_prefix[2] = "";
@@ -94,6 +95,7 @@ static variable_t vars[] = {
  VAR("flood-ctcp",	&flood_ctcp,		VAR_RATE|VAR_NOLHUB,				0, 0, "3:60"),
  VAR("flood-msg",	&flood_msg,		VAR_RATE|VAR_NOLHUB,				0, 0, "5:60"),
  VAR("fork-interval",	&fork_interval,		VAR_INT,					10, 0, "0"),
+ VAR("groups",		groups,			VAR_STRING|VAR_LIST|VAR_NOLHUB,			0, 0, "main"),
  VAR("hijack",		&hijack,		VAR_INT|VAR_DETECTED|VAR_PERM,			0, 4, "die"),
  VAR("homechan",	homechan,		VAR_WORD|VAR_NOLOC|VAR_HIDE,			0, 0, NULL),
  VAR("ident-botnick",   &ident_botnick,		VAR_INT|VAR_BOOL|VAR_NOLHUB,			0, 1, "0"),

+ 1 - 1
src/set.h

@@ -67,7 +67,7 @@ typedef struct rate_b {
  interval_t time;
 } rate_t;
 
-extern char		auth_key[], auth_prefix[2], motd[], alias[], rbl_servers[1024],
+extern char		auth_key[], auth_prefix[2], motd[], alias[], rbl_servers[1024], groups[1024],
 			msgident[], msginvite[], msgop[], msgpass[], msgrelease[],
                         homechan[], altchars[];
 extern bool		dccauth, auth_obscure, manop_warn, auth_chan, oidentd, ident_botnick, irc_autoaway, link_cleartext, use_deaf, use_callerid;