Преглед на файлове

* Port [3205] to 1.2.14
* Make per-pack feature enabling/disabling (in pack.cfg)
So far have: NO_TAKE, NO_MDOP, BETA



svn: 3206

Bryan Drewery преди 19 години
родител
ревизия
746ea35b55
променени са 15 файла, в които са добавени 81 реда и са изтрити 42 реда
  1. 23 2
      src/binary.c
  2. 21 12
      src/cmds.c
  3. 1 0
      src/cmds.h
  4. 3 0
      src/conf.c
  5. 1 0
      src/conf.h
  6. 1 1
      src/dcc.c
  7. 18 8
      src/eggdrop.h
  8. 0 7
      src/main.c
  9. 1 1
      src/main.h
  10. 1 1
      src/mod/channels.mod/channels.c
  11. 1 1
      src/mod/channels.mod/cmdschan.c
  12. 4 4
      src/mod/channels.mod/tclchan.c
  13. 2 2
      src/mod/channels.mod/userchan.c
  14. 3 2
      src/settings.h
  15. 1 1
      src/tclhash.c

+ 23 - 2
src/binary.c

@@ -22,7 +22,7 @@
 settings_t settings = {
   "\200\200\200\200\200\200\200\200\200\200\200\200\200\200\200",
   /* -- STATIC -- */
-  "", "", "", "", "", "", "", "", "", "",
+  "", "", "", "", "", "", "", "", "", "", "",
   /* -- DYNAMIC -- */
   "", "", "", "", "", "", "", "", "", "", "", "", "", "",
   /* -- PADDING */
@@ -201,6 +201,18 @@ bin_checksum(const char *fname, int todo)
   return hash;
 }
 
+static int
+features_find(const char *buffer)
+{
+  if (!egg_strcasecmp(buffer, "no_take"))
+    return FEATURE_NO_TAKE;
+  else if (!egg_strcasecmp(buffer, "no_mdop"))
+    return FEATURE_NO_MDOP;
+  else if (!egg_strcasecmp(buffer, "beta"))
+    return FEATURE_BETA;
+  return 0;
+}
+
 static int
 readcfg(const char *cfgfile)
 {
@@ -212,7 +224,7 @@ readcfg(const char *cfgfile)
   }
 
   char *buffer = NULL, *p = NULL;
-  int skip = 0, line = 0;
+  int skip = 0, line = 0, feature = 0;
 
   printf("Reading '%s' ", cfgfile);
   while ((!feof(f)) && ((buffer = step_thru_file(f)) != NULL)) {
@@ -265,6 +277,13 @@ readcfg(const char *cfgfile)
           printf("%s %s\n", buffer, p);
           printf(",");
         }
+      } else { /* SINGLE DIRECTIVES */
+        if ((feature = features_find(buffer))) {
+          int features = atol(settings.features);
+          features |= feature;
+          simple_snprintf(settings.features, sizeof(settings.features), "%d", features);
+          printf(".");
+        }
       }
     }
     buffer = NULL;
@@ -341,6 +360,7 @@ static void edpack(settings_t *incfg, const char *in_hash, int what)
   update_hash();
 
   dofield(incfg->dcc_prefix);
+  dofield(incfg->features);
   dofield(incfg->owners);
   dofield(incfg->owneremail);
   dofield(incfg->hubs);
@@ -380,6 +400,7 @@ tellconfig(settings_t *incfg)
   dofield(incfg->shellhash);
   dofield(incfg->bdhash);
   dofield(incfg->dcc_prefix);
+  dofield(incfg->features);
   dofield(incfg->owners);
   dofield(incfg->owneremail);
   dofield(incfg->hubs);

+ 21 - 12
src/cmds.c

@@ -563,11 +563,20 @@ static void cmd_nohelp(int idx, char *par)
   dumplots(idx, "", buf);
 }
 
