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.

80 lines
2.9 KiB

4 years ago
5 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 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. username: username.into(),
  14. password: bcrypt::hash(password, 5).unwrap(),
  15. guildcard: 1,
  16. team_id: None,
  17. banned: false,
  18. muted_until: SystemTime::now(),
  19. created_at: SystemTime::now(),
  20. flags: 0,
  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. (user, character)
  28. }
  29. pub async fn log_in_char<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId, username: &str, password: &str) {
  30. let username = username.to_string();
  31. let password = password.to_string();
  32. ship.handle(id, &RecvShipPacket::Login(Login {
  33. tag: 0,
  34. guildcard: 0,
  35. version: 0,
  36. unknown1: [0; 6],
  37. team: 0,
  38. username: utf8_to_array!(username, 16),
  39. unknown2: [0; 32],
  40. password: utf8_to_array!(password, 16),
  41. unknown3: [0; 40],
  42. hwinfo: [0; 8],
  43. session: Session::new(),
  44. })).await.unwrap().for_each(drop);
  45. }
  46. pub async fn join_lobby<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId) {
  47. ship.handle(id, &RecvShipPacket::CharData(CharData {
  48. _unknown: [0; 0x828]
  49. })).await.unwrap().for_each(drop);
  50. }
  51. pub async fn create_room<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId, name: &str, password: &str) {
  52. ship.handle(id, &RecvShipPacket::CreateRoom(CreateRoom {
  53. unknown: [0; 2],
  54. name: utf8_to_utf16_array!(name, 16),
  55. password: utf8_to_utf16_array!(password, 16),
  56. difficulty: 0,
  57. battle: 0,
  58. challenge: 0,
  59. episode: 1,
  60. single_player: 0,
  61. padding: [0; 3],
  62. })).await.unwrap().for_each(drop);
  63. ship.handle(id, &RecvShipPacket::DoneBursting(DoneBursting {})).await.unwrap().for_each(drop);
  64. }
  65. pub async fn join_room<EG: EntityGateway>(ship: &mut ShipServerState<EG>, id: ClientId, room_id: u32) {
  66. ship.handle(id, &RecvShipPacket::MenuSelect(MenuSelect {
  67. menu: ROOM_MENU_ID,
  68. item: room_id,
  69. })).await.unwrap().for_each(drop);
  70. }