(empfile, teldir, motdfil, downfil, disablefil, telfil, annfil)
(banfil, authfil, timestampfil): Make file names relative to DATADIR. (main): emp_server and files change to the data directory. fairland has to write newcap_script to the initial current directory, so it keeps it and makes file names relative to DATADIR absolute. (fixup_files): Nothing to do, remove. This fixes the following bug: fixup_files() formed file names by appending ep->name instead of the base name of ep->file to datadir. Thus, fixup_files() changed file names even when datadir had the compiled-in value. When emp_config() couldn't open econfig, it failed to call fixup_files(), and different file names got used. Note that with this revision the file names revert to the names used before fixup_files() was introduced. Closes #1146080. (print_config): Printing file names as comments is not really useful, remove. (otherfiles, ofiles): Unused, remove. (emp_config, main): Previously, pconfig had to call emp_config() even when it didn't want to read econfig, just to run fixup_files(). This is no longer necessary. Simplify.
This commit is contained in:
parent
1583d0c6a2
commit
29da4b6cf4
8 changed files with 49 additions and 92 deletions
|
@ -37,8 +37,8 @@
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
struct empfile {
|
struct empfile {
|
||||||
char *name; /* file name (e.g., "treaty") */
|
char *name; /* Empire name (e.g., "treaty") */
|
||||||
char *file; /* file path */
|
char *file; /* file name (relative to data directory) */
|
||||||
int flags; /* misc stuff */
|
int flags; /* misc stuff */
|
||||||
int mode; /* O_flags */
|
int mode; /* O_flags */
|
||||||
int size; /* size of object */
|
int size; /* size of object */
|
||||||
|
|
|
@ -88,14 +88,8 @@ emp_config(char *file)
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!file) {
|
if (!file)
|
||||||
if (!*dflt_econfig) {
|
|
||||||
/* No default econfig, use compiled in configuration */
|
|
||||||
fixup_files();
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
file = dflt_econfig;
|
file = dflt_econfig;
|
||||||
}
|
|
||||||
if ((fp = fopen(file, "r")) == NULL) {
|
if ((fp = fopen(file, "r")) == NULL) {
|
||||||
fprintf(stderr, "Can't open %s for reading (%s)\n",
|
fprintf(stderr, "Can't open %s for reading (%s)\n",
|
||||||
file, strerror(errno));
|
file, strerror(errno));
|
||||||
|
@ -163,51 +157,11 @@ emp_config(char *file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
fixup_files();
|
|
||||||
WORLD_X &= ~1; /* make even */
|
WORLD_X &= ~1; /* make even */
|
||||||
|
|
||||||
return -errors;
|
return -errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct otherfiles {
|
|
||||||
char **files;
|
|
||||||
char *name;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* list of other well known files... -maybe tailor these oneday
|
|
||||||
* anyway - meantime they are all relative to datadir */
|
|
||||||
static struct otherfiles ofiles[] = {
|
|
||||||
{&motdfil, "motd"},
|
|
||||||
{&downfil, "down"},
|
|
||||||
{&disablefil, "disable"},
|
|
||||||
{&banfil, "ban"},
|
|
||||||
{&authfil, "auth"},
|
|
||||||
{&annfil, "ann"},
|
|
||||||
{×tampfil, "timestamp"},
|
|
||||||
{&teldir, "tel"},
|
|
||||||
{&telfil, "tel/tel"},
|
|
||||||
{NULL, NULL}
|
|
||||||
};
|
|
||||||
|
|
||||||
/* fix up the empfile struct to reference full path names */
|
|
||||||
static void
|
|
||||||
fixup_files(void)
|
|
||||||
{
|
|
||||||
struct empfile *ep;
|
|
||||||
struct otherfiles *op;
|
|
||||||
s_char buf[1024];
|
|
||||||
|
|
||||||
for (ep = empfile; ep < &empfile[EF_MAX]; ep++) {
|
|
||||||
sprintf(buf, "%s/%s", datadir, ep->name);
|
|
||||||
ep->file = strdup(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (op = ofiles; op->files; op++) {
|
|
||||||
sprintf(buf, "%s/%s", datadir, op->name);
|
|
||||||
*op->files = strdup(buf);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* find the key in the table */
|
/* find the key in the table */
|
||||||
static struct keymatch *
|
static struct keymatch *
|
||||||
keylookup(register s_char *command, struct keymatch *tbl)
|
keylookup(register s_char *command, struct keymatch *tbl)
|
||||||
|
@ -226,9 +180,7 @@ keylookup(register s_char *command, struct keymatch *tbl)
|
||||||
void
|
void
|
||||||
print_config(FILE *fp)
|
print_config(FILE *fp)
|
||||||
{
|
{
|
||||||
struct empfile *ep;
|
|
||||||
struct option_list *op;
|
struct option_list *op;
|
||||||
struct otherfiles *ofp;
|
|
||||||
struct keymatch *kp;
|
struct keymatch *kp;
|
||||||
|
|
||||||
fprintf(fp, "# Empire Configuration File:\n");
|
fprintf(fp, "# Empire Configuration File:\n");
|
||||||
|
@ -267,11 +219,6 @@ print_config(FILE *fp)
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(fp, "\n");
|
fprintf(fp, "\n");
|
||||||
for (ep = empfile; ep < &empfile[EF_MAX]; ep++)
|
|
||||||
fprintf(fp, "# File %s -> %s\n", ep->name, ep->file);
|
|
||||||
for (ofp = ofiles; ofp->files; ofp++)
|
|
||||||
fprintf(fp, "# File %s -> %s\n", ofp->name, *(ofp->files));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -53,49 +53,49 @@
|
||||||
#include "commodity.h"
|
#include "commodity.h"
|
||||||
|
|
||||||
struct empfile empfile[] = {
|
struct empfile empfile[] = {
|
||||||
{"sect", EMPDIR "/data/sector", EFF_XY | EFF_OWNER,
|
{"sect", "sector", EFF_XY | EFF_OWNER,
|
||||||
0, sizeof(struct sctstr), 0, 0, 0, offsetof(struct sctstr, sct_item),
|
0, sizeof(struct sctstr), 0, 0, 0, offsetof(struct sctstr, sct_item),
|
||||||
-1, -1, 0, 0, 0, 0, 0},
|
-1, -1, 0, 0, 0, 0, 0},
|
||||||
{"ship", EMPDIR "/data/ship", EFF_XY | EFF_OWNER | EFF_GROUP,
|
{"ship", "ship", EFF_XY | EFF_OWNER | EFF_GROUP,
|
||||||
0, sizeof(struct shpstr), 0, 0, 0, offsetof(struct shpstr, shp_item),
|
0, sizeof(struct shpstr), 0, 0, 0, offsetof(struct shpstr, shp_item),
|
||||||
-1, -1, 0, 0, 0, 0, 0},
|
-1, -1, 0, 0, 0, 0, 0},
|
||||||
{"plane", EMPDIR "/data/plane", EFF_XY | EFF_OWNER | EFF_GROUP,
|
{"plane", "plane", EFF_XY | EFF_OWNER | EFF_GROUP,
|
||||||
0, sizeof(struct plnstr), 0, 0, 0, 0,
|
0, sizeof(struct plnstr), 0, 0, 0, 0,
|
||||||
-1, -1, 0, 0, 0, 0, 0},
|
-1, -1, 0, 0, 0, 0, 0},
|
||||||
{"land", EMPDIR "/data/land", EFF_XY | EFF_OWNER | EFF_GROUP,
|
{"land", "land", EFF_XY | EFF_OWNER | EFF_GROUP,
|
||||||
0, sizeof(struct lndstr), 0, 0, 0, offsetof(struct lndstr, lnd_item),
|
0, sizeof(struct lndstr), 0, 0, 0, offsetof(struct lndstr, lnd_item),
|
||||||
-1, -1, 0, 0, 0, 0, 0},
|
-1, -1, 0, 0, 0, 0, 0},
|
||||||
{"nuke", EMPDIR "/data/nuke", EFF_XY | EFF_OWNER,
|
{"nuke", "nuke", EFF_XY | EFF_OWNER,
|
||||||
0, sizeof(struct nukstr), 0, 0, 0, 0,
|
0, sizeof(struct nukstr), 0, 0, 0, 0,
|
||||||
-1, -1, 0, 0, 0, 0, 0},
|
-1, -1, 0, 0, 0, 0, 0},
|
||||||
{"news", EMPDIR "/data/news", 0,
|
{"news", "news", 0,
|
||||||
0, sizeof(struct nwsstr), 0, 0, 0, 0,
|
0, sizeof(struct nwsstr), 0, 0, 0, 0,
|
||||||
-1, -1, 0, 0, 0, 0, 0},
|
-1, -1, 0, 0, 0, 0, 0},
|
||||||
{"treaty", EMPDIR "/data/treaty", 0,
|
{"treaty", "treaty", 0,
|
||||||
0, sizeof(struct trtstr), 0, 0, 0, 0,
|
0, sizeof(struct trtstr), 0, 0, 0, 0,
|
||||||
-1, -1, 0, 0, 0, 0, 0},
|
-1, -1, 0, 0, 0, 0, 0},
|
||||||
{"trade", EMPDIR "/data/trade", 0,
|
{"trade", "trade", 0,
|
||||||
0, sizeof(struct trdstr), 0, 0, 0, 0,
|
0, sizeof(struct trdstr), 0, 0, 0, 0,
|
||||||
-1, -1, 0, 0, 0, 0, 0},
|
-1, -1, 0, 0, 0, 0, 0},
|
||||||
{"pow", EMPDIR "/data/power", 0,
|
{"pow", "power", 0,
|
||||||
0, sizeof(struct powstr), 0, 0, 0, 0,
|
0, sizeof(struct powstr), 0, 0, 0, 0,
|
||||||
-1, -1, 0, 0, 0, 0, 0},
|
-1, -1, 0, 0, 0, 0, 0},
|
||||||
{"nat", EMPDIR "/data/nation", 0,
|
{"nat", "nation", 0,
|
||||||
0, sizeof(struct natstr), 0, 0, 0, 0,
|
0, sizeof(struct natstr), 0, 0, 0, 0,
|
||||||
-1, -1, 0, 0, 0, 0, 0},
|
-1, -1, 0, 0, 0, 0, 0},
|
||||||
{"loan", EMPDIR "/data/loan", 0,
|
{"loan", "loan", 0,
|
||||||
0, sizeof(struct lonstr), 0, 0, 0, 0,
|
0, sizeof(struct lonstr), 0, 0, 0, 0,
|
||||||
-1, -1, 0, 0, 0, 0, 0},
|
-1, -1, 0, 0, 0, 0, 0},
|
||||||
{"map", EMPDIR "/data/map", 0,
|
{"map", "map", 0,
|
||||||
0, DEF_WORLD_X * DEF_WORLD_Y / 2, 0, 0, 0, 0,
|
0, DEF_WORLD_X * DEF_WORLD_Y / 2, 0, 0, 0, 0,
|
||||||
-1, -1, 0, 0, 0, 0, 0},
|
-1, -1, 0, 0, 0, 0, 0},
|
||||||
{"bmap", EMPDIR "/data/bmap", 0,
|
{"bmap", "bmap", 0,
|
||||||
0, DEF_WORLD_X * DEF_WORLD_Y / 2, 0, 0, 0, 0,
|
0, DEF_WORLD_X * DEF_WORLD_Y / 2, 0, 0, 0, 0,
|
||||||
-1, -1, 0, 0, 0, 0, 0},
|
-1, -1, 0, 0, 0, 0, 0},
|
||||||
{"commodity", EMPDIR "/data/commodity", 0,
|
{"commodity", "commodity", 0,
|
||||||
0, sizeof(struct comstr), 0, 0, 0, 0,
|
0, sizeof(struct comstr), 0, 0, 0, 0,
|
||||||
-1, -1, 0, 0, 0, 0, 0},
|
-1, -1, 0, 0, 0, 0, 0},
|
||||||
{"lost", EMPDIR "/data/lostitems", 0, 0,
|
{"lost", "lostitems", 0, 0,
|
||||||
sizeof(struct loststr), 0, 0, 0, 0,
|
sizeof(struct loststr), 0, 0, 0, 0,
|
||||||
-1, -1, 0, 0, 0, 0, 0}
|
-1, -1, 0, 0, 0, 0, 0}
|
||||||
};
|
};
|
||||||
|
|
|
@ -38,15 +38,16 @@ char dflt_econfig[] = EMPDIR "/data/econfig";
|
||||||
|
|
||||||
char *infodir = EMPDIR "/info.nr";
|
char *infodir = EMPDIR "/info.nr";
|
||||||
char *datadir = EMPDIR "/data";
|
char *datadir = EMPDIR "/data";
|
||||||
char *teldir = EMPDIR "/data/tel";
|
|
||||||
|
|
||||||
char *motdfil = EMPDIR "/data/motd";
|
/* relative to DATADIR */
|
||||||
char *downfil = EMPDIR "/data/down";
|
char *teldir = "tel";
|
||||||
char *disablefil = EMPDIR "/data/disable";
|
char *motdfil = "motd";
|
||||||
char *telfil = EMPDIR "/data/tel/tel";
|
char *downfil = "down";
|
||||||
char *annfil = EMPDIR "/data/ann";
|
char *disablefil = "disable";
|
||||||
char *banfil = EMPDIR "/data/ban";
|
char *telfil = "tel/tel";
|
||||||
char *authfil = EMPDIR "/data/auth";
|
char *annfil = "ann";
|
||||||
char *timestampfil = EMPDIR "/data/timestamp";
|
char *banfil = "ban";
|
||||||
|
char *authfil = "auth";
|
||||||
|
char *timestampfil = "timestamp";
|
||||||
|
|
||||||
char *loginport = EMP_PORT;
|
char *loginport = EMP_PORT;
|
||||||
|
|
|
@ -37,6 +37,7 @@
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
#include <sys/ioctl.h>
|
#include <sys/ioctl.h>
|
||||||
#endif
|
#endif
|
||||||
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
@ -187,6 +188,10 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
if (emp_config(config_file) < 0)
|
if (emp_config(config_file) < 0)
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
if (chdir(datadir)) {
|
||||||
|
fprintf(stderr, "Can't chdir to %s (%s)\n", datadir, strerror(errno));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
if (install_service_set)
|
if (install_service_set)
|
||||||
|
|
|
@ -64,13 +64,11 @@ static int quiet = 0;
|
||||||
/* lower URAN_MIN for more uranium */
|
/* lower URAN_MIN for more uranium */
|
||||||
#define URAN_MIN 56
|
#define URAN_MIN 56
|
||||||
|
|
||||||
#if defined(aix) || defined(linux) || defined(solaris)
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif /* aix or linux */
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#include "../lib/gen/getopt.h"
|
#include "../lib/gen/getopt.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <errno.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
@ -402,12 +400,16 @@ static int
|
||||||
allocate_memory(void)
|
allocate_memory(void)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
char *fname;
|
||||||
|
|
||||||
sect_fptr = fopen(empfile[EF_SECTOR].file, "wb");
|
fname = malloc(strlen(datadir) + 1 + strlen(empfile[EF_SECTOR].file) + 1);
|
||||||
|
sprintf(fname, "%s/%s", datadir, empfile[EF_SECTOR].file);
|
||||||
|
sect_fptr = fopen(fname, "wb");
|
||||||
if (sect_fptr == NULL) {
|
if (sect_fptr == NULL) {
|
||||||
perror(empfile[EF_SECTOR].file);
|
perror(fname);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
free(fname);
|
||||||
sectsbuf =
|
sectsbuf =
|
||||||
(struct sctstr *)calloc((YSIZE * XSIZE), sizeof(struct sctstr));
|
(struct sctstr *)calloc((YSIZE * XSIZE), sizeof(struct sctstr));
|
||||||
sects = (struct sctstr **)calloc(YSIZE, sizeof(struct sctstr *));
|
sects = (struct sctstr **)calloc(YSIZE, sizeof(struct sctstr *));
|
||||||
|
|
|
@ -33,10 +33,6 @@
|
||||||
* Steve McClure, 1998
|
* Steve McClure, 1998
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(aix) || defined(linux) || defined(solaris)
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif /* aix or linux */
|
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
|
@ -46,6 +42,7 @@
|
||||||
#include <direct.h>
|
#include <direct.h>
|
||||||
#include "../lib/gen/getopt.h"
|
#include "../lib/gen/getopt.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include <errno.h>
|
||||||
#include <stdarg.h>
|
#include <stdarg.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
|
@ -112,6 +109,11 @@ main(int argc, char *argv[])
|
||||||
printf("Can't make game directory\n");
|
printf("Can't make game directory\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
if (chdir(datadir)) {
|
||||||
|
fprintf(stderr, "Can't chdir to %s (%s)\n", datadir, strerror(errno));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
if (!force) {
|
if (!force) {
|
||||||
printf("WARNING: this blasts the existing game in %s (if any)\n",
|
printf("WARNING: this blasts the existing game in %s (if any)\n",
|
||||||
datadir);
|
datadir);
|
||||||
|
|
|
@ -38,9 +38,9 @@
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
*dflt_econfig = 0; /* don't read default econfig */
|
if (argc > 1)
|
||||||
if (emp_config(argc > 1 ? argv[1] : NULL) < 0)
|
if (emp_config(argv[1]) < 0)
|
||||||
exit(1);
|
exit(1);
|
||||||
print_config(stdout);
|
print_config(stdout);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue