You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
2.7 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. use libpso::packet::ship::*;
  2. use crate::common::serverstate::ClientId;
  3. use crate::ship::ship::{SendShipPacket, ShipError, Clients};
  4. use crate::entity::gateway::EntityGateway;
  5. pub async fn update_config<EG: EntityGateway>(id: ClientId,
  6. update_config: &UpdateConfig,
  7. clients: &mut Clients,
  8. entity_gateway: &mut EG)
  9. -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
  10. let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap();
  11. client.character.config.update(update_config);
  12. entity_gateway.save_character(&client.character).await.unwrap();
  13. Box::new(None.into_iter())
  14. }
  15. pub async fn save_options<EG: EntityGateway>(id: ClientId,
  16. save_options: &SaveOptions,
  17. clients: &mut Clients,
  18. entity_gateway: &mut EG)
  19. -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
  20. // TODO: don't unwrap?
  21. let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap();
  22. client.character.option_flags = save_options.options;
  23. entity_gateway.save_character(&client.character).await.unwrap();
  24. Box::new(None.into_iter())
  25. }
  26. pub async fn keyboard_config<EG: EntityGateway>(id: ClientId,
  27. keyboard_config: &KeyboardConfig,
  28. clients: &mut Clients,
  29. entity_gateway: &mut EG)
  30. -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
  31. let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap();
  32. client.character.keyboard_config.update(keyboard_config);
  33. entity_gateway.save_character(&client.character).await.unwrap();
  34. Box::new(None.into_iter())
  35. }
  36. pub async fn gamepad_config<EG: EntityGateway>(id: ClientId,
  37. gamepad_config: &GamepadConfig,
  38. clients: &mut Clients,
  39. entity_gateway: &mut EG)
  40. -> Box<dyn Iterator<Item = (ClientId, SendShipPacket)> + Send> {
  41. let client = clients.get_mut(&id).ok_or(ShipError::ClientNotFound(id)).unwrap();
  42. client.character.gamepad_config.update(gamepad_config);
  43. entity_gateway.save_character(&client.character).await.unwrap();
  44. Box::new(None.into_iter())
  45. }