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
16 changes: 8 additions & 8 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ haya_ecs = { path = "haya_ecs", version = "0.2" }
haya_text = { path = "haya_text", version = "0.2" }
haya_math = { path = "haya_math", version = "0.3" }
haya_collection = { path = "haya_collection", version = "0.4" }

haya_protocol = { path = "haya_protocol", version = "0.7" }
uuid = { version = "1", default-features = false }

[profile.dev.package."minecraft_data"]
Expand Down
4 changes: 2 additions & 2 deletions haya_protocol/src/clientbound/login.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use crate::ComponentJson;
use crate::profile::GameProfileRef;
use crate::profile::GameProfile;
use haya_ident::Ident;
use mser::{ByteArray, Rest, Utf8};

Expand All @@ -18,7 +18,7 @@ pub struct Hello<'a> {

#[derive(Clone, Serialize, Deserialize)]
pub struct LoginFinished<'a> {
pub game_profile: GameProfileRef<'a>,
pub game_profile: GameProfile<'a>,
}

#[derive(Clone, Serialize, Deserialize)]
Expand Down
35 changes: 2 additions & 33 deletions haya_protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,37 +50,6 @@ extern crate alloc;
#[derive(Clone, Copy, Debug)]
pub struct Translatable<'a>(pub &'a str, pub &'a str);

#[derive(Clone, Copy, Debug)]
#[repr(u8)]
pub enum ClientIntent {
Status = 1,
Login = 2,
Transfer = 3,
}

impl Write for ClientIntent {
unsafe fn write(&self, w: &mut Writer) {
unsafe {
w.write_byte(*self as u8);
}
}

fn len_s(&self) -> usize {
1
}
}

impl<'a> Read<'a> for ClientIntent {
fn read(buf: &mut Reader) -> Result<Self, Error> {
match V21::read(buf)?.0 {
1 => Ok(Self::Status),
2 => Ok(Self::Login),
3 => Ok(Self::Transfer),
_ => Err(Error),
}
}
}

#[derive(Clone, Serialize, Deserialize)]
pub struct ComponentJson<'a>(pub Utf8<'a, 262144>);

Expand Down Expand Up @@ -979,7 +948,7 @@ pub struct BlockHitResult {
mod tests {
use super::*;
use crate::clientbound::login::LoginFinished;
use crate::profile::{GameProfileRef, PropertyMap};
use crate::profile::{GameProfile, PropertyMap};
use crate::types::Id as _;
use haya_collection::{List, Map};
use minecraft_data::clientbound__login;
Expand All @@ -988,7 +957,7 @@ mod tests {
#[test]
fn test_write() {
let packet: LoginFinished = LoginFinished {
game_profile: GameProfileRef {
game_profile: GameProfile {
id: Uuid::nil(),
name: Utf8("abc"),
properties: PropertyMap(Map(List::Borrowed(&[]))),
Expand Down
10 changes: 5 additions & 5 deletions haya_protocol/src/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@ use mser::{Either, Read, Utf8, Write};
use uuid::Uuid;

#[derive(Clone, Serialize, Deserialize)]
pub struct GameProfileRef<'a> {
pub struct GameProfile<'a> {
pub id: Uuid,
pub name: Utf8<'a, 16>,
pub properties: PropertyMap<'a>,
}

#[derive(Clone, Serialize, Deserialize)]
pub struct PropertyMap<'a>(pub Map<'a, Utf8<'a, 64>, PropertyRef<'a>, 16>);
pub struct PropertyMap<'a>(pub Map<'a, Utf8<'a, 64>, Property<'a>, 16>);

#[derive(Clone, Copy, Serialize, Deserialize)]
pub struct PropertyRef<'a> {
pub struct Property<'a> {
pub value: Utf8<'a, 32767>,
pub signature: Option<Utf8<'a, 1024>>,
}

#[derive(Clone, Serialize, Deserialize)]
pub struct ResolvableProfile<'a> {
pub profile: Either<GameProfileRef<'a>, Partial<'a>>,
pub profile: Either<GameProfile<'a>, Partial<'a>>,
pub skin_patch: PlayerSkinPatch<'a>,
}

#[derive(Clone, Serialize, Deserialize)]
pub struct Partial<'a> {
pub name: Option<Utf8<'a, 16>>,
pub id: Option<Uuid>,
pub properties: List<'a, PropertyRef<'a>, 16>,
pub properties: List<'a, Property<'a>, 16>,
}

#[derive(Clone, Serialize, Deserialize)]
Expand Down
36 changes: 34 additions & 2 deletions haya_protocol/src/serverbound/handshake.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,41 @@
use crate::{ClientIntent, Utf8};
use crate::Utf8;
use mser::V32;

#[derive(Clone, Serialize, Deserialize)]
pub struct Intention<'a> {
pub protocol_version: Utf8<'a>,
pub protocol_version: V32,
pub host_name: Utf8<'a>, // bungeecord
pub port: u16,
pub intention: ClientIntent,
}

#[derive(Clone, Copy, Debug)]
#[repr(u8)]
pub enum ClientIntent {
Status = 1,
Login = 2,
Transfer = 3,
}

impl mser::Write for ClientIntent {
unsafe fn write(&self, w: &mut mser::Writer) {
unsafe {
w.write_byte(*self as u8);
}
}

fn len_s(&self) -> usize {
1
}
}

impl<'a> mser::Read<'a> for ClientIntent {
fn read(buf: &mut mser::Reader) -> Result<Self, mser::Error> {
match mser::V21::read(buf)?.0 {
1 => Ok(Self::Status),
2 => Ok(Self::Login),
3 => Ok(Self::Transfer),
_ => Err(mser::Error),
}
}
}
25 changes: 13 additions & 12 deletions haya_protocol/src/types.rs
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
pub trait Packet: mser::Write + for<'a> mser::Read<'a> + Clone + Copy + Eq {}
pub trait PacketType: mser::Write + for<'a> mser::Read<'a> + Clone + Copy + Eq {}

pub trait Id {
type T: Packet;
type T: PacketType;

const ID: Self::T;
}

impl Packet for minecraft_data::clientbound__status {}
impl Packet for minecraft_data::clientbound__configuration {}
impl Packet for minecraft_data::clientbound__login {}
impl Packet for minecraft_data::clientbound__play {}
impl Packet for minecraft_data::serverbound__handshake {}
impl Packet for minecraft_data::serverbound__status {}
impl Packet for minecraft_data::serverbound__configuration {}
impl Packet for minecraft_data::serverbound__login {}
impl Packet for minecraft_data::serverbound__play {}
impl PacketType for minecraft_data::clientbound__status {}
impl PacketType for minecraft_data::clientbound__configuration {}
impl PacketType for minecraft_data::clientbound__login {}
impl PacketType for minecraft_data::clientbound__play {}
impl PacketType for minecraft_data::serverbound__handshake {}
impl PacketType for minecraft_data::serverbound__status {}
impl PacketType for minecraft_data::serverbound__configuration {}
impl PacketType for minecraft_data::serverbound__login {}
impl PacketType for minecraft_data::serverbound__play {}

pub fn packet_id<R: Packet, T: Id<T = R>>(_: &T) -> R {
pub fn packet_id<R: PacketType, T: Id<T = R> + ?Sized>(_: &T) -> R {
T::ID
}