Skip to content

Commit

Permalink
Update Client.py
Browse files Browse the repository at this point in the history
  • Loading branch information
gaithern committed May 25, 2024
1 parent ebaf682 commit 92a7fa9
Showing 1 changed file with 11 additions and 18 deletions.
29 changes: 11 additions & 18 deletions worlds/khrecom/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import Utils

check_num = 0
item_num = 1

if __name__ == "__main__":
Utils.init_logging("KHRECOMClient", exception_logger="Client")
Expand Down Expand Up @@ -61,6 +61,8 @@ async def connection_closed(self):
for file in files:
if file.find("obtain") <= -1:
os.remove(root + "/" + file)
global item_num
item_num = 1

@property
def endpoints(self):
Expand All @@ -75,6 +77,8 @@ async def shutdown(self):
for file in files:
if file.find("obtain") <= -1:
os.remove(root+"/"+file)
global item_num
item_num = 1

def on_package(self, cmd: str, args: dict):
if cmd in {"Connected"}:
Expand Down Expand Up @@ -116,29 +120,18 @@ def on_package(self, cmd: str, args: dict):
if cmd in {"ReceivedItems"}:
start_index = args["index"]
if start_index != len(self.items_received):
global item_num
for item in args['items']:
check_num = 0
for filename in os.listdir(self.game_communication_path):
if filename.startswith("AP"):
if int(filename.split("_")[-1].split(".")[0]) > check_num:
check_num = int(filename.split("_")[-1].split(".")[0])
item_id = ""
location_id = ""
player = ""
found = False
item_filename = f"AP_{str(item_num)}.item"
for filename in os.listdir(self.game_communication_path):
if filename.startswith(f"AP"):
with open(os.path.join(self.game_communication_path, filename), 'r') as f:
item_id = str(f.readline()).replace("\n", "")
location_id = str(f.readline()).replace("\n", "")
player = str(f.readline()).replace("\n", "")
if str(item_id) == str(NetworkItem(*item).item) and str(location_id) == str(NetworkItem(*item).location) and str(player) == str(NetworkItem(*item).player):
found = True
if filename == item_filename:
found = True
if not found:
filename = f"AP_{str(check_num+1)}.item"
with open(os.path.join(self.game_communication_path, filename), 'w') as f:
with open(os.path.join(self.game_communication_path, item_filename), 'w') as f:
f.write(str(NetworkItem(*item).item) + "\n" + str(NetworkItem(*item).location) + "\n" + str(NetworkItem(*item).player))
f.close()
item_num = item_num + 1

if cmd in {"RoomUpdate"}:
if "checked_locations" in args:
Expand Down

0 comments on commit 92a7fa9

Please sign in to comment.