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.

137 lines
4.6 KiB

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