feat: complete realtime challenge matchmaking
This commit is contained in:
@@ -26,7 +26,11 @@ class MatchConsumer(AsyncJsonWebsocketConsumer):
|
||||
await self.send_json({"type": "pong"})
|
||||
return
|
||||
if event_type == "progress":
|
||||
answered_count = max(0, min(int(content.get("answered_count", 0)), 100))
|
||||
try:
|
||||
answered_count = max(0, min(int(content.get("answered_count", 0)), 100))
|
||||
except (TypeError, ValueError):
|
||||
await self.send_json({"type": "error", "message": "答题进度无效"})
|
||||
return
|
||||
await self.channel_layer.group_send(
|
||||
self.group_name,
|
||||
{
|
||||
@@ -45,6 +49,15 @@ class MatchConsumer(AsyncJsonWebsocketConsumer):
|
||||
}
|
||||
)
|
||||
|
||||
async def match_state(self, event):
|
||||
await self.send_json(
|
||||
{
|
||||
"type": "state",
|
||||
"reason": event["reason"],
|
||||
"match_id": str(self.match_id),
|
||||
}
|
||||
)
|
||||
|
||||
@database_sync_to_async
|
||||
def _is_participant(self, user_id):
|
||||
return RealtimeMatch.objects.filter(id=self.match_id).filter(
|
||||
|
||||
Reference in New Issue
Block a user