Use proper IP Address abstraction instead of using format!()
This commit is contained in:
parent
ff68b5cac5
commit
d57d9ffdcc
@ -1,9 +1,11 @@
|
|||||||
use std::path::Path;
|
|
||||||
|
|
||||||
use auth_config::AuthenticationConfig;
|
use auth_config::AuthenticationConfig;
|
||||||
use proxy::ProxyConfig;
|
use proxy::ProxyConfig;
|
||||||
use resource_pack::ResourcePackConfig;
|
use resource_pack::ResourcePackConfig;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
use std::{
|
||||||
|
net::{Ipv4Addr, SocketAddr},
|
||||||
|
path::Path,
|
||||||
|
};
|
||||||
|
|
||||||
use crate::{entity::player::GameMode, server::Difficulty};
|
use crate::{entity::player::GameMode, server::Difficulty};
|
||||||
|
|
||||||
@ -33,8 +35,7 @@ pub struct AdvancedConfiguration {
|
|||||||
#[derive(Deserialize, Serialize, Clone)]
|
#[derive(Deserialize, Serialize, Clone)]
|
||||||
pub struct RCONConfig {
|
pub struct RCONConfig {
|
||||||
pub enabled: bool,
|
pub enabled: bool,
|
||||||
pub ip: String,
|
pub address: SocketAddr,
|
||||||
pub port: u16,
|
|
||||||
pub password: String,
|
pub password: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -42,8 +43,7 @@ impl Default for RCONConfig {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
ip: "0.0.0.0".to_string(),
|
address: SocketAddr::new(Ipv4Addr::new(0, 0, 0, 0).into(), 25575),
|
||||||
port: 25575,
|
|
||||||
password: "".to_string(),
|
password: "".to_string(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -116,9 +116,7 @@ pub struct BasicConfiguration {
|
|||||||
/// A version identifier for the configuration format.
|
/// A version identifier for the configuration format.
|
||||||
pub config_version: String,
|
pub config_version: String,
|
||||||
/// The address to bind the server to.
|
/// The address to bind the server to.
|
||||||
pub server_address: String,
|
pub server_address: SocketAddr,
|
||||||
/// The port to listen on.
|
|
||||||
pub server_port: u16,
|
|
||||||
/// 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.
|
/// The maximum number of players allowed on the server.
|
||||||
@ -147,8 +145,7 @@ impl Default for BasicConfiguration {
|
|||||||
fn default() -> Self {
|
fn default() -> Self {
|
||||||
Self {
|
Self {
|
||||||
config_version: CURRENT_BASE_VERSION.to_string(),
|
config_version: CURRENT_BASE_VERSION.to_string(),
|
||||||
server_address: "0.0.0.0".to_string(),
|
server_address: SocketAddr::new(Ipv4Addr::new(0, 0, 0, 0).into(), 25565),
|
||||||
server_port: 25565,
|
|
||||||
seed: "".to_string(),
|
seed: "".to_string(),
|
||||||
max_players: 100000,
|
max_players: 100000,
|
||||||
view_distance: 10,
|
view_distance: 10,
|
||||||
|
|||||||
@ -74,14 +74,7 @@ fn main() -> io::Result<()> {
|
|||||||
let mut events = Events::with_capacity(128);
|
let mut events = Events::with_capacity(128);
|
||||||
|
|
||||||
// Setup the TCP server socket.
|
// Setup the TCP server socket.
|
||||||
|
let addr = basic_config.server_address;
|
||||||
let addr = format!(
|
|
||||||
"{}:{}",
|
|
||||||
basic_config.server_address, basic_config.server_port
|
|
||||||
)
|
|
||||||
.parse()
|
|
||||||
.unwrap();
|
|
||||||
|
|
||||||
let mut listener = TcpListener::bind(addr)?;
|
let mut listener = TcpListener::bind(addr)?;
|
||||||
|
|
||||||
// Register the server with poll we can receive events for it.
|
// Register the server with poll we can receive events for it.
|
||||||
|
|||||||
@ -35,11 +35,8 @@ impl RCONServer {
|
|||||||
server: Arc<tokio::sync::Mutex<Server>>,
|
server: Arc<tokio::sync::Mutex<Server>>,
|
||||||
) -> Result<Self, io::Error> {
|
) -> Result<Self, io::Error> {
|
||||||
assert!(config.enabled, "RCON is not enabled");
|
assert!(config.enabled, "RCON is not enabled");
|
||||||
let addr = format!("{}:{}", config.ip, config.port)
|
|
||||||
.parse()
|
|
||||||
.expect("Failed to parse RCON address");
|
|
||||||
let mut poll = Poll::new().unwrap();
|
let mut poll = Poll::new().unwrap();
|
||||||
let mut listener = TcpListener::bind(addr).unwrap();
|
let mut listener = TcpListener::bind(config.address).unwrap();
|
||||||
|
|
||||||
poll.registry()
|
poll.registry()
|
||||||
.register(&mut listener, SERVER, Interest::READABLE)
|
.register(&mut listener, SERVER, Interest::READABLE)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user