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.

123 lines
5.6 KiB

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