Parcourir la source

* Commit initial work for chanset 'default'

* Add 'default' to commands: chanset/chaninfo/save/reload
* chaninfo * works on 'default' via do_chanset(chan = NULL)
* Added 'chdefault' for sharing UFF so only bots supporting 'default' get the default channel in the userfile
Bryan Drewery il y a 16 ans
Parent
commit
cd0622bf9f

+ 20 - 6
src/chanprog.c

@@ -54,7 +54,9 @@
 #endif
 #include <sys/utsname.h>
 
+char *def_chanset = "+enforcebans +dynamicbans +userbans -bitch +cycle -inactive +userexempts -dynamicexempts +userinvites -dynamicinvites -nodesynch -closed -take -voice -private -fastop +meankicks";
 struct chanset_t 	*chanset = NULL;	/* Channel list			*/
+struct chanset_t	*chanset_default = NULL;	/* Default channel list */
 char 			admin[121] = "";	/* Admin info			*/
 char			origbotnick[NICKLEN + 1] = "";	/* from -B (placed into conf.bot->nick .. for backup when conf is cleared */
 char 			origbotname[NICKLEN + 1] = "";	/* Nick to regain */
@@ -584,6 +586,15 @@ void chanprog()
 
 
   sdprintf("I am: %s", conf.bot->nick);
+
+  /* Add the 'default' virtual channel.
+     The flags will be overwritten when the userfile is loaded,
+     but if there is no userfile yet, or no 'default' channel,
+     then it will take on the properties of 'def_chanset',
+     and then later save this to the userfile.
+   */
+  channel_add(NULL, "default", def_chanset, 1);
+
   if (conf.bot->hub) {
     simple_snprintf(userfile, 121, "%s/.u", dirname(binname));
     loading = 1;
@@ -803,11 +814,11 @@ bool shouldjoin(struct chanset_t *chan)
 /* do_chanset() set (options) on (chan)
  * USES DO_LOCAL|DO_NET bits.
  */
-int do_chanset(char *result, struct chanset_t *chan, const char *options, int local)
+int do_chanset(char *result, struct chanset_t *chan, const char *options, int flags)
 {
   int ret = OK;
 
-  if (local & DO_NET) {
+  if (flags & DO_NET) {
     size_t bufsiz = 0;
          /* malloc(options,chan,'cset ',' ',+ 1) */
     if (chan)
@@ -829,15 +840,15 @@ int do_chanset(char *result, struct chanset_t *chan, const char *options, int lo
     free(buf);
   }
 
-  if (local & DO_LOCAL) {
-    bool cmd = (local & CMD);
+  if (flags & DO_LOCAL) {
+    bool cmd = (flags & CMD);
     struct chanset_t *ch = NULL;
     int all = chan ? 0 : 1;
 
     if (chan)
       ch = chan;
     else
-      ch = chanset;
+      ch = chanset_default; //First iteration changes default, then move on to all chans
 
     while (ch) {
       const char **item = NULL;
@@ -855,7 +866,10 @@ int do_chanset(char *result, struct chanset_t *chan, const char *options, int lo
         if (ret == ERROR) /* just bail if there was an error, no sense in trying more */
           return ret;
 
-        ch = ch->next;
+        if (ch == chanset_default)
+          ch = chanset;
+        else
+          ch = ch->next;
       } else {
         ch = NULL;
       }

+ 2 - 2
src/chanprog.h

@@ -32,8 +32,8 @@ bool is_hub(const char*);
 void load_internal_users();
 void setup_HQ(int);
 
-extern struct chanset_t		*chanset;
-extern char			admin[], origbotnick[NICKLEN + 1], origbotname[NICKLEN + 1], jupenick[NICKLEN], botname[NICKLEN + 1];
+extern struct chanset_t		*chanset, *chanset_default;
+extern char			admin[], origbotnick[NICKLEN + 1], origbotname[NICKLEN + 1], jupenick[NICKLEN], botname[NICKLEN + 1], *def_chanset;
 extern port_t			my_port;
 extern bool			reset_chans, cookies_disabled;
 

+ 14 - 18
src/mod/channels.mod/channels.c

@@ -121,7 +121,7 @@ static void got_cset(char *botnick, char *code, char *par)
   if (!par || !par[0])
    return;
 
-  bool all = 0;
+  bool all = 0, isdefault = 0;
   char *chname = NULL;
   struct chanset_t *chan = NULL;
 
@@ -129,26 +129,22 @@ static void got_cset(char *botnick, char *code, char *par)
     all = 1;
     newsplit(&par);
    } else {
-    if (!strchr(CHANMETA, par[0])) {
-      putlog(LOG_ERROR, "*", "Got bad cset: bot: %s code: %s par: %s", botnick, code, par);
-      return;
-    }
-    chname = newsplit(&par);
-    if (!(chan = findchan_by_dname(chname)))
-      return;
+     chname = newsplit(&par);
+     if (!strcasecmp(chname, "default"))
+       isdefault = 1;
+     else if (!strchr(CHANMETA, chname[0])) {
+       putlog(LOG_ERROR, "*", "Got bad cset: bot: %s code: %s par: %s %s", botnick, code, chname, par);
+       return;
+     }
+     if (isdefault)
+       chan = chanset_default;
+     else if (!(chan = findchan_by_dname(chname)))
+       return;
    }
 
   if (all)
-   chan = chanset;
-
-  while (chan) {
-    chname = chan->dname;
-    do_chanset(NULL, chan, par, DO_LOCAL);
-    if (!all)
-      chan = NULL;
-    else
-      chan = chan->next;
-  }
+   chan = NULL;
+  do_chanset(NULL, chan, par, DO_LOCAL);
 }
 
 /* returns 1 if botn is in bots */

+ 3 - 3
src/mod/channels.mod/channels.h

@@ -37,7 +37,7 @@ struct chanuserrec *add_chanrec(struct userrec *u, char *);
 void del_chanrec(struct userrec *, char *);
 void write_bans(bd::Stream&, int);
 void write_exempts(bd::Stream&, int);
-void write_chans(bd::Stream&, int);
+void write_chans(bd::Stream&, int, bool = 0);
 void write_chans_compat(bd::Stream&, int);
 void write_invites(bd::Stream&, int);
 bool expired_mask(struct chanset_t *, char *);
@@ -48,14 +48,14 @@ int u_sticky_mask(maskrec *, char *);
 int u_setsticky_mask(struct chanset_t *, maskrec *, char *, int, const char);
 int SplitList(char *, const char *, int *, const char ***);
 int channel_modify(char *, struct chanset_t *, int, char **, bool);
-int channel_add(char *, char *, char *);
+int channel_add(char *, char *, char *, bool = 0);
 void clear_channel(struct chanset_t *, bool);
 int u_equals_mask(maskrec *, char *);
 bool u_match_mask(struct maskrec *, char *);
 bool ismasked(masklist *, const char *);
 bool ismodeline(masklist *, const char *);
 void channels_report(int, int);
-void channels_writeuserfile(bd::Stream&, bool = 0);
+void channels_writeuserfile(bd::Stream&, int = 0);
 void rcmd_chans(char *, char *, char *);
 
 extern char		glob_chanset[512];

+ 19 - 7
src/mod/channels.mod/cmdschan.c

@@ -1203,7 +1203,10 @@ static void cmd_chaninfo(int idx, char *par)
       return;
     }
   }
-  chan = findchan_by_dname(chname);
+  if (!strcasecmp(chname, "default"))
+    chan = chanset_default;
+  else
+    chan = findchan_by_dname(chname);
   if (!chan || (chan && privchan(user, chan, PRIV_OP))) {
     dprintf(idx, "No such channel.\n");
     return;
@@ -1314,10 +1317,11 @@ static void cmd_chanset(int idx, char *par)
   char *chname = NULL, result[RESULT_LEN] = "";
   struct chanset_t *chan = NULL;
   int all = 0;
+  bool isdefault = 0;
 
   if (!par[0]) {
     putlog(LOG_CMDS, "*", "#%s# chanset %s", dcc[idx].nick, par);
-    dprintf(idx, "Usage: chanset [%schannel|*] <settings>\n", CHANMETA);
+    dprintf(idx, "Usage: chanset [%schannel|*|default] <settings>\n", CHANMETA);
     return;
   }
 
@@ -1330,10 +1334,17 @@ static void cmd_chanset(int idx, char *par)
     }
     newsplit(&par);
   } else {
-    if (strchr(CHANMETA, par[0])) {
+    if (par && par[0]) {
       chname = newsplit(&par);
+      if (!strcasecmp(chname, "default"))
+        isdefault = 1;
+    }
+    if ((chname[0] && strchr(CHANMETA, chname[0])) || isdefault) {
       get_user_flagrec(dcc[idx].user, &user, chname);
-      chan = findchan_by_dname(chname);
+      if (isdefault)
+        chan = chanset_default;
+      else
+        chan = findchan_by_dname(chname);
 
       if (!glob_master(user) && !chan_master(user)) {
         dprintf(idx, "You don't have access to %s. \n", chname);
@@ -1357,8 +1368,8 @@ static void cmd_chanset(int idx, char *par)
 	par = chname;
       }
     }
-    if (!par[0] || par[0] == '*') {
-      dprintf(idx, "Usage: chanset [%schannel] <settings>\n", CHANMETA);
+    if (!chname[0] || chname[0] == '*') {
+      dprintf(idx, "Usage: chanset [%schannel|*|default] <settings>\n", CHANMETA);
       return;
     }
     if (!chan && !(chan = findchan_by_dname(chname = dcc[idx].u.chat->con_chan))) {
@@ -1373,8 +1384,9 @@ static void cmd_chanset(int idx, char *par)
     dprintf(idx, "Error trying to set { %s } on %s: %s\n", par, all ? "all channels" : chan->dname, result);
     return;
   }
+
   if (all)
-    dprintf(idx, "Successfully set modes { %s } on all channels.\n", par);
+    dprintf(idx, "Successfully set modes { %s } on all channels (Including the default).\n", par);
   else
     dprintf(idx, "Successfully set modes { %s } on %s\n", par, chan->dname);
 

+ 19 - 10
src/mod/channels.mod/tclchan.c

@@ -798,7 +798,7 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
   if ((chan->status ^ old_status) & CHAN_TAKE)
     chan->status |= (CHAN_FASTOP|CHAN_BITCH);		// to avoid bots still mass opping from +take from not using cookies
 
-  if (!conf.bot->hub) {
+  if (!conf.bot->hub && (chan != chanset_default)) {
     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);
@@ -908,9 +908,13 @@ void clear_channel(struct chanset_t *chan, bool reset)
 
 /* Create new channel and parse commands.
  */
-int channel_add(char *result, char *newname, char *options)
+int channel_add(char *result, char *newname, char *options, bool isdefault)
 {
-  if (!newname || !newname[0] || !strchr(CHANMETA, newname[0])) {
+  /* When loading userfile */
+  if (newname && newname[0] && loading && !strcmp(newname, "default"))
+    isdefault = 1;
+
+  if (!newname || !newname[0] || (!isdefault && !strchr(CHANMETA, newname[0]))) {
     if (result)
       strlcpy(result, "invalid channel prefix", RESULT_LEN);
     return ERROR;
@@ -930,8 +934,10 @@ int channel_add(char *result, char *newname, char *options)
   strlcat(buf, def_chanset, sizeof(buf));
   strlcat(buf, " ", sizeof(buf));
   strlcat(buf, glob_chanset, sizeof(buf));
-  strlcat(buf, " ", sizeof(buf));
-  strlcat(buf, options, sizeof(buf));
+  if (options && options[0]) {
+    strlcat(buf, " ", sizeof(buf));
+    strlcat(buf, options, sizeof(buf));
+  }
 
   if (SplitList(result, buf, &items, &item) != OK)
     return ERROR;
@@ -980,7 +986,6 @@ int channel_add(char *result, char *newname, char *options)
     chan->ban_time = global_ban_time;
     chan->exempt_time = global_exempt_time;
     chan->invite_time = global_invite_time;
-    /* let's initialize this stuff for shits & giggles */
     chan->channel.jointime = 0;
     chan->channel.parttime = 0;
     chan->channel.fighting = 0;
@@ -997,10 +1002,14 @@ int channel_add(char *result, char *newname, char *options)
 
     /* Initialize chan->channel info */
     init_channel(chan, 0);
-    list_append((struct list_type **) &chanset, (struct list_type *) chan);
-    /* Channel name is stored in xtra field for sharebot stuff */
-    if (!conf.bot->hub)
-      join = 1;
+    if (isdefault)
+      chanset_default = chan;
+    else {
+      list_append((struct list_type **) &chanset, (struct list_type *) chan);
+      /* Channel name is stored in xtra field for sharebot stuff */
+      if (!conf.bot->hub && !isdefault)
+        join = 1;
+    }
   }
   /* If loading is set, we're loading the userfile. Ignore errors while
    * reading userfile and just return OK. This is for compatability

+ 33 - 23
src/mod/channels.mod/userchan.c

@@ -701,30 +701,24 @@ void write_invites(bd::Stream& stream, int idx)
 
 /* Write the channels to the userfile
  */
-void write_chans(bd::Stream& stream, int idx)
+static void write_chan(bd::Stream& stream, int idx, struct chanset_t* chan)
 {
   bd::String buf;
-
-  putlog(LOG_DEBUG, "*", "Writing channels..");
-
-  stream << buf.printf(CHANS_NAME " - -\n");
-
   char w[1024] = "";
 
-  for (struct chanset_t *chan = chanset; chan; chan = chan->next) {
-    char inactive = 0;
+  char inactive = 0;
 
-    putlog(LOG_DEBUG, "*", "writing channel %s to userfile..", chan->dname);
-    get_mode_protect(chan, w, sizeof(w));
+  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));
+  /* 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));
 
-    stream << buf.printf("\
+  stream << buf.printf("\
 + channel add %s { chanmode { %s } addedby %s addedts %li \
 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 \
@@ -799,8 +793,24 @@ flood-exempt %d flood-lock-time %d knock %d \
  * also include a %ctemp above.
  *      PLSMNS(channel_temp(chan)),
  */
-    );
-  }
+  );
+}
+
+/* Write the channels to the userfile
+ */
+void write_chans(bd::Stream& stream, int idx, bool old)
+{
+  bd::String buf;
+
+  putlog(LOG_DEBUG, "*", "Writing channels..");
+
+  stream << buf.printf(CHANS_NAME " - -\n");
+
+  /* FIXME: Remove after 1.2.15 */
+  if (!old)
+    write_chan(stream, idx, chanset_default);
+  for (struct chanset_t *chan = chanset; chan; chan = chan->next)
+    write_chan(stream, idx, chan);
 }
 
 /* FIXME: remove after 1.2.14 */
@@ -888,12 +898,12 @@ exempt-time %d invite-time %d voice-non-ident %d auto-delay %d \
   }
 }
 
-void channels_writeuserfile(bd::Stream& stream, bool old)
+void channels_writeuserfile(bd::Stream& stream, int old)
 {
   putlog(LOG_DEBUG, "@", "Writing channel/ban/exempt/invite entries.");
-  if (!old)
-    write_chans(stream, -1);
-  else
+  if (old != 1)
+    write_chans(stream, -1, old == 0 ? 0 : 1);
+  else /* flood-* hacks */
     write_chans_compat(stream, -1);
   write_vars_and_cmdpass(stream, -1);
   write_bans(stream, -1);

+ 4 - 1
src/mod/share.mod/share.c

@@ -909,6 +909,9 @@ share_ufyes(int idx, char *par)
 
     lower_bot_linked(idx);
 
+    if (strstr(par, "chdefault"))
+        dcc[idx].u.bot->uff_flags |= UFF_CHDEFAULT;
+
     if (strstr(par, "stream")) {
       updatebot(-1, dcc[idx].nick, '+', 0, 0, 0, NULL);
       /* Start up a tbuf to queue outgoing changes for this bot until the
@@ -950,7 +953,7 @@ share_userfileq(int idx, char *par)
       dprintf(idx, "s un Already sharing.\n");
     else {
       dcc[idx].u.bot->uff_flags |= (UFF_OVERRIDE | UFF_INVITE | UFF_EXEMPT);
-      dprintf(idx, "s uy overbots invites exempts stream\n");
+      dprintf(idx, "s uy overbots invites exempts stream chdefault\n");
       /* Set stat-getting to astatic void race condition (robey 23jun1996) */
       dcc[idx].status |= STAT_SHARE | STAT_GETTING | STAT_AGGRESSIVE;
       if (conf.bot->hub)

+ 1 - 0
src/mod/share.mod/share.h

@@ -9,6 +9,7 @@
 #define	UFF_OVERRIDE	BIT0	/* Override existing bot entries    */
 #define UFF_INVITE	BIT1	/* Send invites in user file	    */
 #define UFF_EXEMPT	BIT2	/* Send exempts in user file	    */
+#define UFF_CHDEFAULT	BIT3
 
 #include "src/users.h"
 

+ 3 - 9
src/set.c

@@ -40,7 +40,6 @@ int dcc_autoaway;
 bool irc_autoaway;
 bool link_cleartext;
 bool dccauth = 0;
-char *def_chanset = "+enforcebans +dynamicbans +userbans -bitch +cycle -inactive +userexempts -dynamicexempts +userinvites -dynamicinvites -nodesynch -closed -take -voice -private -fastop +meankicks ban-type 3";
 int cloak_script = 0;
 rate_t close_threshold;
 int fight_threshold;
@@ -75,7 +74,7 @@ static variable_t vars[] = {
  VAR("auth-key",	auth_key,		VAR_STRING|VAR_PERM,				0, 0, NULL),
  VAR("auth-obscure",	&auth_obscure,		VAR_INT|VAR_BOOL,				0, 1, "0"),
  VAR("auth-prefix",	auth_prefix,		VAR_WORD|VAR_NOLHUB|VAR_PERM,			0, 0, "+"),
- VAR("chanset",		glob_chanset,		VAR_STRING|VAR_CHANSET|VAR_NOLHUB,		0, 0, NULL),
+ VAR("chanset",		glob_chanset,		VAR_STRING|VAR_NOLHUB|VAR_NOLOC|VAR_HIDE,	0, 0, NULL),
  VAR("cloak-script",	&cloak_script,		VAR_INT|VAR_CLOAK|VAR_NOLHUB,			0, 10, "0"),
  VAR("close-threshold",	&close_threshold,	VAR_RATE|VAR_NOLOC,				0, 0, "0:0"),
  VAR("dcc-autoaway",	&dcc_autoaway,		VAR_INT|VAR_NOLOC,				0, (5*60*60), "1800"),
@@ -532,12 +531,8 @@ sdprintf("var: %s (local): %s", var->name, data ? data : "(NULL)");
 sdprintf("var: %s (global): %s", var->name, data ? data : "(NULL)");
     if (data && !clear)
       var->gdata = strdup(data);
-    else {
-      if (var->flags & VAR_CHANSET)
-        var->gdata = strdup(def_chanset);
-      else 
-        var->gdata = var->def ? strdup(var->def) : NULL;
-    }
+    else
+      var->gdata = var->def ? strdup(var->def) : NULL;
 
     if (domem && var->mem)
       var_set_mem(var, var->gdata);
@@ -611,7 +606,6 @@ void init_vars()
     if (!vars[i].gdata && !vars[i].ldata && !(!conf.bot->hub && (vars[i].flags & VAR_NOLDEF)))
       var_set(&vars[i], NULL, NULL);		//empty out and set to defaults
   }
-  var_set_by_name(NULL, "chanset", def_chanset);
 #ifdef DEBUG
   if (!strncmp(conf.bot->nick, "wtest", 5))
     var_set_by_name(NULL, "homechan", "#bryan");

+ 2 - 2
src/set.h

@@ -28,7 +28,7 @@
 #define VAR_PERM	BIT13
 /* Don't set the var data from the mem as default (NICK) */
 #define VAR_NODEF	BIT14
-#define VAR_CHANSET	BIT15
+//#define VAR_UNUSED	BIT15
 /* Don't set the default on startup of a leaf (servers) */
 #define VAR_NOLDEF	BIT16
 /* Don't set global on hub */
@@ -67,7 +67,7 @@ typedef struct rate_b {
  interval_t time;
 } rate_t;
 
-extern char		auth_key[], auth_prefix[2], motd[], *def_chanset, alias[], rbl_servers[1024],
+extern char		auth_key[], auth_prefix[2], motd[], alias[], rbl_servers[1024],
 			msgident[], msginvite[], msgop[], msgpass[],
                         homechan[], altchars[];
 extern bool		dccauth, auth_obscure, manop_warn, auth_chan, oidentd, ident_botnick, irc_autoaway, link_cleartext;

+ 4 - 0
src/userrec.c

@@ -492,6 +492,10 @@ int write_userfile(int idx)
 
   Tempfile *new_userfile = new Tempfile("userfile");
 
+  /* FIXME: Remove after 1.2.15 */
+  if (idx != -1 && !(dcc[idx].u.bot->uff_flags & UFF_CHDEFAULT)) /* channel 'default' */
+    old = 2;
+
   const char salt1[] = SALT1;
   EncryptedStream stream(salt1);
   stream_writeuserfile(stream, userlist);