Parse SocketAddr
this allows for Ipv6 addresses
This commit is contained in:
parent
273803fbb0
commit
c1b6044457
@ -5,6 +5,7 @@ use logging::LoggingConfig;
|
|||||||
use pumpkin_util::{Difficulty, GameMode, PermissionLvl};
|
use pumpkin_util::{Difficulty, GameMode, PermissionLvl};
|
||||||
use serde::{Deserialize, Serialize, de::DeserializeOwned};
|
use serde::{Deserialize, Serialize, de::DeserializeOwned};
|
||||||
|
|
||||||
|
use std::net::SocketAddr;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::{env, fs, num::NonZeroU8, path::Path, sync::LazyLock};
|
use std::{env, fs, num::NonZeroU8, path::Path, sync::LazyLock};
|
||||||
pub mod fun;
|
pub mod fun;
|
||||||
@ -105,11 +106,11 @@ pub struct BasicConfiguration {
|
|||||||
// Whether Java Edition Client's are Accepted
|
// Whether Java Edition Client's are Accepted
|
||||||
pub java_edition: bool,
|
pub java_edition: bool,
|
||||||
/// The address and port to which the Java Edition server will bind
|
/// 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
|
// Whether Bedrock Edition Client's are Accepted
|
||||||
pub bedrock_edition: bool,
|
pub bedrock_edition: bool,
|
||||||
/// The address and port to which the Bedrock Edition server will bind
|
// Whether Bedrock Edition Client's are Accepted
|
||||||
pub bedrock_edition_port: u16,
|
pub bedrock_edition_address: SocketAddr,
|
||||||
/// The seed for world generation.
|
/// The seed for world generation.
|
||||||
pub seed: String,
|
pub seed: String,
|
||||||
/// The maximum number of players allowed on the server. Specifying `0` disables the limit.
|
/// 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 {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
java_edition: true,
|
java_edition: true,
|
||||||
java_edition_port: 25565,
|
java_edition_address: "0.0.0.0:25565".parse().unwrap(),
|
||||||
bedrock_edition: true,
|
bedrock_edition: true,
|
||||||
bedrock_edition_port: 19132,
|
bedrock_edition_address: "0.0.0.0:19132".parse().unwrap(),
|
||||||
seed: "".to_string(),
|
seed: "".to_string(),
|
||||||
max_players: 1000,
|
max_players: 1000,
|
||||||
view_distance: NonZeroU8::new(16).unwrap(),
|
view_distance: NonZeroU8::new(16).unwrap(),
|
||||||
|
|||||||
@ -20,7 +20,6 @@ use rustyline_async::{Readline, ReadlineEvent};
|
|||||||
use simplelog::SharedLogger;
|
use simplelog::SharedLogger;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::io::{Cursor, IsTerminal, stdin};
|
use std::io::{Cursor, IsTerminal, stdin};
|
||||||
use std::net::{Ipv4Addr, SocketAddrV4};
|
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
@ -198,12 +197,9 @@ impl PumpkinServer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Setup the TCP server socket.
|
// Setup the TCP server socket.
|
||||||
let listener = tokio::net::TcpListener::bind(SocketAddrV4::new(
|
let listener = tokio::net::TcpListener::bind(BASIC_CONFIG.java_edition_address)
|
||||||
Ipv4Addr::new(0, 0, 0, 0),
|
.await
|
||||||
BASIC_CONFIG.java_edition_port,
|
.expect("Failed to start `TcpListener`");
|
||||||
))
|
|
||||||
.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
|
// 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
|
let addr = listener
|
||||||
.local_addr()
|
.local_addr()
|
||||||
@ -235,12 +231,9 @@ impl PumpkinServer {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
let udp_socket = UdpSocket::bind(SocketAddrV4::new(
|
let udp_socket = UdpSocket::bind(BASIC_CONFIG.bedrock_edition_address)
|
||||||
Ipv4Addr::new(0, 0, 0, 0),
|
.await
|
||||||
BASIC_CONFIG.bedrock_edition_port,
|
.expect("Failed to bind UDP Socket");
|
||||||
))
|
|
||||||
.await
|
|
||||||
.expect("Failed to bind UDP Socket");
|
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
server: server.clone(),
|
server: server.clone(),
|
||||||
|
|||||||
@ -150,7 +150,7 @@ async fn main() {
|
|||||||
log::info!(
|
log::info!(
|
||||||
"Server is now running. Connect using port: {}{}{}",
|
"Server is now running. Connect using port: {}{}{}",
|
||||||
if BASIC_CONFIG.java_edition {
|
if BASIC_CONFIG.java_edition {
|
||||||
format!("Java Edition: {}", BASIC_CONFIG.java_edition_port)
|
format!("Java Edition: {}", BASIC_CONFIG.java_edition_address)
|
||||||
} else {
|
} else {
|
||||||
String::new()
|
String::new()
|
||||||
},
|
},
|
||||||
@ -160,7 +160,7 @@ async fn main() {
|
|||||||
""
|
""
|
||||||
},
|
},
|
||||||
if BASIC_CONFIG.bedrock_edition {
|
if BASIC_CONFIG.bedrock_edition {
|
||||||
format!("Bedrock Edition: {}", BASIC_CONFIG.bedrock_edition_port)
|
format!("Bedrock Edition: {}", BASIC_CONFIG.bedrock_edition_address)
|
||||||
} else {
|
} else {
|
||||||
String::new()
|
String::new()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user