From e0da49d0482bede1ded76b77f1e1d3daaf5e674c Mon Sep 17 00:00:00 2001 From: andy Date: Tue, 31 Dec 2019 00:03:56 -0400 Subject: [PATCH] moved padding logic to libpso, changed return type from Box to Result --- src/ship/ship.rs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/ship/ship.rs b/src/ship/ship.rs index 6e7002f..59231e6 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -316,19 +316,14 @@ impl ShipServerState { }).collect::>().into_iter()) } - fn player_chat(&mut self, id: ClientId, msg: &PlayerChat) -> Box> { - let client = self.clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap(); - let mut cmsg = PlayerChat::new(0x00010000, client.user.guildcard.unwrap(), msg.message.clone()); - let mut mlen = (cmsg.message.len() * 2) + 0x12; - while mlen & 0x07 != 0 { - cmsg.message.push('\0'); - mlen += 1; - } - - Box::new(self.client_location.get_area_by_user(id).clients().iter() + fn player_chat(&mut self, id: ClientId, msg: &PlayerChat) -> Result>, ShipError> { + let client = self.clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id))?; + let cmsg = PlayerChat::new(0x00010000, client.user.guildcard.unwrap(), msg.message.clone()); + + Ok(Box::new(self.client_location.get_area_by_user(id).clients().iter() .map(move |client| { (client.client_id, SendShipPacket::PlayerChat(cmsg.clone())) - }).collect::>().into_iter()) + }).collect::>().into_iter())) } } @@ -375,7 +370,7 @@ impl ServerState for ShipServerState { }, RecvShipPacket::PlayerChat(msg) => { - self.player_chat(id, msg) + Box::new(self.player_chat(id, msg)?.into_iter()) }, }) }