ghast_protocol/generated/v1_16_5/login/
serverbound.rs1#![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
28pub mod id {
30 pub const LOGIN_START: i32 = 0x00;
32 pub const ENCRYPTION_BEGIN: i32 = 0x01;
34 pub const LOGIN_PLUGIN_RESPONSE: i32 = 0x02;
36}
37
38#[derive(Debug, Clone, PartialEq)]
40pub struct LoginStart {
41 pub username: ByteString,
43}
44impl crate::packet::Packet for LoginStart {
45 const ID: i32 = id::LOGIN_START;
46 const NAME: &'static str = "login_start";
47 const STATE: State = State::Login;
48 const DIRECTION: Direction = Direction::Serverbound;
49}
50impl Decode for LoginStart {
51 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
52 Ok({
53 let v37 = r.read_string()?;
54 LoginStart { username: v37 }
55 })
56 }
57}
58impl Encode for LoginStart {
59 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
60 w.put_string(&(*self).username)?;
61 Ok(())
62 }
63}
64#[cfg(feature = "testgen")]
65impl Generate for LoginStart {
66 fn generate(g: &mut Gen) -> Self {
67 {
68 let v38 = g.string();
69 LoginStart { username: v38 }
70 }
71 }
72}
73impl From<LoginStart> for ServerboundLoginPacket {
74 fn from(p: LoginStart) -> Self {
75 Self::LoginStart(p)
76 }
77}
78
79#[derive(Debug, Clone, PartialEq)]
81pub struct EncryptionBegin {
82 pub shared_secret: Bytes,
84 pub verify_token: Bytes,
86}
87impl crate::packet::Packet for EncryptionBegin {
88 const ID: i32 = id::ENCRYPTION_BEGIN;
89 const NAME: &'static str = "encryption_begin";
90 const STATE: State = State::Login;
91 const DIRECTION: Direction = Direction::Serverbound;
92}
93impl Decode for EncryptionBegin {
94 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
95 Ok({
96 let v39 = r.read_byte_array()?;
97 let v40 = r.read_byte_array()?;
98 EncryptionBegin {
99 shared_secret: v39,
100 verify_token: v40,
101 }
102 })
103 }
104}
105impl Encode for EncryptionBegin {
106 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
107 w.put_byte_array(&(*self).shared_secret)?;
108 w.put_byte_array(&(*self).verify_token)?;
109 Ok(())
110 }
111}
112#[cfg(feature = "testgen")]
113impl Generate for EncryptionBegin {
114 fn generate(g: &mut Gen) -> Self {
115 {
116 let v41 = g.bytes();
117 let v42 = g.bytes();
118 EncryptionBegin {
119 shared_secret: v41,
120 verify_token: v42,
121 }
122 }
123 }
124}
125impl From<EncryptionBegin> for ServerboundLoginPacket {
126 fn from(p: EncryptionBegin) -> Self {
127 Self::EncryptionBegin(p)
128 }
129}
130
131#[derive(Debug, Clone, PartialEq)]
133pub struct LoginPluginResponse {
134 pub message_id: i32,
136 pub data: Option<Bytes>,
138}
139impl crate::packet::Packet for LoginPluginResponse {
140 const ID: i32 = id::LOGIN_PLUGIN_RESPONSE;
141 const NAME: &'static str = "login_plugin_response";
142 const STATE: State = State::Login;
143 const DIRECTION: Direction = Direction::Serverbound;
144}
145impl Decode for LoginPluginResponse {
146 fn decode(r: &mut Reader<'_>) -> DecodeResult<Self> {
147 Ok({
148 let v43 = r.read_varint()?;
149 let v44 = if r.read_bool()? {
150 Some(r.read_rest())
151 } else {
152 None
153 };
154 LoginPluginResponse {
155 message_id: v43,
156 data: v44,
157 }
158 })
159 }
160}
161impl Encode for LoginPluginResponse {
162 fn encode(&self, w: &mut BytesMut) -> EncodeResult {
163 w.put_varint((*self).message_id);
164 match &(*self).data {
165 Some(v45) => {
166 w.put_u8(1);
167 w.put_slice(&(*v45));
168 }
169 None => w.put_u8(0),
170 }
171 Ok(())
172 }
173}
174#[cfg(feature = "testgen")]
175impl Generate for LoginPluginResponse {
176 fn generate(g: &mut Gen) -> Self {
177 {
178 let v46 = (g.int_in(-2147483648, 2147483647, &[]) as i32);
179 let v47 = if g.bool() { Some(g.bytes()) } else { None };
180 LoginPluginResponse {
181 message_id: v46,
182 data: v47,
183 }
184 }
185 }
186}
187impl From<LoginPluginResponse> for ServerboundLoginPacket {
188 fn from(p: LoginPluginResponse) -> Self {
189 Self::LoginPluginResponse(p)
190 }
191}
192
193#[derive(Debug, Clone, PartialEq)]
195pub enum ServerboundLoginPacket {
196 LoginStart(LoginStart),
198 EncryptionBegin(EncryptionBegin),
200 LoginPluginResponse(LoginPluginResponse),
202}
203
204impl PacketSet for ServerboundLoginPacket {
205 const STATE: State = State::Login;
206 const DIRECTION: Direction = Direction::Serverbound;
207 fn decode_raw(raw: &RawPacket) -> DecodeResult<Self> {
208 match raw.id {
209 id::LOGIN_START => decode_exact(&raw.body).map(Self::LoginStart),
210 id::ENCRYPTION_BEGIN => decode_exact(&raw.body).map(Self::EncryptionBegin),
211 id::LOGIN_PLUGIN_RESPONSE => decode_exact(&raw.body).map(Self::LoginPluginResponse),
212 other => Err(DecodeError::UnknownPacketId(other)),
213 }
214 }
215 fn id(&self) -> i32 {
216 match *self {
217 Self::LoginStart(_) => id::LOGIN_START,
218 Self::EncryptionBegin(_) => id::ENCRYPTION_BEGIN,
219 Self::LoginPluginResponse(_) => id::LOGIN_PLUGIN_RESPONSE,
220 }
221 }
222 fn name(&self) -> &'static str {
223 match *self {
224 Self::LoginStart(_) => "login_start",
225 Self::EncryptionBegin(_) => "encryption_begin",
226 Self::LoginPluginResponse(_) => "login_plugin_response",
227 }
228 }
229 fn encode_body(&self, w: &mut BytesMut) -> EncodeResult {
230 match *self {
231 Self::LoginStart(ref p) => p.encode(w),
232 Self::EncryptionBegin(ref p) => p.encode(w),
233 Self::LoginPluginResponse(ref p) => p.encode(w),
234 }
235 }
236 fn name_of(id: i32) -> Option<&'static str> {
237 match id {
238 id::LOGIN_START => Some("login_start"),
239 id::ENCRYPTION_BEGIN => Some("encryption_begin"),
240 id::LOGIN_PLUGIN_RESPONSE => Some("login_plugin_response"),
241 _ => None,
242 }
243 }
244}
245
246impl ServerboundLoginPacket {
247 pub const IDS: &'static [i32] = &[
249 id::LOGIN_START,
250 id::ENCRYPTION_BEGIN,
251 id::LOGIN_PLUGIN_RESPONSE,
252 ];
253 #[cfg(feature = "testgen")]
255 pub fn generate_by_id(id: i32, g: &mut Gen) -> Option<Self> {
256 match id {
257 id::LOGIN_START => Some(Self::LoginStart(<LoginStart as Generate>::generate(g))),
258 id::ENCRYPTION_BEGIN => Some(Self::EncryptionBegin(
259 <EncryptionBegin as Generate>::generate(g),
260 )),
261 id::LOGIN_PLUGIN_RESPONSE => Some(Self::LoginPluginResponse(
262 <LoginPluginResponse as Generate>::generate(g),
263 )),
264 _ => None,
265 }
266 }
267}