1 /* src/server/main.c */
3 #include <errno.h> /* global errno */
4 #include <stdio.h> /* printf() */
5 #include <stdlib.h> /* exit() */
6 #include <sys/stat.h> /* mkfifo(), mkdir() */
7 #include <unistd.h> /* access() */
8 #include "../common/rexit.h" /* exit_err, exit_trouble(), set_cleanup_func() */
9 #include "cleanup.h" /* set_cleanup_flag(), cleanup() */
10 #include "init.h" /* run_game(), obey_argv() */
11 #include "map_object_actions.h" /* init_map_object_actions() */
12 #include "map_objects.h" /* init_map_object_defs() */
13 #include "run.h" /* obey_argv(), run_game() */
14 #include "world.h" /* struct World */
22 int main(int argc, char ** argv)
24 char * f_name = "main()";
26 /* So error exits also go through the server's cleanup() function. */
27 set_cleanup_func(cleanup);
29 /* Init settings from command line / hard-coded values. Print start info. */
30 obey_argv(argc, argv);
33 char * printf_err = "Trouble in main() with printf().";
34 int test = printf("Starting plomrogue-server.\n");
35 exit_err(-1 == test, printf_err);
38 test = printf("Replay mode. Auto-replaying up to turn %d.\n",
40 exit_err(-1 == test, printf_err);
43 world.path_in = "server/in";
44 world.path_out = "server/out";
45 world.path_record = "record";
46 world.tmp_suffix = "_tmp";
48 /* Treat world.path_in file as server process lock file. */
49 char * err = "Found pre-existing input fifo file. This indicates another "
50 "roguelike-server may be running. It should be killed first.";
51 exit_err(!access(world.path_in, F_OK), err);
52 int test = mkdir("server", 0700);
53 exit_trouble(test && EEXIST != errno, f_name, "mkdir()");
54 exit_trouble(mkfifo(world.path_in, 0600), f_name, "mkfifo()");
55 set_cleanup_flag(CLEANUP_FIFO);
57 /* Init from config files map object (action) definitions. */
58 init_map_object_defs("confserver/defs");
59 init_map_object_actions("confserver/map_object_actions");
61 /* Enter play or replay mode loops, then leave properly. */