jake
5 years ago
3 changed files with 56 additions and 46 deletions
@ -0,0 +1,52 @@ |
|||
use std::collections::HashMap;
|
|||
use libpso::packet::ship::*;
|
|||
use crate::common::serverstate::ClientId;
|
|||
use crate::common::leveltable::CharacterLevelTable;
|
|||
use crate::ship::ship::{SendShipPacket, ShipError, ClientState};
|
|||
use crate::ship::character::{CharacterBytesBuilder, FullCharacterBytesBuilder};
|
|||
use crate::ship::location::{ClientLocation, LobbyId, RoomId, RoomLobby, MAX_ROOMS};
|
|||
use libpso::character::character;
|
|||
use crate::entity::gateway::EntityGateway;
|
|||
|
|||
pub fn player_chat(id: ClientId,
|
|||
msg: &PlayerChat,
|
|||
client_location: &ClientLocation,
|
|||
clients: &HashMap<ClientId, ClientState>) -> Result<Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send>, ShipError> {
|
|||
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,
|
|||
request_infoboard: &ViewInfoboardRequest,
|
|||
client_location: &ClientLocation,
|
|||
clients: &HashMap<ClientId, ClientState>)
|
|||
-> 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())
|
|||
}
|
|||
|
|||
pub fn write_infoboard<EG: EntityGateway>(id: ClientId,
|
|||
new_infoboard: &WriteInfoboard,
|
|||
clients: &mut HashMap<ClientId, ClientState>,
|
|||
entity_gateway: &mut EG)
|
|||
-> 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);
|
|||
entity_gateway.save_character(&client.character);
|
|||
Box::new(None.into_iter())
|
|||
}
|
@ -1,3 +1,4 @@ |
|||
pub mod auth;
|
|||
pub mod communication;
|
|||
pub mod lobby;
|
|||
pub mod room;
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue