diff --git a/src/ship/ship.rs b/src/ship/ship.rs index f68c321..5cac2b7 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -37,6 +37,7 @@ pub enum RecvShipPacket { MenuSelect(MenuSelect), CharData(CharData), Message(Message), + DirectMessage(DirectMessage), } impl RecvServerPacket for RecvShipPacket { @@ -46,6 +47,7 @@ impl RecvServerPacket for RecvShipPacket { 0x10 => Ok(RecvShipPacket::MenuSelect(MenuSelect::from_bytes(data)?)), 0x61 => Ok(RecvShipPacket::CharData(CharData::from_bytes(data)?)), 0x60 => Ok(RecvShipPacket::Message(Message::from_bytes(data)?)), + 0x62 => Ok(RecvShipPacket::DirectMessage(DirectMessage::from_bytes(data)?)), _ => Err(PacketParseError::WrongPacketForServerType(u16::from_le_bytes([data[2], data[3]]), data.to_vec())) } } @@ -60,6 +62,7 @@ pub enum SendShipPacket { CharDataRequest(CharDataRequest), JoinLobby(JoinLobby), Message(Message), + DirectMessage(DirectMessage), } impl SendServerPacket for SendShipPacket { @@ -72,6 +75,7 @@ impl SendServerPacket for SendShipPacket { SendShipPacket::CharDataRequest(pkt) => pkt.as_bytes(), SendShipPacket::JoinLobby(pkt) => pkt.as_bytes(), SendShipPacket::Message(pkt) => pkt.as_bytes(), + SendShipPacket::DirectMessage(pkt) => pkt.as_bytes(), } } } @@ -224,9 +228,20 @@ impl ShipServerState { fn message(&mut self, id: ClientId, msg: &Message) -> Box> { let cmsg = msg.clone(); - Box::new(self.client_location.get_client_neighbors(id).into_iter().map(move |client| { - (client, SendShipPacket::Message(cmsg.clone())) - })) + Box::new(self.client_location.get_area_by_user(id).clients().iter() + .filter(|client| client.client_id != id) + .map(move |client| { + (client.client_id, SendShipPacket::Message(cmsg.clone())) + }).collect::>().into_iter()) + } + + fn direct_message(&mut self, id: ClientId, msg: &DirectMessage) -> Box> { + let cmsg = msg.clone(); + Box::new(self.client_location.get_area_by_user(id).clients().iter() + .filter(|client| client.index == cmsg.flag as usize) + .map(|client| { + (client.client_id, SendShipPacket::DirectMessage(cmsg.clone())) + }).collect::>().into_iter()) } } @@ -267,7 +282,10 @@ impl ServerState for ShipServerState { }, RecvShipPacket::Message(msg) => { self.message(id, msg) - } + }, + RecvShipPacket::DirectMessage(msg) => { + self.direct_message(id, msg) + }, }) } }