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.

122 lines
5.6 KiB

3 years ago
3 years ago
  1. use elseware::common::serverstate::{ClientId, ServerState};
  2. use elseware::entity::gateway::{EntityGateway, InMemoryGateway};
  3. use elseware::ship::ship::{ShipServerState, RecvShipPacket, SendShipPacket};
  4. use libpso::packet::ship::*;
  5. #[path = "common.rs"]
  6. mod common;
  7. use common::*;
  8. #[async_std::test]
  9. async fn test_set_valid_quest_group() {
  10. let mut entity_gateway = InMemoryGateway::default();
  11. let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  12. let mut ship = Box::new(ShipServerState::builder()
  13. .gateway(entity_gateway.clone())
  14. .build());
  15. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  16. join_lobby(&mut ship, ClientId(1)).await;
  17. create_room(&mut ship, ClientId(1), "room", "").await;
  18. let packets = ship.handle(ClientId(1), RecvShipPacket::RequestQuestList(RequestQuestList{flag: 0})).await.unwrap();
  19. match &packets[0].1 {
  20. SendShipPacket::QuestCategoryList(quest_cat) => {
  21. assert!(String::from_utf16_lossy(&quest_cat.quest_categories[0].name).starts_with("Retrieval"));
  22. },
  23. _ => panic!("Wrong quest category"),
  24. }
  25. }
  26. #[async_std::test]
  27. async fn test_set_invalid_quest_group() {
  28. let mut entity_gateway = InMemoryGateway::default();
  29. let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  30. let mut ship = Box::new(ShipServerState::builder()
  31. .gateway(entity_gateway.clone())
  32. .build());
  33. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  34. join_lobby(&mut ship, ClientId(1)).await;
  35. create_room(&mut ship, ClientId(1), "room", "").await;
  36. let packets = ship.handle(ClientId(1), RecvShipPacket::RequestQuestList(RequestQuestList{flag: 100})).await.unwrap();
  37. match &packets[0].1 {
  38. SendShipPacket::QuestCategoryList(quest_cat) => {
  39. // flag > quest category length should take the highest value allowed for quest category which is 1 in multimode (for govt quests) and 0 in other modes.
  40. // assuming we create an ep1 room in multimode, we should load the government quests in this test case
  41. assert!(String::from_utf16_lossy(&quest_cat.quest_categories[0].name).starts_with("Government"));
  42. },
  43. _ => panic!("Wrong quest category"),
  44. }
  45. }
  46. #[async_std::test]
  47. async fn test_get_room_info() {
  48. let mut entity_gateway = InMemoryGateway::default();
  49. let (_user1, mut _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  50. _char1.name = String::from("GODmar");
  51. entity_gateway.save_character(&_char1).await.unwrap();
  52. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await;
  53. let mut ship = Box::new(ShipServerState::builder()
  54. .gateway(entity_gateway.clone())
  55. .build());
  56. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  57. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  58. join_lobby(&mut ship, ClientId(1)).await;
  59. join_lobby(&mut ship, ClientId(2)).await;
  60. create_room(&mut ship, ClientId(1), "room", "").await;
  61. let _expectedmsg = String::from("1 Lv1 GODmar\nHUmar Pioneer 2\n");
  62. let packets = ship.handle(ClientId(2), RecvShipPacket::MenuDetail(MenuDetail{menu: 3, item: 0})).await.unwrap();
  63. assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::SmallLeftDialog(SmallLeftDialog{
  64. padding: [17664, 1157645568],
  65. msg: _expectedmsg,
  66. }))));
  67. }
  68. #[async_std::test]
  69. async fn test_cannot_get_room_info_after_room_is_closed() {
  70. let mut entity_gateway = InMemoryGateway::default();
  71. let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  72. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await;
  73. let mut ship = Box::new(ShipServerState::builder()
  74. .gateway(entity_gateway.clone())
  75. .build());
  76. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  77. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  78. join_lobby(&mut ship, ClientId(1)).await;
  79. join_lobby(&mut ship, ClientId(2)).await;
  80. create_room(&mut ship, ClientId(1), "room", "").await;
  81. leave_room(&mut ship, ClientId(1)).await;
  82. let _expectedmsg = String::from("Game is no longer active!\0");
  83. let packets = ship.handle(ClientId(2), RecvShipPacket::MenuDetail(MenuDetail{menu: 3, item: 0})).await.unwrap();
  84. assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::SmallLeftDialog(SmallLeftDialog{
  85. padding: [17664, 1157645568],
  86. msg: _expectedmsg,
  87. }))));
  88. }
  89. #[async_std::test]
  90. async fn test_cannot_join_room_after_its_closed() {
  91. let mut entity_gateway = InMemoryGateway::default();
  92. let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  93. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await;
  94. let mut ship = Box::new(ShipServerState::builder()
  95. .gateway(entity_gateway.clone())
  96. .build());
  97. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  98. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  99. join_lobby(&mut ship, ClientId(1)).await;
  100. join_lobby(&mut ship, ClientId(2)).await;
  101. create_room(&mut ship, ClientId(1), "room", "").await;
  102. leave_room(&mut ship, ClientId(1)).await;
  103. let _expectedmsg = String::from("This room no longer exists!\0");
  104. let packets = ship.handle(ClientId(2), RecvShipPacket::MenuSelect(MenuSelect{menu: 3, item: 0})).await.unwrap();
  105. assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::SmallDialog(SmallDialog{
  106. padding: [0,0],
  107. msg: _expectedmsg, // wow yes cool rust is so great literally the best i can't put a String::from() directly in here.
  108. }))));
  109. }
  110. // TODO: test joining twice errors not hangs forever