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.

112 lines
3.0 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. #![feature(const_generics)]
  2. mod common;
  3. mod login;
  4. mod entity;
  5. use std::thread;
  6. use std::collections::HashMap;
  7. use bcrypt;
  8. use libpso::character::settings;
  9. use libpso::character::character as pso_character;
  10. use libpso::character::guildcard;
  11. use libpso::{utf8_to_array, utf8_to_utf16_array};
  12. use entity::gateway::EntityGateway;
  13. use entity::account::{UserAccount, UserSettings, GuildCardData};
  14. use entity::character::Character;
  15. use login::login::LoginServerState;
  16. use login::character::CharacterServerState;
  17. use std::time::SystemTime;
  18. #[derive(Clone)]
  19. struct LoginStubData {
  20. users: HashMap<String, UserAccount>,
  21. characters: [Option<Character> ;4],
  22. }
  23. impl LoginStubData {
  24. fn new() -> LoginStubData {
  25. let mut c = pso_character::Character::default();
  26. c.name = utf8_to_utf16_array!("Test Char", 16);
  27. let mut users = HashMap::new();
  28. users.insert("hi".to_string(), UserAccount {
  29. id: 1,
  30. username: "hi".to_owned(),
  31. password: bcrypt::hash("qwer", 5).unwrap(),
  32. guildcard: None,
  33. team_id: None,
  34. banned: false,
  35. muted_until: SystemTime::now(),
  36. created_at: SystemTime::now(),
  37. flags: 0,
  38. });
  39. LoginStubData {
  40. users: users,
  41. characters: [Some(Character {
  42. id: 1,
  43. slot: 0,
  44. user_id: 1,
  45. character: c,
  46. }),
  47. None, None, None]
  48. }
  49. }
  50. }
  51. impl EntityGateway for LoginStubData {
  52. fn get_user_by_name(&self, username: String) -> Option<UserAccount> {
  53. self.users.get(&username).map(|user| user.clone())
  54. }
  55. fn get_user_settings_by_user(&self, user: &UserAccount) -> Option<UserSettings> {
  56. Some(UserSettings {
  57. id: 0,
  58. user_id: user.id,
  59. settings: settings::UserSettings::default()
  60. })
  61. }
  62. fn set_user(&mut self, user: &UserAccount) {
  63. self.users.insert(user.username.clone(), user.clone());
  64. }
  65. fn get_characters_by_user(&self, _user: &UserAccount) -> [Option<Character>; 4] {
  66. self.characters
  67. }
  68. fn set_character(&mut self, char: &Character) {
  69. self.characters[char.slot as usize] = Some(char.clone());
  70. }
  71. fn get_guild_card_data_by_user(&self, user: &UserAccount) -> GuildCardData {
  72. GuildCardData {
  73. id: 1,
  74. user_id: user.id,
  75. guildcard: guildcard::GuildCardData::default(),
  76. }
  77. }
  78. }
  79. fn main() {
  80. println!("[login+character] starting server");
  81. let auth_thread = thread::spawn(|| {
  82. let auth_state = LoginServerState::new(LoginStubData::new());
  83. common::mainloop::mainloop(auth_state, login::login::LOGIN_PORT);
  84. });
  85. let char_thread = thread::spawn(|| {
  86. let char_state = CharacterServerState::new(LoginStubData::new());
  87. common::mainloop::mainloop(char_state, login::character::CHARACTER_PORT);
  88. });
  89. auth_thread.join().unwrap();
  90. char_thread.join().unwrap();
  91. }