Skip to content

Commit

Permalink
Revert "small refactor"
Browse files Browse the repository at this point in the history
  • Loading branch information
gaithern authored Jan 12, 2024
1 parent 31783e0 commit bcfbf1e
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 108 deletions.
54 changes: 25 additions & 29 deletions worlds/kh1/Client.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import shutil
import logging
import re
from .MessageHandler import KH1_message_type, KH1_UniversalMessage, KH1_MessageHandler
import time
from calendar import timegm

Expand All @@ -18,8 +17,6 @@

logger = logging.getLogger("Client")



if __name__ == "__main__":
Utils.init_logging("KH1Client", exception_logger="Client")

Expand All @@ -33,7 +30,6 @@ def check_stdin() -> None:
print("WARNING: Console input is not routed reliably on Windows, use the GUI instead.")

class KH1ClientCommandProcessor(ClientCommandProcessor):

def _cmd_deathlink(self):
"""Toggles Deathlink"""
global death_link
Expand All @@ -54,7 +50,6 @@ def __init__(self, server_address, password):
self.send_index: int = 0
self.syncing = False
self.awaiting_bridge = False

# self.game_communication_path: files go in this path to pass data between us and the actual game
if "localappdata" in os.environ:
self.game_communication_path = os.path.expandvars(r"%localappdata%/KH1FM")
Expand All @@ -67,19 +62,6 @@ def __init__(self, server_address, password):
if file.find("obtain") <= -1:
os.remove(root+"/"+file)

self.message_handler = KH1_MessageHandler(2, self.game_communication_path)
#
# self.message_handler.receive_message(KH1_message_type.test, [
# "I'm a test message",
# "with multiple values",
# "isn't that cool?"
# ]);
#
# self.message_handler.receive_message(KH1_message_type.test, [
# "Thats a second test message",
# "with only two values",
# ]);

async def server_auth(self, password_requested: bool = False):
if password_requested and not self.password:
await super(KH1Context, self).server_auth(password_requested)
Expand All @@ -101,7 +83,6 @@ def endpoints(self):
return []

async def shutdown(self):
self.message_handler.stop_sending();
await super(KH1Context, self).shutdown()
for root, dirs, files in os.walk(self.game_communication_path):
for file in files:
Expand All @@ -116,11 +97,6 @@ def on_package(self, cmd: str, args: dict):
filename = f"send{ss}"
with open(os.path.join(self.game_communication_path, filename), 'w') as f:
f.close()
self.message_handler.receive_message(KH1_message_type.test, [
"Connected to the Multiworld!"
]);



if cmd in {"ReceivedItems"}:
start_index = args["index"]
Expand Down Expand Up @@ -167,13 +143,10 @@ def on_package(self, cmd: str, args: dict):
itemCategory = networkItem.flags
recieverName = self.player_names[recieverID]
filename = "sent"
sanitizedItemName = re.sub('[^A-Za-z0-9 ]+', '',str(itemName))[:15];
sanitizedRecieverName = re.sub('[^A-Za-z0-9 ]+', '',str(recieverName))[:6]

with open(os.path.join(self.game_communication_path, filename), 'w') as f:
f.write(
sanitizedItemName + "\n"
+ sanitizedRecieverName + "\n"
re.sub('[^A-Za-z0-9 ]+', '',str(itemName))[:15] + "\n"
+ re.sub('[^A-Za-z0-9 ]+', '',str(recieverName))[:6] + "\n"
+ str(itemCategory) + "\n"
+ str(locationID))
f.close()
Expand All @@ -183,6 +156,29 @@ def on_deathlink(self, data: typing.Dict[str, typing.Any]):
f.write(str(int(data["time"])))
f.close()

#f.write(self.item_names[NetworkItem(*item).item] + "\n" + self.location_names[NetworkItem(*item).location] + "\n" + self.player_names[NetworkItem(*item).player])



#last resort we can probably do better
#input: Krujo sent Magic Upgrade to Tim ((TT3) LocationName)
# if cmd in {"PrintJSON"}:
# data = args["data"]
# if data[0]:
# msg = str(data[0]["text"]);
# #player send a location
# # if msg.startswith(self.auth + " sent "): #debug
# with open(os.path.join(self.game_communication_path, "sent"), 'w') as f:
# msg = msg.replace(self.auth + " sent ", "")
# #Magic Upgrade to Tim ((TT3) LocationName)
# splitTo = msg.split(" to ")
# targetPlayer = splitTo[1].split(" ")[0]
# f.close()





def run_gui(self):
"""Import kivy UI system and start running it as self.ui_task."""
from kvui import GameManager
Expand Down
79 changes: 0 additions & 79 deletions worlds/kh1/MessageHandler.py

This file was deleted.

0 comments on commit bcfbf1e

Please sign in to comment.