Skip to content

Commit

Permalink
restrict tab complete packets (optional)
Browse files Browse the repository at this point in the history
  • Loading branch information
Outfluencer committed Dec 29, 2024
1 parent 144f60d commit 84514b5
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
16 changes: 10 additions & 6 deletions src/server/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ pub struct ProxyConfig {
pub spigot_forward: bool,
pub priorities: Vec<String>,
pub max_packet_per_second: i32,
pub restrict_tab_completes: bool,
pub proxy_protocol: bool,
pub groups: HashMap<String, Vec<String>>,
pub users: HashMap<String, Vec<String>>,
Expand All @@ -73,6 +74,7 @@ impl Default for ProxyConfig {
offline_mode_encryption: false,
prevent_proxy_connections: false,
spigot_forward: true,
restrict_tab_completes: true,
servers: vec![
ServerConfig {
label: "lobby".to_owned(),
Expand Down Expand Up @@ -345,11 +347,13 @@ pub fn run_server() {
favicon: icon,
});
}

if !PluginManager::load_plugins() {
log::error!("Error while loading plugins, shutting down.");
return;
}

ProxyServer::instance().block_on(async move {
if !PluginManager::load_plugins() {
log::error!("Error while loading plugins, shutting down.");
return;
}
});

ProxyServer::instance().spawn_task(async move {
let listener = TcpListener::bind(&ProxyServer::instance().config.bind_address).await.unwrap();
Expand Down Expand Up @@ -509,7 +513,7 @@ impl ProxiedPlayer {

let _ = player.client_handle.drop_redundant(false).await;
} else {
log::warn!("Player {} is not in game state, cancelling server switch.", username);
warn!("Player {} is not in game state, cancelling server switch.", username);
player.sync_data.is_switching_server.store(false, Ordering::Relaxed);
return false;
}
Expand Down
7 changes: 6 additions & 1 deletion src/server/packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use uuid::Uuid;

use crate::{auth::{GameProfile, Property}, chat::Text, server::nbt, util::{EncodingHelper, IOError, IOErrorKind, IOResult, VarInt}, version::*};

use super::{brigadier::Suggestions, compression::RefSizeLimitedReader, encryption::{PacketDecryption, PacketEncryption}, nbt::NbtType, packet_ids::{ClientPacketType, PacketRegistry, ServerPacketType}};
use super::{brigadier::Suggestions, compression::RefSizeLimitedReader, encryption::{PacketDecryption, PacketEncryption}, nbt::NbtType, packet_ids::{ClientPacketType, PacketRegistry, ServerPacketType}, ProxyServer};

pub const PROTOCOL_READ_TIMEOUT: Duration = Duration::from_secs(30);

Expand Down Expand Up @@ -939,6 +939,11 @@ impl Packet for TabCompleteRequest {
position = Some(src.read_i64::<BE>()?);
}
}

if ProxyServer::instance().config.restrict_tab_completes && cursor.len() > 256 {
return Err(IOError::new(ErrorKind::InvalidData, "tab completes can only be up to 256 chars"));
}

Ok(Self {
transaction_id,
cursor,
Expand Down

0 comments on commit 84514b5

Please sign in to comment.