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.

118 lines
5.6 KiB

  1. use networking::serverstate::{ClientId, ServerState};
  2. use entity::gateway::{EntityGateway, InMemoryGateway};
  3. use elseware::ship::ship::{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").await;
  13. let mut ship = standard_ship_buildable(entity_gateway.clone())
  14. .standard_quest_builder(Box::new(quests::load_standard_quests))
  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").await;
  31. let mut ship = standard_ship_buildable(entity_gateway.clone())
  32. .standard_quest_builder(Box::new(quests::load_standard_quests))
  33. .government_quest_builder(Box::new(quests::load_government_quests))
  34. .build();
  35. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  36. join_lobby(&mut ship, ClientId(1)).await;
  37. create_room(&mut ship, ClientId(1), "room", "").await;
  38. let packets = ship.handle(ClientId(1), RecvShipPacket::RequestQuestList(RequestQuestList{flag: 100})).await.unwrap();
  39. match &packets[0].1 {
  40. SendShipPacket::QuestCategoryList(quest_cat) => {
  41. // 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.
  42. // assuming we create an ep1 room in multimode, we should load the government quests in this test case
  43. assert!(String::from_utf16_lossy(&quest_cat.quest_categories[0].name).starts_with("Government"));
  44. },
  45. _ => panic!("Wrong quest category"),
  46. }
  47. }
  48. #[async_std::test]
  49. async fn test_get_room_info() {
  50. let mut entity_gateway = InMemoryGateway::default();
  51. let (_user1, mut _char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  52. _char1.name = String::from("GODmar");
  53. entity_gateway.save_character(&_char1).await.unwrap();
  54. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  55. let mut ship = standard_ship(entity_gateway.clone());
  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").await;
  72. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  73. let mut ship = standard_ship(entity_gateway.clone());
  74. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  75. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  76. join_lobby(&mut ship, ClientId(1)).await;
  77. join_lobby(&mut ship, ClientId(2)).await;
  78. create_room(&mut ship, ClientId(1), "room", "").await;
  79. leave_room(&mut ship, ClientId(1)).await;
  80. let _expectedmsg = String::from("Game is no longer active!\0");
  81. let packets = ship.handle(ClientId(2), RecvShipPacket::MenuDetail(MenuDetail{menu: 3, item: 0})).await.unwrap();
  82. assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::SmallLeftDialog(SmallLeftDialog{
  83. padding: [17664, 1157645568],
  84. msg: _expectedmsg,
  85. }))));
  86. }
  87. #[async_std::test]
  88. async fn test_cannot_join_room_after_its_closed() {
  89. let mut entity_gateway = InMemoryGateway::default();
  90. let (_user1, _char1) = new_user_character(&mut entity_gateway, "a1", "a").await;
  91. let (_user2, _char2) = new_user_character(&mut entity_gateway, "a2", "a").await;
  92. let mut ship = standard_ship(entity_gateway.clone());
  93. log_in_char(&mut ship, ClientId(1), "a1", "a").await;
  94. log_in_char(&mut ship, ClientId(2), "a2", "a").await;
  95. join_lobby(&mut ship, ClientId(1)).await;
  96. join_lobby(&mut ship, ClientId(2)).await;
  97. create_room(&mut ship, ClientId(1), "room", "").await;
  98. leave_room(&mut ship, ClientId(1)).await;
  99. let _expectedmsg = String::from("This room no longer exists!\0");
  100. let packets = ship.handle(ClientId(2), RecvShipPacket::MenuSelect(MenuSelect{menu: 3, item: 0})).await.unwrap();
  101. assert!(matches!(&packets[0], (ClientId(2), SendShipPacket::SmallDialog(SmallDialog{
  102. padding: [0,0],
  103. msg: _expectedmsg, // wow yes cool rust is so great literally the best i can't put a String::from() directly in here.
  104. }))));
  105. }
  106. // TODO: test joining twice errors not hangs forever