X-Git-Url: https://plomlompom.com/repos/berlin_corona.txt?a=blobdiff_plain;ds=sidebyside;f=plomrogue-server.py;h=ef3fdbcc5a8491fe71e8f8418f775132b5b1fcbe;hb=00b22e82c20cdd00058aa96df095435fbbdb2422;hp=772277c8b3916de15234d838004589a9dff210de;hpb=7bedc1d4ffc9c3b623c4195c484539ba7adb2dfd;p=plomrogue diff --git a/plomrogue-server.py b/plomrogue-server.py index 772277c..ef3fdbc 100755 --- a/plomrogue-server.py +++ b/plomrogue-server.py @@ -99,7 +99,7 @@ def obey(command, prefix, replay=False, do_record=False): Tokenize command string with shlex.split(comments=True). If replay is set, a non-meta command from the commands_db merely triggers obey() on the next command from the records file. If not, non-meta commands set - io_db["worldstate_updateable"] to world_db["WORLD_EXISTS"], and, if + io_db["worldstate_updateable"] to world_db["WORLD_ACTIVE"], and, if do_record is set, are recorded to io_db["record_chunk"], and save_world() is called (and io_db["record_chunk"] written) if 15 seconds have passed since the last time it was called. The prefix string is inserted into the @@ -142,7 +142,7 @@ def obey(command, prefix, replay=False, do_record=False): print("Invalid command/argument, or bad number of tokens.") -def atomic_write(path, text, do_append=False): +def atomic_write(path, text, do_append=False, delete=True): """Atomic write of text to file at path, appended if do_append is set.""" path_tmp = path + io_db["tmp_suffix"] mode = "w" @@ -153,7 +153,7 @@ def atomic_write(path, text, do_append=False): file = open(path_tmp, mode) strong_write(file, text) file.close() - if os.access(path, os.F_OK): + if delete and os.access(path, os.F_OK): os.remove(path) os.rename(path_tmp, path) @@ -187,9 +187,9 @@ def save_world(): def helper(category, id_string, special_keys={}): string = "" - for id in world_db[category]: + for id in sorted(world_db[category].keys()): string = string + id_string + " " + str(id) + "\n" - for key in world_db[category][id]: + for key in sorted(world_db[category][id].keys()): if not key in special_keys: x = world_db[category][id][key] argument = quote(x) if str == type(x) else str(x) @@ -199,14 +199,14 @@ def save_world(): return string string = "" - for key in world_db: + for key in sorted(world_db.keys()): if dict != type(world_db[key]) and key != "MAP" and \ key != "WORLD_ACTIVE" and key != "SEED_MAP": string = string + key + " " + str(world_db[key]) + "\n" string = string + "SEED_MAP " + str(world_db["SEED_MAP"]) + "\n" string = string + helper("ThingActions", "TA_ID") string = string + helper("ThingTypes", "TT_ID", {"TT_CORPSE_ID": False}) - for id in world_db["ThingTypes"]: + for id in sorted(world_db["ThingTypes"].keys()): string = string + "TT_ID " + str(id) + "\n" + "TT_CORPSE_ID " + \ str(world_db["ThingTypes"][id]["TT_CORPSE_ID"]) + "\n" string = string + helper("Things", "T_ID", @@ -214,11 +214,11 @@ def save_world(): "T_MEMMAP": mapsetter("T_MEMMAP"), "T_MEMTHING": memthing, "fovmap": False, "T_MEMDEPTHMAP": mapsetter("T_MEMDEPTHMAP")}) - for id in world_db["Things"]: + for id in sorted(world_db["Things"].keys()): if [] != world_db["Things"][id]["T_CARRIES"]: string = string + "T_ID " + str(id) + "\n" - for carried_id in world_db["Things"][id]["T_CARRIES"]: - string = string + "T_CARRIES " + str(carried_id) + "\n" + for carried in sorted(world_db["Things"][id]["T_CARRIES"].keys()): + string = string + "T_CARRIES " + str(carried) + "\n" string = string + "SEED_RANDOMNESS " + str(rand.seed) + "\n" + \ "WORLD_ACTIVE " + str(world_db["WORLD_ACTIVE"]) atomic_write(io_db["path_save"], string) @@ -348,7 +348,7 @@ def try_worldstate_update(): c = world_db["ThingTypes"][mt[0]]["TT_SYMBOL"] mem[(mt[1] * length) + mt[2]] = ord(c) string = write_map(string, mem) - atomic_write(io_db["path_worldstate"], string) + atomic_write(io_db["path_worldstate"], string, delete=False) strong_write(io_db["file_out"], "WORLD_UPDATED\n") io_db["worldstate_updateable"] = False @@ -472,7 +472,6 @@ def update_map_memory(t, age_map=True): t["T_MEMDEPTHMAP"] = bytearray(b' ' * (world_db["MAP_LENGTH"] ** 2)) ord_v = ord("v") ord_0 = ord("0") - ord_9 = ord("9") ord_space = ord(" ") for pos in [pos for pos in range(world_db["MAP_LENGTH"] ** 2) if ord_v == t["fovmap"][pos]]: