prevent user from joining a game they're already in
This commit is contained in:
parent
49351a31b1
commit
286d26d852
1 changed files with 21 additions and 0 deletions
|
@ -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);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue