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.

77 lines
2.8 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
  1. #![feature(const_generics)]
  2. mod common;
  3. mod entity;
  4. mod patch;
  5. mod login;
  6. mod ship;
  7. use std::thread;
  8. use std::time::SystemTime;
  9. use patch::patch::{PatchServerState, generate_patch_tree, load_config};
  10. use login::login::LoginServerState;
  11. use login::character::CharacterServerState;
  12. use ship::ship::ShipServerState;
  13. use entity::account::{UserAccount, UserSettings};
  14. use entity::gateway::{EntityGateway, InMemoryGateway};
  15. use libpso::{utf8_to_array, utf8_to_utf16_array};
  16. //use crate::utf8_to_utf16_array;
  17. fn main() {
  18. let mut entity_gateway = InMemoryGateway::new();
  19. let fake_user = UserAccount {
  20. id: 1,
  21. username: "hi".to_string(),
  22. password: bcrypt::hash("qwer", 5).unwrap(),
  23. guildcard: None,
  24. team_id: None,
  25. banned: false,
  26. muted_until: SystemTime::now(),
  27. created_at: SystemTime::now(),
  28. flags: 0,
  29. };
  30. entity_gateway.set_user(&fake_user);
  31. entity_gateway.create_user_settings_by_user(&fake_user);
  32. let mut character = entity_gateway.new_character_by_user(&fake_user);
  33. character.character.name = utf8_to_utf16_array!("Test Char 1", 0x10);
  34. entity_gateway.set_character(&character);
  35. let mut character = entity_gateway.new_character_by_user(&fake_user);
  36. character.slot = 2;
  37. character.character.name = utf8_to_utf16_array!("Test Char 2", 0x10);
  38. entity_gateway.set_character(&character);
  39. let patch_thread = thread::spawn(|| {
  40. println!("[patch] starting server");
  41. let patch_config = load_config();
  42. let (patch_file_tree, patch_file_lookup) = generate_patch_tree(patch_config.path.as_str());
  43. let patch_state = PatchServerState::new(patch_file_tree, patch_file_lookup);
  44. common::mainloop::mainloop(patch_state, patch_config.port);
  45. });
  46. let thread_entity_gateway = entity_gateway.clone();
  47. let auth_thread = thread::spawn(|| {
  48. println!("[auth] starting server");
  49. let auth_state = LoginServerState::new(thread_entity_gateway);
  50. common::mainloop::mainloop(auth_state, login::login::LOGIN_PORT);
  51. });
  52. let thread_entity_gateway = entity_gateway.clone();
  53. let char_thread = thread::spawn(|| {
  54. println!("[character] starting server");
  55. let char_state = CharacterServerState::new(thread_entity_gateway);
  56. common::mainloop::mainloop(char_state, login::character::CHARACTER_PORT);
  57. });
  58. let thread_entity_gateway = entity_gateway.clone();
  59. let ship_thread = thread::spawn(|| {
  60. println!("[ship] starting server");
  61. let ship_state = ShipServerState::new(thread_entity_gateway);
  62. common::mainloop::mainloop(ship_state, ship::ship::SHIP_PORT);
  63. });
  64. patch_thread.join().unwrap();
  65. auth_thread.join().unwrap();
  66. char_thread.join().unwrap();
  67. ship_thread.join().unwrap();
  68. }