Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions haya_protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ impl<'a, const MAX: usize> Read<'a> for Utf8<'a, MAX> {
#[derive(Clone, Debug)]
pub enum List<'a, T: 'a, const MAX: usize = { usize::MAX }> {
Borrowed(&'a [T]),
Ref(Box<[T]>),
Owned(Box<[T]>),
}

impl<'a, T: Write + 'a, const MAX: usize> Write for List<'a, T, MAX> {
unsafe fn write(&self, w: &mut UnsafeWriter) {
unsafe {
let x = match self {
Self::Borrowed(x) => x,
Self::Ref(x) => &x[..],
Self::Owned(x) => &x[..],
};
V21(x.len() as u32).write(w);
for y in x {
Expand All @@ -113,7 +113,7 @@ impl<'a, T: Write + 'a, const MAX: usize> Write for List<'a, T, MAX> {
fn len_s(&self) -> usize {
let x = match self {
Self::Borrowed(x) => x,
Self::Ref(x) => &x[..],
Self::Owned(x) => &x[..],
};
let mut len = V21(x.len() as u32).len_s();
for y in x {
Expand All @@ -123,7 +123,7 @@ impl<'a, T: Write + 'a, const MAX: usize> Write for List<'a, T, MAX> {
}
}

impl<'a, T: Read<'a> + 'a, const MAX: usize> Read<'a> for List<'a, T, MAX> {
impl<'a, T: Read<'a>, const MAX: usize> Read<'a> for List<'a, T, MAX> {
fn read(buf: &mut &'a [u8]) -> Result<Self, Error> {
let len = V21::read(buf)?.0 as usize;
if len > MAX {
Expand All @@ -133,7 +133,7 @@ impl<'a, T: Read<'a> + 'a, const MAX: usize> Read<'a> for List<'a, T, MAX> {
for _ in 0..len {
vec.push(T::read(buf)?);
}
Ok(List::Ref(vec.into_boxed_slice()))
Ok(Self::Owned(vec.into_boxed_slice()))
}
}

Expand Down
19 changes: 18 additions & 1 deletion haya_protocol/src/serverbound.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use minecraft_data::{serverbound__handshake, serverbound__login, serverbound__status};
use minecraft_data::{
serverbound__configuration, serverbound__handshake, serverbound__login, serverbound__status,
};

pub mod common;
pub mod configuration;
Expand Down Expand Up @@ -63,3 +65,18 @@ packets! {
login_acknowledged = login::LoginAcknowledged,
cookie_response = cookie::CookieResponse<'_>,
}
packets! {
serverbound__configuration,
ConfigurationHandler,
handle,
client_information = common::ConfigurationClientInformation<'_>,
cookie_response = cookie::ConfigurationCookieResponse<'_>,
custom_payload = common::CustomPayload<'_>,
finish_configuration = configuration::FinishConfiguration,
keep_alive = common::KeepAlive,
pong = common::Pong,
resource_pack = common::ResourcePack,
select_known_packs = configuration::SelectKnownPacks<'_>,
custom_click_action = configuration::CustomClickAction<'_>,
accept_code_of_conduct = configuration::AcceptCodeOfConduct,
}
36 changes: 36 additions & 0 deletions haya_protocol/src/serverbound/common.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::{ClientInformation, Rest};
use haya_ident::Ident;
use uuid::Uuid;

#[derive(Clone, Serialize, Deserialize)]
pub struct ConfigurationClientInformation<'a>(pub ClientInformation<'a>);
Expand All @@ -9,3 +10,38 @@ pub struct CustomPayload<'a> {
pub id: Ident<'a>,
pub payload: Rest<'a, 32767>,
}

#[derive(Clone, Serialize, Deserialize)]
pub struct KeepAlive {
pub id: u64,
}

#[derive(Clone, Serialize, Deserialize)]
pub struct Pong {
pub id: u32,
}

#[derive(Clone, Serialize, Deserialize)]
pub struct ResourcePack {
pub id: Uuid,
pub action: ResourcePackAction,
}

#[derive(Clone, Copy, Serialize, Deserialize)]
#[repr(u8)]
pub enum ResourcePackAction {
SuccessfullyLoaded,
Declined,
FailedDownload,
Accepted,
Downloaded,
InvalidUrl,
FailedReload,
Discarded,
}

impl ResourcePackAction {
pub const fn is_terminal(&self) -> bool {
!matches!(self, Self::Accepted | Self::Downloaded)
}
}
18 changes: 18 additions & 0 deletions haya_protocol/src/serverbound/configuration.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,20 @@
use crate::{KnownPack, List};
use haya_ident::Ident;
use haya_nbt::Tag;

#[derive(Clone, Serialize, Deserialize)]
pub struct FinishConfiguration {}

#[derive(Clone, Serialize, Deserialize)]
pub struct SelectKnownPacks<'a> {
pub known_packs: List<'a, KnownPack<'a>, 64>,
}

#[derive(Clone, Serialize, Deserialize)]
pub struct CustomClickAction<'a> {
pub id: Ident<'a>,
pub payload: Option<Tag>,
}

#[derive(Clone, Serialize, Deserialize)]
pub struct AcceptCodeOfConduct {}
2 changes: 1 addition & 1 deletion haya_protocol/src/serverbound/handshake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::{ClientIntent, Utf8};
#[derive(Clone, Serialize, Deserialize)]
pub struct Intention<'a> {
pub protocol_version: Utf8<'a>,
pub host_name: Utf8<'a, 255>,
pub host_name: Utf8<'a>, // bungeecord
pub port: u16,
pub intention: ClientIntent,
}