Skip to main content

ghast_protocol/generated/v1_16_5/login/
clientbound.rs

1// @generated by ghast-codegen-protocol from PrismarineJS minecraft-data 3.119.0
2// (data/pc/1.16.2/protocol.json, Minecraft 1.16.5). Do not edit; run `cargo run -p ghast-codegen-protocol`.
3// minecraft-data is MIT licensed, Copyright (c) 2015 PrismarineJS; see ../NOTICE.
4
5//! Clientbound packets of the login state.
6
7#![allow(
8    unused_imports,
9    unused_variables,
10    unused_mut,
11    unused_parens,
12    unused_braces,
13    clippy::all,
14    clippy::pedantic,
15    non_camel_case_types,
16    non_snake_case
17)]
18use crate::codec::{Decode, DecodeResult, Encode, EncodeResult, McWrite, Reader, decode_exact};
19use crate::error::{DecodeError, EncodeError};
20use crate::nbt::RawNbt;
21use crate::packet::{Direction, PacketSet, RawPacket, State};
22#[cfg(feature = "testgen")]
23use crate::testgen::{Gen, Generate};
24use crate::types::{BlockPos, ByteString, PositionLayout, Uuid};
25use crate::v1_16_5::types;
26use bytes::{BufMut, Bytes, BytesMut};
27
28/// Packet ids.
29pub mod id {
30    /// `disconnect`
31    pub const DISCONNECT: i32 = 0x00;
32    /// `encryption_begin`
33    pub const ENCRYPTION_BEGIN: i32 = 0x01;
34    /// `success`
35    pub const SUCCESS: i32 = 0x02;
36    /// `compress`
37    pub const COMPRESS: i32 = 0x03;
38    /// `login_plugin_request`
39    pub const LOGIN_PLUGIN_REQUEST: i32 = 0x04;
40}
41
42/// `disconnect` (clientbound login, id 0x00).
43#[derive(Debug, Clone, PartialEq)]
44pub struct Disconnect {
45    /// `reason`
46    pub reason: ByteString,
47}
48impl crate::packet::Packet for Disconnect {
49    const ID: i32 = id::DISCONNECT;
50    const NAME: &'static str = "disconnect";
51    const STATE: State = State::Login;
52    const DIRECTION: Direction = Direction::Clientbound;
53}
54impl Decode for Disconnect {
55    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
56        Ok({
57            let v17 = r.read_string()?;
58            Disconnect { reason: v17 }
59        })
60    }
61}
62impl Encode for Disconnect {
63    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
64        w.put_string(&(*self).reason)?;
65        Ok(())
66    }
67}
68#[cfg(feature = "testgen")]
69impl Generate for Disconnect {
70    fn generate(g: &mut Gen) -> Self {
71        {
72            let v18 = g.string();
73            Disconnect { reason: v18 }
74        }
75    }
76}
77impl From<Disconnect> for ClientboundLoginPacket {
78    fn from(p: Disconnect) -> Self {
79        Self::Disconnect(p)
80    }
81}
82
83/// `encryption_begin` (clientbound login, id 0x01).
84#[derive(Debug, Clone, PartialEq)]
85pub struct EncryptionBegin {
86    /// `serverId`
87    pub server_id: ByteString,
88    /// `publicKey`
89    pub public_key: Bytes,
90    /// `verifyToken`
91    pub verify_token: Bytes,
92}
93impl crate::packet::Packet for EncryptionBegin {
94    const ID: i32 = id::ENCRYPTION_BEGIN;
95    const NAME: &'static str = "encryption_begin";
96    const STATE: State = State::Login;
97    const DIRECTION: Direction = Direction::Clientbound;
98}
99impl Decode for EncryptionBegin {
100    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
101        Ok({
102            let v19 = r.read_string()?;
103            let v20 = r.read_byte_array()?;
104            let v21 = r.read_byte_array()?;
105            EncryptionBegin {
106                server_id: v19,
107                public_key: v20,
108                verify_token: v21,
109            }
110        })
111    }
112}
113impl Encode for EncryptionBegin {
114    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
115        w.put_string(&(*self).server_id)?;
116        w.put_byte_array(&(*self).public_key)?;
117        w.put_byte_array(&(*self).verify_token)?;
118        Ok(())
119    }
120}
121#[cfg(feature = "testgen")]
122impl Generate for EncryptionBegin {
123    fn generate(g: &mut Gen) -> Self {
124        {
125            let v22 = g.string();
126            let v23 = g.bytes();
127            let v24 = g.bytes();
128            EncryptionBegin {
129                server_id: v22,
130                public_key: v23,
131                verify_token: v24,
132            }
133        }
134    }
135}
136impl From<EncryptionBegin> for ClientboundLoginPacket {
137    fn from(p: EncryptionBegin) -> Self {
138        Self::EncryptionBegin(p)
139    }
140}
141
142/// `success` (clientbound login, id 0x02).
143#[derive(Debug, Clone, PartialEq)]
144pub struct Success {
145    /// `uuid`
146    pub uuid: Uuid,
147    /// `username`
148    pub username: ByteString,
149}
150impl crate::packet::Packet for Success {
151    const ID: i32 = id::SUCCESS;
152    const NAME: &'static str = "success";
153    const STATE: State = State::Login;
154    const DIRECTION: Direction = Direction::Clientbound;
155}
156impl Decode for Success {
157    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
158        Ok({
159            let v25 = r.read_uuid()?;
160            let v26 = r.read_string()?;
161            Success {
162                uuid: v25,
163                username: v26,
164            }
165        })
166    }
167}
168impl Encode for Success {
169    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
170        w.put_uuid(&(*self).uuid);
171        w.put_string(&(*self).username)?;
172        Ok(())
173    }
174}
175#[cfg(feature = "testgen")]
176impl Generate for Success {
177    fn generate(g: &mut Gen) -> Self {
178        {
179            let v27 = g.uuid();
180            let v28 = g.string();
181            Success {
182                uuid: v27,
183                username: v28,
184            }
185        }
186    }
187}
188impl From<Success> for ClientboundLoginPacket {
189    fn from(p: Success) -> Self {
190        Self::Success(p)
191    }
192}
193
194/// `compress` (clientbound login, id 0x03).
195#[derive(Debug, Clone, PartialEq)]
196pub struct Compress {
197    /// `threshold`
198    pub threshold: i32,
199}
200impl crate::packet::Packet for Compress {
201    const ID: i32 = id::COMPRESS;
202    const NAME: &'static str = "compress";
203    const STATE: State = State::Login;
204    const DIRECTION: Direction = Direction::Clientbound;
205}
206impl Decode for Compress {
207    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
208        Ok({
209            let v29 = r.read_varint()?;
210            Compress { threshold: v29 }
211        })
212    }
213}
214impl Encode for Compress {
215    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
216        w.put_varint((*self).threshold);
217        Ok(())
218    }
219}
220#[cfg(feature = "testgen")]
221impl Generate for Compress {
222    fn generate(g: &mut Gen) -> Self {
223        {
224            let v30 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
225            Compress { threshold: v30 }
226        }
227    }
228}
229impl From<Compress> for ClientboundLoginPacket {
230    fn from(p: Compress) -> Self {
231        Self::Compress(p)
232    }
233}
234
235/// `login_plugin_request` (clientbound login, id 0x04).
236#[derive(Debug, Clone, PartialEq)]
237pub struct LoginPluginRequest {
238    /// `messageId`
239    pub message_id: i32,
240    /// `channel`
241    pub channel: ByteString,
242    /// `data`
243    pub data: Bytes,
244}
245impl crate::packet::Packet for LoginPluginRequest {
246    const ID: i32 = id::LOGIN_PLUGIN_REQUEST;
247    const NAME: &'static str = "login_plugin_request";
248    const STATE: State = State::Login;
249    const DIRECTION: Direction = Direction::Clientbound;
250}
251impl Decode for LoginPluginRequest {
252    fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
253        Ok({
254            let v31 = r.read_varint()?;
255            let v32 = r.read_string()?;
256            let v33 = r.read_rest();
257            LoginPluginRequest {
258                message_id: v31,
259                channel: v32,
260                data: v33,
261            }
262        })
263    }
264}
265impl Encode for LoginPluginRequest {
266    fn encode(&self, w: &mut BytesMut) -> EncodeResult {
267        w.put_varint((*self).message_id);
268        w.put_string(&(*self).channel)?;
269        w.put_slice(&(*self).data);
270        Ok(())
271    }
272}
273#[cfg(feature = "testgen")]
274impl Generate for LoginPluginRequest {
275    fn generate(g: &mut Gen) -> Self {
276        {
277            let v34 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
278            let v35 = g.string();
279            let v36 = g.bytes();
280            LoginPluginRequest {
281                message_id: v34,
282                channel: v35,
283                data: v36,
284            }
285        }
286    }
287}
288impl From<LoginPluginRequest> for ClientboundLoginPacket {
289    fn from(p: LoginPluginRequest) -> Self {
290        Self::LoginPluginRequest(p)
291    }
292}
293
294/// Every Clientbound packet of the Login state.
295#[derive(Debug, Clone, PartialEq)]
296pub enum ClientboundLoginPacket {
297    /// `disconnect`
298    Disconnect(Disconnect),
299    /// `encryption_begin`
300    EncryptionBegin(EncryptionBegin),
301    /// `success`
302    Success(Success),
303    /// `compress`
304    Compress(Compress),
305    /// `login_plugin_request`
306    LoginPluginRequest(LoginPluginRequest),
307}
308
309impl PacketSet for ClientboundLoginPacket {
310    const STATE: State = State::Login;
311    const DIRECTION: Direction = Direction::Clientbound;
312    fn decode_raw(raw: &RawPacket) -> DecodeResult<Self> {
313        match raw.id {
314            id::DISCONNECT => decode_exact(&raw.body).map(Self::Disconnect),
315            id::ENCRYPTION_BEGIN => decode_exact(&raw.body).map(Self::EncryptionBegin),
316            id::SUCCESS => decode_exact(&raw.body).map(Self::Success),
317            id::COMPRESS => decode_exact(&raw.body).map(Self::Compress),
318            id::LOGIN_PLUGIN_REQUEST => decode_exact(&raw.body).map(Self::LoginPluginRequest),
319            other => Err(DecodeError::UnknownPacketId(other)),
320        }
321    }
322    fn id(&self) -> i32 {
323        match *self {
324            Self::Disconnect(_) => id::DISCONNECT,
325            Self::EncryptionBegin(_) => id::ENCRYPTION_BEGIN,
326            Self::Success(_) => id::SUCCESS,
327            Self::Compress(_) => id::COMPRESS,
328            Self::LoginPluginRequest(_) => id::LOGIN_PLUGIN_REQUEST,
329        }
330    }
331    fn name(&self) -> &'static str {
332        match *self {
333            Self::Disconnect(_) => "disconnect",
334            Self::EncryptionBegin(_) => "encryption_begin",
335            Self::Success(_) => "success",
336            Self::Compress(_) => "compress",
337            Self::LoginPluginRequest(_) => "login_plugin_request",
338        }
339    }
340    fn encode_body(&self, w: &mut BytesMut) -> EncodeResult {
341        match *self {
342            Self::Disconnect(ref p) => p.encode(w),
343            Self::EncryptionBegin(ref p) => p.encode(w),
344            Self::Success(ref p) => p.encode(w),
345            Self::Compress(ref p) => p.encode(w),
346            Self::LoginPluginRequest(ref p) => p.encode(w),
347        }
348    }
349    fn name_of(id: i32) -> Option<&'static str> {
350        match id {
351            id::DISCONNECT => Some("disconnect"),
352            id::ENCRYPTION_BEGIN => Some("encryption_begin"),
353            id::SUCCESS => Some("success"),
354            id::COMPRESS => Some("compress"),
355            id::LOGIN_PLUGIN_REQUEST => Some("login_plugin_request"),
356            _ => None,
357        }
358    }
359}
360
361impl ClientboundLoginPacket {
362    /// All packet ids of this set, ascending.
363    pub const IDS: &'static [i32] = &[
364        id::DISCONNECT,
365        id::ENCRYPTION_BEGIN,
366        id::SUCCESS,
367        id::COMPRESS,
368        id::LOGIN_PLUGIN_REQUEST,
369    ];
370    /// Generates a random packet with the given id (test support).
371    #[cfg(feature = "testgen")]
372    pub fn generate_by_id(id: i32, g: &mut Gen) -> Option<Self> {
373        match id {
374            id::DISCONNECT => Some(Self::Disconnect(<Disconnect as Generate>::generate(g))),
375            id::ENCRYPTION_BEGIN => Some(Self::EncryptionBegin(
376                <EncryptionBegin as Generate>::generate(g),
377            )),
378            id::SUCCESS => Some(Self::Success(<Success as Generate>::generate(g))),
379            id::COMPRESS => Some(Self::Compress(<Compress as Generate>::generate(g))),
380            id::LOGIN_PLUGIN_REQUEST => Some(Self::LoginPluginRequest(
381                <LoginPluginRequest as Generate>::generate(g),
382            )),
383            _ => None,
384        }
385    }
386}