90 lines
3.4 KiB
Rust
90 lines
3.4 KiB
Rust
use libpso::packet::ship::*;
|
|
use crate::common::serverstate::ClientId;
|
|
use crate::ship::ship::{SendShipPacket, Clients};
|
|
use entity::gateway::EntityGateway;
|
|
|
|
pub async fn update_config<EG>(id: ClientId,
|
|
update_config: UpdateConfig,
|
|
clients: &Clients,
|
|
entity_gateway: &mut EG)
|
|
-> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error>
|
|
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)>, anyhow::Error>
|
|
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)>, anyhow::Error>
|
|
where
|
|
EG: EntityGateway + Clone + 'static,
|
|
{
|
|
clients.with_mut(id, |client| {
|
|
let mut entity_gateway = entity_gateway.clone();
|
|
Box::pin(async move {
|
|
client.settings.settings.keyboard_config = keyboard_config.keyboard_config;
|
|
entity_gateway.save_user_settings(&client.settings).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)>, anyhow::Error>
|
|
where
|
|
EG: EntityGateway + Clone + 'static,
|
|
{
|
|
clients.with_mut(id, |client| {
|
|
let mut entity_gateway = entity_gateway.clone();
|
|
Box::pin(async move {
|
|
client.settings.settings.gamepad_config = gamepad_config.gamepad_config;
|
|
entity_gateway.save_user_settings(&client.settings).await
|
|
})}).await??;
|
|
Ok(Vec::new())
|
|
}
|
|
|
|
pub async fn update_tech_menu<EG>(id: ClientId,
|
|
update_tech_menu: UpdateTechMenu,
|
|
clients: &Clients,
|
|
entity_gateway: &mut EG)
|
|
-> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error>
|
|
where
|
|
EG: EntityGateway + Clone + 'static,
|
|
{
|
|
clients.with_mut(id, |client| {
|
|
let mut entity_gateway = entity_gateway.clone();
|
|
Box::pin(async move {
|
|
client.character.tech_menu.tech_menu = update_tech_menu.config;
|
|
entity_gateway.save_character(&client.character).await
|
|
})}).await??;
|
|
Ok(Vec::new())
|
|
}
|