Parse SocketAddr

this allows for Ipv6 addresses
This commit is contained in:
Alexander Medvedev 2025-08-16 17:02:25 +02:00
parent 273803fbb0
commit c1b6044457
3 changed files with 14 additions and 20 deletions

View File

@ -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(),

View File

@ -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(),

View File

@ -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()
}