diff options
Diffstat (limited to 'apworld/context.py')
-rw-r--r-- | apworld/context.py | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/apworld/context.py b/apworld/context.py index 63645a4..7b5f0bc 100644 --- a/apworld/context.py +++ b/apworld/context.py | |||
@@ -229,6 +229,21 @@ class Lingo2GameContext: | |||
229 | 229 | ||
230 | async_start(self.send_msgs([msg]), name="update worldports") | 230 | async_start(self.send_msgs([msg]), name="update worldports") |
231 | 231 | ||
232 | def send_path_reply(self, object_type: str, object_id: int | None, path: list[str]): | ||
233 | if self.server is None: | ||
234 | return | ||
235 | |||
236 | msg = { | ||
237 | "cmd": "PathReply", | ||
238 | "type": object_type, | ||
239 | "path": path, | ||
240 | } | ||
241 | |||
242 | if object_id is not None: | ||
243 | msg["id"] = object_id | ||
244 | |||
245 | async_start(self.send_msgs([msg]), name="path reply") | ||
246 | |||
232 | async def send_msgs(self, msgs: list[Any]) -> None: | 247 | async def send_msgs(self, msgs: list[Any]) -> None: |
233 | """ `msgs` JSON serializable """ | 248 | """ `msgs` JSON serializable """ |
234 | if not self.server or not self.server.socket.open or self.server.socket.closed: | 249 | if not self.server or not self.server.socket.open or self.server.socket.closed: |
@@ -254,11 +269,8 @@ class Lingo2ClientContext(CommonContext): | |||
254 | return ui | 269 | return ui |
255 | 270 | ||
256 | async def server_auth(self, password_requested: bool = False): | 271 | async def server_auth(self, password_requested: bool = False): |
257 | if password_requested: | 272 | if password_requested and not self.password: |
258 | if self.password is None: | 273 | self.manager.game_ctx.send_connection_refused("Invalid password.") |
259 | self.manager.game_ctx.send_connection_refused("Slot requires a password.") | ||
260 | else: | ||
261 | self.manager.game_ctx.send_connection_refused("Invalid password.") | ||
262 | else: | 274 | else: |
263 | self.auth = self.username | 275 | self.auth = self.username |
264 | await self.send_connect() | 276 | await self.send_connect() |
@@ -545,6 +557,17 @@ async def process_game_cmd(manager: Lingo2Manager, args: dict): | |||
545 | if len(updates) > 0: | 557 | if len(updates) > 0: |
546 | async_start(manager.client_ctx.update_worldports(updates), name="client update worldports") | 558 | async_start(manager.client_ctx.update_worldports(updates), name="client update worldports") |
547 | manager.game_ctx.send_update_worldports(updates) | 559 | manager.game_ctx.send_update_worldports(updates) |
560 | elif cmd == "GetPath": | ||
561 | path = None | ||
562 | |||
563 | if args["type"] == "location": | ||
564 | path = manager.tracker.get_path_to_location(args["id"]) | ||
565 | elif args["type"] == "worldport": | ||
566 | path = manager.tracker.get_path_to_port(args["id"]) | ||
567 | elif args["type"] == "goal": | ||
568 | path = manager.tracker.get_path_to_goal() | ||
569 | |||
570 | manager.game_ctx.send_path_reply(args["type"], args.get("id", None), path) | ||
548 | elif cmd == "Quit": | 571 | elif cmd == "Quit": |
549 | manager.client_ctx.exit_event.set() | 572 | manager.client_ctx.exit_event.set() |
550 | 573 | ||