move some config things into networking
This commit is contained in:
parent
2767eff91a
commit
ad39b28d6d
@ -1,7 +1,6 @@
|
|||||||
use log::warn;
|
use log::warn;
|
||||||
use logging::LoggingConfig;
|
use logging::LoggingConfig;
|
||||||
use pumpkin_core::{Difficulty, GameMode, PermissionLvl};
|
use pumpkin_core::{Difficulty, GameMode, PermissionLvl};
|
||||||
use query::QueryConfig;
|
|
||||||
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
use serde::{de::DeserializeOwned, Deserialize, Serialize};
|
||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
@ -12,29 +11,26 @@ use std::{
|
|||||||
sync::LazyLock,
|
sync::LazyLock,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub mod auth;
|
|
||||||
pub mod logging;
|
pub mod logging;
|
||||||
pub mod proxy;
|
pub mod networking;
|
||||||
pub mod query;
|
|
||||||
pub mod resource_pack;
|
pub mod resource_pack;
|
||||||
|
|
||||||
pub use auth::AuthenticationConfig;
|
|
||||||
pub use commands::CommandsConfig;
|
pub use commands::CommandsConfig;
|
||||||
pub use compression::CompressionConfig;
|
pub use networking::auth::AuthenticationConfig;
|
||||||
pub use lan_broadcast::LANBroadcastConfig;
|
pub use networking::compression::CompressionConfig;
|
||||||
|
pub use networking::lan_broadcast::LANBroadcastConfig;
|
||||||
|
pub use networking::rcon::RCONConfig;
|
||||||
pub use pvp::PVPConfig;
|
pub use pvp::PVPConfig;
|
||||||
pub use rcon::RCONConfig;
|
|
||||||
pub use server_links::ServerLinksConfig;
|
pub use server_links::ServerLinksConfig;
|
||||||
|
|
||||||
mod commands;
|
mod commands;
|
||||||
pub mod compression;
|
|
||||||
mod lan_broadcast;
|
|
||||||
pub mod op;
|
pub mod op;
|
||||||
mod pvp;
|
mod pvp;
|
||||||
mod rcon;
|
|
||||||
mod server_links;
|
mod server_links;
|
||||||
|
|
||||||
use proxy::ProxyConfig;
|
use networking::NetworkingConfig;
|
||||||
use resource_pack::ResourcePackConfig;
|
use resource_pack::ResourcePackConfig;
|
||||||
|
|
||||||
const CONFIG_ROOT_FOLDER: &str = "config/";
|
const CONFIG_ROOT_FOLDER: &str = "config/";
|
||||||
@ -52,17 +48,12 @@ pub static BASIC_CONFIG: LazyLock<BasicConfiguration> = LazyLock::new(BasicConfi
|
|||||||
#[derive(Deserialize, Serialize, Default)]
|
#[derive(Deserialize, Serialize, Default)]
|
||||||
#[serde(default)]
|
#[serde(default)]
|
||||||
pub struct AdvancedConfiguration {
|
pub struct AdvancedConfiguration {
|
||||||
pub proxy: ProxyConfig,
|
|
||||||
pub authentication: AuthenticationConfig,
|
|
||||||
pub packet_compression: CompressionConfig,
|
|
||||||
pub resource_pack: ResourcePackConfig,
|
|
||||||
pub commands: CommandsConfig,
|
|
||||||
pub rcon: RCONConfig,
|
|
||||||
pub pvp: PVPConfig,
|
|
||||||
pub logging: LoggingConfig,
|
pub logging: LoggingConfig,
|
||||||
pub query: QueryConfig,
|
pub resource_pack: ResourcePackConfig,
|
||||||
|
pub networking: NetworkingConfig,
|
||||||
|
pub commands: CommandsConfig,
|
||||||
|
pub pvp: PVPConfig,
|
||||||
pub server_links: ServerLinksConfig,
|
pub server_links: ServerLinksConfig,
|
||||||
pub lan_broadcast: LANBroadcastConfig,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize)]
|
#[derive(Serialize, Deserialize)]
|
||||||
|
|||||||
24
pumpkin-config/src/networking/mod.rs
Normal file
24
pumpkin-config/src/networking/mod.rs
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
use auth::AuthenticationConfig;
|
||||||
|
use proxy::ProxyConfig;
|
||||||
|
use query::QueryConfig;
|
||||||
|
use rcon::RCONConfig;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::{CompressionConfig, LANBroadcastConfig};
|
||||||
|
|
||||||
|
pub mod auth;
|
||||||
|
pub mod compression;
|
||||||
|
pub mod lan_broadcast;
|
||||||
|
pub mod proxy;
|
||||||
|
pub mod query;
|
||||||
|
pub mod rcon;
|
||||||
|
|
||||||
|
#[derive(Deserialize, Serialize, Default)]
|
||||||
|
pub struct NetworkingConfig {
|
||||||
|
pub authentication: AuthenticationConfig,
|
||||||
|
pub query: QueryConfig,
|
||||||
|
pub rcon: RCONConfig,
|
||||||
|
pub proxy: ProxyConfig,
|
||||||
|
pub packet_compression: CompressionConfig,
|
||||||
|
pub lan_broadcast: LANBroadcastConfig,
|
||||||
|
}
|
||||||
@ -161,7 +161,7 @@ async fn main() {
|
|||||||
.expect("Unable to get the address of server!");
|
.expect("Unable to get the address of server!");
|
||||||
|
|
||||||
let use_console = ADVANCED_CONFIG.commands.use_console;
|
let use_console = ADVANCED_CONFIG.commands.use_console;
|
||||||
let rcon = ADVANCED_CONFIG.rcon.clone();
|
let rcon = ADVANCED_CONFIG.networking.rcon.clone();
|
||||||
|
|
||||||
let server = Arc::new(Server::new());
|
let server = Arc::new(Server::new());
|
||||||
let mut ticker = Ticker::new(BASIC_CONFIG.tps);
|
let mut ticker = Ticker::new(BASIC_CONFIG.tps);
|
||||||
@ -179,12 +179,12 @@ async fn main() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if ADVANCED_CONFIG.query.enabled {
|
if ADVANCED_CONFIG.networking.query.enabled {
|
||||||
log::info!("Query protocol enabled. Starting...");
|
log::info!("Query protocol enabled. Starting...");
|
||||||
tokio::spawn(query::start_query_handler(server.clone(), addr));
|
tokio::spawn(query::start_query_handler(server.clone(), addr));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ADVANCED_CONFIG.lan_broadcast.enabled {
|
if ADVANCED_CONFIG.networking.lan_broadcast.enabled {
|
||||||
log::info!("LAN broadcast enabled. Starting...");
|
log::info!("LAN broadcast enabled. Starting...");
|
||||||
tokio::spawn(lan_broadcast::start_lan_broadcast(addr));
|
tokio::spawn(lan_broadcast::start_lan_broadcast(addr));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
use std::{collections::HashMap, net::IpAddr};
|
use std::{collections::HashMap, net::IpAddr};
|
||||||
|
|
||||||
use base64::{engine::general_purpose, Engine};
|
use base64::{engine::general_purpose, Engine};
|
||||||
use pumpkin_config::{auth::TextureConfig, ADVANCED_CONFIG};
|
use pumpkin_config::{networking::auth::TextureConfig, ADVANCED_CONFIG};
|
||||||
use pumpkin_protocol::Property;
|
use pumpkin_protocol::Property;
|
||||||
use reqwest::{StatusCode, Url};
|
use reqwest::{StatusCode, Url};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
@ -50,8 +50,13 @@ pub async fn authenticate(
|
|||||||
ip: &IpAddr,
|
ip: &IpAddr,
|
||||||
auth_client: &reqwest::Client,
|
auth_client: &reqwest::Client,
|
||||||
) -> Result<GameProfile, AuthError> {
|
) -> Result<GameProfile, AuthError> {
|
||||||
let address = if ADVANCED_CONFIG.authentication.prevent_proxy_connections {
|
let address = if ADVANCED_CONFIG
|
||||||
|
.networking
|
||||||
|
.authentication
|
||||||
|
.prevent_proxy_connections
|
||||||
|
{
|
||||||
let auth_url = ADVANCED_CONFIG
|
let auth_url = ADVANCED_CONFIG
|
||||||
|
.networking
|
||||||
.authentication
|
.authentication
|
||||||
.prevent_proxy_connection_auth_url
|
.prevent_proxy_connection_auth_url
|
||||||
.as_deref()
|
.as_deref()
|
||||||
@ -63,6 +68,7 @@ pub async fn authenticate(
|
|||||||
.replace("{ip}", &ip.to_string())
|
.replace("{ip}", &ip.to_string())
|
||||||
} else {
|
} else {
|
||||||
let auth_url = ADVANCED_CONFIG
|
let auth_url = ADVANCED_CONFIG
|
||||||
|
.networking
|
||||||
.authentication
|
.authentication
|
||||||
.auth_url
|
.auth_url
|
||||||
.as_deref()
|
.as_deref()
|
||||||
|
|||||||
@ -10,7 +10,7 @@ const BROADCAST_ADDRESS: SocketAddr =
|
|||||||
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(224, 0, 2, 60)), 4445);
|
SocketAddr::new(IpAddr::V4(Ipv4Addr::new(224, 0, 2, 60)), 4445);
|
||||||
|
|
||||||
pub async fn start_lan_broadcast(bound_addr: SocketAddr) {
|
pub async fn start_lan_broadcast(bound_addr: SocketAddr) {
|
||||||
let port = ADVANCED_CONFIG.lan_broadcast.port.unwrap_or(0);
|
let port = ADVANCED_CONFIG.networking.lan_broadcast.port.unwrap_or(0);
|
||||||
|
|
||||||
let socket = UdpSocket::bind(format!("0.0.0.0:{port}"))
|
let socket = UdpSocket::bind(format!("0.0.0.0:{port}"))
|
||||||
.await
|
.await
|
||||||
@ -22,6 +22,7 @@ pub async fn start_lan_broadcast(bound_addr: SocketAddr) {
|
|||||||
|
|
||||||
let motd: String;
|
let motd: String;
|
||||||
let advanced_motd = &ADVANCED_CONFIG
|
let advanced_motd = &ADVANCED_CONFIG
|
||||||
|
.networking
|
||||||
.lan_broadcast
|
.lan_broadcast
|
||||||
.motd
|
.motd
|
||||||
.clone()
|
.clone()
|
||||||
|
|||||||
@ -14,7 +14,7 @@ use crate::{
|
|||||||
};
|
};
|
||||||
|
|
||||||
use crossbeam::atomic::AtomicCell;
|
use crossbeam::atomic::AtomicCell;
|
||||||
use pumpkin_config::compression::CompressionInfo;
|
use pumpkin_config::networking::compression::CompressionInfo;
|
||||||
use pumpkin_core::{text::TextComponent, ProfileAction};
|
use pumpkin_core::{text::TextComponent, ProfileAction};
|
||||||
use pumpkin_protocol::{
|
use pumpkin_protocol::{
|
||||||
bytebuf::{packet_id::Packet, ReadingError},
|
bytebuf::{packet_id::Packet, ReadingError},
|
||||||
|
|||||||
@ -105,7 +105,7 @@ impl Client {
|
|||||||
// default game profile, when no online mode
|
// default game profile, when no online mode
|
||||||
// TODO: make offline uuid
|
// TODO: make offline uuid
|
||||||
let mut gameprofile = self.gameprofile.lock().await;
|
let mut gameprofile = self.gameprofile.lock().await;
|
||||||
let proxy = &ADVANCED_CONFIG.proxy;
|
let proxy = &ADVANCED_CONFIG.networking.proxy;
|
||||||
if proxy.enabled {
|
if proxy.enabled {
|
||||||
if proxy.velocity.enabled {
|
if proxy.velocity.enabled {
|
||||||
velocity::velocity_login(self).await;
|
velocity::velocity_login(self).await;
|
||||||
@ -146,7 +146,7 @@ impl Client {
|
|||||||
)
|
)
|
||||||
.await;
|
.await;
|
||||||
} else {
|
} else {
|
||||||
if ADVANCED_CONFIG.packet_compression.enabled {
|
if ADVANCED_CONFIG.networking.packet_compression.enabled {
|
||||||
self.enable_compression().await;
|
self.enable_compression().await;
|
||||||
}
|
}
|
||||||
self.finish_login(&profile).await;
|
self.finish_login(&profile).await;
|
||||||
@ -205,14 +205,18 @@ impl Client {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ADVANCED_CONFIG.packet_compression.enabled {
|
if ADVANCED_CONFIG.networking.packet_compression.enabled {
|
||||||
self.enable_compression().await;
|
self.enable_compression().await;
|
||||||
}
|
}
|
||||||
self.finish_login(profile).await;
|
self.finish_login(profile).await;
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn enable_compression(&self) {
|
async fn enable_compression(&self) {
|
||||||
let compression = ADVANCED_CONFIG.packet_compression.compression_info.clone();
|
let compression = ADVANCED_CONFIG
|
||||||
|
.networking
|
||||||
|
.packet_compression
|
||||||
|
.compression_info
|
||||||
|
.clone();
|
||||||
self.send_packet(&CSetCompression::new(compression.threshold.into()))
|
self.send_packet(&CSetCompression::new(compression.threshold.into()))
|
||||||
.await;
|
.await;
|
||||||
self.set_compression(Some(compression)).await;
|
self.set_compression(Some(compression)).await;
|
||||||
@ -237,11 +241,13 @@ impl Client {
|
|||||||
// Check if player should join
|
// Check if player should join
|
||||||
if let Some(actions) = &profile.profile_actions {
|
if let Some(actions) = &profile.profile_actions {
|
||||||
if ADVANCED_CONFIG
|
if ADVANCED_CONFIG
|
||||||
|
.networking
|
||||||
.authentication
|
.authentication
|
||||||
.player_profile
|
.player_profile
|
||||||
.allow_banned_players
|
.allow_banned_players
|
||||||
{
|
{
|
||||||
for allowed in &ADVANCED_CONFIG
|
for allowed in &ADVANCED_CONFIG
|
||||||
|
.networking
|
||||||
.authentication
|
.authentication
|
||||||
.player_profile
|
.player_profile
|
||||||
.allowed_actions
|
.allowed_actions
|
||||||
@ -261,7 +267,7 @@ impl Client {
|
|||||||
for property in &profile.properties {
|
for property in &profile.properties {
|
||||||
authentication::validate_textures(
|
authentication::validate_textures(
|
||||||
property,
|
property,
|
||||||
&ADVANCED_CONFIG.authentication.textures,
|
&ADVANCED_CONFIG.networking.authentication.textures,
|
||||||
)
|
)
|
||||||
.map_err(AuthError::TextureError)?;
|
.map_err(AuthError::TextureError)?;
|
||||||
}
|
}
|
||||||
@ -281,7 +287,7 @@ impl Client {
|
|||||||
}
|
}
|
||||||
pub async fn handle_plugin_response(&self, plugin_response: SLoginPluginResponse) {
|
pub async fn handle_plugin_response(&self, plugin_response: SLoginPluginResponse) {
|
||||||
log::debug!("Handling plugin");
|
log::debug!("Handling plugin");
|
||||||
let velocity_config = &ADVANCED_CONFIG.proxy.velocity;
|
let velocity_config = &ADVANCED_CONFIG.networking.proxy.velocity;
|
||||||
if velocity_config.enabled {
|
if velocity_config.enabled {
|
||||||
let mut address = self.address.lock().await;
|
let mut address = self.address.lock().await;
|
||||||
match velocity::receive_velocity_plugin_response(
|
match velocity::receive_velocity_plugin_response(
|
||||||
|
|||||||
@ -5,7 +5,7 @@ use std::net::{IpAddr, SocketAddr};
|
|||||||
|
|
||||||
use bytes::{BufMut, BytesMut};
|
use bytes::{BufMut, BytesMut};
|
||||||
use hmac::{Hmac, Mac};
|
use hmac::{Hmac, Mac};
|
||||||
use pumpkin_config::proxy::VelocityConfig;
|
use pumpkin_config::networking::proxy::VelocityConfig;
|
||||||
use pumpkin_protocol::{
|
use pumpkin_protocol::{
|
||||||
bytebuf::ByteBuf, client::login::CLoginPluginRequest, server::login::SLoginPluginResponse,
|
bytebuf::ByteBuf, client::login::CLoginPluginRequest, server::login::SLoginPluginResponse,
|
||||||
Property,
|
Property,
|
||||||
|
|||||||
@ -17,7 +17,7 @@ use crate::server::{Server, CURRENT_MC_VERSION};
|
|||||||
|
|
||||||
pub async fn start_query_handler(server: Arc<Server>, bound_addr: SocketAddr) {
|
pub async fn start_query_handler(server: Arc<Server>, bound_addr: SocketAddr) {
|
||||||
let mut query_addr = bound_addr;
|
let mut query_addr = bound_addr;
|
||||||
if let Some(port) = ADVANCED_CONFIG.query.port {
|
if let Some(port) = ADVANCED_CONFIG.networking.query.port {
|
||||||
query_addr.set_port(port);
|
query_addr.set_port(port);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -83,7 +83,7 @@ impl RCONClient {
|
|||||||
let Some(packet) = self.receive_packet().await? else {
|
let Some(packet) = self.receive_packet().await? else {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
let config = &ADVANCED_CONFIG.rcon;
|
let config = &ADVANCED_CONFIG.networking.rcon;
|
||||||
match packet.get_type() {
|
match packet.get_type() {
|
||||||
ServerboundPacket::Auth => {
|
ServerboundPacket::Auth => {
|
||||||
if packet.get_body() == password {
|
if packet.get_body() == password {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user