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