home · contact · privacy
ec8017d02369f261784f5dad92f6d65be7c27ace
[plomrogue] / src / server / cleanup.c
1 /* src/server/cleanup.c
2  *
3  * This file is part of PlomRogue. PlomRogue is licensed under the GPL version 3
4  * or any later version. For details on its copyright, license, and warranties,
5  * see the file NOTICE in the root directory of the PlomRogue source package.
6  */
7
8 #include "cleanup.h"
9 #include <stdint.h> /* uint32_t */
10 #include <stdlib.h> /* free() */
11 #include <unistd.h> /* unlink() */
12 #include "../common/readwrite.h" /* try_fclose() */
13 #include "hardcoded_strings.h" /* s */
14 #include "thing_actions.h" /* free_thing_actions() */
15 #include "things.h" /* free_things(), free_thing_types() */
16 #include "world.h" /* global world */
17
18
19
20
21 /* The clean-up flags set by set_cleanup_flag(). */
22 static uint32_t cleanup_flags = 0x0000;
23
24
25
26 extern void cleanup()
27 {
28     free(world.queue);
29     free(world.map.cells);
30     if (cleanup_flags & CLEANUP_WORLDSTATE)
31     {
32         unlink(s[S_PATH_WORLDSTATE]);
33     }
34     if (cleanup_flags & CLEANUP_THINGS)
35     {
36         free_things(world.things);
37     }
38     if (cleanup_flags & CLEANUP_THING_TYPES)
39     {
40         free_thing_types(world.thing_types);
41     }
42     if (cleanup_flags & CLEANUP_THING_ACTIONS)
43     {
44         free_thing_actions(world.thing_actions);
45     }
46     if (cleanup_flags & CLEANUP_IN)
47     {
48         try_fclose(world.file_in, __func__);
49         unlink(s[S_PATH_IN]);
50     }
51     if (cleanup_flags & CLEANUP_OUT)
52     {
53         try_fclose(world.file_out, __func__);
54         free(world.server_test);
55         unlink(s[S_PATH_OUT]);
56     }
57 }
58
59
60 extern void set_cleanup_flag(enum cleanup_flag flag)
61 {
62     cleanup_flags = cleanup_flags | flag;
63 }
64
65
66
67 extern void unset_cleanup_flag(enum cleanup_flag flag)
68 {
69     cleanup_flags = cleanup_flags ^ flag;
70 }