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.

86 lines
3.3 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 std::time::SystemTime;
  3. use elseware::common::serverstate::{ClientId, ServerState};
  4. use elseware::entity::gateway::EntityGateway;
  5. use elseware::entity::account::{UserAccountEntity, NewUserAccountEntity, NewUserSettingsEntity};
  6. use elseware::entity::character::{CharacterEntity, NewCharacterEntity};
  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) -> (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. team_id: None,
  19. banned_until: None,
  20. muted_until: None,
  21. created_at: chrono::Utc::now(),
  22. flags: 0,
  23. };
  24. let user = entity_gateway.create_user(new_user).await.unwrap();
  25. let new_settings = NewUserSettingsEntity::new(user.id);
  26. let _settings = entity_gateway.create_user_settings(new_settings).await.unwrap();
  27. let new_character = NewCharacterEntity::new(user.id);
  28. let character = entity_gateway.create_character(new_character).await.unwrap();
  29. (user, character)
  30. }
  31. pub async fn log_in_char<EG: EntityGateway>(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().for_each(drop);
  47. }
  48. pub async fn join_lobby<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId) {
  49. ship.handle(id, &RecvShipPacket::CharData(CharData {
  50. _unknown: [0; 0x828]
  51. })).await.unwrap().for_each(drop);
  52. }
  53. pub async fn create_room<EG: EntityGateway>(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 create_room_with_difficulty<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId, name: &str, password: &str, difficulty: Difficulty) {
  57. ship.handle(id, &RecvShipPacket::CreateRoom(CreateRoom {
  58. unknown: [0; 2],
  59. name: utf8_to_utf16_array!(name, 16),
  60. password: utf8_to_utf16_array!(password, 16),
  61. difficulty: difficulty.into(),
  62. battle: 0,
  63. challenge: 0,
  64. episode: 1,
  65. single_player: 0,
  66. padding: [0; 3],
  67. })).await.unwrap().for_each(drop);
  68. ship.handle(id, &RecvShipPacket::DoneBursting(DoneBursting {})).await.unwrap().for_each(drop);
  69. }
  70. pub async fn join_room<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId, room_id: u32) {
  71. ship.handle(id, &RecvShipPacket::MenuSelect(MenuSelect {
  72. menu: ROOM_MENU_ID,
  73. item: room_id,
  74. })).await.unwrap().for_each(drop);
  75. }