3 def setup_server_io(io_db):
4 """Fill IO files DB with proper file( path)s. Write process IO test string.
6 Ensure IO files directory at server/. Remove any old in file if found. Set
7 up new in file (io_db["file_in"]) for reading at io_db["path_in"], and new
8 out file (io_db["file_out"]) for writing at io_db["path_out"]. Start out
9 file with process hash line of format PID + " " + floated UNIX time
10 (io_db["teststring"]). Set worldstate file path io_db["path_worldstate"].
13 io_db["path_in"] = io_dir + "in"
14 io_db["path_out"] = io_dir + "out"
15 io_db["path_worldstate"] = io_dir + "worldstate"
16 io_db["teststring"] = str(os.getpid()) + " " + str(time.time())
17 os.makedirs(io_dir, exist_ok=True)
18 io_db["file_out"] = open(io_db["path_out"], "w")
19 io_db["file_out"].write(io_db["teststring"] + "\n")
20 io_db["file_out"].flush() # TODO: Explain necessity.
21 if os.access(io_db["path_in"], os.F_OK):
22 os.remove(io_db["path_in"])
23 io_db["file_in"] = open(io_db["path_in"], "w")
24 io_db["file_in"].close()
25 io_db["file_in"] = open(io_db["path_in"], "r")
27 def cleanup_server_io(io_db):
28 """Close and remove all files in IO files DB."""
29 io_db["file_out"].close()
30 os.remove(io_db["path_out"])
31 io_db["file_in"].close()
32 os.remove(io_db["path_in"])
33 if "file_worldstate" in io_db: # This file is only set up
34 io_db["file_worldstate"].close() # properly when the game
35 if os.access(io_db["path_worldstate"], os.F_OK): # world is active, which is
36 os.remove(io_db["path_worldstate"]) # not guaranteed.
40 print("DUMMY: Obey command-line arguments.")
41 print("DUMMY: Open files.")
42 setup_server_io(io_db)
43 print("DUMMY: Run game.")
45 print("SOMETHING WENT WRONG\n")
48 cleanup_server_io(io_db)
49 print("DUMMY: (Clean up C heap.)")