From 6d79a365f32ef3a00e406aea07df07c28d849a43 Mon Sep 17 00:00:00 2001 From: OTCompa <41562938+OTCompa@users.noreply.github.com> Date: Thu, 19 Jun 2025 14:19:47 -0500 Subject: [PATCH] Add config for world address to be served by lobby server --- src/config.rs | 14 ++++++++++++++ src/lobby/connection.rs | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 60e253c..0cc65ab 100644 --- a/src/config.rs +++ b/src/config.rs @@ -195,6 +195,8 @@ pub struct WorldConfig { pub port: u16, #[serde(default = "WorldConfig::default_listen_address")] pub listen_address: String, + #[serde(default = "WorldConfig::default_world_address")] + pub world_address: String, /// See the World Excel sheet. #[serde(default = "WorldConfig::default_world_id")] pub world_id: u16, @@ -221,6 +223,7 @@ impl Default for WorldConfig { Self { port: Self::default_port(), listen_address: Self::default_listen_address(), + world_address: Self::default_world_address(), world_id: Self::default_world_id(), scripts_location: Self::default_scripts_location(), rcon_port: Self::default_rcon_port(), @@ -240,6 +243,10 @@ impl WorldConfig { "0.0.0.0".to_string() } + fn default_world_address() -> String { + "127.0.0.1".to_string() + } + fn default_world_id() -> u16 { 63 // Gilgamesh } @@ -274,6 +281,13 @@ impl WorldConfig { )) } + pub fn get_world_socketaddr(&self) -> SocketAddr { + SocketAddr::from(( + IpAddr::from_str(&self.world_address).expect("Invalid IP address format in config!"), + self.port, + )) + } + /// Returns the configured IP address & port as a `SocketAddr` for RCON. pub fn get_rcon_socketaddr(&self) -> SocketAddr { SocketAddr::from(( diff --git a/src/lobby/connection.rs b/src/lobby/connection.rs index 1379faf..7ceb7ca 100644 --- a/src/lobby/connection.rs +++ b/src/lobby/connection.rs @@ -250,7 +250,7 @@ impl LobbyConnection { content_id, token: String::new(), port: config.world.port, - host: config.world.listen_address, + host: config.world.world_address, }; let ipc = ServerLobbyIpcSegment { @@ -538,7 +538,7 @@ impl LobbyConnection { pub async fn send_custom_world_packet(segment: CustomIpcSegment) -> Option { let config = get_config(); - let addr = config.world.get_socketaddr(); + let addr = config.world.get_world_socketaddr(); let mut stream = TcpStream::connect(addr).await.unwrap();