mirror of
https://github.com/szymon-jozef/checkers.git
synced 2026-10-27 19:20:44 +01:00
fix: remove double sending board state
This commit is contained in:
@@ -96,13 +96,11 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
match msg {
|
match msg {
|
||||||
Some(ClientData::GameStart {
|
Some(ClientData::GameStart {
|
||||||
identity,
|
identity,
|
||||||
board_view,
|
|
||||||
}) => {
|
}) => {
|
||||||
info!(
|
info!(
|
||||||
"Got new identity: {} and board_view. Game is about to start!",
|
"Got new identity: {}",
|
||||||
identity
|
identity
|
||||||
);
|
);
|
||||||
println!("{}", board_view.to_string(&identity.id));
|
|
||||||
indentity = Some(identity);
|
indentity = Some(identity);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -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
|
/// Data that network client gives to normal client. I have no better idea for this name, hence this
|
||||||
/// comment
|
/// comment
|
||||||
pub enum ClientData {
|
pub enum ClientData {
|
||||||
GameStart {
|
GameStart { identity: NetworkIdentity },
|
||||||
identity: NetworkIdentity,
|
|
||||||
board_view: BoardView,
|
|
||||||
},
|
|
||||||
GameEnd(GameResult),
|
GameEnd(GameResult),
|
||||||
|
|
||||||
AvailableCaptures(Vec<CapturePath>),
|
AvailableCaptures(Vec<CapturePath>),
|
||||||
@@ -167,10 +164,9 @@ impl Client {
|
|||||||
|
|
||||||
ServerMessage::GameStart {
|
ServerMessage::GameStart {
|
||||||
identity,
|
identity,
|
||||||
board_view,
|
|
||||||
} => {
|
} => {
|
||||||
debug!("Got GameStart message! Identity: {}", identity);
|
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!(),
|
ServerMessage::AvailableCaptures { captures } => todo!(),
|
||||||
|
|||||||
@@ -42,33 +42,18 @@ where
|
|||||||
pub enum ServerMessage {
|
pub enum ServerMessage {
|
||||||
RequestHandshake,
|
RequestHandshake,
|
||||||
AcceptHandshake,
|
AcceptHandshake,
|
||||||
DeclineHandshake {
|
DeclineHandshake { reason: String },
|
||||||
reason: String,
|
|
||||||
},
|
|
||||||
|
|
||||||
GameStart {
|
GameStart { identity: NetworkIdentity },
|
||||||
identity: NetworkIdentity,
|
|
||||||
board_view: BoardView,
|
|
||||||
},
|
|
||||||
|
|
||||||
AvailableCaptures {
|
AvailableCaptures { captures: Vec<CapturePath> },
|
||||||
captures: Vec<CapturePath>,
|
AvailableMoves { moves: Vec<MovePath> },
|
||||||
},
|
|
||||||
AvailableMoves {
|
|
||||||
moves: Vec<MovePath>,
|
|
||||||
},
|
|
||||||
|
|
||||||
BroadcastBoardState {
|
BroadcastBoardState { board: BoardView },
|
||||||
board: BoardView,
|
|
||||||
},
|
|
||||||
|
|
||||||
BroadcastCurrentTurn {
|
BroadcastCurrentTurn { active_player: Uuid },
|
||||||
active_player: Uuid,
|
|
||||||
},
|
|
||||||
|
|
||||||
GameEnd {
|
GameEnd { result: GameResult },
|
||||||
result: GameResult,
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone)]
|
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone)]
|
||||||
|
|||||||
@@ -195,11 +195,11 @@ impl Server {
|
|||||||
},
|
},
|
||||||
|
|
||||||
ClientMessage::RequestCapture { capture_path } => {
|
ClientMessage::RequestCapture { capture_path } => {
|
||||||
self.process_capture(capture_path);
|
self.process_capture(capture_path).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientMessage::RequestMove { from, to } => {
|
ClientMessage::RequestMove { from, to } => {
|
||||||
self.process_move(from, to);
|
self.process_move(from, to).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientMessage::TextMessage (content) => {
|
ClientMessage::TextMessage (content) => {
|
||||||
@@ -232,7 +232,6 @@ impl Server {
|
|||||||
let game_master = GameMaster::new(&names[0], &names[1]);
|
let game_master = GameMaster::new(&names[0], &names[1]);
|
||||||
|
|
||||||
let names_and_ids: Vec<(String, Uuid)> = game_master.get_players_names_and_ids();
|
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![];
|
let mut msgs: Vec<(SocketAddr, Result<Message<ServerMessage>, postcard::Error>)> = vec![];
|
||||||
|
|
||||||
@@ -245,7 +244,6 @@ impl Server {
|
|||||||
*addr,
|
*addr,
|
||||||
Message::new(ServerMessage::GameStart {
|
Message::new(ServerMessage::GameStart {
|
||||||
identity: networkidentity.identity.clone(),
|
identity: networkidentity.identity.clone(),
|
||||||
board_view: board_view.clone(),
|
|
||||||
}),
|
}),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
@@ -324,7 +322,7 @@ impl Server {
|
|||||||
"{} signaled readiness. Currently ready: {}/{}",
|
"{} signaled readiness. Currently ready: {}/{}",
|
||||||
addr, self.state.ready_count, self.settings.max_connections
|
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 {
|
if self.state.ready_count == self.settings.max_connections {
|
||||||
info!("All players are ready! Changing state to ServerStage::Game");
|
info!("All players are ready! Changing state to ServerStage::Game");
|
||||||
|
|||||||
Reference in New Issue
Block a user