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.

125 lines
5.7 KiB

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