Browse Source

Merge branch 'issue_038' of jake/elseware into master

pbs
jake 5 years ago
committed by Gogs
parent
commit
3ece862163
  1. 18
      src/ship/ship.rs

18
src/ship/ship.rs

@ -38,6 +38,7 @@ pub enum RecvShipPacket {
CharData(CharData), CharData(CharData),
Message(Message), Message(Message),
DirectMessage(DirectMessage), DirectMessage(DirectMessage),
PlayerChat(PlayerChat),
} }
impl RecvServerPacket for RecvShipPacket { impl RecvServerPacket for RecvShipPacket {
@ -48,6 +49,7 @@ impl RecvServerPacket for RecvShipPacket {
0x61 => Ok(RecvShipPacket::CharData(CharData::from_bytes(data)?)), 0x61 => Ok(RecvShipPacket::CharData(CharData::from_bytes(data)?)),
0x60 => Ok(RecvShipPacket::Message(Message::from_bytes(data)?)), 0x60 => Ok(RecvShipPacket::Message(Message::from_bytes(data)?)),
0x62 => Ok(RecvShipPacket::DirectMessage(DirectMessage::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())) _ => Err(PacketParseError::WrongPacketForServerType(u16::from_le_bytes([data[2], data[3]]), data.to_vec()))
} }
} }
@ -64,6 +66,7 @@ pub enum SendShipPacket {
AddToLobby(AddToLobby), AddToLobby(AddToLobby),
Message(Message), Message(Message),
DirectMessage(DirectMessage), DirectMessage(DirectMessage),
PlayerChat(PlayerChat),
} }
impl SendServerPacket for SendShipPacket { impl SendServerPacket for SendShipPacket {
@ -78,6 +81,7 @@ impl SendServerPacket for SendShipPacket {
SendShipPacket::AddToLobby(pkt) => pkt.as_bytes(), SendShipPacket::AddToLobby(pkt) => pkt.as_bytes(),
SendShipPacket::Message(pkt) => pkt.as_bytes(), SendShipPacket::Message(pkt) => pkt.as_bytes(),
SendShipPacket::DirectMessage(pkt) => pkt.as_bytes(), SendShipPacket::DirectMessage(pkt) => pkt.as_bytes(),
SendShipPacket::PlayerChat(pkt) => pkt.as_bytes(),
} }
} }
} }
@ -311,6 +315,16 @@ impl<EG: EntityGateway> ShipServerState<EG> {
(client.client_id, SendShipPacket::DirectMessage(cmsg.clone())) (client.client_id, SendShipPacket::DirectMessage(cmsg.clone()))
}).collect::<Vec<_>>().into_iter()) }).collect::<Vec<_>>().into_iter())
} }
fn player_chat(&mut self, id: ClientId, msg: &PlayerChat) -> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)>>, 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::<Vec<_>>().into_iter()))
}
} }
@ -354,6 +368,10 @@ impl<EG: EntityGateway> ServerState for ShipServerState<EG> {
RecvShipPacket::DirectMessage(msg) => { RecvShipPacket::DirectMessage(msg) => {
self.direct_message(id, msg) self.direct_message(id, msg)
}, },
RecvShipPacket::PlayerChat(msg) => {
Box::new(self.player_chat(id, msg)?.into_iter())
},
}) })
} }
} }
Loading…
Cancel
Save