azalea_protocol/packets/status/
c_status_response.rs1use std::io::{self, Cursor, Write};
2
3use azalea_buf::{AzBuf, BufReadError};
4use azalea_chat::FormattedText;
5use azalea_codec::Codec;
6use azalea_protocol_macros::ClientboundStatusPacket;
7
8#[derive(Clone, Debug, PartialEq, Codec)]
9pub struct Version {
10 pub name: String,
11 pub protocol: i32,
12}
13
14#[derive(Clone, Debug, PartialEq, Codec)]
15pub struct SamplePlayer {
16 pub id: String,
17 pub name: String,
18}
19
20#[derive(Clone, Debug, PartialEq, Codec)]
21pub struct Players {
22 pub max: i32,
23 pub online: i32,
24 #[codec(lenient)]
25 pub sample: Vec<SamplePlayer>,
26}
27
28#[derive(ClientboundStatusPacket, Clone, Debug, PartialEq, Codec)]
30pub struct ClientboundStatusResponse {
31 #[codec(lenient)]
32 pub description: FormattedText,
33 #[codec(lenient)]
34 pub favicon: Option<String>,
35 #[codec(lenient)]
36 pub players: Option<Players>,
37 #[codec(lenient)]
38 pub version: Option<Version>,
39 #[codec(lenient)]
40 #[codec(rename = "enforcesSecureChat")]
41 pub enforces_secure_chat: Option<bool>,
42 #[codec(lenient)]
43 pub contact: Option<String>,
44}
45
46impl AzBuf for ClientboundStatusResponse {
47 fn azalea_read(ctx: azalea_buf::Ctx, buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
48 let string = String::azalea_read(ctx, buf)?;
49 let mut string = string.into_bytes();
50 let json = simd_json::from_slice::<simd_json::OwnedValue>(&mut string)?;
51
52 Ok(Self::codec_read(&json)?)
53 }
54 fn azalea_write(&self, ctx: azalea_buf::Ctx, buf: &mut impl Write) -> io::Result<()> {
55 let json: simd_json::OwnedValue = Self::codec_write(self).unwrap();
56 let string = simd_json::to_string(&json)?;
57 string.azalea_write(ctx, buf)
58 }
59}