prevent crash when submitting empty judge request

This commit is contained in:
Adam 2024-08-28 18:13:02 -04:00
parent 1b6452cad0
commit 574471fbfb
2 changed files with 14 additions and 12 deletions

View file

@ -142,13 +142,11 @@ impl Game {
pub fn judge_round(&mut self, request: JudgeDecisionRequest, player_user_id: String) {
// Check if player is czar
if self.czar.read().unwrap().uuid.to_string() == player_user_id {
let winner_id = self
.judge_pile_meta
.get(&request.winning_cards)
.unwrap()
.clone();
self.end_round(winner_id)
if let Some(winner_id) = self.judge_pile_meta.get(&request.winning_cards) {
self.end_round(winner_id.to_string())
} else {
tracing::error!("Attempted to look up nonexistent cards for judging!");
}
} else {
tracing::error!("Player is not czar!");
}

View file

@ -80,11 +80,15 @@ impl MessageHandler {
_judge_decision
if let Ok(judge_request) = from_str::<JudgeDecisionRequest>(&text) =>
{
self.state
.games_tx
.send(JudgeDecision(judge_request, addr))
.await
.unwrap();
if !judge_request.winning_cards.is_empty() {
self.state
.games_tx
.send(JudgeDecision(judge_request, addr))
.await
.unwrap();
} else {
tracing::debug!("Judge request received with empty cards");
}
}
_delete_game if let Ok(delete_request) = from_str::<GameDeleteRequest>(&text) => {