73 lines
2.7 KiB
Rust

use libpso::packet::ship::*;
use crate::common::serverstate::ClientId;
use crate::ship::ship::{SendShipPacket, ShipError, Clients};
use crate::entity::gateway::EntityGateway;
pub async fn update_config<EG>(id: ClientId,
update_config: UpdateConfig,
clients: &Clients,
entity_gateway: &mut EG)
-> Result<Vec<(ClientId, SendShipPacket)>, ShipError>
where
EG: EntityGateway + Clone + 'static,
{
clients.with_mut(id, |client| {
let mut entity_gateway = entity_gateway.clone();
Box::pin(async move {
client.character.config.update(&update_config);
entity_gateway.save_character(&client.character).await
})}).await??;
Ok(Vec::new())
}
pub async fn save_options<EG>(id: ClientId,
save_options: SaveOptions,
clients: &Clients,
entity_gateway: &mut EG)
-> Result<Vec<(ClientId, SendShipPacket)>, ShipError>
where
EG: EntityGateway + Clone + 'static,
{
clients.with_mut(id, |client| {
let mut entity_gateway = entity_gateway.clone();
Box::pin(async move {
client.character.option_flags = save_options.options;
entity_gateway.save_character(&client.character).await
})}).await??;
Ok(Vec::new())
}
pub async fn keyboard_config<EG>(id: ClientId,
keyboard_config: KeyboardConfig,
clients: &Clients,
entity_gateway: &mut EG)
-> Result<Vec<(ClientId, SendShipPacket)>, ShipError>
where
EG: EntityGateway + Clone + 'static,
{
clients.with_mut(id, |client| {
let mut entity_gateway = entity_gateway.clone();
Box::pin(async move {
client.character.keyboard_config.update(&keyboard_config);
entity_gateway.save_character(&client.character).await
})}).await??;
Ok(Vec::new())
}
pub async fn gamepad_config<EG>(id: ClientId,
gamepad_config: GamepadConfig,
clients: &Clients,
entity_gateway: &mut EG)
-> Result<Vec<(ClientId, SendShipPacket)>, ShipError>
where
EG: EntityGateway + Clone + 'static,
{
clients.with_mut(id, |client| {
let mut entity_gateway = entity_gateway.clone();
Box::pin(async move {
client.character.gamepad_config.update(&gamepad_config);
entity_gateway.save_character(&client.character).await
})}).await??;
Ok(Vec::new())
}