From 903a2b283f37f96fa1b3ae7ee011d060e1869cc9 Mon Sep 17 00:00:00 2001 From: andy Date: Thu, 26 Dec 2019 18:47:00 -0400 Subject: [PATCH] initial chat packets. wip --- src/ship/ship.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/ship/ship.rs b/src/ship/ship.rs index 0272bdb..795c12e 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,24 @@ impl ShipServerState { (client.client_id, SendShipPacket::DirectMessage(cmsg.clone())) }).collect::>().into_iter()) } + + fn player_chat(&mut self, id: ClientId, msg: &PlayerChat) -> Box> { + let mut cmsg = PlayerChat::new(0, 0, String::new()); + let client = self.clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap(); + cmsg.padding = 0x00010000; + cmsg.guildcard = client.user.guildcard.unwrap(); + cmsg.message.push_str(msg.message.as_str()); + 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() + .map(move |client| { + (client.client_id, SendShipPacket::PlayerChat(cmsg.clone())) + }).collect::>().into_iter()) + } } @@ -354,6 +376,10 @@ impl ServerState for ShipServerState { RecvShipPacket::DirectMessage(msg) => { self.direct_message(id, msg) }, + + RecvShipPacket::PlayerChat(msg) => { + self.player_chat(id, msg) + }, }) } }