about summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--apworld/context.py28
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
2import os 2import os
3import pkgutil 3import pkgutil
4import subprocess 4import subprocess
5import sys
5from typing import Any 6from typing import Any
6 7
7import websockets 8import 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":