Skip to content

Commit

Permalink
move some config things into networking
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Jan 2, 2025
1 parent 2767eff commit ad39b28
Show file tree
Hide file tree
Showing 16 changed files with 63 additions and 35 deletions.
29 changes: 10 additions & 19 deletions pumpkin-config/src/lib.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand All @@ -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/";
Expand All @@ -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 logging: LoggingConfig,
pub resource_pack: ResourcePackConfig,
pub networking: NetworkingConfig,
pub commands: CommandsConfig,
pub rcon: RCONConfig,
pub pvp: PVPConfig,
pub logging: LoggingConfig,
pub query: QueryConfig,
pub server_links: ServerLinksConfig,
pub lan_broadcast: LANBroadcastConfig,
}

#[derive(Serialize, Deserialize)]
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
24 changes: 24 additions & 0 deletions pumpkin-config/src/networking/mod.rs
Original file line number Diff line number Diff line change
@@ -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,
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions pumpkin/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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));
}
Expand Down
10 changes: 8 additions & 2 deletions pumpkin/src/net/authentication.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down
3 changes: 2 additions & 1 deletion pumpkin/src/net/lan_broadcast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion pumpkin/src/net/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down
18 changes: 12 additions & 6 deletions pumpkin/src/net/packet/login.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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)?;
}
Expand All @@ -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(
Expand Down
2 changes: 1 addition & 1 deletion pumpkin/src/net/proxy/velocity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pumpkin/src/net/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
2 changes: 1 addition & 1 deletion pumpkin/src/net/rcon/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit ad39b28

Please sign in to comment.