mirror of
https://github.com/szymon-jozef/checkers.git
synced 2026-10-27 19:20:44 +01:00
fix: server allowing sending ready while hands not shaken
This commit is contained in:
@@ -32,8 +32,11 @@ pub struct Client {
|
||||
}
|
||||
|
||||
impl Client {
|
||||
pub async fn new() -> Option<Client> {
|
||||
let settings = ClientSettings::new();
|
||||
pub async fn new(settings: Option<ClientSettings>) -> Option<Client> {
|
||||
let Some(settings) = settings.or(Some(ClientSettings::new())) else {
|
||||
error!("Could not load client settings");
|
||||
return None;
|
||||
};
|
||||
|
||||
let (conn_sender, conn_reciever) =
|
||||
mpsc::channel::<(SocketAddr, Message<ServerMessage>)>(1024);
|
||||
|
||||
@@ -33,6 +33,7 @@ pub struct NetworkServerIdentity {
|
||||
// writing this since 10 a.m. and it's 9 p.m. already)
|
||||
pub identity: NetworkIdentity,
|
||||
pub sender: Sender<Message<ServerMessage>>,
|
||||
pub is_handshaken: bool,
|
||||
}
|
||||
|
||||
impl NetworkServerIdentity {
|
||||
@@ -40,6 +41,7 @@ impl NetworkServerIdentity {
|
||||
Self {
|
||||
identity: NetworkIdentity::default(),
|
||||
sender,
|
||||
is_handshaken: false,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +186,7 @@ impl Server {
|
||||
|
||||
ClientMessage::SignalReadiness => {
|
||||
self.handle_readiness(addr).await
|
||||
},
|
||||
}
|
||||
|
||||
ClientMessage::RequestCapture { capture_path } => {
|
||||
self.process_capture(capture_path).await;
|
||||
@@ -282,7 +282,8 @@ impl Server {
|
||||
return;
|
||||
};
|
||||
|
||||
identity.identity.name = fixed_name
|
||||
identity.identity.name = fixed_name;
|
||||
identity.is_handshaken = true;
|
||||
}
|
||||
|
||||
async fn process_capture(&mut self, capture_path: CapturePath) {
|
||||
@@ -313,6 +314,14 @@ impl Server {
|
||||
}
|
||||
|
||||
async fn handle_readiness(&mut self, addr: SocketAddr) {
|
||||
if !self.connections[&addr].is_handshaken {
|
||||
warn!(
|
||||
"Connection: {} tried sending readiness, but it have not shaken hands. Ignoring...",
|
||||
addr
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
self.state.ready_count += 1;
|
||||
info!(
|
||||
"{} signaled readiness. Currently ready: {}/{}",
|
||||
|
||||
Reference in New Issue
Block a user