chunkedge_server/
brand.rs

1use chunkedge_binary::{Bounded, Encode};
2use chunkedge_protocol::packets::play::CustomPayloadS2c;
3use chunkedge_protocol::{ident, VarInt, WritePacket};
4
5pub trait SetBrand {
6    /// Sets the brand of the server.
7    ///
8    /// The Brand is displayed to the client in the F3 screen
9    /// and is often used to display the server name.
10    /// Any valid &str can be used.
11    ///
12    /// However, the legacy formatting codes are used,
13    /// which means that while color and other formatting can technically be
14    /// used, it needs to use the ยง character, which needs to be encoded as
15    /// 0xC2, 0xA7.
16    fn set_brand(&mut self, brand: &str);
17}
18
19impl<T: WritePacket> SetBrand for T {
20    fn set_brand(&mut self, brand: &str) {
21        let mut buf = vec![];
22        let _ = VarInt(brand.len() as i32).encode(&mut buf);
23        buf.extend_from_slice(brand.as_bytes());
24        self.write_packet(&CustomPayloadS2c {
25            channel: ident!("minecraft:brand").into(),
26            data: Bounded(buf.as_slice().into()),
27        });
28    }
29}