home · contact · privacy
Client: Minor variable renaming.
[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.log);
30     free(world.map.cells);
31     if (cleanup_flags & CLEANUP_WORLDSTATE)
32     {
33         unlink(s[S_PATH_WORLDSTATE]);
34     }
35     if (cleanup_flags & CLEANUP_THINGS)
36     {
37         free_things(world.things);
38     }
39     if (cleanup_flags & CLEANUP_THING_TYPES)
40     {
41         free_thing_types(world.thing_types);
42     }
43     if (cleanup_flags & CLEANUP_THING_ACTIONS)
44     {
45         free_thing_actions(world.thing_actions);
46     }
47     if (cleanup_flags & CLEANUP_IN)
48     {
49         try_fclose(world.file_in, __func__);
50         unlink(s[S_PATH_IN]);
51     }
52     if (cleanup_flags & CLEANUP_OUT)
53     {
54         try_fclose(world.file_out, __func__);
55         free(world.server_test);
56         unlink(s[S_PATH_OUT]);
57     }
58 }
59
60
61 extern void set_cleanup_flag(enum cleanup_flag flag)
62 {
63     cleanup_flags = cleanup_flags | flag;
64 }
65
66
67
68 extern void unset_cleanup_flag(enum cleanup_flag flag)
69 {
70     cleanup_flags = cleanup_flags ^ flag;
71 }