2020-04-21 23:40:44 -06:00
|
|
|
use libpso::packet::ship::*;
|
|
|
|
use crate::common::serverstate::ClientId;
|
2020-05-02 22:08:37 -03:00
|
|
|
use crate::ship::ship::{SendShipPacket, ShipError, Clients};
|
|
|
|
use crate::ship::location::{ClientLocation};
|
2020-04-21 23:40:44 -06:00
|
|
|
use crate::entity::gateway::EntityGateway;
|
|
|
|
|
|
|
|
pub fn player_chat(id: ClientId,
|
|
|
|
msg: &PlayerChat,
|
|
|
|
client_location: &ClientLocation,
|
2020-04-22 23:49:49 -06:00
|
|
|
clients: &Clients) -> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError> {
|
2020-04-21 23:40:44 -06:00
|
|
|
let client = clients.get(&id).ok_or(ShipError::ClientNotFound(id))?;
|
|
|
|
let cmsg = PlayerChat::new(client.user.id.0, msg.message.clone());
|
|
|
|
|
|
|
|
Ok(Box::new(client_location.get_all_clients_by_client(id).unwrap().into_iter()
|
|
|
|
.map(move |client| {
|
|
|
|
(client.client, SendShipPacket::PlayerChat(cmsg.clone()))
|
|
|
|
})))
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn request_infoboard(id: ClientId,
|
|
|
|
client_location: &ClientLocation,
|
2020-04-22 23:49:49 -06:00
|
|
|
clients: &Clients)
|
2020-04-21 23:40:44 -06:00
|
|
|
-> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
|
|
|
|
let area_clients = client_location.get_client_neighbors(id).unwrap();
|
|
|
|
let r = area_clients.iter()
|
|
|
|
.filter_map(|c| {
|
|
|
|
clients.get(&c.client)
|
|
|
|
})
|
|
|
|
.map(|client| {
|
|
|
|
InfoboardResponse {
|
|
|
|
name: libpso::utf8_to_utf16_array!(client.character.name, 16),
|
|
|
|
message: client.character.info_board.as_bytes(),
|
|
|
|
}
|
|
|
|
}).collect();
|
|
|
|
Box::new(vec![(id, SendShipPacket::ViewInfoboardResponse(ViewInfoboardResponse {response: r}))].into_iter())
|
|
|
|
}
|
|
|
|
|
2020-06-02 18:51:18 -06:00
|
|
|
pub async fn write_infoboard<EG: EntityGateway>(id: ClientId,
|
2020-04-21 23:40:44 -06:00
|
|
|
new_infoboard: &WriteInfoboard,
|
2020-04-22 23:49:49 -06:00
|
|
|
clients: &mut Clients,
|
2022-07-30 15:02:18 -06:00
|
|
|
mut entity_gateway: EG)
|
2020-04-21 23:40:44 -06:00
|
|
|
-> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
|
|
|
|
let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap();
|
|
|
|
client.character.info_board.update_infoboard(new_infoboard);
|
2020-10-26 00:02:48 -06:00
|
|
|
entity_gateway.save_character(&client.character).await.unwrap();
|
2020-04-21 23:40:44 -06:00
|
|
|
Box::new(None.into_iter())
|
|
|
|
}
|