From 4883d00347c908f2f66c2df2f4256963dddfe82c Mon Sep 17 00:00:00 2001 From: Brandon <103316367+okbrandon@users.noreply.github.com> Date: Thu, 14 Nov 2024 21:47:20 +0100 Subject: [PATCH] Challenge: Fixed match flags and invitations --- backend/api/consumers/match.py | 6 +++--- backend/api/views/users.py | 10 +++++++++- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/backend/api/consumers/match.py b/backend/api/consumers/match.py index c4678b8c..3f3ef9e9 100644 --- a/backend/api/consumers/match.py +++ b/backend/api/consumers/match.py @@ -569,10 +569,10 @@ async def handle_spectate_request(self, data): match_state['spectators'].append(self.user.userID) playerA = await self.get_user_from_id(match.playerA['id']) playerB = await self.get_user_from_id(match.playerB['id']) if match.playerB else None - + playerA_data = UserSerializer(playerA).data playerB_data = UserSerializer(playerB).data if playerB else None - + safe_playerA = get_safe_profile(playerA_data, me=False) safe_playerB = get_safe_profile(playerB_data, me=False) if playerB_data else None @@ -663,7 +663,7 @@ def find_or_create_match(self, match_type): logger.error(f"[{self.__class__.__name__}] Failed to connect to bot: {str(e)}") return new_match elif match_type == 'challenge': - available_match = Match.objects.filter(finishedAt__isnull=True, whitelist__userID=self.user.userID, flags__exact=4).first() + available_match = Match.objects.filter(finishedAt__isnull=True, whitelist__userID=self.user.userID, flags__exact=5).first() if available_match: logger.info(f"[{self.__class__.__name__}] Found existing challenge match: {MatchSerializer(available_match).data}") diff --git a/backend/api/views/users.py b/backend/api/views/users.py index e2f0a5e5..defb5f18 100644 --- a/backend/api/views/users.py +++ b/backend/api/views/users.py @@ -674,6 +674,14 @@ def post(self, request, identifier, inviteID, action): return Response({"error": "Inviter is not free to play"}, status=status.HTTP_400_BAD_REQUEST) + # Check if the invitee is available to play + if invitee.status['online'] != True: + return Response({"error": "Invitee is not online"}, + status=status.HTTP_400_BAD_REQUEST) + if invitee.status['activity'] != 'HOME': + return Response({"error": "Invitee is not free to play"}, + status=status.HTTP_400_BAD_REQUEST) + # Action processing if action == 'accept': invite.status = 'ACCEPTED' @@ -685,7 +693,7 @@ def post(self, request, identifier, inviteID, action): winnerID=None, scores={}, finishedAt=None, - flags=4 + flags=5 ) new_match.whitelist.add(inviter, invitee) new_match.save()