diff --git a/src/ship/ship.rs b/src/ship/ship.rs index 0272bdb..847ba34 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -38,6 +38,7 @@ pub enum RecvShipPacket { CharData(CharData), Message(Message), DirectMessage(DirectMessage), + PlayerChat(PlayerChat), } impl RecvServerPacket for RecvShipPacket { @@ -48,6 +49,7 @@ impl RecvServerPacket for RecvShipPacket { 0x61 => Ok(RecvShipPacket::CharData(CharData::from_bytes(data)?)), 0x60 => Ok(RecvShipPacket::Message(Message::from_bytes(data)?)), 0x62 => Ok(RecvShipPacket::DirectMessage(DirectMessage::from_bytes(data)?)), + 0x06 => Ok(RecvShipPacket::PlayerChat(PlayerChat::from_bytes(data)?)), _ => Err(PacketParseError::WrongPacketForServerType(u16::from_le_bytes([data[2], data[3]]), data.to_vec())) } } @@ -64,6 +66,7 @@ pub enum SendShipPacket { AddToLobby(AddToLobby), Message(Message), DirectMessage(DirectMessage), + PlayerChat(PlayerChat), } impl SendServerPacket for SendShipPacket { @@ -78,6 +81,7 @@ impl SendServerPacket for SendShipPacket { SendShipPacket::AddToLobby(pkt) => pkt.as_bytes(), SendShipPacket::Message(pkt) => pkt.as_bytes(), SendShipPacket::DirectMessage(pkt) => pkt.as_bytes(), + SendShipPacket::PlayerChat(pkt) => pkt.as_bytes(), } } } @@ -311,6 +315,16 @@ impl ShipServerState { (client.client_id, SendShipPacket::DirectMessage(cmsg.clone())) }).collect::>().into_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(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())) + } } @@ -354,6 +368,10 @@ impl ServerState for ShipServerState { RecvShipPacket::DirectMessage(msg) => { self.direct_message(id, msg) }, + + RecvShipPacket::PlayerChat(msg) => { + Box::new(self.player_chat(id, msg)?.into_iter()) + }, }) } }