aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets/login/serverbound_hello_packet.rs
blob: 06cf1fa77a9abb35bb43a3ba7e40332e5af1140e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
use azalea_buf::McBuf;
use azalea_protocol_macros::ServerboundLoginPacket;
use uuid::Uuid;

#[derive(Clone, Debug, ServerboundLoginPacket, McBuf, PartialEq)]
pub struct ServerboundHelloPacket {
    pub username: String,
    pub public_key: Option<ProfilePublicKeyData>,
    pub profile_id: Option<Uuid>,
}

#[derive(Clone, Debug, McBuf, PartialEq)]
pub struct ProfilePublicKeyData {
    pub expires_at: u64,
    pub key: Vec<u8>,
    pub key_signature: Vec<u8>,
}

#[cfg(test)]
mod tests {
    use super::*;
    use azalea_buf::{McBufReadable, McBufWritable};

    #[test]
    fn test_read_write() {
        let packet = ServerboundHelloPacket {
            username: "test".to_string(),
            public_key: None,
            profile_id: Some(Uuid::from_u128(0)),
        };
        let mut buf = Vec::new();
        packet.write_into(&mut buf).unwrap();
        let packet2 = ServerboundHelloPacket::read_from(&mut buf.as_slice()).unwrap();
        assert_eq!(packet, packet2);
    }
}