mirror of
https://github.com/szymon-jozef/checkers.git
synced 2026-10-28 11:10:44 +01:00
feat: add handshake answer
This commit is contained in:
@@ -68,7 +68,7 @@ impl Client {
|
|||||||
loop {
|
loop {
|
||||||
if let Some(oldest_msg) = conn_reciever_incoming.recv().await {
|
if let Some(oldest_msg) = conn_reciever_incoming.recv().await {
|
||||||
let (addr, msg) = oldest_msg;
|
let (addr, msg) = oldest_msg;
|
||||||
info!("Got message from: {:?}", addr);
|
debug!("Got message from: {:?}", addr);
|
||||||
|
|
||||||
match msg.content {
|
match msg.content {
|
||||||
ServerMessage::RequestHandshake => {
|
ServerMessage::RequestHandshake => {
|
||||||
@@ -79,7 +79,9 @@ impl Client {
|
|||||||
|
|
||||||
let _ = sender.send(msg.unwrap()).await;
|
let _ = sender.send(msg.unwrap()).await;
|
||||||
}
|
}
|
||||||
ServerMessage::AcceptHandshake { player_id } => todo!(),
|
ServerMessage::AcceptHandshake => {
|
||||||
|
info!("Server accepted us! Yay :D");
|
||||||
|
}
|
||||||
ServerMessage::DeclineHandshake { reason } => {
|
ServerMessage::DeclineHandshake { reason } => {
|
||||||
error!("Server declined connection: {}", reason);
|
error!("Server declined connection: {}", reason);
|
||||||
break;
|
break;
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ where
|
|||||||
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone)]
|
#[derive(Deserialize, Serialize, Debug, PartialEq, Eq, Clone)]
|
||||||
pub enum ServerMessage {
|
pub enum ServerMessage {
|
||||||
RequestHandshake,
|
RequestHandshake,
|
||||||
AcceptHandshake { player_id: Uuid },
|
AcceptHandshake,
|
||||||
DeclineHandshake { reason: String },
|
DeclineHandshake { reason: String },
|
||||||
|
|
||||||
AvailableCaptures { captures: Vec<CapturePath> },
|
AvailableCaptures { captures: Vec<CapturePath> },
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ impl Server {
|
|||||||
|
|
||||||
match msg.content {
|
match msg.content {
|
||||||
ClientMessage::AnswerHandshake { player_name } => {
|
ClientMessage::AnswerHandshake { player_name } => {
|
||||||
self.process_handshake(addr, player_name);
|
self.process_handshake(addr, player_name).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClientMessage::ConnectionDead { addr } => {
|
ClientMessage::ConnectionDead { addr } => {
|
||||||
@@ -183,7 +183,7 @@ impl Server {
|
|||||||
// TODO! Should decrement ready_counter if player was ready. But
|
// TODO! Should decrement ready_counter if player was ready. But
|
||||||
// how to check that? Maybe create new struct that will hold
|
// how to check that? Maybe create new struct that will hold
|
||||||
// sender and ready and maybe some other data.
|
// sender and ready and maybe some other data.
|
||||||
self.connections.remove(&addr);
|
self.remove_client(addr);
|
||||||
},
|
},
|
||||||
|
|
||||||
ClientMessage::SignalReadiness => {
|
ClientMessage::SignalReadiness => {
|
||||||
@@ -192,6 +192,8 @@ impl Server {
|
|||||||
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");
|
||||||
self.state.stage = 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 ======== */
|
/* ======= 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);
|
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) {
|
fn process_capture(&mut self, capture_path: CapturePath) {
|
||||||
|
|||||||
Reference in New Issue
Block a user