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.

58 lines
2.4 KiB

4 years ago
3 years ago
  1. use log::{info};
  2. use entity::gateway::postgres::PostgresGateway;
  3. use elseware::login::login::LoginServerState;
  4. use elseware::login::character::CharacterServerState;
  5. use networking::interserver::AuthToken;
  6. fn main() {
  7. let colors = fern::colors::ColoredLevelConfig::new()
  8. .error(fern::colors::Color::Red)
  9. .warn(fern::colors::Color::Yellow)
  10. .info(fern::colors::Color::Green)
  11. .debug(fern::colors::Color::White)
  12. .trace(fern::colors::Color::BrightBlack);
  13. let stdio = fern::Dispatch::new()
  14. .level(log::LevelFilter::Debug)
  15. .format(move |out, message, record| {
  16. out.finish(format_args!(
  17. "\x1B[{}m[{}][{}][{}] {}\x1B[0m",
  18. colors.get_color(&record.level()).to_fg_str(),
  19. chrono::Local::now().format("%Y-%m-%d %H:%M:%S"),
  20. record.target(),
  21. record.level(),
  22. message,
  23. ))
  24. })
  25. .chain(std::io::stdout());
  26. fern::Dispatch::new()
  27. .chain(stdio)
  28. .apply().unwrap();
  29. let db_host = std::env::var("DB_HOST").unwrap();
  30. let db_username = std::env::var("DB_USERNAME").unwrap();
  31. let db_password = std::env::var("DB_PASSWORD").unwrap();
  32. let db_dbname = std::env::var("DB_DBNAME").unwrap();
  33. let charserv_ip = std::env::var("CHARSERV_IP").unwrap().parse().unwrap();
  34. let shipgate_token = std::env::var("SHIPGATE_TOKEN").unwrap();
  35. let entity_gateway = PostgresGateway::new(&db_host, &db_dbname, &db_username, &db_password);
  36. let login_state = LoginServerState::new(entity_gateway.clone(), charserv_ip);
  37. let login_loop = async_std::task::spawn(async move {
  38. networking::mainloop::run_server(login_state, elseware::login::login::LOGIN_PORT).await;
  39. });
  40. let char_state = CharacterServerState::new(entity_gateway, AuthToken(shipgate_token));
  41. let sub_char_state = char_state.clone();
  42. let character_loop = async_std::task::spawn(async move {
  43. networking::mainloop::run_server(sub_char_state, elseware::login::character::CHARACTER_PORT).await;
  44. });
  45. let inter_character_loop = async_std::task::spawn(async move {
  46. networking::mainloop::run_interserver_listen(char_state, elseware::login::login::COMMUNICATION_PORT).await;
  47. });
  48. info!("[auth/character] starting server");
  49. async_std::task::block_on(async move {
  50. futures::future::join_all(vec![login_loop, character_loop, inter_character_loop]).await
  51. });
  52. }