home · contact · privacy
3c8829b7067ec010267382f27d80b04d9da47bcf
[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_config       = "confserver/world";
39     world.path_worldstate   = "server/worldstate";
40     world.path_out          = "server/out";
41     world.path_in           = "server/in";
42     world.path_record       = "record";
43     world.tmp_suffix        = "_tmp";
44     set_err_try_fgets_delim("%%\n");
45
46     /* Init map, map object configurations and server i/o files. */
47     init_map_and_map_objects_configs();
48     setup_server_io();
49
50     /* Enter play or replay mode loops, then leave properly. */
51     run_game();
52     cleanup();
53     exit(EXIT_SUCCESS);
54 }