mirror of
https://github.com/szymon-jozef/checkers.git
synced 2026-10-27 19:20:44 +01:00
feat: add handshake answer
This commit is contained in:
@@ -68,7 +68,7 @@ impl Client {
|
||||
loop {
|
||||
if let Some(oldest_msg) = conn_reciever_incoming.recv().await {
|
||||
let (addr, msg) = oldest_msg;
|
||||
info!("Got message from: {:?}", addr);
|
||||
debug!("Got message from: {:?}", addr);
|
||||
|
||||
match msg.content {
|
||||
ServerMessage::RequestHandshake => {
|
||||
@@ -79,7 +79,9 @@ impl Client {
|
||||
|
||||
let _ = sender.send(msg.unwrap()).await;
|
||||
}
|
||||
ServerMessage::AcceptHandshake { player_id } => todo!(),
|
||||
ServerMessage::AcceptHandshake => {
|
||||
info!("Server accepted us! Yay :D");
|
||||
}
|
||||
ServerMessage::DeclineHandshake { reason } => {
|
||||
error!("Server declined connection: {}", reason);
|
||||
break;
|
||||
|
||||
@@ -37,7 +37,7 @@ where
|
||||
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone)]
|
||||
pub enum ServerMessage {
|
||||
RequestHandshake,
|
||||
AcceptHandshake { player_id: Uuid },
|
||||
AcceptHandshake,
|
||||
DeclineHandshake { reason: String },
|
||||
|
||||
AvailableCaptures { captures: Vec<CapturePath> },
|
||||
|
||||
@@ -175,7 +175,7 @@ impl Server {
|
||||
|
||||
match msg.content {
|
||||
ClientMessage::AnswerHandshake { player_name } => {
|
||||
self.process_handshake(addr, player_name);
|
||||
self.process_handshake(addr, player_name).await;
|
||||
}
|
||||
|
||||
ClientMessage::ConnectionDead { addr } => {
|
||||
@@ -183,7 +183,7 @@ impl Server {
|
||||
// TODO! Should decrement ready_counter if player was ready. But
|
||||
// how to check that? Maybe create new struct that will hold
|
||||
// sender and ready and maybe some other data.
|
||||
self.connections.remove(&addr);
|
||||
self.remove_client(addr);
|
||||
},
|
||||
|
||||
ClientMessage::SignalReadiness => {
|
||||
@@ -192,6 +192,8 @@ impl Server {
|
||||
if self.state.ready_count == self.settings.max_connections {
|
||||
info!("All players are ready! Changing state to ServerStage::Game");
|
||||
self.state.stage = ServerStage::Game;
|
||||
|
||||
self.start_game();
|
||||
}
|
||||
},
|
||||
|
||||
@@ -216,11 +218,17 @@ impl Server {
|
||||
}
|
||||
}
|
||||
|
||||
fn start_game(&self) {
|
||||
todo!();
|
||||
}
|
||||
|
||||
/* ======= Processing messages :D helper functions ======== */
|
||||
|
||||
fn process_handshake(&self, addr: SocketAddr, player_name: String) {
|
||||
async fn process_handshake(&mut self, addr: SocketAddr, player_name: String) {
|
||||
info!("Client: {:?} sent us his name: {}", addr, player_name);
|
||||
// TODO! Do something with this name i guess
|
||||
self.send_message(addr, Message::new(ServerMessage::AcceptHandshake))
|
||||
.await;
|
||||
// TODO! Validate if the name isn't already in use and append something to it if it is
|
||||
}
|
||||
|
||||
fn process_capture(&mut self, capture_path: CapturePath) {
|
||||
|
||||
Reference in New Issue
Block a user