diff --git a/resources/Caddyfile b/resources/Caddyfile index 4bb50cf..a3bbeb6 100644 --- a/resources/Caddyfile +++ b/resources/Caddyfile @@ -14,6 +14,10 @@ launcher.ffxiv.localhost:80 { reverse_proxy :5802 } +config-dl.ffxiv.localhost:80 { + reverse_proxy :5803 +} + frontier.ffxiv.localhost:80 { reverse_proxy :5857 } diff --git a/scripts/run.sh b/scripts/run.sh index 8bb51fd..657ff9b 100755 --- a/scripts/run.sh +++ b/scripts/run.sh @@ -10,4 +10,5 @@ cargo run -q --package kawari --features oodle --bin kawari-web & cargo run -q --package kawari --features oodle --bin kawari-lobby & cargo run -q --package kawari --features oodle --bin kawari-world & cargo run -q --package kawari --features oodle --bin kawari-launcher & +cargo run -q --package kawari --features oodle --bin kawari-savedatabank & wait diff --git a/src/bin/kawari-savedatabank.rs b/src/bin/kawari-savedatabank.rs new file mode 100644 index 0000000..b57c3bf --- /dev/null +++ b/src/bin/kawari-savedatabank.rs @@ -0,0 +1,32 @@ +use kawari::RECEIVE_BUFFER_SIZE; +use kawari::config::get_config; +use tokio::io::AsyncReadExt; +use tokio::net::TcpListener; + +#[tokio::main] +async fn main() { + tracing_subscriber::fmt::init(); + + let config = get_config(); + + let addr = config.save_data_bank.get_socketaddr(); + + let listener = TcpListener::bind(addr).await.unwrap(); + + tracing::info!("Server started on {addr}"); + + loop { + let (mut socket, _) = listener.accept().await.unwrap(); + + tokio::spawn(async move { + loop { + let mut buf = vec![0; RECEIVE_BUFFER_SIZE]; + let n = socket.read(&mut buf).await.expect("Failed to read data!"); + + if n != 0 { + dbg!(buf); + } + } + }); + } +} diff --git a/src/config.rs b/src/config.rs index b9fe867..cba59fa 100644 --- a/src/config.rs +++ b/src/config.rs @@ -289,6 +289,32 @@ impl LauncherConfig { } } +/// Configuration for the save data bank server. +#[derive(Serialize, Deserialize)] +pub struct SaveDataBankConfig { + pub port: u16, + pub listen_address: String, +} + +impl Default for SaveDataBankConfig { + fn default() -> Self { + Self { + port: 5803, + listen_address: "127.0.0.1".to_string(), + } + } +} + +impl SaveDataBankConfig { + /// Returns the configured IP address & port as a `SocketAddr`. + pub fn get_socketaddr(&self) -> SocketAddr { + SocketAddr::from(( + IpAddr::from_str(&self.listen_address).expect("Invalid IP address format in config!"), + self.port, + )) + } +} + /// Global and all-encompassing config. /// Settings that affect all servers belong here. #[derive(Serialize, Deserialize)] @@ -323,6 +349,9 @@ pub struct Config { #[serde(default)] pub launcher: LauncherConfig, + #[serde(default)] + pub save_data_bank: SaveDataBankConfig, + /// Enable various packet debug functions. This will clutter your working directory! #[serde(default)] pub packet_debugging: bool, @@ -341,6 +370,7 @@ impl Default for Config { web: WebConfig::default(), world: WorldConfig::default(), launcher: LauncherConfig::default(), + save_data_bank: SaveDataBankConfig::default(), packet_debugging: false, } }