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.

85 lines
3.3 KiB

4 years ago
5 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. team_id: None,
  18. banned_until: None,
  19. muted_until: None,
  20. created_at: chrono::Utc::now(),
  21. flags: 0,
  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. (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 create_room_with_difficulty<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId, name: &str, password: &str, difficulty: Difficulty) {
  56. ship.handle(id, &RecvShipPacket::CreateRoom(CreateRoom {
  57. unknown: [0; 2],
  58. name: utf8_to_utf16_array!(name, 16),
  59. password: utf8_to_utf16_array!(password, 16),
  60. difficulty: difficulty.into(),
  61. battle: 0,
  62. challenge: 0,
  63. episode: 1,
  64. single_player: 0,
  65. padding: [0; 3],
  66. })).await.unwrap().for_each(drop);
  67. ship.handle(id, &RecvShipPacket::DoneBursting(DoneBursting {})).await.unwrap().for_each(drop);
  68. }
  69. pub async fn join_room<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId, room_id: u32) {
  70. ship.handle(id, &RecvShipPacket::MenuSelect(MenuSelect {
  71. menu: ROOM_MENU_ID,
  72. item: room_id,
  73. })).await.unwrap().for_each(drop);
  74. }