Răsfoiți Sursa

Merge branch '21-botgroups' into next

* 21-botgroups:
  * Share groups with all bots
  * Properly check the correct bots' groups in bot_shouldjoin
  * Remove obsolete code botshouldjoin()
Bryan Drewery 14 ani în urmă
părinte
comite
a812748bff
7 a modificat fișierele cu 12 adăugiri și 80 ștergeri
  1. 4 64
      src/chanprog.c
  2. 0 1
      src/chanprog.h
  3. 1 9
      src/mod/channels.mod/userchan.c
  4. 1 1
      src/set.c
  5. 1 0
      src/set.h
  6. 0 1
      src/tandem.h
  7. 5 4
      src/userent.c

+ 4 - 64
src/chanprog.c

@@ -45,6 +45,7 @@
 #include "userrec.h"
 #include "main.h"
 #include "debug.h"
+#include "set.h"
 #include "dccutil.h"
 #include "botmsg.h"
 #if HAVE_GETRUSAGE
@@ -743,68 +744,6 @@ int isowner(char *name)
   }
 }
 
-/* this method is slow, but is only called when sharing and adding/removing chans */
-
-int 
-botshouldjoin(struct userrec *u, struct chanset_t *chan)
-{
-  /* just return 1 for now */
-  return 1;
-/*
-  char *chans = NULL;
-  struct userrec *u = NULL;
- 
-  u = get_user_by_handle(userlist, bot);
-  if (!u)
-    return;
-  chans = get_user(&USERENTRY_CHANS, u);
-*/
-}
-/* future use ?
-void
-chans_addbot(const char *bot, struct chanset_t *chan)
-{
-  char *chans = NULL;
-  struct userrec *u = NULL;
- 
-  u = get_user_by_handle(userlist, bot);
-  if (!u)
-    return;
-  chans = get_user(&USERENTRY_CHANS, u);
-  if (!botshouldjoin(u, chan)) {		
-    size_t size;
-    char *buf = NULL;
-   
-    size = strlen(chans) + strlen(chan->dname) + 2;
-    buf = (char *) my_calloc(1, size);
-    simple_snprintf(buf, size, "%s %s", chans, chan->dname);
-    set_user(&USERENTRY_CHANS, u, buf);
-    free(buf);
-  }
-}
-
-void 
-chans_delbot(const char *bot, struct chanset_t *chan)
-{
-  char *chans = NULL;
-  struct userrec *u = NULL;
- 
-  u = get_user_by_handle(userlist, bot);
-  if (!u)
-    return;
- 
-  if (botshouldjoin(u, chan)) {			
-    char *chans = NULL, *buf = NULL;
-    size_t size;
-
-    chans = get_user(&USERENTRY_CHANS, u);
-    size = strlen(chans) - strlen(chan->dname) + 2;
-
-    
-  }
-}
-*/
-
 bool bot_shouldjoin(struct userrec* u, struct flag_record* fr, struct chanset_t* chan, bool ignore_inactive)
 {
   // If restarting, keep this channel.
@@ -827,8 +766,9 @@ bool bot_shouldjoin(struct userrec* u, struct flag_record* fr, struct chanset_t*
   }
 #endif
 
-  // Am I in the groups that this channel has?
-  bd::Array<bd::String> my_groupsArray(bd::String(groups).split(','));
+  // Is this bot in the groups that this channel has?
+  const char *botgroups = u == conf.bot->u ? groups : var_get_bot_data(u, "groups");
+  bd::Array<bd::String> my_groupsArray(bd::String(botgroups).split(','));
   bool group_match = 0;
 
   if (chan->groups && chan->groups->length()) {

+ 0 - 1
src/chanprog.h

@@ -23,7 +23,6 @@ void rmspace(char *s);
 void set_chanlist(const char *host, struct userrec *rec);
 void clear_chanlist(void);
 void clear_chanlist_member(const char *nick);
-int botshouldjoin(struct userrec *u, struct chanset_t *);
 bool bot_shouldjoin(struct userrec* , struct flag_record *, struct chanset_t *, bool = 0);
 bool shouldjoin(struct chanset_t *);
 char *samechans(const char *, const char *);

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

@@ -701,9 +701,6 @@ static void write_chan(bd::Stream& stream, int idx, struct chanset_t* chan)
   putlog(LOG_DEBUG, "*", "writing channel %s to userfile..", chan->dname);
 
   bool force_inactive = 0;
-  /* if a bot should explicitly NOT join, just set it +inactive ... */
-  if (idx >= 0 && !botshouldjoin(dcc[idx].user, chan))
-    force_inactive = 1;
 
   stream << bd::String::printf("+ channel add %s { ", chan->dname);
   if (chan != chanset_default)
@@ -826,12 +823,7 @@ void write_chans_compat(bd::Stream& stream, int idx)
     putlog(LOG_DEBUG, "*", "writing channel %s to userfile..", chan->dname);
     get_mode_protect(chan, w, sizeof(w));
 
-    /* if a bot should explicitly NOT join, just set it +inactive ... */
-    if (idx >= 0 && !botshouldjoin(dcc[idx].user, chan))
-      inactive = '+';
-    /* ... otherwise give the bot the *actual* setting */
-    else
-      inactive = PLSMNS(channel_inactive(chan));
+    inactive = PLSMNS(channel_inactive(chan));
 
     stream << bd::String::printf("\
 + channel add %s { chanmode { %s } addedby %s addedts %li \

+ 1 - 1
src/set.c

@@ -702,7 +702,7 @@ void var_userfile_share_line(char *line, int idx, bool share)
     check_removed_server();
 }
 
-static const char *var_get_bot_data(struct userrec *u, const char *name)
+const char *var_get_bot_data(struct userrec *u, const char *name)
 {
   if (!u)
     return NULL;

+ 1 - 0
src/set.h

@@ -86,6 +86,7 @@ void var_parse_my_botset();
 void init_vars();
 void var_set_by_name(const char *, const char *, const char *);
 void var_set_userentry(const char *, const char *, const char *);
+const char *var_get_bot_data(struct userrec *u, const char *name);
 int cmd_set_real(const char *, int idx, char *);
 const char *var_get_str_by_name(const char *);
 

+ 0 - 1
src/tandem.h

@@ -14,7 +14,6 @@ typedef struct tand_t_struct {
   time_t buildts;
   int localhub;
   struct userrec* u;
-  char *not_chans;
   char commit[10];
   char bot[HANDLEN + 1];
   char version[151];

+ 5 - 4
src/userent.c

@@ -367,12 +367,13 @@ static bool set_gotshare(struct userrec *u, struct user_entry *e, char *buf, int
 static void set_write_userfile(bd::Stream& stream, const struct userrec *u, const struct user_entry *e, int idx)
 {
   int localhub = nextbot(u->handle);
-  /* only write if saving local, or if sending to hub, or if sending to same user as entry, or the localhub in the chain */
-  if (idx == -1 || dcc[idx].hub || dcc[idx].user == u || (localhub != -1 && idx == localhub)) {
-    struct xtra_key *x = (struct xtra_key *) e->u.extra;
+  struct xtra_key *x = (struct xtra_key *) e->u.extra;
 
-    for (; x; x = x->next)
+  for (; x; x = x->next) {
+    /* only write if saving local, or if sending to hub, or if sending to same user as entry, or the localhub in the chain, or sending 'groups' */
+    if (idx == -1 || dcc[idx].hub || dcc[idx].user == u || (localhub != -1 && idx == localhub) || !strcmp(x->key, "groups")) {
       stream << bd::String::printf("--%s %s %s\n", e->type->name, x->key, x->data ? x->data : "");
+    }
   }
 }