diff --git a/api/config.py b/api/config.py index 43a8c95..17b6050 100644 --- a/api/config.py +++ b/api/config.py @@ -23,7 +23,7 @@ def __init__(self): self.REDIS_PASSWORD = os.environ.get("redis_password") self.RATE_LIMIT_MINUTE = 120 self.RATE_LIMIT_HOUR = 7200 - self.API_VERSION = "v2.10.0-alpha" + self.API_VERSION = "v2.11.0-alpha" self.MATCH_VERSION = "v2.11.1-alpha" def setMATCH_VERSION(self, match_version): diff --git a/api/routers/interactions/functions.py b/api/routers/interactions/functions.py index 1801cfa..ba5eae0 100644 --- a/api/routers/interactions/functions.py +++ b/api/routers/interactions/functions.py @@ -195,12 +195,19 @@ async def ping_update(group_identifier, request, manager, login): await manager.broadcast(group_identifier=group_identifier, payload=payload) -async def search_request(request, websocket, login): +async def search_request(request, websocket, login, manager): if not await ratelimit(connecting_IP=websocket.client.host): return logger.info(f"{login} -> Search") data = await search_match(search=request["search"]) if data is None: + await websocket.send_json( + { + "detail": "search match data", + "search_match_data": dict(), + } + ) + await manager.disconnect(websocket=websocket, group_identifier="0") return logger.info(f"{login} <- Search") await websocket.send_json( @@ -209,6 +216,7 @@ async def search_request(request, websocket, login): "search_match_data": data.dict(), } ) + await manager.disconnect(websocket=websocket, group_identifier="0") async def quick_match(request, websocket, login): diff --git a/api/routers/interactions/handler.py b/api/routers/interactions/handler.py index 014c4e1..1ef74f8 100644 --- a/api/routers/interactions/handler.py +++ b/api/routers/interactions/handler.py @@ -75,7 +75,9 @@ async def handle_request( ) case "search_match": - await search_request(request=request, websocket=websocket, login=login) + await search_request( + request=request, websocket=websocket, login=login, manager=manager + ) case "quick_match": await quick_match(request=request, websocket=websocket, login=login) diff --git a/api/utilities/manager.py b/api/utilities/manager.py index 4ce2acd..242c303 100644 --- a/api/utilities/manager.py +++ b/api/utilities/manager.py @@ -91,7 +91,8 @@ async def disconnect(self, websocket: WebSocket, group_identifier: str): if group_identifier not in list(self.active_connections.keys()): return - self.active_connections[group_identifier].remove(websocket) + if websocket in self.active_connections[group_identifier]: + self.active_connections[group_identifier].remove(websocket) if group_identifier != "0": key, m = await get_match_from_ID(group_identifier=group_identifier) @@ -108,8 +109,8 @@ async def disconnect(self, websocket: WebSocket, group_identifier: str): return await redis_client.set(name=key, value=str(m.dict())) - logger.info(f"{login} << {group_identifier}") try: + logger.info(f"{login} << {group_identifier}") # Try to disconnect socket, if it's already been disconnected then ignore and eat exception. await websocket.close(1000) except Exception as e: