#![allow(
unused_imports,
unused_variables,
unused_mut,
unused_parens,
unused_braces,
clippy::all,
clippy::pedantic,
non_camel_case_types,
non_snake_case
)]
use crate::codec::{Decode, DecodeResult, Encode, EncodeResult, McWrite, Reader, decode_exact};
use crate::error::{DecodeError, EncodeError};
use crate::nbt::RawNbt;
use crate::packet::{Direction, PacketSet, RawPacket, State};
#[cfg(feature = "testgen")]
use crate::testgen::{Gen, Generate};
use crate::types::{BlockPos, ByteString, PositionLayout, Uuid};
use crate::v1_8::types;
use bytes::{BufMut, Bytes, BytesMut};
pub mod id {
pub const DISCONNECT: i32 = 0x00;
pub const ENCRYPTION_BEGIN: i32 = 0x01;
pub const SUCCESS: i32 = 0x02;
pub const COMPRESS: i32 = 0x03;
}
#[derive(Debug, Clone, PartialEq)]
pub struct Disconnect {
pub reason: ByteString,
}
impl crate::packet::Packet for Disconnect {
const ID: i32 = id::DISCONNECT;
const NAME: &'static str = "disconnect";
const STATE: State = State::Login;
const DIRECTION: Direction = Direction::Clientbound;
}
impl Decode for Disconnect {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v17 = r.read_string()?;
Disconnect { reason: v17 }
})
}
}
impl Encode for Disconnect {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_string(&(*self).reason)?;
Ok(())
}
}
#[cfg(feature = "testgen")]
impl Generate for Disconnect {
fn generate(g: &mut Gen) -> Self {
{
let v18 = g.string();
Disconnect { reason: v18 }
}
}
}
impl From<Disconnect> for ClientboundLoginPacket {
fn from(p: Disconnect) -> Self {
Self::Disconnect(p)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct EncryptionBegin {
pub server_id: ByteString,
pub public_key: Bytes,
pub verify_token: Bytes,
}
impl crate::packet::Packet for EncryptionBegin {
const ID: i32 = id::ENCRYPTION_BEGIN;
const NAME: &'static str = "encryption_begin";
const STATE: State = State::Login;
const DIRECTION: Direction = Direction::Clientbound;
}
impl Decode for EncryptionBegin {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v19 = r.read_string()?;
let v20 = r.read_byte_array()?;
let v21 = r.read_byte_array()?;
EncryptionBegin {
server_id: v19,
public_key: v20,
verify_token: v21,
}
})
}
}
impl Encode for EncryptionBegin {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_string(&(*self).server_id)?;
w.put_byte_array(&(*self).public_key)?;
w.put_byte_array(&(*self).verify_token)?;
Ok(())
}
}
#[cfg(feature = "testgen")]
impl Generate for EncryptionBegin {
fn generate(g: &mut Gen) -> Self {
{
let v22 = g.string();
let v23 = g.bytes();
let v24 = g.bytes();
EncryptionBegin {
server_id: v22,
public_key: v23,
verify_token: v24,
}
}
}
}
impl From<EncryptionBegin> for ClientboundLoginPacket {
fn from(p: EncryptionBegin) -> Self {
Self::EncryptionBegin(p)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Success {
pub uuid: ByteString,
pub username: ByteString,
}
impl crate::packet::Packet for Success {
const ID: i32 = id::SUCCESS;
const NAME: &'static str = "success";
const STATE: State = State::Login;
const DIRECTION: Direction = Direction::Clientbound;
}
impl Decode for Success {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v25 = r.read_string()?;
let v26 = r.read_string()?;
Success {
uuid: v25,
username: v26,
}
})
}
}
impl Encode for Success {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_string(&(*self).uuid)?;
w.put_string(&(*self).username)?;
Ok(())
}
}
#[cfg(feature = "testgen")]
impl Generate for Success {
fn generate(g: &mut Gen) -> Self {
{
let v27 = g.string();
let v28 = g.string();
Success {
uuid: v27,
username: v28,
}
}
}
}
impl From<Success> for ClientboundLoginPacket {
fn from(p: Success) -> Self {
Self::Success(p)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Compress {
pub threshold: i32,
}
impl crate::packet::Packet for Compress {
const ID: i32 = id::COMPRESS;
const NAME: &'static str = "compress";
const STATE: State = State::Login;
const DIRECTION: Direction = Direction::Clientbound;
}
impl Decode for Compress {
fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
Ok({
let v29 = r.read_varint()?;
Compress { threshold: v29 }
})
}
}
impl Encode for Compress {
fn encode(&self, w: &mut BytesMut) -> EncodeResult {
w.put_varint((*self).threshold);
Ok(())
}
}
#[cfg(feature = "testgen")]
impl Generate for Compress {
fn generate(g: &mut Gen) -> Self {
{
let v30 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
Compress { threshold: v30 }
}
}
}
impl From<Compress> for ClientboundLoginPacket {
fn from(p: Compress) -> Self {
Self::Compress(p)
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum ClientboundLoginPacket {
Disconnect(Disconnect),
EncryptionBegin(EncryptionBegin),
Success(Success),
Compress(Compress),
}
impl PacketSet for ClientboundLoginPacket {
const STATE: State = State::Login;
const DIRECTION: Direction = Direction::Clientbound;
fn decode_raw(raw: &RawPacket) -> DecodeResult<Self> {
match raw.id {
id::DISCONNECT => decode_exact(&raw.body).map(Self::Disconnect),
id::ENCRYPTION_BEGIN => decode_exact(&raw.body).map(Self::EncryptionBegin),
id::SUCCESS => decode_exact(&raw.body).map(Self::Success),
id::COMPRESS => decode_exact(&raw.body).map(Self::Compress),
other => Err(DecodeError::UnknownPacketId(other)),
}
}
fn id(&self) -> i32 {
match *self {
Self::Disconnect(_) => id::DISCONNECT,
Self::EncryptionBegin(_) => id::ENCRYPTION_BEGIN,
Self::Success(_) => id::SUCCESS,
Self::Compress(_) => id::COMPRESS,
}
}
fn name(&self) -> &'static str {
match *self {
Self::Disconnect(_) => "disconnect",
Self::EncryptionBegin(_) => "encryption_begin",
Self::Success(_) => "success",
Self::Compress(_) => "compress",
}
}
fn encode_body(&self, w: &mut BytesMut) -> EncodeResult {
match *self {
Self::Disconnect(ref p) => p.encode(w),
Self::EncryptionBegin(ref p) => p.encode(w),
Self::Success(ref p) => p.encode(w),
Self::Compress(ref p) => p.encode(w),
}
}
fn name_of(id: i32) -> Option<&'static str> {
match id {
id::DISCONNECT => Some("disconnect"),
id::ENCRYPTION_BEGIN => Some("encryption_begin"),
id::SUCCESS => Some("success"),
id::COMPRESS => Some("compress"),
_ => None,
}
}
}
impl ClientboundLoginPacket {
pub const IDS: &'static [i32] = &[
id::DISCONNECT,
id::ENCRYPTION_BEGIN,
id::SUCCESS,
id::COMPRESS,
];
#[cfg(feature = "testgen")]
pub fn generate_by_id(id: i32, g: &mut Gen) -> Option<Self> {
match id {
id::DISCONNECT => Some(Self::Disconnect(<Disconnect as Generate>::generate(g))),
id::ENCRYPTION_BEGIN => Some(Self::EncryptionBegin(
<EncryptionBegin as Generate>::generate(g),
)),
id::SUCCESS => Some(Self::Success(<Success as Generate>::generate(g))),
id::COMPRESS => Some(Self::Compress(<Compress as Generate>::generate(g))),
_ => None,
}
}
}