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.

62 lines
2.4 KiB

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