Merge pre-4-2-20-invasive. Summary of changes:
* Acquire resources before daemonizing, fail in foreground * Initialize threads and signals after daemonizing * Make most file names relative to data directory * emp_server and files make it their working directory * emp_config() no longer screws up some file names * Missing or incorrect econfig is now fatal * Don't log to default log file when econfig changes it
This commit is contained in:
commit
5b57f4c222
17 changed files with 201 additions and 267 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 */
|
||||||
|
|
|
@ -34,6 +34,8 @@
|
||||||
#ifndef _ITEM_H_
|
#ifndef _ITEM_H_
|
||||||
#define _ITEM_H_
|
#define _ITEM_H_
|
||||||
|
|
||||||
|
#include "misc.h"
|
||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
IPKG, /* "inefficient" packaging (eff<60) */
|
IPKG, /* "inefficient" packaging (eff<60) */
|
||||||
NPKG, /* no special packaging */
|
NPKG, /* no special packaging */
|
||||||
|
|
|
@ -124,6 +124,7 @@ typedef short coord;
|
||||||
#define days(x) (60*60*24*(x))
|
#define days(x) (60*60*24*(x))
|
||||||
|
|
||||||
extern int debug;
|
extern int debug;
|
||||||
|
extern int daemonize;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If EXPR is true, an internal error occured.
|
* If EXPR is true, an internal error occured.
|
||||||
|
|
|
@ -37,6 +37,9 @@
|
||||||
|
|
||||||
#include "nsc.h"
|
#include "nsc.h"
|
||||||
|
|
||||||
|
/* Default econfig file */
|
||||||
|
extern char dflt_econfig[];
|
||||||
|
|
||||||
struct option_list {
|
struct option_list {
|
||||||
char *opt_key;
|
char *opt_key;
|
||||||
int *opt_valuep;
|
int *opt_valuep;
|
||||||
|
|
|
@ -48,7 +48,8 @@
|
||||||
extern void close_files(void);
|
extern void close_files(void);
|
||||||
extern void panic(int sig);
|
extern void panic(int sig);
|
||||||
extern void shutdwn(int sig);
|
extern void shutdwn(int sig);
|
||||||
extern void start_server(int, char *);
|
extern void init_server(void);
|
||||||
|
extern void start_server(int);
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
extern void loc_NTTerm(void);
|
extern void loc_NTTerm(void);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -35,9 +35,9 @@
|
||||||
#define SERVICE_H
|
#define SERVICE_H
|
||||||
|
|
||||||
#define DEFAULT_SERVICE_NAME "Empire Server"
|
#define DEFAULT_SERVICE_NAME "Empire Server"
|
||||||
extern char *config_file;
|
|
||||||
|
|
||||||
extern int install_service(char *program_name, char *service_name, int datadir_set);
|
extern int install_service(char *program_name, char *service_name,
|
||||||
|
int datadir_set, char *config_file);
|
||||||
extern int remove_service(char *service_name);
|
extern int remove_service(char *service_name);
|
||||||
extern void WINAPI service_main(DWORD argc, LPTSTR *argv);
|
extern void WINAPI service_main(DWORD argc, LPTSTR *argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -472,7 +472,7 @@ empth_exit(void)
|
||||||
if (pThread->bMainThread) {
|
if (pThread->bMainThread) {
|
||||||
/* The main line. Wait forever. */
|
/* The main line. Wait forever. */
|
||||||
while (1) {
|
while (1) {
|
||||||
if (!debug) {
|
if (daemonize) {
|
||||||
if (service_stopped())
|
if (service_stopped())
|
||||||
shutdwn(0);
|
shutdwn(0);
|
||||||
Sleep(3);
|
Sleep(3);
|
||||||
|
|
|
@ -54,7 +54,7 @@ disassoc(void)
|
||||||
|
|
||||||
if (fork() != 0)
|
if (fork() != 0)
|
||||||
exit(0);
|
exit(0);
|
||||||
for (i = 0; i < 10; i++)
|
for (i = 0; i < 2; i++)
|
||||||
(void)close(i);
|
(void)close(i);
|
||||||
(void)open("/", O_RDONLY, 0);
|
(void)open("/", O_RDONLY, 0);
|
||||||
(void)dup2(0, 1);
|
(void)dup2(0, 1);
|
||||||
|
|
|
@ -88,10 +88,8 @@ emp_config(char *file)
|
||||||
int errors = 0;
|
int errors = 0;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (file == NULL) {
|
if (!file)
|
||||||
fixup_files();
|
file = dflt_econfig;
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
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));
|
||||||
|
@ -159,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)
|
||||||
|
@ -222,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");
|
||||||
|
@ -263,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));
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,14 +36,10 @@
|
||||||
|
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "service.h"
|
#include "service.h"
|
||||||
#include "../gen/getopt.h"
|
|
||||||
#include "optlist.h"
|
#include "optlist.h"
|
||||||
|
|
||||||
|
|
||||||
char *config_file = NULL;
|
|
||||||
|
|
||||||
int
|
int
|
||||||
install_service(char *program_name, char *service_name, int datadir_set)
|
install_service(char *program_name, char *service_name, int datadir_set, char *config_file)
|
||||||
{
|
{
|
||||||
char strDir[1024];
|
char strDir[1024];
|
||||||
HANDLE schSCManager,schService;
|
HANDLE schSCManager,schService;
|
||||||
|
@ -74,8 +70,7 @@ install_service(char *program_name, char *service_name, int datadir_set)
|
||||||
schSCManager = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
|
schSCManager = OpenSCManager(NULL,NULL,SC_MANAGER_ALL_ACCESS);
|
||||||
|
|
||||||
if (schSCManager == NULL) {
|
if (schSCManager == NULL) {
|
||||||
logerror("install_service failed to open Service Control Manager");
|
fprintf(stderr, "install_service failed to open Service Control Manager\n");
|
||||||
printf("Install service: failed to open Service Control Manager.\n");
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,8 +91,7 @@ install_service(char *program_name, char *service_name, int datadir_set)
|
||||||
NULL); /* no password */
|
NULL); /* no password */
|
||||||
|
|
||||||
if (schService == NULL) {
|
if (schService == NULL) {
|
||||||
logerror("install_service failed to create service %s", service_name);
|
fprintf(stderr, "install_service failed to create service %s\n", service_name);
|
||||||
printf("Install service: failed to create service %s.\n", service_name);
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
sdBuf.lpDescription = "Server for Empire game";
|
sdBuf.lpDescription = "Server for Empire game";
|
||||||
|
@ -106,11 +100,9 @@ install_service(char *program_name, char *service_name, int datadir_set)
|
||||||
schService, /* handle to service */
|
schService, /* handle to service */
|
||||||
SERVICE_CONFIG_DESCRIPTION, /* change: description */
|
SERVICE_CONFIG_DESCRIPTION, /* change: description */
|
||||||
&sdBuf)) { /* value: new description */
|
&sdBuf)) { /* value: new description */
|
||||||
logerror("install_service failed to set the description");
|
fprintf(stderr, "install_service failed to set the description\n");
|
||||||
printf("Install service: failed to set the description.\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
logerror("install_service successfully created the service %s", service_name);
|
|
||||||
printf("Service %s installed.\n", service_name);
|
printf("Service %s installed.\n", service_name);
|
||||||
CloseServiceHandle(schService);
|
CloseServiceHandle(schService);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
@ -130,31 +122,26 @@ remove_service(char *service_name)
|
||||||
schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_ALL_ACCESS);
|
||||||
|
|
||||||
if (schSCManager == NULL) {
|
if (schSCManager == NULL) {
|
||||||
logerror("remove_service failed to open Service Control Manager");
|
fprintf(stderr, "remove_service failed to open Service Control Manager\n");
|
||||||
printf("remove service: failed to open Service Control Manager.\n");
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
hService = OpenService(schSCManager, service_name, SERVICE_ALL_ACCESS);
|
hService = OpenService(schSCManager, service_name, SERVICE_ALL_ACCESS);
|
||||||
|
|
||||||
if (hService == NULL) {
|
if (hService == NULL) {
|
||||||
logerror("remove_service failed to open service %s", service_name);
|
fprintf(stderr, "remove_service failed to open service %s\n", service_name);
|
||||||
printf("Remove service: failed to open service %s.\n", service_name);
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DeleteService(hService) == 0) {
|
if (DeleteService(hService) == 0) {
|
||||||
logerror("remove_service failed to remove service %s", service_name);
|
fprintf(stderr, "remove_service failed to remove service %s\n", service_name);
|
||||||
printf("Remove service: failed to remove service %s.\n", service_name);
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (CloseServiceHandle(hService) == 0) {
|
if (CloseServiceHandle(hService) == 0) {
|
||||||
logerror("remove_service failed to close service %s", service_name);
|
fprintf(stderr, "remove_service failed to close service %s\n", service_name);
|
||||||
printf("Remove service: failed to close service %s.\n", service_name);
|
|
||||||
return EXIT_FAILURE;
|
return EXIT_FAILURE;
|
||||||
} else {
|
} else {
|
||||||
logerror("remove_service successfully removed service %s", service_name);
|
|
||||||
printf("Service %s removed.\n", service_name);
|
printf("Service %s removed.\n", service_name);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
@ -216,28 +203,6 @@ service_ctrl_handler(DWORD Opcode)
|
||||||
void WINAPI
|
void WINAPI
|
||||||
service_main(DWORD argc, LPTSTR *argv)
|
service_main(DWORD argc, LPTSTR *argv)
|
||||||
{
|
{
|
||||||
int op;
|
|
||||||
s_char tbuf[256];
|
|
||||||
DWORD status;
|
|
||||||
|
|
||||||
optind = 1;
|
|
||||||
opterr = 1;
|
|
||||||
while ((op = getopt(argc, argv, "D:e:")) != EOF) {
|
|
||||||
switch (op) {
|
|
||||||
case 'D':
|
|
||||||
datadir = optarg;
|
|
||||||
break;
|
|
||||||
case 'e':
|
|
||||||
config_file = optarg;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config_file == NULL) {
|
|
||||||
sprintf(tbuf, "%s/econfig", datadir);
|
|
||||||
config_file = tbuf;
|
|
||||||
}
|
|
||||||
|
|
||||||
service_status.dwServiceType = SERVICE_WIN32;
|
service_status.dwServiceType = SERVICE_WIN32;
|
||||||
service_status.dwCurrentState = SERVICE_START_PENDING;
|
service_status.dwCurrentState = SERVICE_START_PENDING;
|
||||||
service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
|
service_status.dwControlsAccepted = SERVICE_ACCEPT_STOP;
|
||||||
|
@ -254,8 +219,7 @@ service_main(DWORD argc, LPTSTR *argv)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialization code goes here. */
|
start_server(0);
|
||||||
start_server(0, config_file);
|
|
||||||
|
|
||||||
/* Initialization complete - report running status. */
|
/* Initialization complete - report running status. */
|
||||||
service_status.dwCurrentState = SERVICE_RUNNING;
|
service_status.dwCurrentState = SERVICE_RUNNING;
|
||||||
|
@ -263,18 +227,17 @@ service_main(DWORD argc, LPTSTR *argv)
|
||||||
service_status.dwWaitHint = 0;
|
service_status.dwWaitHint = 0;
|
||||||
|
|
||||||
if (!SetServiceStatus (service_status_handle, &service_status)) {
|
if (!SetServiceStatus (service_status_handle, &service_status)) {
|
||||||
status = GetLastError();
|
logerror("SetServiceStatus error %ld\n", GetLastError());
|
||||||
logerror("SetServiceStatus error %ld\n",status);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
empth_exit();
|
empth_exit();
|
||||||
|
|
||||||
/* We should never get here. But, just in case... */
|
/* We should never get here. But, just in case... */
|
||||||
close_files();
|
close_files();
|
||||||
|
|
||||||
loc_NTTerm();
|
loc_NTTerm();
|
||||||
|
|
||||||
// This is where the service does its work.
|
/* This is where the service does its work. */
|
||||||
logerror("Returning the Main Thread \n",0);
|
logerror("Returning the Main Thread \n",0);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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}
|
||||||
};
|
};
|
||||||
|
|
|
@ -33,19 +33,21 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "gamesdef.h"
|
#include "gamesdef.h"
|
||||||
#include "misc.h"
|
|
||||||
|
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;
|
||||||
|
|
|
@ -63,13 +63,61 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
struct emp_qelem Players;
|
static struct emp_qelem Players;
|
||||||
|
static int player_socket;
|
||||||
|
|
||||||
void
|
void
|
||||||
player_init(void)
|
player_init(void)
|
||||||
{
|
{
|
||||||
|
struct sockaddr_in sin;
|
||||||
|
struct servent *sp;
|
||||||
|
int s;
|
||||||
|
short port;
|
||||||
|
int val;
|
||||||
|
|
||||||
emp_initque(&Players);
|
emp_initque(&Players);
|
||||||
init_player_commands();
|
init_player_commands();
|
||||||
|
|
||||||
|
|
||||||
|
sp = getservbyname("empire", "tcp");
|
||||||
|
if (sp == 0)
|
||||||
|
port = htons(atoi(loginport));
|
||||||
|
else
|
||||||
|
port = sp->s_port;
|
||||||
|
sin.sin_addr.s_addr = INADDR_ANY;
|
||||||
|
sin.sin_port = port;
|
||||||
|
sin.sin_family = AF_INET;
|
||||||
|
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
||||||
|
logerror("inet socket create");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
val = 1;
|
||||||
|
#if !(defined(__linux__) && defined(__alpha__))
|
||||||
|
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val))
|
||||||
|
< 0) {
|
||||||
|
logerror("inet socket setsockopt SO_REUSEADDR (%d)", errno);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
logerror("Alpha/Linux? You don't support SO_REUSEADDR yet, do you?\n");
|
||||||
|
#endif
|
||||||
|
if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
|
||||||
|
logerror("inet socket bind");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
#ifdef LISTENMAXCONN /* because someone in linux world didn't want to use
|
||||||
|
* SOMAXCONN as defined in the header files... */
|
||||||
|
if (listen(s, LISTENMAXCONN) < 0) {
|
||||||
|
logerror("inet socket listen");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
if (listen(s, SOMAXCONN) < 0) {
|
||||||
|
logerror("inet socket listen");
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
player_socket = s;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct player *
|
struct player *
|
||||||
|
@ -199,10 +247,7 @@ void
|
||||||
player_accept(void *unused)
|
player_accept(void *unused)
|
||||||
{
|
{
|
||||||
struct sockaddr_in sin;
|
struct sockaddr_in sin;
|
||||||
struct servent *sp;
|
int s = player_socket;
|
||||||
int s;
|
|
||||||
short port;
|
|
||||||
int val;
|
|
||||||
struct player *np;
|
struct player *np;
|
||||||
int len;
|
int len;
|
||||||
int ns;
|
int ns;
|
||||||
|
@ -210,45 +255,6 @@ player_accept(void *unused)
|
||||||
int stacksize;
|
int stacksize;
|
||||||
char buf[128];
|
char buf[128];
|
||||||
|
|
||||||
player_init();
|
|
||||||
sp = getservbyname("empire", "tcp");
|
|
||||||
if (sp == 0)
|
|
||||||
port = htons(atoi(loginport));
|
|
||||||
else
|
|
||||||
port = sp->s_port;
|
|
||||||
sin.sin_addr.s_addr = INADDR_ANY;
|
|
||||||
sin.sin_port = port;
|
|
||||||
sin.sin_family = AF_INET;
|
|
||||||
if ((s = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
|
|
||||||
logerror("inet socket create");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
val = 1;
|
|
||||||
#if !(defined(__linux__) && defined(__alpha__))
|
|
||||||
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *)&val, sizeof(val))
|
|
||||||
< 0) {
|
|
||||||
logerror("inet socket setsockopt SO_REUSEADDR (%d)", errno);
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
logerror("Alpha/Linux? You don't support SO_REUSEADDR yet, do you?\n");
|
|
||||||
#endif
|
|
||||||
if (bind(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
|
|
||||||
logerror("inet socket bind");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
#ifdef LISTENMAXCONN /* because someone in linux world didn't want to use
|
|
||||||
* SOMAXCONN as defined in the header files... */
|
|
||||||
if (listen(s, LISTENMAXCONN) < 0) {
|
|
||||||
logerror("inet socket listen");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
#else
|
|
||||||
if (listen(s, SOMAXCONN) < 0) {
|
|
||||||
logerror("inet socket listen");
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
while (1) {
|
while (1) {
|
||||||
empth_select(s, EMPTH_FD_READ);
|
empth_select(s, EMPTH_FD_READ);
|
||||||
len = sizeof(sin);
|
len = sizeof(sin);
|
||||||
|
|
|
@ -33,14 +33,11 @@
|
||||||
* Doug Hay, 1998
|
* Doug Hay, 1998
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#if defined(aix) || defined(linux)
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif /* aix or linux */
|
|
||||||
|
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#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>
|
||||||
|
@ -51,6 +48,7 @@
|
||||||
#include <process.h>
|
#include <process.h>
|
||||||
#include "../lib/gen/getopt.h"
|
#include "../lib/gen/getopt.h"
|
||||||
#include "service.h"
|
#include "service.h"
|
||||||
|
#include "direct.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "misc.h"
|
#include "misc.h"
|
||||||
|
@ -77,12 +75,10 @@ static void loc_NTInit(void);
|
||||||
|
|
||||||
static int mainpid = 0;
|
static int mainpid = 0;
|
||||||
|
|
||||||
/*
|
/* Debugging? If yes call abort() on internal error. */
|
||||||
* Debugging?
|
|
||||||
* If yes, don't fork into background, don't catch certain signals,
|
|
||||||
* call abort() on internal error.
|
|
||||||
*/
|
|
||||||
int debug = 0;
|
int debug = 0;
|
||||||
|
/* Run as daemon? If yes, detach from controlling terminal etc. */
|
||||||
|
int daemonize = 1;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_usage(char *program_name)
|
print_usage(char *program_name)
|
||||||
|
@ -108,11 +104,12 @@ main(int argc, char **argv)
|
||||||
char *service_name = NULL;
|
char *service_name = NULL;
|
||||||
int remove_service_set = 0;
|
int remove_service_set = 0;
|
||||||
int datadir_set = 0;
|
int datadir_set = 0;
|
||||||
#else
|
|
||||||
char *config_file = NULL;
|
|
||||||
#endif
|
#endif
|
||||||
|
char *config_file = NULL;
|
||||||
int op;
|
int op;
|
||||||
|
#if defined(__linux__) && defined(_EMPTH_POSIX)
|
||||||
s_char tbuf[256];
|
s_char tbuf[256];
|
||||||
|
#endif
|
||||||
|
|
||||||
mainpid = getpid();
|
mainpid = getpid();
|
||||||
|
|
||||||
|
@ -130,6 +127,7 @@ main(int argc, char **argv)
|
||||||
break;
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
debug++;
|
debug++;
|
||||||
|
daemonize = 0;
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
config_file = optarg;
|
config_file = optarg;
|
||||||
|
@ -155,9 +153,11 @@ main(int argc, char **argv)
|
||||||
#else
|
#else
|
||||||
case 'p':
|
case 'p':
|
||||||
flags |= EMPTH_PRINT;
|
flags |= EMPTH_PRINT;
|
||||||
|
daemonize = 0;
|
||||||
break;
|
break;
|
||||||
case 's':
|
case 's':
|
||||||
flags |= EMPTH_PRINT | EMPTH_STACKCHECK;
|
flags |= EMPTH_PRINT | EMPTH_STACKCHECK;
|
||||||
|
daemonize = 0;
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
case 'h':
|
case 'h':
|
||||||
|
@ -167,64 +167,68 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loginit("server");
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
if ((debug || datadir_set || config_file != NULL) &&
|
if ((debug || datadir_set || config_file != NULL) &&
|
||||||
remove_service_set) {
|
remove_service_set) {
|
||||||
logerror("Can't use -d, -D or -e with either "
|
fprintf(stderr, "Can't use -d, -D or -e with either "
|
||||||
"-r or -R options when starting the server");
|
"-r or -R options when starting the server\n");
|
||||||
printf("Can't use -d, -D or -e with either -r "
|
|
||||||
"or -R options\n");
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
if (debug && install_service_set) {
|
if (debug && install_service_set) {
|
||||||
logerror("Can't use -d with either "
|
fprintf(stderr, "Can't use -d with either "
|
||||||
"-i or -I options when starting the server");
|
"-i or -I options when starting the server\n");
|
||||||
printf("Can't use -d with either -i "
|
|
||||||
"or -I options\n");
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
if (install_service_set && remove_service_set) {
|
if (install_service_set && remove_service_set) {
|
||||||
logerror("Can't use both -r or -R and -i or -I options when starting "
|
fprintf(stderr, "Can't use both -r or -R and -i or -I options when starting "
|
||||||
"the server");
|
"the server\n");
|
||||||
printf("Can't use both -r or -R and -i or -I options\n");
|
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
if (install_service_set)
|
#endif /* _WIN32 */
|
||||||
return install_service(argv[0], service_name, datadir_set);
|
|
||||||
|
|
||||||
|
#if defined(_WIN32)
|
||||||
if (remove_service_set)
|
if (remove_service_set)
|
||||||
return remove_service(service_name);
|
return remove_service(service_name);
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
if (config_file == NULL) {
|
if (emp_config(config_file) < 0)
|
||||||
sprintf(tbuf, "%s/econfig", datadir);
|
exit(EXIT_FAILURE);
|
||||||
config_file = tbuf;
|
if (chdir(datadir)) {
|
||||||
|
fprintf(stderr, "Can't chdir to %s (%s)\n", datadir, strerror(errno));
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
logerror("------------------------------------------------------");
|
#if defined(_WIN32)
|
||||||
logerror("Empire server (pid %d) started", (int)getpid());
|
if (install_service_set)
|
||||||
|
return install_service(argv[0], service_name, datadir_set, config_file);
|
||||||
|
#endif /* _WIN32 */
|
||||||
|
|
||||||
|
init_server();
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
if (debug == 0) {
|
if (daemonize != 0) {
|
||||||
SERVICE_TABLE_ENTRY DispatchTable[]={{"Empire Server", service_main},{NULL, NULL}};
|
SERVICE_TABLE_ENTRY DispatchTable[]={{"Empire Server", service_main},{NULL, NULL}};
|
||||||
if (StartServiceCtrlDispatcher(DispatchTable))
|
if (StartServiceCtrlDispatcher(DispatchTable))
|
||||||
return 0;
|
return 0;
|
||||||
else
|
else {
|
||||||
|
/*
|
||||||
|
* If it is service startup error then exit otherwise
|
||||||
|
* start server in the foreground
|
||||||
|
*/
|
||||||
if (GetLastError() != ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) {
|
if (GetLastError() != ERROR_FAILED_SERVICE_CONTROLLER_CONNECT) {
|
||||||
logerror("Failed to dispatch service (%d)", GetLastError());
|
logerror("Failed to dispatch service (%d)", GetLastError());
|
||||||
printf("Failed to dispatch service (%d)\n", GetLastError());
|
printf("Failed to dispatch service (%d)\n", GetLastError());
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
} else /* start in the foreground */
|
|
||||||
debug = 1;
|
|
||||||
}
|
}
|
||||||
#else
|
}
|
||||||
if (debug == 0 && flags == 0) {
|
}
|
||||||
|
daemonize = 0;
|
||||||
|
#else /* !_WIN32 */
|
||||||
|
if (daemonize)
|
||||||
disassoc();
|
disassoc();
|
||||||
}
|
#endif /* !_WIN32 */
|
||||||
#endif
|
start_server(flags);
|
||||||
|
|
||||||
start_server(flags, config_file);
|
|
||||||
|
|
||||||
#if defined(__linux__) && defined(_EMPTH_POSIX)
|
#if defined(__linux__) && defined(_EMPTH_POSIX)
|
||||||
strcpy(tbuf, argv[0]);
|
strcpy(tbuf, argv[0]);
|
||||||
|
@ -248,20 +252,39 @@ main(int argc, char **argv)
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
start_server(int flags, char *config_file)
|
init_server(void)
|
||||||
|
{
|
||||||
|
srand(time(NULL));
|
||||||
|
#if defined(_WIN32)
|
||||||
|
loc_NTInit();
|
||||||
|
#endif
|
||||||
|
update_policy_check();
|
||||||
|
nullify_objects();
|
||||||
|
global_init();
|
||||||
|
shutdown_init();
|
||||||
|
player_init();
|
||||||
|
ef_init();
|
||||||
|
init_files();
|
||||||
|
io_init();
|
||||||
|
init_nreport();
|
||||||
|
|
||||||
|
if (opt_MOB_ACCESS) {
|
||||||
|
/* This fixes up mobility upon restart */
|
||||||
|
mobility_init();
|
||||||
|
}
|
||||||
|
|
||||||
|
loginit("server");
|
||||||
|
logerror("------------------------------------------------------");
|
||||||
|
logerror("Empire server (pid %d) started", (int)getpid());
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
start_server(int flags)
|
||||||
{
|
{
|
||||||
#ifdef POSIXSIGNALS
|
#ifdef POSIXSIGNALS
|
||||||
struct sigaction act;
|
struct sigaction act;
|
||||||
#endif /* POSIXSIGNALS */
|
#endif /* POSIXSIGNALS */
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
loc_NTInit();
|
|
||||||
#endif
|
|
||||||
emp_config(config_file);
|
|
||||||
update_policy_check();
|
|
||||||
|
|
||||||
nullify_objects();
|
|
||||||
|
|
||||||
#if !defined(_WIN32)
|
#if !defined(_WIN32)
|
||||||
/* signal() should not be used with mit pthreads. Anyway if u
|
/* signal() should not be used with mit pthreads. Anyway if u
|
||||||
have a posix threads u definitly have posix signals -- Sasha */
|
have a posix threads u definitly have posix signals -- Sasha */
|
||||||
|
@ -302,20 +325,8 @@ start_server(int flags, char *config_file)
|
||||||
signal(SIGPIPE, SIG_IGN);
|
signal(SIGPIPE, SIG_IGN);
|
||||||
#endif /* POSIXSIGNALS */
|
#endif /* POSIXSIGNALS */
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
empth_init((char **)&player, flags);
|
|
||||||
srand(time(NULL));
|
|
||||||
global_init();
|
|
||||||
shutdown_init();
|
|
||||||
player_init();
|
|
||||||
ef_init();
|
|
||||||
init_files();
|
|
||||||
io_init();
|
|
||||||
init_nreport();
|
|
||||||
|
|
||||||
if (opt_MOB_ACCESS) {
|
empth_init((char **)&player, flags);
|
||||||
/* This fixes up mobility upon restart */
|
|
||||||
mobility_init();
|
|
||||||
}
|
|
||||||
|
|
||||||
empth_create(PP_ACCEPT, player_accept, (50 * 1024), flags,
|
empth_create(PP_ACCEPT, player_accept, (50 * 1024), flags,
|
||||||
"AcceptPlayers", "Accept network connections", 0);
|
"AcceptPlayers", "Accept network connections", 0);
|
||||||
|
|
|
@ -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>
|
||||||
|
@ -191,7 +189,6 @@ main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
int opt;
|
int opt;
|
||||||
char *config_file = NULL;
|
char *config_file = NULL;
|
||||||
char tbuf[512];
|
|
||||||
int i = 0;
|
int i = 0;
|
||||||
|
|
||||||
rnd_seed = time(NULL);
|
rnd_seed = time(NULL);
|
||||||
|
@ -222,11 +219,8 @@ main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
srandom(rnd_seed);
|
srandom(rnd_seed);
|
||||||
if (config_file == NULL) {
|
if (emp_config(config_file))
|
||||||
sprintf(tbuf, "%s/econfig", datadir);
|
exit(1);
|
||||||
config_file = tbuf;
|
|
||||||
}
|
|
||||||
emp_config(config_file);
|
|
||||||
|
|
||||||
parse_args(argc - optind, argv + optind);
|
parse_args(argc - optind, argv + optind);
|
||||||
if (allocate_memory() == -1)
|
if (allocate_memory() == -1)
|
||||||
|
@ -406,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>
|
||||||
|
|
||||||
|
@ -77,7 +74,6 @@ int
|
||||||
main(int argc, char *argv[])
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
s_char buf[255];
|
s_char buf[255];
|
||||||
s_char tbuf[512];
|
|
||||||
s_char *filename;
|
s_char *filename;
|
||||||
int x, y;
|
int x, y;
|
||||||
struct natstr nat;
|
struct natstr nat;
|
||||||
|
@ -102,12 +98,9 @@ main(int argc, char *argv[])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Try to use the existing data directory */
|
if (emp_config(config_file) < 0)
|
||||||
if (config_file == NULL) {
|
exit(1);
|
||||||
sprintf(tbuf, "%s/econfig", datadir);
|
|
||||||
config_file = tbuf;
|
|
||||||
}
|
|
||||||
emp_config(config_file);
|
|
||||||
empfile[EF_MAP].size = (WORLD_X * WORLD_Y) / 2;
|
empfile[EF_MAP].size = (WORLD_X * WORLD_Y) / 2;
|
||||||
empfile[EF_BMAP].size = (WORLD_X * WORLD_Y) / 2;
|
empfile[EF_BMAP].size = (WORLD_X * WORLD_Y) / 2;
|
||||||
|
|
||||||
|
@ -116,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);
|
||||||
|
|
|
@ -31,18 +31,16 @@
|
||||||
* Julian Onions
|
* Julian Onions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <gamesdef.h>
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
#include "optlist.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
emp_config(argv[1]);
|
if (emp_config(argv[1]) < 0)
|
||||||
else
|
exit(1);
|
||||||
emp_config(NULL);
|
|
||||||
|
|
||||||
print_config(stdout);
|
print_config(stdout);
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue