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.

77 lines
3.3 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
  1. use networking::serverstate::{ClientId, ServerState};
  2. use entity::gateway::{EntityGateway, InMemoryGateway};
  3. use elseware::ship::ship::RecvShipPacket;
  4. use libpso::character::settings::{DEFAULT_KEYBOARD_CONFIG1, 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").await;
  13. let mut ship = standard_ship(entity_gateway.clone());
  14. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  15. join_lobby(&mut ship, ClientId(1)).await;
  16. ship.handle(ClientId(1), RecvShipPacket::SaveOptions(SaveOptions{
  17. options: 12345,
  18. })).await.unwrap();
  19. let characters = entity_gateway.get_characters_by_user(&user1).await.unwrap();
  20. let char = characters[0].as_ref().unwrap();
  21. assert!(char.option_flags == 12345);
  22. }
  23. #[async_std::test]
  24. async fn test_change_keyboard_mappings() {
  25. let mut entity_gateway = InMemoryGateway::default();
  26. let (user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 2).await;
  27. let mut ship = standard_ship(entity_gateway.clone());
  28. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  29. join_lobby(&mut ship, ClientId(1)).await;
  30. let settings = entity_gateway.get_user_settings_by_user(&user1).await.unwrap();
  31. assert!(settings.settings.keyboard_config == DEFAULT_KEYBOARD_CONFIG1);
  32. // update from default2 to default4
  33. // the client simply sends the full 364 bytes...
  34. ship.handle(ClientId(1), RecvShipPacket::KeyboardConfig(KeyboardConfig{
  35. keyboard_config: [
  36. 0, 0, 0, 0, 117, 0, 0, 0, 0, 0, 0, 0, 105, 0, 0, 0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0, 0, 48, 0, 0, 0,
  57. 0, 0, 0, 0, 49, 0, 0, 0, 0, 0, 0, 0, 50, 0, 0, 0,
  58. 0, 0, 0, 0, 51, 0, 0, 0, 1, 0, 0, 0
  59. ],
  60. })).await.unwrap();
  61. let settings = entity_gateway.get_user_settings_by_user(&user1).await.unwrap();
  62. assert!(settings.settings.keyboard_config == DEFAULT_KEYBOARD_CONFIG4);
  63. }