diff --git a/src/common/mainloop/client.rs b/src/common/mainloop/client.rs index 9e91b81..d8f3af9 100644 --- a/src/common/mainloop/client.rs +++ b/src/common/mainloop/client.rs @@ -224,7 +224,7 @@ async fn state_client_loop(state: Arc>, match action { ClientAction::NewClient(client_id, sender) => { clients.insert(client_id, sender.clone()); - for action in state.on_connect(client_id) { + for action in state.on_connect(client_id).await { match action { OnConnect::Cipher((inc, outc)) => { sender.send(ServerStateAction::Cipher(inc, outc)).await; @@ -251,7 +251,7 @@ async fn state_client_loop(state: Arc>, } }, ClientAction::Disconnect(client_id) => { - let pkts = state.on_disconnect(client_id); + let pkts = state.on_disconnect(client_id).await; for (client_id, pkt) in pkts { if let Some(client) = clients.get_mut(&client_id) { client.send(ServerStateAction::Packet(pkt)).await; diff --git a/src/common/serverstate.rs b/src/common/serverstate.rs index f1573ae..d22c9c6 100644 --- a/src/common/serverstate.rs +++ b/src/common/serverstate.rs @@ -24,9 +24,9 @@ pub trait ServerState { type RecvPacket: RecvServerPacket; type PacketError; - fn on_connect(&mut self, id: ClientId) -> Vec>; + async fn on_connect(&mut self, id: ClientId) -> Vec>; async fn handle(&mut self, id: ClientId, pkt: &Self::RecvPacket) -> Result + Send>, Self::PacketError>; - fn on_disconnect(&mut self, id: ClientId) -> Vec<(ClientId, Self::SendPacket)>; + async fn on_disconnect(&mut self, id: ClientId) -> Vec<(ClientId, Self::SendPacket)>; } diff --git a/src/login/login.rs b/src/login/login.rs index 95e8b08..e2c8bc2 100644 --- a/src/login/login.rs +++ b/src/login/login.rs @@ -113,7 +113,7 @@ impl ServerState for LoginServerState { type RecvPacket = RecvLoginPacket; type PacketError = LoginError; - fn on_connect(&mut self, _id: ClientId) -> Vec> { + async fn on_connect(&mut self, _id: ClientId) -> Vec> { let mut rng = rand::thread_rng(); let mut server_key = [0u8; 48]; @@ -140,7 +140,7 @@ impl ServerState for LoginServerState { }) } - fn on_disconnect(&mut self, _id: ClientId) -> Vec<(ClientId, SendLoginPacket)> { + async fn on_disconnect(&mut self, _id: ClientId) -> Vec<(ClientId, SendLoginPacket)> { Vec::new() } } diff --git a/src/patch/patch.rs b/src/patch/patch.rs index b96616e..ec88b5c 100644 --- a/src/patch/patch.rs +++ b/src/patch/patch.rs @@ -160,7 +160,7 @@ impl ServerState for PatchServerState { type RecvPacket = RecvPatchPacket; type PacketError = PatchError; - fn on_connect(&mut self, _id: ClientId) -> Vec> { + async fn on_connect(&mut self, _id: ClientId) -> Vec> { let mut rng = rand::thread_rng(); let key_in: u32 = rng.gen(); let key_out: u32 = rng.gen(); @@ -202,7 +202,7 @@ impl ServerState for PatchServerState { }) } - fn on_disconnect(&mut self, _id: ClientId) -> Vec<(ClientId, SendPatchPacket)> { + async fn on_disconnect(&mut self, _id: ClientId) -> Vec<(ClientId, SendPatchPacket)> { Vec::new() } } diff --git a/src/ship/ship.rs b/src/ship/ship.rs index 0f51bc7..10cecac 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -456,7 +456,7 @@ impl ServerState for ShipServerState { type RecvPacket = RecvShipPacket; type PacketError = ShipError; - fn on_connect(&mut self, _id: ClientId) -> Vec> { + async fn on_connect(&mut self, _id: ClientId) -> Vec> { let mut rng = rand::thread_rng(); let mut server_key = [0u8; 48]; @@ -577,7 +577,7 @@ impl ServerState for ShipServerState { }) } - fn on_disconnect(&mut self, id: ClientId) -> Vec<(ClientId, SendShipPacket)> { + async fn on_disconnect(&mut self, id: ClientId) -> Vec<(ClientId, SendShipPacket)> { // TODO: don't unwrap! let client = self.clients.get(&id).unwrap(); let area_client = self.client_location.get_local_client(id).unwrap();