home · contact · privacy
Server's remake_world() unlinks any pre-existing record file.
[plomrogue] / src / server / init.c
index 1644cee35c3f3db6e08771cb7f8295b85dcfa9c5..7ab5c9de6b469906d8610b475878ea06a42f5634 100644 (file)
@@ -1,12 +1,13 @@
 /* src/server/init.c */
 
 #include "init.h"
+#include <errno.h> /* errno */
 #include <stddef.h> /* NULL */
 #include <stdint.h> /* uint32_t */
 #include <stdlib.h> /* exit(), free() */
 #include <string.h> /* atoi() */
 #include <time.h> /* time() */
-#include <unistd.h> /* optarg, getopt(), access() */
+#include <unistd.h> /* optarg, getopt(), access(), unlink() */
 #include "../common/readwrite.h" /* try_fopen(), try_fclose(), textfile_sizes(),
                                   * try_fgets()
                                   */
@@ -49,15 +50,12 @@ extern void obey_argv(int argc, char * argv[])
 extern void remake_world(uint32_t seed)
 {
     free(world.log);
-    world.log = NULL;
+    world.log = NULL;  /* map_object_action.c's update_log() checks for this. */
     world.seed = seed;
     world.map_obj_count = 0;
     world.score = 0;
     free(world.map.cells);
-    if (world.map_objs)
-    {
-        free_map_objects(world.map_objs);
-    }
+    free_map_objects(world.map_objs);
     world.last_update_turn = 0;
     world.turn = 1;
     init_map();
@@ -68,6 +66,9 @@ extern void remake_world(uint32_t seed)
     add_map_objects(4, 1 + rrand() % 3);
     add_map_objects(5, 1 + rrand() % 3);
     set_cleanup_flag(CLEANUP_MAP_OBJECTS);
+    int test = unlink(world.path_record);
+    char * err = "remake_world() fails to unlink() record file.";
+    exit_err(test && errno != ENOENT, err);
 }