home · contact · privacy
4ad970ceaf44365e6b16202b00b4ce8ba3fa6ed2
[plomrogue] / src / server / cleanup.c
1 /* src/server/cleanup.c */
2
3 #include "cleanup.h"
4 #include <stdint.h> /* uint32_t */
5 #include <stdlib.h> /* free() */
6 #include <unistd.h> /* unlink() */
7 #include "map_object_actions.h" /* free_map_object_actions() */
8 #include "map_objects.h" /* free_map_objects(), free_map_object_defs() */
9 #include "world.h" /* global world */
10
11
12
13 /* The clean-up flags set by set_cleanup_flag(). */
14 static uint32_t cleanup_flags = 0x0000;
15
16
17
18 extern void cleanup()
19 {
20     free(world.queue);
21     free(world.log);
22     free(world.map.cells);
23     if (cleanup_flags & CLEANUP_OUTFILE)
24     {
25         unlink(world.path_out);
26     }
27     if (cleanup_flags & CLEANUP_MAP_OBJECTS)
28     {
29         free_map_objects(world.map_objs);
30     }
31     if (cleanup_flags & CLEANUP_MAP_OBJECT_DEFS)
32     {
33         free_map_object_defs(world.map_obj_defs);
34     }
35     if (cleanup_flags & CLEANUP_MAP_OBJECT_ACTS)
36     {
37         free_map_object_actions(world.map_obj_acts);
38     }
39     if (cleanup_flags & CLEANUP_FIFO)    /* Fifo also serves as lockfile that */
40     {                                    /* affirms the running of a server   */
41         unlink(world.path_in);           /* instance. Therefore it should be  */
42     }                                    /* the last thing to be deleted.     */
43 }
44
45
46 extern void set_cleanup_flag(enum cleanup_flag flag)
47 {
48     cleanup_flags = cleanup_flags | flag;
49 }