chunkedge_protocol/packets/configuration/
server_links_s2c.rs

1use std::borrow::Cow;
2use std::io::Write;
3
4use chunkedge_binary::{Decode, Encode, TextComponent};
5
6use crate::{Packet, PacketState};
7
8#[derive(Clone, Debug, Encode, Decode, Packet)]
9#[packet(state = PacketState::Configuration)]
10pub struct ServerLinksS2c<'a> {
11    pub links: Vec<ServerLink<'a>>,
12}
13
14#[derive(Clone, Debug, Encode, Decode)]
15pub struct ServerLink<'a> {
16    pub label: ServerLinkEnum,
17    pub url: Cow<'a, str>,
18}
19
20#[derive(Clone, Debug)]
21pub enum ServerLinkEnum {
22    BuiltIn(BuiltInLinkType),
23    CustomText(TextComponent),
24}
25
26impl Encode for ServerLinkEnum {
27    fn encode(&self, mut w: impl Write) -> anyhow::Result<()> {
28        match self {
29            ServerLinkEnum::BuiltIn(label) => {
30                true.encode(&mut w)?;
31                label.encode(w)
32            }
33            ServerLinkEnum::CustomText(label) => {
34                false.encode(&mut w)?;
35                label.encode(w)
36            }
37        }
38    }
39}
40
41impl Decode<'_> for ServerLinkEnum {
42    fn decode(r: &mut &[u8]) -> anyhow::Result<Self> {
43        Ok(if bool::decode(r)? {
44            ServerLinkEnum::BuiltIn(Decode::decode(r)?)
45        } else {
46            ServerLinkEnum::CustomText(Decode::decode(r)?)
47        })
48    }
49}
50
51#[derive(Clone, Copy, PartialEq, Eq, Debug, Encode, Decode)]
52pub enum BuiltInLinkType {
53    BugReport,
54    CommunityGuidelines,
55    Support,
56    Status,
57    Feedback,
58    Community,
59    Website,
60    Forums,
61    News,
62    Announcements,
63}