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.

90 lines
3.5 KiB

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