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.

102 lines
4.4 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
  1. use elseware::common::serverstate::{ClientId, ServerState};
  2. use elseware::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().for_each(drop);
  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_default3_keyboard_mappings() {
  27. /*
  28. check if keyboard is set to default3 when specified. this will only occur for things like creating characters from the web page.
  29. normal client behaviour will simply use default1 when creating a character.
  30. gamepad only has 1 default config
  31. */
  32. let mut entity_gateway = InMemoryGateway::default();
  33. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 3).await;
  34. assert!(char1.keyboard_config.as_bytes() == DEFAULT_KEYBOARD_CONFIG3);
  35. }
  36. #[async_std::test]
  37. async fn test_invalid_keyboard_preset_value() {
  38. // check if keyboard_config self-corrects to DEFAULT1 if an invalid value (>4) is given
  39. let mut entity_gateway = InMemoryGateway::default();
  40. let (_user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 10).await;
  41. assert!(char1.keyboard_config.as_bytes() == DEFAULT_KEYBOARD_CONFIG1);
  42. }
  43. #[async_std::test]
  44. async fn test_change_keyboard_mappings() {
  45. let mut entity_gateway = InMemoryGateway::default();
  46. let (user1, char1) = new_user_character(&mut entity_gateway, "a1", "a", 2).await;
  47. let mut ship = Box::new(ShipServerState::builder()
  48. .gateway(entity_gateway.clone())
  49. .build());
  50. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  51. join_lobby(&mut ship, ClientId(1)).await;
  52. assert!(char1.keyboard_config.as_bytes() == DEFAULT_KEYBOARD_CONFIG2);
  53. // update from default2 to default4
  54. // the client simply sends the full 364 bytes...
  55. ship.handle(ClientId(1), &RecvShipPacket::KeyboardConfig(KeyboardConfig{
  56. keyboard_config: [
  57. 0, 0, 0, 0, 117, 0, 0, 0, 0, 0, 0, 0, 105, 0, 0, 0,
  58. 0, 0, 0, 0, 113, 0, 0, 0, 0, 0, 0, 0, 115, 0, 0, 0,
  59. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  60. 0, 0, 0, 0, 97, 0, 0, 0, 0, 0, 0, 0, 80, 0, 0, 0,
  61. 0, 0, 0, 0, 6, 0, 0, 0, 0, 0, 0, 0, 89, 0, 0, 0,
  62. 0, 0, 0, 0, 94, 0, 0, 0, 0, 0, 0, 0, 93, 0, 0, 0,
  63. 0, 0, 0, 0, 92, 0, 0, 0, 0, 0, 0, 0, 95, 0, 0, 0,
  64. 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 93, 0, 0, 0,
  65. 0, 0, 0, 0, 92, 0, 0, 0, 0, 0, 0, 0, 95, 0, 0, 0,
  66. 0, 0, 0, 0, 86, 0, 0, 0, 0, 0, 0, 0, 94, 0, 0, 0,
  67. 0, 0, 0, 0, 64, 0, 0, 0, 0, 0, 0, 0, 65, 0, 0, 0,
  68. 0, 0, 0, 0, 66, 0, 0, 0, 0, 0, 0, 0, 67, 0, 0, 0,
  69. 0, 0, 0, 0, 68, 0, 0, 0, 0, 0, 0, 0, 69, 0, 0, 0,
  70. 0, 0, 0, 0, 70, 0, 0, 0, 0, 0, 0, 0, 71, 0, 0, 0,
  71. 0, 0, 0, 0, 72, 0, 0, 0, 0, 0, 0, 0, 73, 0, 0, 0,
  72. 0, 0, 0, 0, 74, 0, 0, 0, 0, 0, 0, 0, 75, 0, 0, 0,
  73. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
  74. 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 42, 0, 0, 0,
  75. 0, 0, 0, 0, 43, 0, 0, 0, 0, 0, 0, 0, 44, 0, 0, 0,
  76. 0, 0, 0, 0, 45, 0, 0, 0, 0, 0, 0, 0, 46, 0, 0, 0,
  77. 0, 0, 0, 0, 47, 0, 0, 0, 0, 0, 0, 0, 48, 0, 0, 0,
  78. 0, 0, 0, 0, 49, 0, 0, 0, 0, 0, 0, 0, 50, 0, 0, 0,
  79. 0, 0, 0, 0, 51, 0, 0, 0, 1, 0, 0, 0
  80. ],
  81. })).await.unwrap().for_each(drop);
  82. let characters = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  83. let char = characters[0].as_ref().unwrap();
  84. assert!(char.keyboard_config.as_bytes() == DEFAULT_KEYBOARD_CONFIG4);
  85. }