X-Git-Url: https://plomlompom.com/repos/%7B%7Bprefix%7D%7D/copy_free?a=blobdiff_plain;f=plomrogue-server.py;h=e5b7c0e68bc3a0067384e15b6dd50d55cf1161fe;hb=54a5049dbbc45cfe4582a31f0594320159a6b48c;hp=44c86a949f85a7e1ca614dd26d7dee1f4c0fe8e4;hpb=5fba7c516c6568a5e2c30ccf7114f7529619df01;p=plomrogue diff --git a/plomrogue-server.py b/plomrogue-server.py index 44c86a9..e5b7c0e 100755 --- a/plomrogue-server.py +++ b/plomrogue-server.py @@ -53,9 +53,9 @@ def detect_atomic_leftover(path): raise SystemExit(msg) -def obey(cmd, io_db): #, path_recordfile): +def obey(cmd, io_db, prefix): """""" - print("Input: " + cmd) + print("input " + prefix + ": " + cmd) try: tokens = shlex.split(cmd, comments=True) except ValueError as err: @@ -77,11 +77,20 @@ def obey(cmd, io_db): #, path_recordfile): def record(cmd, path_recordfile): """Append cmd string plus newline to file at path_recordfile.""" + # Doesn't yet replace old record() fully. file = open(path_recordfile, "a") file.write(cmd + "\n") file.close() +def obey_lines_in_file(path, name): + """Call obey() on each line of path's file, use name in input prefix.""" + file = open(io_db["path_worldconf"], "r") + line_n = 1 + for line in file.readlines(): + obey(line.rstrip(), io_db, name + "file line " + str(line_n)) + line_n = line_n + 1 + file.close() io_db = {} try: @@ -100,17 +109,16 @@ try: " (if so late a turn is to be found).") if not os.access(io_db["path_record"], os.F_OK): raise SystemExit("No record file found to replay.") - elif os.access(io_db["path_save"], os.F_OK): - print(open(io_db["path_save"], "r").read()) else: - if not os.access(io_db["path_worldconf"], os.F_OK): - msg = "No world config file from which to start a new world." - raise SystemExit(msg) - file = open(io_db["path_worldconf"]) - for line in file.readlines(): - obey(line.rstrip(), io_db) - file.close() - obey("MAKE_WORLD " + str(int(time.time())), io_db) + if os.access(io_db["path_save"], os.F_OK): + obey_lines_in_file(io_db["path_save"], "save") + else: + if not os.access(io_db["path_worldconf"], os.F_OK): + msg = "No world config file from which to start a new world." + raise SystemExit(msg) + obey_lines_in_file(io_db["path_worldconf"], "world config ") + obey("MAKE_WORLD " + str(int(time.time())), io_db, "in file") + # print("DUMMY: Run io_loop().") except SystemExit as exit: print("ABORTING: " + exit.args[0]) except: