Skip to content

Commit

Permalink
Merge pull request #83 from NeverScapeAlone/develop
Browse files Browse the repository at this point in the history
v2.11.0-alpha
  • Loading branch information
Ferrariic authored Aug 21, 2022
2 parents 4269e9c + ecddde9 commit faa012f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion api/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 9 additions & 1 deletion api/routers/interactions/functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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):
Expand Down
4 changes: 3 additions & 1 deletion api/routers/interactions/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions api/utilities/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down

0 comments on commit faa012f

Please sign in to comment.