From c7c64dcc56432e85e92a7c619a260bd01bf56e56 Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Wed, 1 Oct 2025 11:23:06 -0400 Subject: Show error message when can't connect --- apworld/context.py | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/apworld/context.py b/apworld/context.py index 76ca11e..63645a4 100644 --- a/apworld/context.py +++ b/apworld/context.py @@ -2,6 +2,7 @@ import asyncio import os import pkgutil import subprocess +import sys from typing import Any import websockets @@ -106,6 +107,17 @@ class Lingo2GameContext: async_start(self.send_msgs([msg]), name="game Connected") + def send_connection_refused(self, text): + if self.server is None: + return + + msg = { + "cmd": "ConnectionRefused", + "text": text, + } + + async_start(self.send_msgs([msg]), name="game ConnectionRefused") + def send_item_sent_notification(self, item_name, receiver_name, item_flags): if self.server is None: return @@ -242,8 +254,20 @@ class Lingo2ClientContext(CommonContext): return ui async def server_auth(self, password_requested: bool = False): - self.auth = self.username - await self.send_connect() + if password_requested: + if self.password is None: + self.manager.game_ctx.send_connection_refused("Slot requires a password.") + else: + self.manager.game_ctx.send_connection_refused("Invalid password.") + else: + self.auth = self.username + await self.send_connect() + + def handle_connection_loss(self, msg: str): + super().handle_connection_loss(msg) + + exc_info = sys.exc_info() + self.manager.game_ctx.send_connection_refused(str(exc_info[1])) def on_package(self, cmd: str, args: dict): if cmd == "RoomInfo": -- cgit 1.4.1