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.

81 lines
3.5 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. use networking::serverstate::{ClientId, ServerState};
  2. use entity::gateway::{EntityGateway, InMemoryGateway};
  3. use elseware::ship::ship::{ShipServerState, RecvShipPacket};
  4. use libpso::character::settings::{DEFAULT_KEYBOARD_CONFIG1, DEFAULT_KEYBOARD_CONFIG2, DEFAULT_KEYBOARD_CONFIG3, DEFAULT_KEYBOARD_CONFIG4};
  5. use libpso::packet::ship::*;
  6. #[path = "common.rs"]
  7. mod common;
  8. use common::*;
  9. #[async_std::test]
  10. async fn test_save_options() {
  11. let mut entity_gateway = InMemoryGateway::default();
  12. let (user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  13. let mut ship = Box::new(ShipServerState::builder()
  14. .gateway(entity_gateway.clone())
  15. .build());
  16. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  17. join_lobby(&mut ship, ClientId(1)).await;
  18. ship.handle(ClientId(1), RecvShipPacket::SaveOptions(SaveOptions{
  19. options: 12345,
  20. })).await.unwrap();
  21. let characters = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  22. let char = characters[0].as_ref().unwrap();
  23. assert!(char.option_flags == 12345);
  24. }
  25. #[async_std::test]
  26. async fn test_change_keyboard_mappings() {
  27. let mut entity_gateway = InMemoryGateway::default();
  28. let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 2).await;
  29. let mut ship = Box::new(ShipServerState::builder()
  30. .gateway(entity_gateway.clone())
  31. .build());
  32. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  33. join_lobby(&mut ship, ClientId(1)).await;
  34. let settings = entity_gateway.get_user_settings_by_user(&user1).await.unwrap();
  35. assert!(settings.settings.keyboard_config == DEFAULT_KEYBOARD_CONFIG1);
  36. // update from default2 to default4
  37. // the client simply sends the full 364 bytes...
  38. ship.handle(ClientId(1), RecvShipPacket::KeyboardConfig(KeyboardConfig{
  39. keyboard_config: [
  40. 0, 0, 0, 0, 117, 0, 0, 0, 0, 0, 0, 0, 105, 0, 0, 0,
  41. 0, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 115, 0, 0, 0,
  42. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  43. 0, 0, 0, 0, 97, 0, 0, 0, 0, 0, 0, 0, 80, 0, 0, 0,
  44. 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 89, 0, 0, 0,
  45. 0, 0, 0, 0, 94, 0, 0, 0, 0, 0, 0, 0, 93, 0, 0, 0,
  46. 0, 0, 0, 0, 92, 0, 0, 0, 0, 0, 0, 0, 95, 0, 0, 0,
  47. 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 93, 0, 0, 0,
  48. 0, 0, 0, 0, 92, 0, 0, 0, 0, 0, 0, 0, 95, 0, 0, 0,
  49. 0, 0, 0, 0, 86, 0, 0, 0, 0, 0, 0, 0, 94, 0, 0, 0,
  50. 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0,
  51. 0, 0, 0, 0, 66, 0, 0, 0, 0, 0, 0, 0, 67, 0, 0, 0,
  52. 0, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 69, 0, 0, 0,
  53. 0, 0, 0, 0, 70, 0, 0, 0, 0, 0, 0, 0, 71, 0, 0, 0,
  54. 0, 0, 0, 0, 72, 0, 0, 0, 0, 0, 0, 0, 73, 0, 0, 0,
  55. 0, 0, 0, 0, 74, 0, 0, 0, 0, 0, 0, 0, 75, 0, 0, 0,
  56. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  57. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 0, 0, 0,
  58. 0, 0, 0, 0, 43, 0, 0, 0, 0, 0, 0, 0, 44, 0, 0, 0,
  59. 0, 0, 0, 0, 45, 0, 0, 0, 0, 0, 0, 0, 46, 0, 0, 0,
  60. 0, 0, 0, 0, 47, 0, 0, 0, 0, 0, 0, 0, 48, 0, 0, 0,
  61. 0, 0, 0, 0, 49, 0, 0, 0, 0, 0, 0, 0, 50, 0, 0, 0,
  62. 0, 0, 0, 0, 51, 0, 0, 0, 1, 0, 0, 0
  63. ],
  64. })).await.unwrap();
  65. let settings = entity_gateway.get_user_settings_by_user(&user1).await.unwrap();
  66. assert!(settings.settings.keyboard_config == DEFAULT_KEYBOARD_CONFIG4);
  67. }