mod client; mod interserver; use std::pin::Pin; use futures::future::{Future, join_all, FutureExt}; use async_std::sync::{Arc, Mutex}; use crate::common::mainloop::client::client_accept_mainloop; use crate::common::mainloop::interserver::{ship_connect_mainloop, login_listen_mainloop}; pub use crate::common::mainloop::client::NetworkError; use crate::patch::patch::PatchServerState; use crate::login::login::LoginServerState; use crate::login::character::CharacterServerState; use crate::ship::ship::ShipServerState; use crate::entity::gateway::entitygateway::EntityGateway; pub fn patch_mainloop(patch_state: PatchServerState, patch_port: u16) -> Pin>> { let patch_state = Arc::new(Mutex::new(patch_state)); let client_mainloop = client_accept_mainloop(patch_state, patch_port); Box::pin(client_mainloop) } pub fn login_mainloop(login_state: LoginServerState, login_port: u16) -> Pin>> { let login_state = Arc::new(Mutex::new(login_state)); let client_mainloop = client_accept_mainloop(login_state, login_port); Box::pin(client_mainloop) } pub fn character_mainloop(character_state: CharacterServerState, character_port: u16, comm_port: u16) -> Pin>> { let character_state = Arc::new(Mutex::new(character_state)); let client_mainloop = client_accept_mainloop(character_state.clone(), character_port); let ship_communication_mainloop = login_listen_mainloop(character_state, comm_port); Box::pin(join_all(vec![client_mainloop, ship_communication_mainloop]).map(|_| ())) } pub fn ship_mainloop(ship_state: ShipServerState, ship_port: u16, comm_ip: std::net::Ipv4Addr, comm_port: u16) -> Pin>> { let ship_state = Arc::new(Mutex::new(ship_state)); let client_mainloop = client_accept_mainloop(ship_state.clone(), ship_port); let login_communication_mainloop = ship_connect_mainloop(ship_state, comm_ip, comm_port); Box::pin(join_all(vec![client_mainloop, login_communication_mainloop]).map(|_| ())) }