From a3db5b65e2738674d140ceb81ff4ae8e2955fe54 Mon Sep 17 00:00:00 2001 From: jake Date: Tue, 17 Nov 2020 18:25:01 -0700 Subject: [PATCH] add ability for servers to manually send messages to eachother --- src/common/mainloop/interserver.rs | 24 ++++++++++++++++++++---- src/login/character.rs | 7 +++++++ src/ship/ship.rs | 7 +++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/common/mainloop/interserver.rs b/src/common/mainloop/interserver.rs index 34143a9..8c42f23 100644 --- a/src/common/mainloop/interserver.rs +++ b/src/common/mainloop/interserver.rs @@ -186,7 +186,7 @@ pub fn login_listen_mainloop(state: Arc(state: Arc(state: Arc(state: Arc>>, ip: std::net::Ipv4Addr, port: u16) -> Pin>> { Box::pin(async_std::task::spawn(async move { let mut id = 0; - let (server_state_sender, server_state_receiver) = async_std::sync::channel(1024); - interserver_state_loop(state, server_state_receiver).await; + + interserver_state_loop(state.clone(), server_state_receiver).await; loop { info!("trying to connect to loginserv"); @@ -225,6 +233,14 @@ pub fn ship_connect_mainloop(state: Arc { level_table: CharacterLevelTable, auth_token: AuthToken, authenticated_ships: BTreeSet, + ship_sender: BTreeMap>, } @@ -296,9 +297,14 @@ impl CharacterServerState { level_table: CharacterLevelTable::new(), auth_token: auth_token, authenticated_ships: BTreeSet::new(), + ship_sender: BTreeMap::new(), } } + pub fn set_sender(&mut self, server_id: ServerId, sender: Box) { + self.ship_sender.insert(server_id, sender); + } + async fn validate_login(&mut self, id: ClientId, pkt: &Login) -> Result, anyhow::Error> { let client = self.clients.get_mut(&id).ok_or(CharacterError::ClientNotFound(id))?; Ok(match get_login_status(&self.entity_gateway, pkt).await.and_then(check_if_already_online) { @@ -595,6 +601,7 @@ impl InterserverActor for CharacterServerState { async fn on_disconnect(&mut self, id: ServerId) -> Vec<(ServerId, Self::SendMessage)> { self.ships.remove(&id); + self.ship_sender.remove(&id); Vec::new() } } diff --git a/src/ship/ship.rs b/src/ship/ship.rs index a0aa5d3..93a5487 100644 --- a/src/ship/ship.rs +++ b/src/ship/ship.rs @@ -351,6 +351,7 @@ impl ShipServerStateBuilder { port: self.port.unwrap_or(SHIP_PORT), shops: Box::new(ItemShops::new()), auth_token: self.auth_token.unwrap_or(AuthToken("".into())), + shipgate_sender: None, } } } @@ -368,6 +369,8 @@ pub struct ShipServerState { port: u16, shops: Box, auth_token: AuthToken, + + shipgate_sender: Option>, } impl ShipServerState { @@ -375,6 +378,10 @@ impl ShipServerState { ShipServerStateBuilder::new() } + pub fn set_sender(&mut self, sender: Box) { + self.shipgate_sender = Some(sender); + } + async fn message(&mut self, id: ClientId, msg: &Message) -> Result + Send>, anyhow::Error> { Ok(match &msg.msg { GameMessage::RequestExp(request_exp) => {