fix: remove double sending board state

This commit is contained in:
2026-08-17 19:44:09 +02:00
parent a8a6e11350
commit 8ee7242726
4 changed files with 13 additions and 36 deletions

View File

@@ -96,13 +96,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
match msg {
Some(ClientData::GameStart {
identity,
board_view,
}) => {
info!(
"Got new identity: {} and board_view. Game is about to start!",
"Got new identity: {}",
identity
);
println!("{}", board_view.to_string(&identity.id));
indentity = Some(identity);
}

View File

@@ -39,10 +39,7 @@ pub enum ClientCommands {
/// Data that network client gives to normal client. I have no better idea for this name, hence this
/// comment
pub enum ClientData {
GameStart {
identity: NetworkIdentity,
board_view: BoardView,
},
GameStart { identity: NetworkIdentity },
GameEnd(GameResult),
AvailableCaptures(Vec<CapturePath>),
@@ -167,10 +164,9 @@ impl Client {
ServerMessage::GameStart {
identity,
board_view,
} => {
debug!("Got GameStart message! Identity: {}", identity);
let _ = update_sender.send(ClientData::GameStart { identity, board_view }).await;
let _ = update_sender.send(ClientData::GameStart { identity }).await;
}
ServerMessage::AvailableCaptures { captures } => todo!(),

View File

@@ -42,33 +42,18 @@ where
pub enum ServerMessage {
RequestHandshake,
AcceptHandshake,
DeclineHandshake {
reason: String,
},
DeclineHandshake { reason: String },
GameStart {
identity: NetworkIdentity,
board_view: BoardView,
},
GameStart { identity: NetworkIdentity },
AvailableCaptures {
captures: Vec<CapturePath>,
},
AvailableMoves {
moves: Vec<MovePath>,
},
AvailableCaptures { captures: Vec<CapturePath> },
AvailableMoves { moves: Vec<MovePath> },
BroadcastBoardState {
board: BoardView,
},
BroadcastBoardState { board: BoardView },
BroadcastCurrentTurn {
active_player: Uuid,
},
BroadcastCurrentTurn { active_player: Uuid },
GameEnd {
result: GameResult,
},
GameEnd { result: GameResult },
}
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone)]

View File

@@ -195,11 +195,11 @@ impl Server {
},
ClientMessage::RequestCapture { capture_path } => {
self.process_capture(capture_path);
self.process_capture(capture_path).await;
}
ClientMessage::RequestMove { from, to } => {
self.process_move(from, to);
self.process_move(from, to).await;
}
ClientMessage::TextMessage (content) => {
@@ -232,7 +232,6 @@ impl Server {
let game_master = GameMaster::new(&names[0], &names[1]);
let names_and_ids: Vec<(String, Uuid)> = game_master.get_players_names_and_ids();
let board_view: BoardView = game_master.get_board_view();
let mut msgs: Vec<(SocketAddr, Result<Message<ServerMessage>, postcard::Error>)> = vec![];
@@ -245,7 +244,6 @@ impl Server {
*addr,
Message::new(ServerMessage::GameStart {
identity: networkidentity.identity.clone(),
board_view: board_view.clone(),
}),
));
}
@@ -324,7 +322,7 @@ impl Server {
"{} signaled readiness. Currently ready: {}/{}",
addr, self.state.ready_count, self.settings.max_connections
);
self.connections.get_mut(&addr).expect("Couldn't get the identity of the ready player. I guess this should never happen so i'm panicking like a little bitch").identity.is_ready = true;
self.connections.get_mut(&addr).expect("Couldn't get the identity of the ready player. I guess this should never happen so i'm panicking like a little bitch").identity.is_ready = true; // TODO! This sometimes happens for some reason (when there is a game going, both player leave and someone tries to join)
if self.state.ready_count == self.settings.max_connections {
info!("All players are ready! Changing state to ServerStage::Game");