diff options
author | Star Rauchenberger <fefferburbia@gmail.com> | 2025-10-01 11:23:06 -0400 |
---|---|---|
committer | Star Rauchenberger <fefferburbia@gmail.com> | 2025-10-01 11:23:06 -0400 |
commit | c7c64dcc56432e85e92a7c619a260bd01bf56e56 (patch) | |
tree | afa4cabfb714817f9a4b9493dde07cd4adbc0d3a | |
parent | cbfe9c4c8faa4f69f6149fdedf09e59909c6748e (diff) | |
download | lingo2-archipelago-c7c64dcc56432e85e92a7c619a260bd01bf56e56.tar.gz lingo2-archipelago-c7c64dcc56432e85e92a7c619a260bd01bf56e56.tar.bz2 lingo2-archipelago-c7c64dcc56432e85e92a7c619a260bd01bf56e56.zip |
Show error message when can't connect
-rw-r--r-- | apworld/context.py | 28 |
1 files 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 | |||
2 | import os | 2 | import os |
3 | import pkgutil | 3 | import pkgutil |
4 | import subprocess | 4 | import subprocess |
5 | import sys | ||
5 | from typing import Any | 6 | from typing import Any |
6 | 7 | ||
7 | import websockets | 8 | import websockets |
@@ -106,6 +107,17 @@ class Lingo2GameContext: | |||
106 | 107 | ||
107 | async_start(self.send_msgs([msg]), name="game Connected") | 108 | async_start(self.send_msgs([msg]), name="game Connected") |
108 | 109 | ||
110 | def send_connection_refused(self, text): | ||
111 | if self.server is None: | ||
112 | return | ||
113 | |||
114 | msg = { | ||
115 | "cmd": "ConnectionRefused", | ||
116 | "text": text, | ||
117 | } | ||
118 | |||
119 | async_start(self.send_msgs([msg]), name="game ConnectionRefused") | ||
120 | |||
109 | def send_item_sent_notification(self, item_name, receiver_name, item_flags): | 121 | def send_item_sent_notification(self, item_name, receiver_name, item_flags): |
110 | if self.server is None: | 122 | if self.server is None: |
111 | return | 123 | return |
@@ -242,8 +254,20 @@ class Lingo2ClientContext(CommonContext): | |||
242 | return ui | 254 | return ui |
243 | 255 | ||
244 | async def server_auth(self, password_requested: bool = False): | 256 | async def server_auth(self, password_requested: bool = False): |
245 | self.auth = self.username | 257 | if password_requested: |
246 | await self.send_connect() | 258 | if self.password is None: |
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: | ||
263 | self.auth = self.username | ||
264 | await self.send_connect() | ||
265 | |||
266 | def handle_connection_loss(self, msg: str): | ||
267 | super().handle_connection_loss(msg) | ||
268 | |||
269 | exc_info = sys.exc_info() | ||
270 | self.manager.game_ctx.send_connection_refused(str(exc_info[1])) | ||
247 | 271 | ||
248 | def on_package(self, cmd: str, args: dict): | 272 | def on_package(self, cmd: str, args: dict): |
249 | if cmd == "RoomInfo": | 273 | if cmd == "RoomInfo": |