use log::{info}; use entity::gateway::postgres::PostgresGateway; use elseware::login::login::LoginServerState; use elseware::login::character::CharacterServerState; use networking::interserver::AuthToken; fn main() { let colors = fern::colors::ColoredLevelConfig::new() .error(fern::colors::Color::Red) .warn(fern::colors::Color::Yellow) .info(fern::colors::Color::Green) .debug(fern::colors::Color::White) .trace(fern::colors::Color::BrightBlack); let stdio = fern::Dispatch::new() .level(log::LevelFilter::Debug) .format(move |out, message, record| { out.finish(format_args!( "\x1B[{}m[{}][{}][{}] {}\x1B[0m", colors.get_color(&record.level()).to_fg_str(), chrono::Local::now().format("%Y-%m-%d %H:%M:%S"), record.target(), record.level(), message, )) }) .chain(std::io::stdout()); fern::Dispatch::new() .chain(stdio) .apply().unwrap(); let db_host = std::env::var("DB_HOST").unwrap(); let db_username = std::env::var("DB_USERNAME").unwrap(); let db_password = std::env::var("DB_PASSWORD").unwrap(); let db_dbname = std::env::var("DB_DBNAME").unwrap(); let charserv_ip = std::env::var("CHARSERV_IP").unwrap().parse().unwrap(); let shipgate_token = std::env::var("SHIPGATE_TOKEN").unwrap(); let entity_gateway = PostgresGateway::new(&db_host, &db_dbname, &db_username, &db_password); let login_state = LoginServerState::new(entity_gateway.clone(), charserv_ip); let login_loop = async_std::task::spawn(async move { networking::mainloop::run_server(login_state, elseware::login::login::LOGIN_PORT).await; }); let char_state = CharacterServerState::new(entity_gateway, AuthToken(shipgate_token)); let sub_char_state = char_state.clone(); let character_loop = async_std::task::spawn(async move { networking::mainloop::run_server(sub_char_state, elseware::login::character::CHARACTER_PORT).await; }); let inter_character_loop = async_std::task::spawn(async move { networking::mainloop::run_interserver_listen(char_state, elseware::login::login::COMMUNICATION_PORT).await; }); info!("[auth/character] starting server"); async_std::task::block_on(async move { futures::future::join_all(vec![login_loop, character_loop, inter_character_loop]).await }); }