From 286d26d852f5c80724675db08256469b444fc1dc Mon Sep 17 00:00:00 2001 From: Adam <24621027+adoyle0@users.noreply.github.com> Date: Sun, 18 Aug 2024 19:11:38 -0400 Subject: [PATCH] prevent user from joining a game they're already in --- server/src/game_handler.rs | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/server/src/game_handler.rs b/server/src/game_handler.rs index acf33a7..ea5e2ae 100644 --- a/server/src/game_handler.rs +++ b/server/src/game_handler.rs @@ -1,7 +1,9 @@ use crate::user_handler::*; use crate::AppState; use crate::GameHandlerMessage::*; +use crate::SendUserMessage::*; use crate::User; +use crate::UserHandlerMessage::*; use anyhow::{Context, Result}; use lib::*; use rand::prelude::IteratorRandom; @@ -108,6 +110,25 @@ impl GameHandler { .unwrap() .clone(); + if this_game + .read() + .unwrap() + .players + .contains_key(&this_user.read().unwrap().uuid) + { + self.state + .users_tx + .send(DmUserAddr { + addr, + message: SendChatMessage(ChatMessage { + text: "You're already in this game!".to_owned(), + }), + }) + .await + .unwrap(); + return; + } + // Create player this_game.write().unwrap().create_player(this_user);