2020-04-21 23:45:40 -06:00
|
|
|
use libpso::packet::ship::*;
|
|
|
|
use crate::common::serverstate::ClientId;
|
2023-01-30 18:05:36 -07:00
|
|
|
use crate::ship::ship::{SendShipPacket, Clients};
|
2020-04-21 23:45:40 -06:00
|
|
|
use crate::entity::gateway::EntityGateway;
|
|
|
|
|
2022-10-18 04:46:21 -06:00
|
|
|
pub async fn update_config<EG>(id: ClientId,
|
|
|
|
update_config: UpdateConfig,
|
|
|
|
clients: &Clients,
|
|
|
|
entity_gateway: &mut EG)
|
2023-01-28 20:12:20 -07:00
|
|
|
-> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error>
|
2022-10-18 04:46:21 -06:00
|
|
|
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())
|
2020-04-21 23:45:40 -06:00
|
|
|
}
|
2020-10-02 21:24:32 -03:00
|
|
|
|
2022-10-18 04:46:21 -06:00
|
|
|
pub async fn save_options<EG>(id: ClientId,
|
|
|
|
save_options: SaveOptions,
|
|
|
|
clients: &Clients,
|
|
|
|
entity_gateway: &mut EG)
|
2023-01-28 20:12:20 -07:00
|
|
|
-> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error>
|
2022-10-18 04:46:21 -06:00
|
|
|
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())
|
2020-10-26 00:02:48 -06:00
|
|
|
}
|
2021-05-30 19:02:56 +00:00
|
|
|
|
2022-10-18 04:46:21 -06:00
|
|
|
pub async fn keyboard_config<EG>(id: ClientId,
|
|
|
|
keyboard_config: KeyboardConfig,
|
|
|
|
clients: &Clients,
|
|
|
|
entity_gateway: &mut EG)
|
2023-01-28 20:12:20 -07:00
|
|
|
-> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error>
|
2022-10-18 04:46:21 -06:00
|
|
|
where
|
|
|
|
EG: EntityGateway + Clone + 'static,
|
|
|
|
{
|
|
|
|
clients.with_mut(id, |client| {
|
|
|
|
let mut entity_gateway = entity_gateway.clone();
|
|
|
|
Box::pin(async move {
|
2023-01-29 20:41:12 -07:00
|
|
|
client.settings.settings.keyboard_config = keyboard_config.keyboard_config;
|
|
|
|
entity_gateway.save_user_settings(&client.settings).await
|
2022-10-18 04:46:21 -06:00
|
|
|
})}).await??;
|
|
|
|
Ok(Vec::new())
|
2022-01-05 22:57:15 +00:00
|
|
|
}
|
|
|
|
|
2022-10-18 04:46:21 -06:00
|
|
|
pub async fn gamepad_config<EG>(id: ClientId,
|
|
|
|
gamepad_config: GamepadConfig,
|
|
|
|
clients: &Clients,
|
|
|
|
entity_gateway: &mut EG)
|
2023-01-28 20:12:20 -07:00
|
|
|
-> Result<Vec<(ClientId, SendShipPacket)>, anyhow::Error>
|
2022-10-18 04:46:21 -06:00
|
|
|
where
|
|
|
|
EG: EntityGateway + Clone + 'static,
|
|
|
|
{
|
|
|
|
clients.with_mut(id, |client| {
|
|
|
|
let mut entity_gateway = entity_gateway.clone();
|
|
|
|
Box::pin(async move {
|
2023-01-29 20:41:12 -07:00
|
|
|
client.settings.settings.gamepad_config = gamepad_config.gamepad_config;
|
|
|
|
entity_gateway.save_user_settings(&client.settings).await
|
2022-10-18 04:46:21 -06:00
|
|
|
})}).await??;
|
|
|
|
Ok(Vec::new())
|
2022-07-30 15:02:18 -06:00
|
|
|
}
|