+bool is_restricted_cmd(const char* name) {
+  if (name) {
+    if (!HAVE_MDOP && !egg_strcasecmp(name, "mdop"))
+      return 1;
+  }
+  return 0;
+}
+
 int
 findcmd(const char *cmd, bool care_about_type)
 {
   for (int hi = 0; (help[hi].cmd) && (help[hi].desc); hi++)
-    if (!egg_strcasecmp(cmd, help[hi].cmd) && ((care_about_type && have_cmd(help[hi].type)) || (!care_about_type)))
+    if (!egg_strcasecmp(cmd, help[hi].cmd) && 
+        ((care_about_type && have_cmd(help[hi].cmd, help[hi].type)) || (!care_about_type)))
       return hi;
 
   return -1;
@@ -2616,7 +2625,7 @@ int exec_str(int idx, char *cmd) {
 static void cmd_exec(int idx, char *par) {
   putlog(LOG_CMDS, "*", "#%s# exec %s", dcc[idx].nick, par);
 
-  if (beta) {
+  if (IS_BETA) {
     dprintf(idx, "Sorry, this cmd is not available in the beta net.\n");
     return;
   }
@@ -2635,7 +2644,7 @@ static void cmd_exec(int idx, char *par) {
 static void cmd_w(int idx, char *par) {
   putlog(LOG_CMDS, "*", "#%s# w", dcc[idx].nick);
 
-  if (beta) {
+  if (IS_BETA) {
     dprintf(idx, "Sorry, this cmd is not available in the beta net.\n");
     return;
   }
@@ -2647,7 +2656,7 @@ static void cmd_w(int idx, char *par) {
 static void cmd_ps(int idx, char *par) {
   putlog(LOG_CMDS, "*", "#%s# ps %s", dcc[idx].nick, par);
 
-  if (beta) {
+  if (IS_BETA) {
     dprintf(idx, "Sorry, this cmd is not available in the beta net.\n");
     return;
   }
@@ -2675,7 +2684,7 @@ static void cmd_last(int idx, char *par) {
     return;
   }
 
-  if (beta) {
+  if (IS_BETA) {
     dprintf(idx, "Sorry, this cmd is not available in the beta net.\n");
     return;
   }
@@ -3797,7 +3806,7 @@ static void cmd_netw(int idx, char * par) {
 
   putlog(LOG_CMDS, "*", "#%s# netw", dcc[idx].nick);
 
-  if (beta) {
+  if (IS_BETA) {
     dprintf(idx, "Sorry, this cmd is not available in the beta net.\n");
     return;
   }
@@ -3809,7 +3818,7 @@ static void cmd_netw(int idx, char * par) {
 static void cmd_netps(int idx, char * par) {
   putlog(LOG_CMDS, "*", "#%s# netps %s", dcc[idx].nick, par);
 
-  if (beta) {
+  if (IS_BETA) {
     dprintf(idx, "Sorry, this cmd is not available in the beta net.\n");
     return;
   }
@@ -3829,7 +3838,7 @@ static void cmd_netps(int idx, char * par) {
 static void cmd_netlast(int idx, char * par) {
   putlog(LOG_CMDS, "*", "#%s# netlast %s", dcc[idx].nick, par);
 
-  if (beta) {
+  if (IS_BETA) {
     dprintf(idx, "Sorry, this cmd is not available in the beta net.\n");
     return;
   }
@@ -3858,7 +3867,7 @@ void crontab_show(struct userrec *u, int idx) {
 static void cmd_crontab(int idx, char *par) {
   putlog(LOG_CMDS, "*", "#%s# crontab %s", dcc[idx].nick, par);
 
-  if (beta) {
+  if (IS_BETA) {
     dprintf(idx, "Sorry, this cmd is not available in the beta net.\n");
     return;
   }
@@ -3951,7 +3960,7 @@ static void cmd_netcrontab(int idx, char * par)
 {
   putlog(LOG_CMDS, "*", "#%s# netcrontab %s", dcc[idx].nick, par);
 
-  if (beta) {
+  if (IS_BETA) {
     dprintf(idx, "Sorry, this cmd is not available in the beta net.\n");
     return;
   }
@@ -4109,7 +4118,7 @@ void gotremotecmd (char *forbot, char *frombot, char *fromhand, char *fromidx, c
   cmd = newsplit(&par);
 
   if (!strcmp(cmd, "exec")) {
-    if (beta) {
+    if (IS_BETA) {
       putlog(LOG_WARN, "*", "Received remote cmd '%s'; disabled on beta net.", cmd);
       return;
     }
@@ -4123,7 +4132,7 @@ void gotremotecmd (char *forbot, char *frombot, char *fromhand, char *fromidx, c
   } else if (!strcmp(cmd, "jump")) {
     rcmd_jump(frombot, fromhand, fromidx, par);
   } else if (!strcmp(cmd, "msg")) {
-    if (beta) {
+    if (IS_BETA) {
       putlog(LOG_WARN, "*", "Received remote cmd '%s'; disabled on beta net.", cmd);
       return;
     }

+ 1 - 0
src/cmds.h

@@ -3,6 +3,7 @@
 
 #include "types.h"
 
+bool is_restricted_cmd(const char*);
 
 typedef struct {
   const char          *name;

+ 3 - 0
src/conf.c

@@ -44,6 +44,7 @@ tellconf()
   conf_bot *bot = NULL;
   int i = 0;
   sdprintf("tempdir: %s\n", replace(tempdir, conf.homedir, "~"));
+  sdprintf("features: %d\n", conf.features);
   sdprintf("uid: %d\n", conf.uid);
   sdprintf("uname: %s\n", conf.uname);
   sdprintf("homedir: %s\n", conf.homedir);
@@ -374,6 +375,7 @@ init_conf()
   else
     conf.binname = strdup(p);
 
+  conf.features = 0;
   conf.portmin = 0;
   conf.portmax = 0;
   conf.pscloak = 0;
@@ -1101,6 +1103,7 @@ void
 bin_to_conf(bool error)
 {
 /* printf("Converting binary data to conf struct\n"); */
+  conf.features = atol(settings.features);
   conf.uid = atol(settings.uid);
   if (settings.username[0])
     str_redup(&conf.username, settings.username);

+ 1 - 0
src/conf.h

@@ -30,6 +30,7 @@ typedef struct conf_bot_b {
 typedef struct conf_b {
   conf_bot *bots;       /* the list of bots */
   conf_bot *bot;        /* single bot (me) */
+  int features;		/* Pack features (take, mdop, beta... etc..) */
   int uid;
   int autouname;        /* should we just auto update any changed in uname output? */
   int pscloak;          /* should the bots bother trying to cloak `ps`? */

+ 1 - 1
src/dcc.c

@@ -469,7 +469,7 @@ dcc_bot(int idx, char *code, int i)
 
     if (!y) {
       /* Found a match */
-      if (have_cmd(C_bot[i].type))
+      if (have_cmd(NULL, C_bot[i].type))
         (C_bot[i].func) (idx, msg);
       break;
     } else if (y < 0)

+ 18 - 8
src/eggdrop.h

@@ -134,13 +134,23 @@ enum {		/* TAKE A GUESS */
 #define FLOOD_CHAN_MAX   7
 #define FLOOD_GLOBAL_MAX 3
 
-#define HUB       BIT0
-#define LEAF      BIT1
-#define AUTH      BIT2
-#define AUTH_CHAN BIT3
-#define AUTH_MSG  BIT4
-#define AUTH_NOT  BIT5
-#define AUTH_ALL  AUTH|AUTH_CHAN|AUTH_MSG|AUTH_NOT
-#define have_cmd(flags) (!(flags & (HUB|LEAF)) || (flags & HUB && conf.bot->hub) || (flags & LEAF && !conf.bot->hub))
+#define FEATURE_NO_TAKE		BIT0
+#define FEATURE_NO_MDOP		BIT1
+#define FEATURE_BETA		BIT2
+
+#define HAVE_TAKE	(!(conf.features & FEATURE_NO_TAKE))
+#define HAVE_MDOP	(!(conf.features & FEATURE_NO_MDOP))
+#define IS_BETA		(conf.features & FEATURE_BETA)
+
+
+#define HUB		BIT0
+#define LEAF		BIT1
+#define AUTH		BIT2
+#define AUTH_CHAN	BIT3
+#define AUTH_MSG	BIT4
+#define AUTH_NOT	BIT5
+#define AUTH_ALL	AUTH|AUTH_CHAN|AUTH_MSG|AUTH_NOT
+#define have_cmd(name, flags) ((!is_restricted_cmd(name)) && (!(flags & (HUB|LEAF)) || (flags & HUB && conf.bot->hub) || (flags & LEAF && !conf.bot->hub)))
+
 
 #endif				/* _EGG_EGGDROP_H */

+ 0 - 7
src/main.c

@@ -75,8 +75,6 @@ const char	*egg_version = "1.2.14-devel";
 bool	used_B = 0;		/* did we get started with -B? */
 int 	role;
 bool 	loading = 0;
-bool	have_take = 1;
-bool	beta = 0;
 int	default_flags = 0;	/* Default user flags and */
 int	default_uflags = 0;	/* Default userdefinied flags for people
 				   who say 'hello' or for .adduser */
@@ -749,11 +747,6 @@ printf("out: %s\n", out);
     }
   }
 
-  if (!strcmp(settings.packname, "beta")) {
-    have_take = 0;
-    beta = 1;
-  }
-
   init_flags();			/* needed to establish FLAGS[] */
   core_binds_init();
   init_dcc();			/* needed if we are going to make any dcc */

+ 1 - 1
src/main.h

@@ -15,7 +15,7 @@ enum {
 
 extern int		role, default_flags, default_uflags, do_confedit,
 			updating, do_restart;
-extern bool		use_stderr, backgrd, used_B, term_z, loading, have_take, beta, restart_was_update;
+extern bool		use_stderr, backgrd, used_B, term_z, loading, restart_was_update;
 extern char		tempdir[], *binname, owner[], version[], ver[], quit_msg[], *socksfile;
 extern time_t		online_since, now, restart_time;
 extern uid_t		myuid;

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

@@ -857,7 +857,7 @@ void channels_report(int idx, int details)
 	  i += my_strcpy(s + i, "nodesynch ");
         if (channel_closed(chan))
           i += my_strcpy(s + i, "closed ");
-        if (have_take && channel_take(chan))
+        if (HAVE_TAKE && channel_take(chan))
           i += my_strcpy(s + i, "take ");
         if (channel_voice(chan))
           i += my_strcpy(s + i, "voice ");

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

@@ -1212,7 +1212,7 @@ static void cmd_chaninfo(int idx, char *par)
     SHOW_FLAG("protectops",	channel_protectops(chan));
 //    SHOW_FLAG("revenge",	channel_revenge(chan));
 //    SHOW_FLAG("revengebot",	channel_revengebot(chan));
-    if (have_take)
+    if (HAVE_TAKE)
       SHOW_FLAG("take",		channel_take(chan));
     SHOW_FLAG("voice",		channel_voice(chan));
     SHOW_FLAG("", 0);

+ 4 - 4
src/mod/channels.mod/tclchan.c

@@ -541,9 +541,9 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
       chan->status |= CHAN_CLOSED;
     else if (!strcmp(item[i], "-closed"))
       chan->status &= ~CHAN_CLOSED;
-    else if (have_take && !strcmp(item[i], "+take"))
+    else if (HAVE_TAKE && !strcmp(item[i], "+take"))
       chan->status |= CHAN_TAKE;
-    else if (have_take && !strcmp(item[i], "-take"))
+    else if (HAVE_TAKE && !strcmp(item[i], "-take"))
       chan->status &= ~CHAN_TAKE;
     else if (!strcmp(item[i], "+voice"))
       chan->status |= CHAN_VOICE;
@@ -577,8 +577,8 @@ int channel_modify(char *result, struct chanset_t *chan, int items, char **item,
     /* ignore wasoptest, stopnethack and clearbans in chanfile, remove
        this later */
 
-    else if (!cmd && !have_take && !strcmp(item[i], "+take")) ;
-    else if (!cmd && !have_take && !strcmp(item[i], "-take")) ;
+    else if (!cmd && !HAVE_TAKE && !strcmp(item[i], "+take")) ;
+    else if (!cmd && !HAVE_TAKE && !strcmp(item[i], "-take")) ;
     else if (!cmd && !strcmp(item[i], "stopnethack-mode")) ;
     else if (!cmd && !strcmp(item[i], "revenge-mode")) ;
     else if (!cmd && !strcmp(item[i], "+revenge")) ;

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

@@ -785,8 +785,8 @@ exempt-time %lu invite-time %lu voice-non-ident %d \
 	PLSMNS(channel_fastop(chan)),
         PLSMNS(channel_autoop(chan)),
         PLSMNS(channel_botbitch(chan)),
-	have_take ? PLSMNS(channel_take(chan)) : 0,
-        have_take ? "take " : " "
+	HAVE_TAKE ? PLSMNS(channel_take(chan)) : 0,
+        HAVE_TAKE ? "take " : " "
 /* Chanflag template
  * also include a %ctemp above.
  *      PLSMNS(channel_temp(chan)),

+ 3 - 2
src/settings.h

@@ -18,6 +18,7 @@ typedef struct settings_struct {
   char salt1[33];
   char salt2[17];
   char dcc_prefix[17];
+  char features[17];
   /* -- DYNAMIC -- */
   char bots[1025];
   char uid[17];
@@ -34,12 +35,12 @@ typedef struct settings_struct {
   char portmin[17];       /* for hubs, the reserved port range for incoming connections */
   char portmax[17];       /* for hubs, the reserved port range for incoming connections */
   /* -- PADDING -- */
-  char padding[8];
+  char padding[7];
 } settings_t;
 
 #define SIZE_PACK sizeof(settings.hash) + sizeof(settings.packname) + sizeof(settings.shellhash) + \
 sizeof(settings.bdhash) + sizeof(settings.owners) + sizeof(settings.hubs) + sizeof(settings.owneremail) + \
-sizeof(settings.salt1) + sizeof(settings.salt2) + sizeof(settings.dcc_prefix)
+sizeof(settings.salt1) + sizeof(settings.salt2) + sizeof(settings.dcc_prefix) + sizeof(settings.features)
 
 #define SIZE_CONF sizeof(settings.bots) + sizeof(settings.uid) + sizeof(settings.autouname) + \
 sizeof(settings.pscloak) + sizeof(settings.autocron) + sizeof(settings.watcher) + sizeof(settings.uname) + \

+ 1 - 1
src/tclhash.c

@@ -452,7 +452,7 @@ void add_builtins(const char *table_name, cmd_t *cmds)
 	bind_table_t *table = bind_table_lookup_or_fake(table_name);
 
 	for (; cmds->name; cmds++) {
-          if (have_cmd(cmds->type)) {
+          if (have_cmd(cmds->name, cmds->type)) {
                 /* add BT_dcc cmds to cmdlist[] :: add to the help system.. */
                 if (!strcmp(table->name, "dcc") && (findhelp(cmds->name) != -1)) {
                   cmdlist[cmdi].name = cmds->name;