Skip to content

Commit

Permalink
Challenge: Fixed match flags and invitations
Browse files Browse the repository at this point in the history
  • Loading branch information
okbrandon committed Nov 14, 2024
1 parent 2d19868 commit 4883d00
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
6 changes: 3 additions & 3 deletions backend/api/consumers/match.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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}")
Expand Down
10 changes: 9 additions & 1 deletion backend/api/views/users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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()
Expand Down

0 comments on commit 4883d00

Please sign in to comment.