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.

93 lines
3.8 KiB

4 years ago
4 years ago
3 years ago
4 years ago
4 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::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. 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 log_in_char<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId, username: &str, password: &str) {
  31. let username = username.to_string();
  32. let password = password.to_string();
  33. ship.handle(id, &RecvShipPacket::Login(Login {
  34. tag: 0,
  35. guildcard: 0,
  36. version: 0,
  37. unknown1: [0; 6],
  38. team: 0,
  39. username: utf8_to_array!(username, 16),
  40. unknown2: [0; 32],
  41. password: utf8_to_array!(password, 16),
  42. unknown3: [0; 40],
  43. hwinfo: [0; 8],
  44. session: Session::new(),
  45. })).await.unwrap().for_each(drop);
  46. }
  47. pub async fn join_lobby<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId) {
  48. ship.handle(id, &RecvShipPacket::CharData(CharData {
  49. _unknown: [0; 0x828]
  50. })).await.unwrap().for_each(drop);
  51. }
  52. pub async fn create_room<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId, name: &str, password: &str) {
  53. create_room_with_difficulty(ship, id, name, password, Difficulty::Normal).await;
  54. }
  55. pub async fn leave_room<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId) {
  56. ship.handle(id, &RecvShipPacket::LobbySelect(LobbySelect {
  57. menu: 3,
  58. lobby: 0,
  59. })).await.unwrap().for_each(drop);
  60. }
  61. pub async fn create_room_with_difficulty<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId, name: &str, password: &str, difficulty: Difficulty) {
  62. ship.handle(id, &RecvShipPacket::CreateRoom(CreateRoom {
  63. unknown: [0; 2],
  64. name: utf8_to_utf16_array!(name, 16),
  65. password: utf8_to_utf16_array!(password, 16),
  66. difficulty: difficulty.into(),
  67. battle: 0,
  68. challenge: 0,
  69. episode: 1,
  70. single_player: 0,
  71. padding: [0; 3],
  72. })).await.unwrap().for_each(drop);
  73. ship.handle(id, &RecvShipPacket::DoneBursting(DoneBursting {})).await.unwrap().for_each(drop);
  74. }
  75. pub async fn join_room<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId, room_id: u32) {
  76. ship.handle(id, &RecvShipPacket::MenuSelect(MenuSelect {
  77. menu: ROOM_MENU_ID,
  78. item: room_id,
  79. })).await.unwrap().for_each(drop);
  80. ship.handle(id, &RecvShipPacket::DoneBursting(DoneBursting {})).await.unwrap().for_each(drop);
  81. }