Skip to content
This repository was archived by the owner on Sep 14, 2020. It is now read-only.

Commit a39d1f8

Browse files
committed
Add all login, status, and handshake packets for 1.15.2
1 parent 949a55e commit a39d1f8

File tree

12 files changed

+134
-13
lines changed

12 files changed

+134
-13
lines changed

src/io.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -320,3 +320,36 @@ where
320320
LengthPrefixedVec(Cow::Borrowed(slice))
321321
}
322322
}
323+
324+
/// A vector of bytes which consumes all remaining bytes in this packet.
325+
/// This is used by the plugin messaging packets, for one.
326+
pub struct LengthInferredVecU8<'a>(pub Cow<'a, [u8]>);
327+
328+
impl<'a> Readable for LengthInferredVecU8<'a> {
329+
fn read(buffer: &mut Cursor<&[u8]>, _version: ProtocolVersion) -> anyhow::Result<Self>
330+
where
331+
Self: Sized,
332+
{
333+
let mut vec = Vec::new();
334+
buffer.read_to_end(&mut vec)?;
335+
Ok(LengthInferredVecU8(Cow::Owned(vec)))
336+
}
337+
}
338+
339+
impl<'a> Writeable for LengthInferredVecU8<'a> {
340+
fn write(&self, buffer: &mut Vec<u8>, _version: ProtocolVersion) {
341+
buffer.extend_from_slice(&*self.0);
342+
}
343+
}
344+
345+
impl<'a> From<&'a [u8]> for LengthInferredVecU8<'a> {
346+
fn from(slice: &'a [u8]) -> Self {
347+
LengthInferredVecU8(Cow::Borrowed(slice))
348+
}
349+
}
350+
351+
impl<'a> From<LengthInferredVecU8<'a>> for Vec<u8> {
352+
fn from(x: LengthInferredVecU8<'a>) -> Self {
353+
x.0.into_owned()
354+
}
355+
}

src/packets.rs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ macro_rules! user_type {
55
(LengthPrefixedVec <$inner:ident>) => {
66
Vec<$inner>
77
};
8+
(LengthInferredVecU8) => {
9+
Vec<u8>
10+
};
811
($typ:ty) => {
912
$typ
1013
};
@@ -17,6 +20,9 @@ macro_rules! user_type_convert_to_writeable {
1720
(LengthPrefixedVec <$inner:ident>, $e:expr) => {
1821
LengthPrefixedVec::from($e.as_slice())
1922
};
23+
(LengthInferredVecU8, $e:expr) => {
24+
LengthInferredVecU8::from($e.as_slice())
25+
};
2026
($typ:ty, $e:expr) => {
2127
$e
2228
};
@@ -29,8 +35,8 @@ macro_rules! packets {
2935
$(
3036
$field:ident $typ:ident $(<$generics:ident>)?
3137
);* $(;)?
32-
}
33-
),* $(,)?
38+
} $(,)?
39+
)*
3440
) => {
3541
$(
3642
#[derive(Debug, Clone)]
@@ -40,6 +46,7 @@ macro_rules! packets {
4046
)*
4147
}
4248

49+
#[allow(unused_imports, unused_variables)]
4350
impl crate::Readable for $packet {
4451
fn read(buffer: &mut ::std::io::Cursor<&[u8]>, version: crate::ProtocolVersion) -> anyhow::Result<Self>
4552
where
@@ -60,6 +67,7 @@ macro_rules! packets {
6067
}
6168
}
6269

70+
#[allow(unused_variables)]
6371
impl crate::Writeable for $packet {
6472
fn write(&self, buffer: &mut Vec<u8>, version: crate::ProtocolVersion) {
6573
$(
@@ -163,7 +171,7 @@ macro_rules! def_enum {
163171
};
164172
}
165173

166-
use crate::io::{LengthPrefixedVec, VarInt};
174+
use crate::io::{LengthInferredVecU8, LengthPrefixedVec, VarInt};
167175

168-
pub mod handshake;
169-
pub mod login;
176+
pub mod client;
177+
pub mod server;

src/packets/client.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
//! Packets sent from client to server.
2+
3+
use super::*;
4+
5+
mod handshake;
6+
mod login;
7+
mod play;
8+
mod status;
9+
10+
pub use handshake::*;
11+
pub use login::*;
12+
pub use play::*;
13+
pub use status::*;

src/packets/client/login.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
use super::*;
2+
3+
packets! {
4+
LoginStart {
5+
name String;
6+
}
7+
8+
EncryptionResponse {
9+
shared_secret LengthPrefixedVec<u8>;
10+
verify_token LengthPrefixedVec<u8>;
11+
}
12+
13+
LoginPluginResponse {
14+
message_id VarInt;
15+
successful bool;
16+
data LengthInferredVecU8;
17+
}
18+
}

src/packets/client/play.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

src/packets/client/status.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
packets! {
2+
Request {}
3+
4+
Ping {
5+
payload i64;
6+
}
7+
}

src/packets/login.rs

Lines changed: 0 additions & 8 deletions
This file was deleted.

src/packets/server.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//! Packets sent from server to client;
2+
3+
use super::*;
4+
5+
mod login;
6+
mod play;
7+
mod status;
8+
9+
pub use login::*;
10+
pub use play::*;
11+
pub use status::*;

src/packets/server/login.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
use super::*;
2+
3+
packets! {
4+
Disconnect {
5+
reason String;
6+
}
7+
8+
EncryptionRequest {
9+
server_id String;
10+
public_key LengthPrefixedVec<u8>;
11+
verify_token LengthPrefixedVec<u8>;
12+
}
13+
14+
LoginSuccess {
15+
uuid String;
16+
username String;
17+
}
18+
19+
SetCompression {
20+
threshold VarInt;
21+
}
22+
23+
LoginPluginRequest {
24+
message_id VarInt;
25+
successful bool;
26+
data LengthInferredVecU8;
27+
}
28+
}

0 commit comments

Comments
 (0)