blob: dd11f7f77e9e45e9271c76bcaeea19cdcbf7dfc3 (
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
37
|
use std::io::{Read, Write};
use super::LoginPacket;
use crate::mc_buf::McBufReadable;
use crate::mc_buf::{Readable, Writable};
use azalea_auth::game_profile::GameProfile;
use azalea_core::serializable_uuid::SerializableUuid;
use uuid::Uuid;
#[derive(Clone, Debug)]
pub struct ClientboundGameProfilePacket {
pub game_profile: GameProfile,
}
// TODO: add derives to GameProfile and have an impl McBufReadable/Writable for GameProfile
impl ClientboundGameProfilePacket {
pub fn get(self) -> LoginPacket {
LoginPacket::ClientboundGameProfilePacket(self)
}
pub fn write(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
for n in self.game_profile.uuid.to_int_array() {
buf.write_int(n as i32).unwrap();
}
buf.write_utf(self.game_profile.name.as_str()).unwrap();
Ok(())
}
pub fn read(buf: &mut impl Read) -> Result<LoginPacket, String> {
let uuid = Uuid::read_into(buf)?;
let name = buf.read_utf_with_len(16)?;
Ok(ClientboundGameProfilePacket {
game_profile: GameProfile::new(uuid, name),
}
.get())
}
}
|