diff --git a/pumpkin-config/src/lib.rs b/pumpkin-config/src/lib.rs index 449214884..0d7670ff8 100644 --- a/pumpkin-config/src/lib.rs +++ b/pumpkin-config/src/lib.rs @@ -5,6 +5,7 @@ use logging::LoggingConfig; use pumpkin_util::{Difficulty, GameMode, PermissionLvl}; use serde::{Deserialize, Serialize, de::DeserializeOwned}; +use std::net::SocketAddr; use std::path::PathBuf; use std::{env, fs, num::NonZeroU8, path::Path, sync::LazyLock}; pub mod fun; @@ -105,11 +106,11 @@ pub struct BasicConfiguration { // Whether Java Edition Client's are Accepted pub java_edition: bool, /// The address and port to which the Java Edition server will bind - pub java_edition_port: u16, + pub java_edition_address: SocketAddr, // Whether Bedrock Edition Client's are Accepted pub bedrock_edition: bool, - /// The address and port to which the Bedrock Edition server will bind - pub bedrock_edition_port: u16, + // Whether Bedrock Edition Client's are Accepted + pub bedrock_edition_address: SocketAddr, /// The seed for world generation. pub seed: String, /// The maximum number of players allowed on the server. Specifying `0` disables the limit. @@ -158,9 +159,9 @@ impl Default for BasicConfiguration { fn default() -> Self { Self { java_edition: true, - java_edition_port: 25565, + java_edition_address: "0.0.0.0:25565".parse().unwrap(), bedrock_edition: true, - bedrock_edition_port: 19132, + bedrock_edition_address: "0.0.0.0:19132".parse().unwrap(), seed: "".to_string(), max_players: 1000, view_distance: NonZeroU8::new(16).unwrap(), diff --git a/pumpkin/src/lib.rs b/pumpkin/src/lib.rs index 9759d2024..2a9117fc0 100644 --- a/pumpkin/src/lib.rs +++ b/pumpkin/src/lib.rs @@ -20,7 +20,6 @@ use rustyline_async::{Readline, ReadlineEvent}; use simplelog::SharedLogger; use std::collections::HashMap; use std::io::{Cursor, IsTerminal, stdin}; -use std::net::{Ipv4Addr, SocketAddrV4}; use std::str::FromStr; use std::sync::Arc; use std::sync::atomic::{AtomicBool, Ordering}; @@ -198,12 +197,9 @@ impl PumpkinServer { } // Setup the TCP server socket. - let listener = tokio::net::TcpListener::bind(SocketAddrV4::new( - Ipv4Addr::new(0, 0, 0, 0), - BASIC_CONFIG.java_edition_port, - )) - .await - .expect("Failed to start `TcpListener`"); + let listener = tokio::net::TcpListener::bind(BASIC_CONFIG.java_edition_address) + .await + .expect("Failed to start `TcpListener`"); // In the event the user puts 0 for their port, this will allow us to know what port it is running on let addr = listener .local_addr() @@ -235,12 +231,9 @@ impl PumpkinServer { }); }; - let udp_socket = UdpSocket::bind(SocketAddrV4::new( - Ipv4Addr::new(0, 0, 0, 0), - BASIC_CONFIG.bedrock_edition_port, - )) - .await - .expect("Failed to bind UDP Socket"); + let udp_socket = UdpSocket::bind(BASIC_CONFIG.bedrock_edition_address) + .await + .expect("Failed to bind UDP Socket"); Self { server: server.clone(), diff --git a/pumpkin/src/main.rs b/pumpkin/src/main.rs index a71d0ae29..f016114a0 100644 --- a/pumpkin/src/main.rs +++ b/pumpkin/src/main.rs @@ -150,7 +150,7 @@ async fn main() { log::info!( "Server is now running. Connect using port: {}{}{}", if BASIC_CONFIG.java_edition { - format!("Java Edition: {}", BASIC_CONFIG.java_edition_port) + format!("Java Edition: {}", BASIC_CONFIG.java_edition_address) } else { String::new() }, @@ -160,7 +160,7 @@ async fn main() { "" }, if BASIC_CONFIG.bedrock_edition { - format!("Bedrock Edition: {}", BASIC_CONFIG.bedrock_edition_port) + format!("Bedrock Edition: {}", BASIC_CONFIG.bedrock_edition_address) } else { String::new() }