From 331e463592dc0f33b01127f38f036346b5aa2eb1 Mon Sep 17 00:00:00 2001 From: qvalentin Date: Mon, 28 Mar 2022 16:29:53 +0200 Subject: [PATCH] init - fix redirect --- Code/Communication/APIRequests.py | 1 + Code/Communication/Neighbours.py | 2 ++ Code/Communication/RequestHandler.py | 19 ++++++++++++------- Code/UI/PlayingField.py | 1 + 4 files changed, 16 insertions(+), 7 deletions(-) diff --git a/Code/Communication/APIRequests.py b/Code/Communication/APIRequests.py index 8f15d8e..ceaf50f 100644 --- a/Code/Communication/APIRequests.py +++ b/Code/Communication/APIRequests.py @@ -20,4 +20,5 @@ class APIRequests: def toggle_pause(self, neighbour: Member, new_state: bool): action = "start" if new_state else "stop" + print(f"sending {action} to {neighbour}") response = requests.post(f"http://{neighbour.ip}:{neighbour.port}/pause/{action}") diff --git a/Code/Communication/Neighbours.py b/Code/Communication/Neighbours.py index 0c76adc..3cb66f0 100644 --- a/Code/Communication/Neighbours.py +++ b/Code/Communication/Neighbours.py @@ -27,6 +27,7 @@ class Neighbours: def get_edge(self, direction: Direction): if direction in self.neighbours: + print(f"Getting ghost edge from {self.neighbours[direction]}") return self.api.get_edge(self.neighbours[direction], mirror(direction)) elif direction == Direction.RIGHT or direction.LEFT: return [False] * GeneralConfig.fields_amount_y @@ -34,4 +35,5 @@ class Neighbours: def toggle_pause(self,new_state:bool): for neighbour in self.neighbours.values(): + print(f"Telling member {neighbour} toggle pause with {new_state}") self.api.toggle_pause(neighbour,new_state) diff --git a/Code/Communication/RequestHandler.py b/Code/Communication/RequestHandler.py index 2b51bed..9a5c5d8 100644 --- a/Code/Communication/RequestHandler.py +++ b/Code/Communication/RequestHandler.py @@ -25,8 +25,10 @@ class RequestHandler(BaseHTTPRequestHandler): self.end_headers() self.wfile.write(json.dumps(cells).encode('utf8')) - def handle(self) -> None: - super().handle() + else: + self.send_response(404) + self.end_headers() + """ /connect/right @@ -52,21 +54,24 @@ class RequestHandler(BaseHTTPRequestHandler): self.end_headers() self.wfile.write(json.dumps(asdict(neighbour)).encode('utf8')) else: - self.send_response(303) - self.send_header('Location', f"http://{neighbour.ip}:{neighbour.port}") + self.send_response(307) + self.send_header('Location', f"http://{neighbour.ip}:{neighbour.port}{self.path}") self.end_headers() elif self.path.startswith("/pause/"): new_state = re.findall("/pause/(stop|start)", self.path, flags=re.IGNORECASE)[0] == "start" - print(f"pause endpoint {new_state} old state") + print(f"pause endpoint {new_state} old state {self.game_state.pause_for_input}") if new_state == self.game_state.pause_for_input: + print("got pause signal but already in the correct state") self.send_response(200) self.end_headers() else: self.send_response(200) - self.end_headers() self.game_state.pause_for_input = new_state self.neighbours.toggle_pause(new_state) + self.end_headers() - self.end_headers() + else: + self.send_response(404) + self.end_headers() diff --git a/Code/UI/PlayingField.py b/Code/UI/PlayingField.py index 2e78ff0..b726c95 100644 --- a/Code/UI/PlayingField.py +++ b/Code/UI/PlayingField.py @@ -60,6 +60,7 @@ def run_game(game_state: GameState): time_elapsed_since_last_action = 0 while game_state.run: + print(f"running {game_state.pause_for_input}") game_state.event_handler() for event in game_state.update_field_events: