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.

129 lines
5.4 KiB

4 years ago
5 years ago
3 years ago
4 years ago
4 years ago
3 years ago
3 years ago
3 years ago
4 years ago
4 years ago
4 years ago
  1. #![allow(dead_code)]
  2. use elseware::common::serverstate::{ClientId, ServerState};
  3. use elseware::entity::gateway::EntityGateway;
  4. use elseware::entity::account::{UserAccountEntity, NewUserAccountEntity, NewUserSettingsEntity};
  5. use elseware::entity::item::{Meseta, BankName};
  6. use elseware::entity::character::{CharacterEntity, NewCharacterEntity, SectionID};
  7. use elseware::ship::ship::{ShipServerState, RecvShipPacket};
  8. use elseware::ship::room::Difficulty;
  9. use libpso::packet::ship::*;
  10. use libpso::packet::login::{Login, Session};
  11. use libpso::{utf8_to_array, utf8_to_utf16_array};
  12. pub async fn new_user_character<EG: EntityGateway>(entity_gateway: &mut EG, username: &str, password: &str, kb_conf_preset: usize) -> (UserAccountEntity, CharacterEntity) {
  13. let new_user = NewUserAccountEntity {
  14. email: format!("{}@pso.com", username),
  15. username: username.into(),
  16. password: bcrypt::hash(password, 5).unwrap(),
  17. guildcard: 1,
  18. activated: true,
  19. ..NewUserAccountEntity::default()
  20. };
  21. let user = entity_gateway.create_user(new_user).await.unwrap();
  22. let new_settings = NewUserSettingsEntity::new(user.id);
  23. let _settings = entity_gateway.create_user_settings(new_settings).await.unwrap();
  24. let new_character = NewCharacterEntity::new(user.id, kb_conf_preset);
  25. let character = entity_gateway.create_character(new_character).await.unwrap();
  26. entity_gateway.set_character_meseta(&character.id, Meseta(0)).await.unwrap();
  27. entity_gateway.set_bank_meseta(&character.id, &BankName("".into()), Meseta(0)).await.unwrap();
  28. (user, character)
  29. }
  30. pub async fn new_user_character_with_sid<EG: EntityGateway>(entity_gateway: &mut EG, username: &str, password: &str, sid: SectionID) -> (UserAccountEntity, CharacterEntity) {
  31. let new_user = NewUserAccountEntity {
  32. email: format!("{}@pso.com", username),
  33. username: username.into(),
  34. password: bcrypt::hash(password, 5).unwrap(),
  35. guildcard: 1,
  36. activated: true,
  37. ..NewUserAccountEntity::default()
  38. };
  39. let user = entity_gateway.create_user(new_user).await.unwrap();
  40. let new_settings = NewUserSettingsEntity::new(user.id);
  41. let _settings = entity_gateway.create_user_settings(new_settings).await.unwrap();
  42. let mut new_character = NewCharacterEntity::new(user.id, 1);
  43. new_character.section_id = sid;
  44. let character = entity_gateway.create_character(new_character).await.unwrap();
  45. entity_gateway.set_character_meseta(&character.id, Meseta(0)).await.unwrap();
  46. entity_gateway.set_bank_meseta(&character.id, BankName("".into()), Meseta(0)).await.unwrap();
  47. (user, character)
  48. }
  49. pub async fn log_in_char<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId, username: &str, password: &str) {
  50. let username = username.to_string();
  51. let password = password.to_string();
  52. ship.handle(id, &RecvShipPacket::Login(Login {
  53. tag: 0,
  54. guildcard: 0,
  55. version: 0,
  56. unknown1: [0; 6],
  57. team: 0,
  58. username: utf8_to_array!(username, 16),
  59. unknown2: [0; 32],
  60. password: utf8_to_array!(password, 16),
  61. unknown3: [0; 40],
  62. hwinfo: [0; 8],
  63. session: Session::new(),
  64. })).await.unwrap().for_each(drop);
  65. }
  66. pub async fn join_lobby<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId) {
  67. ship.handle(id, &RecvShipPacket::CharData(CharData {
  68. _unknown: [0; 0x828]
  69. })).await.unwrap().for_each(drop);
  70. }
  71. pub async fn create_room<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId, name: &str, password: &str) {
  72. create_room_with_difficulty(ship, id, name, password, Difficulty::Normal).await;
  73. }
  74. pub async fn leave_room<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId) {
  75. ship.handle(id, &RecvShipPacket::LobbySelect(LobbySelect {
  76. menu: 3,
  77. lobby: 0,
  78. })).await.unwrap().for_each(drop);
  79. }
  80. pub async fn create_room_with_difficulty<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId, name: &str, password: &str, difficulty: Difficulty) {
  81. ship.handle(id, &RecvShipPacket::CreateRoom(CreateRoom {
  82. unknown: [0; 2],
  83. name: utf8_to_utf16_array!(name, 16),
  84. password: utf8_to_utf16_array!(password, 16),
  85. difficulty: difficulty.into(),
  86. battle: 0,
  87. challenge: 0,
  88. episode: 1,
  89. single_player: 0,
  90. padding: [0; 3],
  91. })).await.unwrap().for_each(drop);
  92. ship.handle(id, &RecvShipPacket::DoneBursting(DoneBursting {})).await.unwrap().for_each(drop);
  93. }
  94. pub async fn create_ep2_room_with_difficulty<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId, name: &str, password: &str, difficulty: Difficulty) {
  95. ship.handle(id, &RecvShipPacket::CreateRoom(CreateRoom {
  96. unknown: [0; 2],
  97. name: utf8_to_utf16_array!(name, 16),
  98. password: utf8_to_utf16_array!(password, 16),
  99. difficulty: difficulty.into(),
  100. battle: 0,
  101. challenge: 0,
  102. episode: 2,
  103. single_player: 0,
  104. padding: [0; 3],
  105. })).await.unwrap().for_each(drop);
  106. ship.handle(id, &RecvShipPacket::DoneBursting(DoneBursting {})).await.unwrap().for_each(drop);
  107. }
  108. pub async fn join_room<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId, room_id: u32) {
  109. ship.handle(id, &RecvShipPacket::MenuSelect(MenuSelect {
  110. menu: ROOM_MENU_ID,
  111. item: room_id,
  112. })).await.unwrap().for_each(drop);
  113. ship.handle(id, &RecvShipPacket::DoneBursting(DoneBursting {})).await.unwrap().for_each(drop);
  114. }