ghast_protocol/generated/v26_2/login/
serverbound.rs1#![allow(
9 unused_imports,
10 unused_variables,
11 unused_mut,
12 unused_parens,
13 unused_braces,
14 clippy::all,
15 clippy::pedantic,
16 non_camel_case_types,
17 non_snake_case
18)]
19use crate::codec::{Decode, DecodeResult, Encode, EncodeResult, McWrite, Reader, decode_exact};
20use crate::error::{DecodeError, EncodeError};
21use crate::nbt::{AnonNbt, RawNbt};
22use crate::packet::{Direction, PacketSet, RawPacket, State};
23#[cfg(feature = "testgen")]
24use crate::testgen::{Gen, Generate};
25use crate::types::{BlockPos, ByteString, Holder, HolderSet, LpVec3, PositionLayout, Uuid};
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 pub const LOGIN_ACKNOWLEDGED: i32 = 0x03;
38 pub const COOKIE_RESPONSE: i32 = 0x04;
40}
41
42pub type LoginStart = crate::defs::p775::login::serverbound::LoginStart<776>;
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 From<LoginStart> for ServerboundLoginPacket {
51 fn from(p: LoginStart) -> Self {
52 Self::LoginStart(p)
53 }
54}
55
56pub type EncryptionBegin = crate::defs::p47::login::serverbound::EncryptionBegin<776>;
58impl crate::packet::Packet for EncryptionBegin {
59 const ID: i32 = id::ENCRYPTION_BEGIN;
60 const NAME: &'static str = "encryption_begin";
61 const STATE: State = State::Login;
62 const DIRECTION: Direction = Direction::Serverbound;
63}
64impl From<EncryptionBegin> for ServerboundLoginPacket {
65 fn from(p: EncryptionBegin) -> Self {
66 Self::EncryptionBegin(p)
67 }
68}
69
70pub type LoginPluginResponse = crate::defs::p754::login::serverbound::LoginPluginResponse<776>;
72impl crate::packet::Packet for LoginPluginResponse {
73 const ID: i32 = id::LOGIN_PLUGIN_RESPONSE;
74 const NAME: &'static str = "login_plugin_response";
75 const STATE: State = State::Login;
76 const DIRECTION: Direction = Direction::Serverbound;
77}
78impl From<LoginPluginResponse> for ServerboundLoginPacket {
79 fn from(p: LoginPluginResponse) -> Self {
80 Self::LoginPluginResponse(p)
81 }
82}
83
84pub type LoginAcknowledged = crate::defs::p775::login::serverbound::LoginAcknowledged<776>;
86impl crate::packet::Packet for LoginAcknowledged {
87 const ID: i32 = id::LOGIN_ACKNOWLEDGED;
88 const NAME: &'static str = "login_acknowledged";
89 const STATE: State = State::Login;
90 const DIRECTION: Direction = Direction::Serverbound;
91}
92impl From<LoginAcknowledged> for ServerboundLoginPacket {
93 fn from(p: LoginAcknowledged) -> Self {
94 Self::LoginAcknowledged(p)
95 }
96}
97
98pub type CookieResponse = crate::defs::p775::login::serverbound::CookieResponse<776>;
100impl crate::packet::Packet for CookieResponse {
101 const ID: i32 = id::COOKIE_RESPONSE;
102 const NAME: &'static str = "cookie_response";
103 const STATE: State = State::Login;
104 const DIRECTION: Direction = Direction::Serverbound;
105}
106impl From<CookieResponse> for ServerboundLoginPacket {
107 fn from(p: CookieResponse) -> Self {
108 Self::CookieResponse(p)
109 }
110}
111
112#[derive(Debug, Clone, PartialEq)]
114pub enum ServerboundLoginPacket {
115 LoginStart(LoginStart),
117 EncryptionBegin(EncryptionBegin),
119 LoginPluginResponse(LoginPluginResponse),
121 LoginAcknowledged(LoginAcknowledged),
123 CookieResponse(CookieResponse),
125}
126
127impl PacketSet for ServerboundLoginPacket {
128 const STATE: State = State::Login;
129 const DIRECTION: Direction = Direction::Serverbound;
130 fn decode_raw(raw: &RawPacket) -> DecodeResult<Self> {
131 match raw.id {
132 id::LOGIN_START => decode_exact(&raw.body).map(Self::LoginStart),
133 id::ENCRYPTION_BEGIN => decode_exact(&raw.body).map(Self::EncryptionBegin),
134 id::LOGIN_PLUGIN_RESPONSE => decode_exact(&raw.body).map(Self::LoginPluginResponse),
135 id::LOGIN_ACKNOWLEDGED => decode_exact(&raw.body).map(Self::LoginAcknowledged),
136 id::COOKIE_RESPONSE => decode_exact(&raw.body).map(Self::CookieResponse),
137 other => Err(DecodeError::UnknownPacketId(other)),
138 }
139 }
140 fn id(&self) -> i32 {
141 match *self {
142 Self::LoginStart(_) => id::LOGIN_START,
143 Self::EncryptionBegin(_) => id::ENCRYPTION_BEGIN,
144 Self::LoginPluginResponse(_) => id::LOGIN_PLUGIN_RESPONSE,
145 Self::LoginAcknowledged(_) => id::LOGIN_ACKNOWLEDGED,
146 Self::CookieResponse(_) => id::COOKIE_RESPONSE,
147 }
148 }
149 fn name(&self) -> &'static str {
150 match *self {
151 Self::LoginStart(_) => "login_start",
152 Self::EncryptionBegin(_) => "encryption_begin",
153 Self::LoginPluginResponse(_) => "login_plugin_response",
154 Self::LoginAcknowledged(_) => "login_acknowledged",
155 Self::CookieResponse(_) => "cookie_response",
156 }
157 }
158 fn encode_body(&self, w: &mut BytesMut) -> EncodeResult {
159 match *self {
160 Self::LoginStart(ref p) => p.encode(w),
161 Self::EncryptionBegin(ref p) => p.encode(w),
162 Self::LoginPluginResponse(ref p) => p.encode(w),
163 Self::LoginAcknowledged(ref p) => p.encode(w),
164 Self::CookieResponse(ref p) => p.encode(w),
165 }
166 }
167 fn name_of(id: i32) -> Option<&'static str> {
168 match id {
169 id::LOGIN_START => Some("login_start"),
170 id::ENCRYPTION_BEGIN => Some("encryption_begin"),
171 id::LOGIN_PLUGIN_RESPONSE => Some("login_plugin_response"),
172 id::LOGIN_ACKNOWLEDGED => Some("login_acknowledged"),
173 id::COOKIE_RESPONSE => Some("cookie_response"),
174 _ => None,
175 }
176 }
177}
178
179impl ServerboundLoginPacket {
180 pub const IDS: &'static [i32] = &[
182 id::LOGIN_START,
183 id::ENCRYPTION_BEGIN,
184 id::LOGIN_PLUGIN_RESPONSE,
185 id::LOGIN_ACKNOWLEDGED,
186 id::COOKIE_RESPONSE,
187 ];
188 #[cfg(feature = "testgen")]
190 pub fn generate_by_id(id: i32, g: &mut Gen) -> Option<Self> {
191 match id {
192 id::LOGIN_START => Some(Self::LoginStart(<LoginStart as Generate>::generate(g))),
193 id::ENCRYPTION_BEGIN => Some(Self::EncryptionBegin(
194 <EncryptionBegin as Generate>::generate(g),
195 )),
196 id::LOGIN_PLUGIN_RESPONSE => Some(Self::LoginPluginResponse(
197 <LoginPluginResponse as Generate>::generate(g),
198 )),
199 id::LOGIN_ACKNOWLEDGED => Some(Self::LoginAcknowledged(
200 <LoginAcknowledged as Generate>::generate(g),
201 )),
202 id::COOKIE_RESPONSE => Some(Self::CookieResponse(
203 <CookieResponse as Generate>::generate(g),
204 )),
205 _ => None,
206 }
207 }
208}