changed return value from `String` to `Box<str>` which is smaller and makes more sense since we don't mutate packet data String — 24 bytes (ptr + len + capacity) Box<str> — 16 bytes (ptr + len)
33 lines
1.1 KiB
Rust
33 lines
1.1 KiB
Rust
use std::io::Read;
|
|
|
|
use pumpkin_data::packet::serverbound::PLAY_CUSTOM_PAYLOAD;
|
|
use pumpkin_macros::java_packet;
|
|
use pumpkin_util::version::JavaMinecraftVersion;
|
|
|
|
use crate::{ReadingError, ServerPacket, ser::NetworkReadExt};
|
|
|
|
/// The maximum allowed size for a play custom payload (32 KiB).
|
|
const MAX_PAYLOAD_SIZE: usize = 32_767;
|
|
|
|
/// A packet used for custom communication between the client and server.
|
|
///
|
|
/// This allows mods, plugins, or proxy software to send proprietary data over the standard
|
|
/// Minecraft protocol.
|
|
#[java_packet(PLAY_CUSTOM_PAYLOAD)]
|
|
pub struct SCustomPayload {
|
|
/// The name of the channel used to distinguish different types of messages.
|
|
/// Example: `minecraft:brand` or `voicechat:request_secret`.
|
|
pub channel: Box<str>,
|
|
/// The payload sent by the client.
|
|
pub data: Box<[u8]>,
|
|
}
|
|
|
|
impl ServerPacket for SCustomPayload {
|
|
fn read(mut read: impl Read, _version: &JavaMinecraftVersion) -> Result<Self, ReadingError> {
|
|
Ok(Self {
|
|
channel: read.get_str()?,
|
|
data: read.read_remaining_to_boxed_slice(MAX_PAYLOAD_SIZE)?,
|
|
})
|
|
}
|
|
}
|