From 7a831c35c42501c86d08ae7af3b559b9cae021ee Mon Sep 17 00:00:00 2001 From: jake Date: Thu, 22 Oct 2020 13:16:24 -0600 Subject: [PATCH] add separate binaries for the server types --- src/bin/login.rs | 25 +++++++++++++++++++++++++ src/bin/patch.rs | 16 ++++++++++++++++ src/bin/ship.rs | 30 ++++++++++++++++++++++++++++++ 3 files changed, 71 insertions(+) create mode 100644 src/bin/login.rs create mode 100644 src/bin/patch.rs create mode 100644 src/bin/ship.rs diff --git a/src/bin/login.rs b/src/bin/login.rs new file mode 100644 index 0000000..42c3324 --- /dev/null +++ b/src/bin/login.rs @@ -0,0 +1,25 @@ +use log::{info}; +use elseware::entity::gateway::postgres::PostgresGateway; +use elseware::login::login::LoginServerState; +use elseware::login::character::CharacterServerState; +use elseware::common::mainloop::{login_mainloop, character_mainloop}; + +async fn main() { + 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 entity_gateway = PostgresGateway::new(&db_host, &db_dbname, &db_username, &db_password); + + let thread_entity_gateway = entity_gateway.clone(); + let login_state = LoginServerState::new(thread_entity_gateway); + let login_loop = login_mainloop(login_state, elseware::login::login::LOGIN_PORT); + + let char_state = CharacterServerState::new(entity_gateway); + let character_loop = character_mainloop(char_state, elseware::login::character::CHARACTER_PORT, elseware::login::login::COMMUNICATION_PORT); + + info!("[auth/character] starting server"); + async_std::task::block_on(async move { + futures::future::join_all(vec![login_loop, character_loop]).await + }); +} diff --git a/src/bin/patch.rs b/src/bin/patch.rs new file mode 100644 index 0000000..17bceda --- /dev/null +++ b/src/bin/patch.rs @@ -0,0 +1,16 @@ +use elseware::patch::patch::{PatchServerState, generate_patch_tree, load_config, load_motd}; +use log::{info}; +use elseware::common::mainloop::patch_mainloop; + +fn main() { + info!("[patch] starting server"); + let patch_config = load_config(); + let patch_motd = load_motd(); + let (patch_file_tree, patch_file_lookup) = generate_patch_tree(patch_config.path.as_str()); + let patch_state = PatchServerState::new(patch_file_tree, patch_file_lookup, patch_motd); + let patch_loop = patch_mainloop(patch_state, patch_config.port); + + async_std::task::block_on(async move { + patch_loop.await + }); +} diff --git a/src/bin/ship.rs b/src/bin/ship.rs new file mode 100644 index 0000000..fd1d367 --- /dev/null +++ b/src/bin/ship.rs @@ -0,0 +1,30 @@ +use log::{info}; +use elseware::entity::gateway::postgres::PostgresGateway; +use elseware::ship::ship::ShipServerState; +use elseware::ship::ship::ShipServerStateBuilder; +use elseware::common::mainloop::ship_mainloop; + +async fn main() { + 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 entity_gateway = PostgresGateway::new(&db_host, &db_dbname, &db_username, &db_password); + + let ship_name = std::env::var("SHIP_NAME").unwrap().parse().unwrap(); + let ip = std::env::var("SELF_IP").unwrap().parse().unwrap(); + let ship_state = ShipServerStateBuilder::new() + .name(ship_name) + .ip(ip) + .port(elseware::ship::ship::SHIP_PORT) + .gateway(entity_gateway) + .build(); + + let shipgate_ip = std::env::var("SHIPGATE_IP").unwrap().parse().unwrap(); + let ship_loop = ship_mainloop(ship_state, elseware::ship::ship::SHIP_PORT, shipgate_ip, elseware::login::login::COMMUNICATION_PORT); + + info!("[auth/character] starting server"); + async_std::task::block_on(async move { + ship_loop.await + }); +}