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.

94 lines
3.7 KiB

4 years ago
5 years ago
3 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};
  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. //TODO: remove kb_conf_preset
  13. pub async fn new_user_character<EG: EntityGateway + Clone>(entity_gateway: &mut EG, username: &str, password: &str, kb_conf_preset: usize) -> (UserAccountEntity, CharacterEntity) {
  14. let new_user = NewUserAccountEntity {
  15. email: format!("{}@pso.com", username),
  16. username: username.into(),
  17. password: bcrypt::hash(password, 5).unwrap(),
  18. guildcard: 1,
  19. activated: true,
  20. ..NewUserAccountEntity::default()
  21. };
  22. let user = entity_gateway.create_user(new_user).await.unwrap();
  23. let new_settings = NewUserSettingsEntity::new(user.id);
  24. let _settings = entity_gateway.create_user_settings(new_settings).await.unwrap();
  25. let new_character = NewCharacterEntity::new(user.id);
  26. let character = entity_gateway.create_character(new_character).await.unwrap();
  27. entity_gateway.set_character_meseta(&character.id, Meseta(0)).await.unwrap();
  28. entity_gateway.set_bank_meseta(&character.id, &BankName("".into()), Meseta(0)).await.unwrap();
  29. (user, character)
  30. }
  31. pub async fn log_in_char<EG: EntityGateway + Clone>(ship: &mut ShipServerState<EG>, id: ClientId, username: &str, password: &str) {
  32. let username = username.to_string();
  33. let password = password.to_string();
  34. ship.handle(id, RecvShipPacket::Login(Login {
  35. tag: 0,
  36. guildcard: 0,
  37. version: 0,
  38. unknown1: [0; 6],
  39. team: 0,
  40. username: utf8_to_array!(username, 16),
  41. unknown2: [0; 32],
  42. password: utf8_to_array!(password, 16),
  43. unknown3: [0; 40],
  44. hwinfo: [0; 8],
  45. session: Session::new(),
  46. })).await.unwrap();
  47. }
  48. pub async fn join_lobby<EG: EntityGateway + Clone>(ship: &mut ShipServerState<EG>, id: ClientId) {
  49. ship.handle(id, RecvShipPacket::CharData(CharData {
  50. _unknown: [0; 0x828]
  51. })).await.unwrap();
  52. }
  53. pub async fn create_room<EG: EntityGateway + Clone>(ship: &mut ShipServerState<EG>, id: ClientId, name: &str, password: &str) {
  54. create_room_with_difficulty(ship, id, name, password, Difficulty::Normal).await;
  55. }
  56. pub async fn leave_room<EG: EntityGateway + Clone>(ship: &mut ShipServerState<EG>, id: ClientId) {
  57. ship.handle(id, RecvShipPacket::LobbySelect(LobbySelect {
  58. menu: 3,
  59. lobby: 0,
  60. })).await.unwrap();
  61. }
  62. pub async fn create_room_with_difficulty<EG: EntityGateway + Clone>(ship: &mut ShipServerState<EG>, id: ClientId, name: &str, password: &str, difficulty: Difficulty) {
  63. ship.handle(id, RecvShipPacket::CreateRoom(CreateRoom {
  64. unknown: [0; 2],
  65. name: utf8_to_utf16_array!(name, 16),
  66. password: utf8_to_utf16_array!(password, 16),
  67. difficulty: difficulty.into(),
  68. battle: 0,
  69. challenge: 0,
  70. episode: 1,
  71. single_player: 0,
  72. padding: [0; 3],
  73. })).await.unwrap();
  74. ship.handle(id, RecvShipPacket::DoneBursting(DoneBursting {})).await.unwrap();
  75. }
  76. pub async fn join_room<EG: EntityGateway + Clone>(ship: &mut ShipServerState<EG>, id: ClientId, room_id: u32) {
  77. ship.handle(id, RecvShipPacket::MenuSelect(MenuSelect {
  78. menu: ROOM_MENU_ID,
  79. item: room_id,
  80. })).await.unwrap();
  81. ship.handle(id, RecvShipPacket::DoneBursting(DoneBursting {})).await.unwrap();
  82. }