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