From: Christian Heller Date: Tue, 28 Jan 2014 06:10:31 +0000 (+0100) Subject: Check for existence of server config files. X-Git-Tag: tce~850 X-Git-Url: https://plomlompom.com/repos/%7B%7B%20web_path%20%7D%7D/static/%7B%7Bprefix%7D%7D/%7B%7Bdb.prefix%7D%7D/edit?a=commitdiff_plain;h=6052be616897d692fc57ab15b56266b4b3f4668b;p=plomrogue Check for existence of server config files. --- diff --git a/src/server/main.c b/src/server/main.c index 09ce530..0384ada 100644 --- a/src/server/main.c +++ b/src/server/main.c @@ -41,12 +41,20 @@ int main(int argc, char ** argv) exit_err(-1 == test, printf_err); } } + world.path_map_obj_defs = "confserver/defs"; + world.path_map_obj_acts = "confserver/map_object_actions"; world.path_in = "server/in"; world.path_out = "server/out"; world.path_record = "record"; world.tmp_suffix = "_tmp"; set_err_try_fgets_delim("%%\n"); + /* Check existence of config files. */ + char * err_mod = "No map object definitions file."; + char * err_moa = "No map object actions file."; + exit_err(access(world.path_map_obj_defs, F_OK), err_mod); + exit_err(access(world.path_map_obj_acts, F_OK), err_moa); + /* Treat world.path_in file as server process lock file. */ char * err = "Found pre-existing input fifo file. This indicates another " "roguelike-server may be running. It should be killed first."; @@ -57,8 +65,8 @@ int main(int argc, char ** argv) set_cleanup_flag(CLEANUP_FIFO); /* Init from config files map object (action) definitions. */ - init_map_object_defs("confserver/defs"); - init_map_object_actions("confserver/map_object_actions"); + init_map_object_defs(); + init_map_object_actions(); /* Enter play or replay mode loops, then leave properly. */ run_game(); diff --git a/src/server/map_object_actions.c b/src/server/map_object_actions.c index 476ba91..561a2e2 100644 --- a/src/server/map_object_actions.c +++ b/src/server/map_object_actions.c @@ -219,10 +219,10 @@ static void playerbonus_use(uint8_t no_object, uint8_t wrong_object) -extern void init_map_object_actions(char * path) +extern void init_map_object_actions() { char * f_name = "init_map_object_actions()"; - FILE * file = try_fopen(path, "r", f_name); + FILE * file = try_fopen(world.path_map_obj_acts, "r", f_name); uint16_t linemax = textfile_sizes(file, NULL); char line[linemax + 1]; struct MapObjAct ** moa_ptr_ptr = &world.map_obj_acts; diff --git a/src/server/map_object_actions.h b/src/server/map_object_actions.h index ae015e6..983f1aa 100644 --- a/src/server/map_object_actions.h +++ b/src/server/map_object_actions.h @@ -24,8 +24,8 @@ struct MapObjAct -/* Init MapObjAct chain at world.map_obj_acts from file at "path". */ -extern void init_map_object_actions(char * path); +/* Init MapObjAct chain at world.map_obj_acts. */ +extern void init_map_object_actions(); /* Free MapObjAct * chain starting at "moa". */ extern void free_map_object_actions(struct MapObjAct * moa); diff --git a/src/server/map_objects.c b/src/server/map_objects.c index 05cfc9a..0401c76 100644 --- a/src/server/map_objects.c +++ b/src/server/map_objects.c @@ -101,13 +101,13 @@ static void add_map_object(uint8_t type) -extern void init_map_object_defs(char * filename) +extern void init_map_object_defs() { char * f_name = "init_map_object_defs()"; char * context = "Failed reading map object definitions file. "; char * err_toolarge = "Value is too large."; char * err_uniq = "Declaration of ID already used."; - FILE * file = try_fopen(filename, "r", f_name); + FILE * file = try_fopen(world.path_map_obj_defs, "r", f_name); uint16_t linemax = textfile_sizes(file, NULL); struct MapObjDef ** last_mod_ptr_ptr = &world.map_obj_defs; char line[linemax + 1]; diff --git a/src/server/map_objects.h b/src/server/map_objects.h index d5dc5b3..0796c3c 100644 --- a/src/server/map_objects.h +++ b/src/server/map_objects.h @@ -37,8 +37,8 @@ struct MapObjDef -/* Initialize map object definitions chain from file at path "filename". */ -extern void init_map_object_defs(char * filename); +/* Initialize map object definitions chain. */ +extern void init_map_object_defs(); /* Free map object definitions chain starting at "mod_start". */ extern void free_map_object_defs(struct MapObjDef * mod_start); diff --git a/src/server/world.h b/src/server/world.h index 56a5f28..3bea1f1 100644 --- a/src/server/world.h +++ b/src/server/world.h @@ -24,6 +24,8 @@ struct World char * path_in; /* Fifo to receive command messages. */ char * path_out; /* File to write the game state as visible to clients.*/ char * path_record; /* Record file from which to read the game history. */ + char * path_map_obj_defs; /* path for map object definitions config file */ + char * path_map_obj_acts; /* path for map object actions config file */ char * tmp_suffix; /* Appended to paths of files for their tmp versions. */ char * queue; /* Stores un-processed messages received via input fifo. */ uint32_t queue_size;/* Length of .queue sequence of \0-terminated strings.*/