prevent user from joining a game they're already in

This commit is contained in:
Adam 2024-08-18 19:11:38 -04:00
parent 49351a31b1
commit 286d26d852

View file

@ -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);