Skip to content

Commit 0c0a882

Browse files
committed
feat: add command auto-completion when running behind a proxy (#16)
1 parent 241c821 commit 0c0a882

File tree

20 files changed

+106
-1
lines changed

20 files changed

+106
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ packets required for client login and maintaining connection (keep-alive) withou
2323
When idle, PicoLimbo uses almost no resources: 0% CPU and less than 10 MB of memory, making it extremely lightweight.
2424

2525
While not aiming to replicate every Minecraft server feature, PicoLimbo supports **all Minecraft versions from 1.7.2
26-
through 1.21.6**, excluding snapshots, with only 27 implemented packets covering over 46 different protocol versions or
26+
through 1.21.6**, excluding snapshots, with only 28 implemented packets covering over 46 different protocol versions or
2727
74 Minecraft versions.
2828

2929
## Features

binaries/pico_limbo/src/handlers/configuration.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use minecraft_packets::configuration::registry_data_packet::{
77
RegistryDataCodecPacket, RegistryDataPacket,
88
};
99
use minecraft_packets::play::chunk_data_and_update_light_packet::ChunkDataAndUpdateLightPacket;
10+
use minecraft_packets::play::commands_packet::CommandsPacket;
1011
use minecraft_packets::play::game_event_packet::GameEventPacket;
1112
use minecraft_packets::play::legacy_chat_message_packet::LegacyChatMessage;
1213
use minecraft_packets::play::login_packet::LoginPacket;
@@ -102,6 +103,11 @@ pub async fn send_play_packets(client: Client, state: ServerState) -> Result<(),
102103
client.send_packet(packet).await?;
103104
}
104105

106+
if protocol_version >= ProtocolVersion::V1_13 {
107+
let packet = CommandsPacket::empty();
108+
client.send_packet(packet).await?;
109+
}
110+
105111
if protocol_version >= ProtocolVersion::V1_20_3 {
106112
// Send Game Event
107113
let packet = GameEventPacket::start_waiting_for_chunks(0.0);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
use minecraft_protocol::prelude::*;
2+
use thiserror::Error;
3+
4+
/// This packet is sent since 1.13
5+
#[derive(Debug, PacketOut)]
6+
#[packet_id("play/clientbound/minecraft:commands")]
7+
pub struct CommandsPacket {
8+
/// An array of nodes.
9+
nodes: LengthPaddedVec<Node>,
10+
/// Index of the `root` node in the previous array.
11+
root_index: VarInt,
12+
}
13+
14+
impl CommandsPacket {
15+
pub fn empty() -> Self {
16+
Self {
17+
nodes: vec![Node {
18+
flags: 0,
19+
children: LengthPaddedVec::default(),
20+
}]
21+
.into(),
22+
root_index: VarInt::from(0),
23+
}
24+
}
25+
}
26+
27+
#[derive(Debug, Default)]
28+
struct Node {
29+
flags: i8,
30+
/// Array of indices of child nodes.
31+
children: LengthPaddedVec<VarInt>,
32+
}
33+
34+
#[derive(Debug, Error)]
35+
pub enum NodeError {
36+
#[error(transparent)]
37+
LengthPaddedVecEncode(#[from] LengthPaddedVecEncodeError),
38+
#[error(transparent)]
39+
Infallible(#[from] std::convert::Infallible),
40+
}
41+
42+
impl EncodePacketField for Node {
43+
type Error = NodeError;
44+
45+
fn encode(&self, bytes: &mut Vec<u8>, protocol_version: u32) -> Result<(), Self::Error> {
46+
self.flags.encode(bytes, protocol_version)?;
47+
self.children.encode(bytes, protocol_version)?;
48+
Ok(())
49+
}
50+
}

crates/minecraft_packets/src/play/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
pub mod chunk_data_and_update_light_packet;
22
pub mod client_bound_keep_alive_packet;
3+
pub mod commands_packet;
34
mod data;
45
pub mod game_event_packet;
56
pub mod legacy_chat_message_packet;

data/generated/V1_13/reports/packets.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
},
4747
"minecraft:legacy_chat_message": {
4848
"protocol_id": 14
49+
},
50+
"minecraft:commands": {
51+
"protocol_id": 17
4952
}
5053
},
5154
"serverbound": {}

data/generated/V1_14/reports/packets.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
},
4747
"minecraft:legacy_chat_message": {
4848
"protocol_id": 14
49+
},
50+
"minecraft:commands": {
51+
"protocol_id": 17
4952
}
5053
},
5154
"serverbound": {}

data/generated/V1_15/reports/packets.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
},
4747
"minecraft:legacy_chat_message": {
4848
"protocol_id": 15
49+
},
50+
"minecraft:commands": {
51+
"protocol_id": 18
4952
}
5053
},
5154
"serverbound": {}

data/generated/V1_16/reports/packets.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@
4646
},
4747
"minecraft:legacy_chat_message": {
4848
"protocol_id": 14
49+
},
50+
"minecraft:commands": {
51+
"protocol_id": 17
4952
}
5053
},
5154
"serverbound": {}

data/generated/V1_16_2/reports/packets.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
},
5353
"minecraft:legacy_chat_message": {
5454
"protocol_id": 14
55+
},
56+
"minecraft:commands": {
57+
"protocol_id": 16
5558
}
5659
},
5760
"serverbound": {}

data/generated/V1_17/reports/packets.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
},
5353
"minecraft:legacy_chat_message": {
5454
"protocol_id": 15
55+
},
56+
"minecraft:commands": {
57+
"protocol_id": 18
5558
}
5659
},
5760
"serverbound": {}

0 commit comments

Comments
 (0)