Compare commits

..

No commits in common. "856b33f2dc3b18cb4d3bda9c6bbd0e80d8bddfa7" and "9ff2e95c66b1d773362936733273350e4bdd399a" have entirely different histories.

3 changed files with 19 additions and 36 deletions

View File

@ -13,6 +13,8 @@ serde = { version = "1", features = ["derive"] }
serde_json = "1" serde_json = "1"
async-trait = "0.1.75" async-trait = "0.1.75"
rand = "0.8.5" rand = "0.8.5"
# aes = "0.8.4"
aes = "0.7" aes = "0.7"
# rsa = "0.9.6"
rsa = "0.6" rsa = "0.6"
pkcs8 = "0.8" pkcs8 = "0.8"

View File

@ -28,7 +28,6 @@ pub enum PacketError {
ValueTooLarge, ValueTooLarge,
RanOutOfBytes, RanOutOfBytes,
InvalidPacketId, InvalidPacketId,
InvalidUUIDString,
EncryptionError, EncryptionError,
} }
@ -41,8 +40,6 @@ impl fmt::Display for PacketError {
write!(f, "Ran out of bytes while reading VarInt"), write!(f, "Ran out of bytes while reading VarInt"),
PacketError::InvalidPacketId => PacketError::InvalidPacketId =>
write!(f, "Invalid packet id"), write!(f, "Invalid packet id"),
PacketError::InvalidUUIDString =>
write!(f, "Invalid UUID format"),
PacketError::EncryptionError => PacketError::EncryptionError =>
write!(f, "Encryption Error"), write!(f, "Encryption Error"),
} }
@ -408,6 +405,23 @@ async fn read_var_int_stream_encrypted(
Ok(varint) Ok(varint)
} }
fn read_var_int_vec(stream: &mut Vec<u8>) -> Result<i32> {
let mut data: Vec<u8> = vec![];
loop {
let current_byte = stream.remove(0);
data.append(&mut vec![current_byte]);
if (current_byte & CONTINUE_BIT) == 0 {
break;
}
}
let varint = get_var_int(&mut data)?;
Ok(varint)
}
pub trait PacketArray: Sized { pub trait PacketArray: Sized {
fn get(data: &mut Vec<u8>) -> Result<Self>; fn get(data: &mut Vec<u8>) -> Result<Self>;
@ -575,38 +589,6 @@ pub fn convert_uuid(value: u128) -> Vec<u8> {
(value & 0xFF) as u8, (value & 0xFF) as u8,
] ]
} }
pub fn uuid_u128_to_string(uuid: u128) -> String {
let uuid_bytes = convert_uuid(uuid);
format!(
"{:08x}-{:04x}-{:04x}-{:04x}-{:012x}",
get_u32(&mut vec![
uuid_bytes[0],
uuid_bytes[1],
uuid_bytes[2],
uuid_bytes[3],
]),
get_u16(&mut vec![uuid_bytes[4], uuid_bytes[5]]),
get_u16(&mut vec![uuid_bytes[6], uuid_bytes[7]]),
get_u16(&mut vec![uuid_bytes[8], uuid_bytes[9]]),
get_u64(&mut vec![
0,
0,
uuid_bytes[10],
uuid_bytes[11],
uuid_bytes[12],
uuid_bytes[13],
uuid_bytes[14],
uuid_bytes[15],
]),
)
}
pub fn uuid_string_to_u128(uuid: &str) -> Result<u128> {
let cleaned_uuid = uuid.replace("-", "");
if cleaned_uuid.len() != 32 {
return Err(Box::new(PacketError::InvalidUUIDString));
}
Ok(u128::from_str_radix(&cleaned_uuid, 16)?)
}
pub fn get_var_int(data: &mut Vec<u8>) -> Result<i32> { pub fn get_var_int(data: &mut Vec<u8>) -> Result<i32> {
Ok(get_var(data, 32)? as i32) Ok(get_var(data, 32)? as i32)

View File

@ -26,7 +26,6 @@ pub mod clientbound {
pub sample: Option<Vec<StatusPlayerInfo>> pub sample: Option<Vec<StatusPlayerInfo>>
} }
#[allow(non_snake_case)]
#[derive(Serialize, Deserialize)] #[derive(Serialize, Deserialize)]
pub struct StatusResponseData { pub struct StatusResponseData {
pub version: StatusVersion, pub version: StatusVersion,