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