|
@ -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,24 @@ 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) -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)>> {
|
|
|
|
|
|
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::<Vec<_>>().into_iter())
|
|
|
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -354,6 +376,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) => {
|
|
|
|
|
|
self.player_chat(id, msg)
|
|
|
|
|
|
},
|
|
|
})
|
|
|
})
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|