X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=plomrogue-server.py;h=d6c1930da2613a88c98e844b830b861c9fd2c482;hb=21ba1d03b1e883564d301c2781039017dd704b20;hp=f5c3c102a16c7182ce510c15414e9f33964802f0;hpb=7cb786bc1b01c60c7112b377128baf24df0c3628;p=plomrogue diff --git a/plomrogue-server.py b/plomrogue-server.py index f5c3c10..d6c1930 100755 --- a/plomrogue-server.py +++ b/plomrogue-server.py @@ -72,7 +72,7 @@ def obey(command, prefix, replay=False, do_record=False): if len(tokens) > 0 and tokens[0] in commands_db \ and len(tokens) == commands_db[tokens[0]][0] + 1: if commands_db[tokens[0]][1]: - commands_db[tokens[0]][2]() + commands_db[tokens[0]][2](*tokens[1:]) elif replay: print("Due to replay mode, reading command as 'go on in record'.") line = io_db["file_record"].readline() @@ -249,21 +249,30 @@ def read_command(): def try_worldstate_update(): """Write worldstate file if io_db["worldstate_updateable"] is set.""" if io_db["worldstate_updateable"]: + inventory = "" + if [] == world_db["Things"][0]["T_CARRIES"]: + inventory = "(none)\n" + else: + for id in world_db["Things"][0]["T_CARRIES"]: + type_id = world_db["Things"][id]["T_TYPE"] + name = world_db["ThingTypes"][type_id]["TT_NAME"] + inventory = inventory + name + "\n" string = str(world_db["TURN"]) + "\n" + \ str(world_db["Things"][0]["T_LIFEPOINTS"]) + "\n" + \ str(world_db["Things"][0]["T_SATIATION"]) + "\n" + \ - "(none)\n%\n" + \ + inventory + "%\n" + \ str(world_db["Things"][0]["T_POSY"]) + "\n" + \ str(world_db["Things"][0]["T_POSX"]) + "\n" + \ str(world_db["MAP_LENGTH"]) + "\n" - # TODO: no inventory so far length = world_db["MAP_LENGTH"] for i in range(length): line = world_db["MAP"][i * length:(i * length) + length].decode() string = string + line + "\n" # TODO: no proper user-subjective map atomic_write(io_db["path_worldstate"], string) - atomic_write(io_db["path_out"], "WORLD_UPDATED\n", do_append=True) + io_db["file_out"].write("WORLD_UPDATED\n") + io_db["file_out"].flush() + os.fsync(io_db["file_out"]) io_db["worldstate_updateable"] = False @@ -409,6 +418,7 @@ def command_ping(): """Send PONG line to server output file.""" io_db["file_out"].write("PONG\n") io_db["file_out"].flush() + os.fsync(io_db["file_out"].fileno()) def command_quit(): @@ -416,6 +426,11 @@ def command_quit(): raise SystemExit("received QUIT command") +def command_thingshere(y, x): + # DUMMY + print("Ignoring not-yet implemented THINGS_HERE command.") + + def command_seedmap(seed_string): """Set world_db["SEED_MAP"] to int(seed_string), then (re-)make map.""" setter(None, "SEED_MAP", 0, 4294967295)(seed_string) @@ -744,6 +759,7 @@ to be called on it. commands_db = { "QUIT": (0, True, command_quit), "PING": (0, True, command_ping), + "THINGS_HERE": (2, True, command_thingshere), "MAKE_WORLD": (1, False, command_makeworld), "SEED_MAP": (1, False, command_seedmap), "SEED_RANDOMNESS": (1, False, setter(None, "SEED_RANDOMNESS",