diff --git a/server/src/connection.rs b/server/src/connection.rs index 1ec5d42..47b72e8 100644 --- a/server/src/connection.rs +++ b/server/src/connection.rs @@ -104,7 +104,7 @@ pub async fn handle_connection( connections: ConnectionMap, matches: MatchMap, waiting_queue: WaitingQueue, - event_system: crate::events::EventSystem, + //event_system: crate::events::EventSystem, ) -> anyhow::Result<()> { use tokio_tungstenite::accept_async; @@ -152,18 +152,19 @@ pub async fn handle_connection( Join { username } => { { let mut conn_map = connections.lock().await; - let mut player = conn_map.get_mut(&player_id).unwrap(); + let player = conn_map.get_mut(&player_id).unwrap(); player.username = Some(username); } //respone to client let response: EventResponse = EventResponse { - response: core::result::Result::Ok(true), + response: core::result::Result::Ok(()), }; println!("response: {:?}", response); - send_message_to_player( + //event_system.send_event(player_id, &response, &connections); + let _ = send_message_to_player( &connections, player_id, &serde_json::to_string(&response).unwrap(), diff --git a/server/src/events.rs b/server/src/events.rs index 817965a..94b14ea 100644 --- a/server/src/events.rs +++ b/server/src/events.rs @@ -26,10 +26,10 @@ pub enum ClientEvent { #[derive(Serialize, Deserialize, Debug)] pub struct EventResponse { - pub response: Result, + pub response: Result<(), String>, } -pub struct EventSystem { +/*pub struct EventSystem { sender: mpsc::UnboundedSender<(Uuid, EventResponse)>, receiver: Arc>>, } @@ -59,12 +59,13 @@ impl EventSystem { connections: &ConnectionMap, ) -> Result<(), Box> { //self.sender.send((player_id, event))?; - + println!("Hellodsjaoidsaid"); crate::connection::send_message_to_player( &connections, player_id, &serde_json::to_string(&event).unwrap(), - ); + ) + .await; Ok(()) } @@ -81,7 +82,6 @@ impl Default for EventSystem { } } -/* #[cfg(test)] mod tests { use super::*; diff --git a/server/src/main.rs b/server/src/main.rs index ec0ce08..cd50264 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -16,14 +16,14 @@ async fn main() -> anyhow::Result<()> { let waiting_queue = connection::new_waiting_queue(); // Event system for communication between components - let event_system = events::EventSystem::new(); + //let event_system = events::EventSystem::new(); // Start matchmaking background task let matchmaker = matchmaking::MatchmakingSystem::new( connections.clone(), matches.clone(), waiting_queue.clone(), - event_system.clone(), + //event_system.clone(), ); tokio::spawn(async move { matchmaker.run().await; @@ -34,7 +34,7 @@ async fn main() -> anyhow::Result<()> { let connections = connections.clone(); let matches = matches.clone(); let waiting_queue = waiting_queue.clone(); - let event_system = event_system.clone(); + //let event_system = event_system.clone(); tokio::spawn(async move { if let Err(e) = connection::handle_connection( @@ -42,7 +42,7 @@ async fn main() -> anyhow::Result<()> { connections, matches, waiting_queue, - event_system, + //event_system, ) .await { diff --git a/server/src/matchmaking.rs b/server/src/matchmaking.rs index 4f4cc27..1aae4ea 100644 --- a/server/src/matchmaking.rs +++ b/server/src/matchmaking.rs @@ -1,5 +1,5 @@ use crate::connection::{ConnectionMap, GameMatch, MatchMap, WaitingQueue}; -use crate::events::EventSystem; +//use crate::events::EventSystem; use rand::random; use uuid::Uuid; @@ -7,7 +7,7 @@ pub struct MatchmakingSystem { connections: ConnectionMap, matches: MatchMap, waiting_queue: WaitingQueue, - event_system: EventSystem, + //event_system: EventSystem, } impl MatchmakingSystem { @@ -15,13 +15,13 @@ impl MatchmakingSystem { connections: ConnectionMap, matches: MatchMap, waiting_queue: WaitingQueue, - event_system: EventSystem, + //event_system: EventSystem, ) -> Self { Self { connections, matches, waiting_queue, - event_system, + //event_system, } } @@ -114,7 +114,7 @@ impl MatchmakingSystem { #[cfg(test)] mod tests { use super::*; - use crate::events::EventSystem; + //use crate::events::EventSystem; use uuid::Uuid; use crate::connection::new_connection_map; @@ -126,13 +126,13 @@ mod tests { let connections = new_connection_map(); let matches = new_match_map(); let waiting_queue = new_waiting_queue(); - let event_system = EventSystem::new(); + //let event_system = EventSystem::new(); let matchmaking = MatchmakingSystem::new( connections.clone(), matches.clone(), waiting_queue.clone(), - event_system.clone(), + //event_system.clone(), ); let player1 = Uuid::new_v4(); @@ -172,13 +172,13 @@ mod tests { let connections = new_connection_map(); let matches = new_match_map(); let waiting_queue = new_waiting_queue(); - let event_system = EventSystem::new(); + //let event_system = EventSystem::new(); let matchmaking = MatchmakingSystem::new( connections.clone(), matches.clone(), waiting_queue.clone(), - event_system.clone(), + //event_system.clone(), ); let player1 = Uuid::new_v4();