1 /* src/server/cleanup.c */
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 "hardcoded_strings.h" /* s */
9 #include "thing_actions.h" /* free_thing_actions() */
10 #include "things.h" /* free_things(), free_thing_types() */
11 #include "world.h" /* global world */
16 /* The clean-up flags set by set_cleanup_flag(). */
17 static uint32_t cleanup_flags = 0x0000;
23 char * f_name = "cleanup()";
26 free(world.map.cells);
27 if (cleanup_flags & CLEANUP_WORLDSTATE)
29 unlink(s[PATH_WORLDSTATE]);
31 if (cleanup_flags & CLEANUP_THINGS)
33 free_things(world.things);
35 if (cleanup_flags & CLEANUP_THING_TYPES)
37 free_thing_types(world.thing_types);
39 if (cleanup_flags & CLEANUP_THING_ACTIONS)
41 free_thing_actions(world.thing_actions);
43 if (cleanup_flags & CLEANUP_IN)
45 try_fclose(world.file_in, f_name);
48 if (cleanup_flags & CLEANUP_OUT)
50 try_fclose(world.file_out, f_name);
51 free(world.server_test);
57 extern void set_cleanup_flag(enum cleanup_flag flag)
59 cleanup_flags = cleanup_flags | flag;
64 extern void unset_cleanup_flag(enum cleanup_flag flag)
66 cleanup_flags = cleanup_flags ^ flag;