home · contact · privacy
9bfddaecb4bb6d6a21ed5dc6435f55ddacaa4172
[plomrogue] / src / server / main.c
1 /* src/server/main.c */
2
3 #include <stdio.h> /* printf() */
4 #include <stdlib.h> /* exit() */
5 #include "../common/err_try_fgets.h" /* set_err_try_fgets_delim() */
6 #include "../common/rexit.h" /* exit_err, set_cleanup_func() */
7 #include "cleanup.h" /* set_cleanup_flag(), cleanup() */
8 #include "init.h" /* run_game(), obey_argv(), obey_argv(), setup_server_io(),
9                    * init_map_and_map_object_configs()
10                    */
11 #include "world.h" /* struct World */
12
13
14
15 struct World world;
16
17
18
19 int main(int argc, char ** argv)
20 {
21     /* So error exits also go through the server's cleanup() function. */
22     set_cleanup_func(cleanup);
23
24     /* Init settings from command line / hard-coded values. Print start info. */
25     obey_argv(argc, argv);
26     if (world.is_verbose)
27     {
28         char * printf_err = "Trouble in main() with printf().";
29         int test = printf("Starting plomrogue-server.\n");
30         exit_err(-1 == test, printf_err);
31         if (world.replay)
32         {
33             test = printf("Replay mode. Auto-replaying up to turn %d.\n",
34                          world.replay);
35             exit_err(-1 == test, printf_err);
36         }
37     }
38     world.path_map_obj_defs = "confserver/map_objects";
39     world.path_map_obj_acts = "confserver/map_object_actions";
40     world.path_worldstate   = "server/worldstate";
41     world.path_out          = "server/out";
42     world.path_in           = "server/in";
43     world.path_record       = "record";
44     world.tmp_suffix        = "_tmp";
45     set_err_try_fgets_delim("%%\n");
46
47     /* Init map, map object configurations and server i/o files. */
48     init_map_and_map_objects_configs();
49     setup_server_io();
50
51     /* Enter play or replay mode loops, then leave properly. */
52     run_game();
53     cleanup();
54     exit(EXIT_SUCCESS);
55 }