Skip to main content

steel_protocol/packets/config/
c_server_links.rs

1use serde::{Deserialize, Serialize};
2use steel_macros::{ClientPacket, WriteTo};
3use steel_registry::packets::config::C_SERVER_LINKS;
4use steel_utils::codec::Or;
5use text_components::TextComponent;
6
7#[derive(ClientPacket, WriteTo, Clone, Debug)]
8#[packet_id(Config = C_SERVER_LINKS)]
9pub struct CServerLinks {
10    pub links: Vec<Link>,
11}
12
13#[derive(WriteTo, Clone, Copy, Debug, Serialize, Deserialize)]
14#[write(as = VarInt)]
15#[serde(rename_all = "snake_case")]
16pub enum ServerLinksType {
17    BugReport = 0,
18    CommunityGuidelines = 1,
19    Support = 2,
20    Status = 3,
21    Feedback = 4,
22    Community = 5,
23    Website = 6,
24    Forums = 7,
25    News = 8,
26    Announcements = 9,
27}
28
29#[derive(WriteTo, Clone, Debug)]
30pub struct Link {
31    pub is_built_in: bool,
32    pub label: Label,
33    #[write(as = Prefixed(VarInt))]
34    pub url: String,
35}
36
37impl Link {
38    #[must_use]
39    pub const fn new(label: Label, url: String) -> Self {
40        Self {
41            is_built_in: label.is_left(),
42            label,
43            url,
44        }
45    }
46}
47
48/// Label can be either a built-in `ServerLinksType` (Left) or a custom `TextComponent` (Right).
49/// The discriminant is stored separately in the `is_built_in` field of the Link struct.
50pub type Label = Or<ServerLinksType, TextComponent>; // TextComponent goes here when uncommented