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.

119 lines
5.7 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 = standard_ship_buildable(entity_gateway.clone())
  14. .standard_quest_builder(Box::new(quests::load_standard_quests))
  15. .government_quest_builder(Box::new(quests::load_government_quests))
  16. .build();
  17. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  18. join_lobby(&mut ship, ClientId(1)).await;
  19. create_room(&mut ship, ClientId(1), "room", "").await;
  20. let packets = ship.handle(ClientId(1), RecvShipPacket::RequestQuestList(RequestQuestList{flag: 0})).await.unwrap();
  21. match &packets[0].1 {
  22. SendShipPacket::QuestCategoryList(quest_cat) => {
  23. assert!(String::from_utf16_lossy(&quest_cat.quest_categories[0].name).starts_with("Retrieval"));
  24. },
  25. _ => panic!("Wrong quest category"),
  26. }
  27. }
  28. #[async_std::test]
  29. async fn test_set_invalid_quest_group() {
  30. let mut entity_gateway = InMemoryGateway::default();
  31. let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  32. let mut ship = standard_ship_buildable(entity_gateway.clone())
  33. .standard_quest_builder(Box::new(quests::load_standard_quests))
  34. .government_quest_builder(Box::new(quests::load_government_quests))
  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 = standard_ship(entity_gateway.clone());
  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 = standard_ship(entity_gateway.clone());
  75. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  76. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  77. join_lobby(&mut ship, ClientId(1)).await;
  78. join_lobby(&mut ship, ClientId(2)).await;
  79. create_room(&mut ship, ClientId(1), "room", "").await;
  80. leave_room(&mut ship, ClientId(1)).await;
  81. let _expectedmsg = String::from("Game is no longer active!\0");
  82. let packets = ship.handle(ClientId(2), RecvShipPacket::MenuDetail(MenuDetail{menu: 3, item: 0})).await.unwrap();
  83. assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::SmallLeftDialog(SmallLeftDialog{
  84. padding: [17664, 1157645568],
  85. msg: _expectedmsg,
  86. }))));
  87. }
  88. #[async_std::test]
  89. async fn test_cannot_join_room_after_its_closed() {
  90. let mut entity_gateway = InMemoryGateway::default();
  91. let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a", 1).await;
  92. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a", 1).await;
  93. let mut ship = standard_ship(entity_gateway.clone());
  94. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  95. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  96. join_lobby(&mut ship, ClientId(1)).await;
  97. join_lobby(&mut ship, ClientId(2)).await;
  98. create_room(&mut ship, ClientId(1), "room", "").await;
  99. leave_room(&mut ship, ClientId(1)).await;
  100. let _expectedmsg = String::from("This room no longer exists!\0");
  101. let packets = ship.handle(ClientId(2), RecvShipPacket::MenuSelect(MenuSelect{menu: 3, item: 0})).await.unwrap();
  102. assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::SmallDialog(SmallDialog{
  103. padding: [0,0],
  104. msg: _expectedmsg, // wow yes cool rust is so great literally the best i can't put a String::from() directly in here.
  105. }))));
  106. }
  107. // TODO: test joining twice errors not hangs forever