home · contact · privacy
Re-wrote large parts of the server client architecture. No more fifo.
[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 "../common/readwrite.h" /* try_fclose() */
8 #include "map_object_actions.h" /* free_map_object_actions() */
9 #include "map_objects.h" /* free_map_objects(), free_map_object_defs() */
10 #include "world.h" /* global world */
11
12
13
14
15 /* The clean-up flags set by set_cleanup_flag(). */
16 static uint32_t cleanup_flags = 0x0000;
17
18
19
20 extern void cleanup()
21 {
22     char * f_name = "cleanup()";
23     free(world.queue);
24     free(world.log);
25     free(world.map.cells);
26     if (cleanup_flags & CLEANUP_WORLDSTATE)
27     {
28         unlink(world.path_worldstate);
29     }
30     if (cleanup_flags & CLEANUP_MAP_OBJECTS)
31     {
32         free_map_objects(world.map_objs);
33     }
34     if (cleanup_flags & CLEANUP_MAP_OBJECT_DEFS)
35     {
36         free_map_object_defs(world.map_obj_defs);
37     }
38     if (cleanup_flags & CLEANUP_MAP_OBJECT_ACTS)
39     {
40         free_map_object_actions(world.map_obj_acts);
41     }
42     if (cleanup_flags & CLEANUP_IN)
43     {
44         try_fclose(world.file_in, f_name);
45         unlink(world.path_in);
46     }
47     if (cleanup_flags & CLEANUP_OUT)
48     {
49         try_fclose(world.file_out, f_name);
50         free(world.server_test);
51         unlink(world.path_out);
52     }
53 }
54
55
56 extern void set_cleanup_flag(enum cleanup_flag flag)
57 {
58     cleanup_flags = cleanup_flags | flag;
59 }
60
61
62
63 extern void unset_cleanup_flag(enum cleanup_flag flag)
64 {
65     cleanup_flags = cleanup_flags ^ flag;
66 }