mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
22w43a
This commit is contained in:
parent
4e5b4be30d
commit
ff9cdd9a33
9 changed files with 78 additions and 153 deletions
|
@ -9,7 +9,7 @@ A collection of Rust crates for making Minecraft bots, clients, and tools.
|
|||
</p>
|
||||
|
||||
<!-- The line below is automatically read and updated by the migrate script, so don't change it manually. -->
|
||||
*Currently supported Minecraft version: `22w42a`.*
|
||||
*Currently supported Minecraft version: `22w43a`.*
|
||||
|
||||
## ⚠️ Azalea is still very unfinished, though some crates are in a somewhat useable state
|
||||
|
||||
|
|
|
@ -17,9 +17,8 @@ use azalea_protocol::{
|
|||
},
|
||||
handshake::client_intention_packet::ClientIntentionPacket,
|
||||
login::{
|
||||
serverbound_hello_packet::{RemoteChatSessionData, ServerboundHelloPacket},
|
||||
serverbound_key_packet::{NonceOrSaltSignature, ServerboundKeyPacket},
|
||||
ClientboundLoginPacket,
|
||||
serverbound_hello_packet::ServerboundHelloPacket,
|
||||
serverbound_key_packet::ServerboundKeyPacket, ClientboundLoginPacket,
|
||||
},
|
||||
ConnectionProtocol, PROTOCOL_VERSION,
|
||||
},
|
||||
|
@ -177,10 +176,6 @@ impl Client {
|
|||
conn.write(
|
||||
ServerboundHelloPacket {
|
||||
name: account.username.clone(),
|
||||
chat_session: RemoteChatSessionData {
|
||||
session_id: Uuid::nil(),
|
||||
profile_public_key: None,
|
||||
},
|
||||
profile_id: None,
|
||||
}
|
||||
.get(),
|
||||
|
@ -208,8 +203,8 @@ impl Client {
|
|||
|
||||
conn.write(
|
||||
ServerboundKeyPacket {
|
||||
nonce_or_salt_signature: NonceOrSaltSignature::Nonce(e.encrypted_nonce),
|
||||
key_bytes: e.encrypted_public_key,
|
||||
encrypted_challenge: e.encrypted_nonce,
|
||||
}
|
||||
.get(),
|
||||
)
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
use crate::packets::login::serverbound_hello_packet::RemoteChatSessionData;
|
||||
use azalea_auth::game_profile::{GameProfile, ProfilePropertyValue};
|
||||
use azalea_buf::{
|
||||
BufReadError, McBuf, McBufReadable, McBufVarReadable, McBufVarWritable, McBufWritable,
|
||||
|
@ -29,6 +28,19 @@ pub struct PlayerInfoEntry {
|
|||
pub chat_session: Option<RemoteChatSessionData>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, McBuf)]
|
||||
pub struct RemoteChatSessionData {
|
||||
pub session_id: Uuid,
|
||||
pub profile_public_key: Option<ProfilePublicKeyData>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, McBuf, PartialEq, Eq)]
|
||||
pub struct ProfilePublicKeyData {
|
||||
pub expires_at: u64,
|
||||
pub key: Vec<u8>,
|
||||
pub key_signature: Vec<u8>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, McBuf)]
|
||||
pub struct AddPlayerAction {
|
||||
pub name: String,
|
||||
|
|
|
@ -111,6 +111,7 @@ pub mod serverbound_change_difficulty_packet;
|
|||
pub mod serverbound_chat_ack_packet;
|
||||
pub mod serverbound_chat_command_packet;
|
||||
pub mod serverbound_chat_packet;
|
||||
pub mod serverbound_chat_session_update_packet;
|
||||
pub mod serverbound_client_command_packet;
|
||||
pub mod serverbound_client_information_packet;
|
||||
pub mod serverbound_command_suggestion_packet;
|
||||
|
@ -193,24 +194,25 @@ declare_state_packets!(
|
|||
0x1d: serverbound_player_command_packet::ServerboundPlayerCommandPacket,
|
||||
0x1e: serverbound_player_input_packet::ServerboundPlayerInputPacket,
|
||||
0x1f: serverbound_pong_packet::ServerboundPongPacket,
|
||||
0x20: serverbound_recipe_book_change_settings_packet::ServerboundRecipeBookChangeSettingsPacket,
|
||||
0x21: serverbound_recipe_book_seen_recipe_packet::ServerboundRecipeBookSeenRecipePacket,
|
||||
0x22: serverbound_rename_item_packet::ServerboundRenameItemPacket,
|
||||
0x23: serverbound_resource_pack_packet::ServerboundResourcePackPacket,
|
||||
0x24: serverbound_seen_advancements_packet::ServerboundSeenAdvancementsPacket,
|
||||
0x25: serverbound_select_trade_packet::ServerboundSelectTradePacket,
|
||||
0x26: serverbound_set_beacon_packet::ServerboundSetBeaconPacket,
|
||||
0x27: serverbound_set_carried_item_packet::ServerboundSetCarriedItemPacket,
|
||||
0x28: serverbound_set_command_block_packet::ServerboundSetCommandBlockPacket,
|
||||
0x29: serverbound_set_command_minecart_packet::ServerboundSetCommandMinecartPacket,
|
||||
0x2a: serverbound_set_creative_mode_slot_packet::ServerboundSetCreativeModeSlotPacket,
|
||||
0x2b: serverbound_set_jigsaw_block_packet::ServerboundSetJigsawBlockPacket,
|
||||
0x2c: serverbound_set_structure_block_packet::ServerboundSetStructureBlockPacket,
|
||||
0x2d: serverbound_sign_update_packet::ServerboundSignUpdatePacket,
|
||||
0x2e: serverbound_swing_packet::ServerboundSwingPacket,
|
||||
0x2f: serverbound_teleport_to_entity_packet::ServerboundTeleportToEntityPacket,
|
||||
0x30: serverbound_use_item_on_packet::ServerboundUseItemOnPacket,
|
||||
0x31: serverbound_use_item_packet::ServerboundUseItemPacket,
|
||||
0x20: serverbound_chat_session_update_packet::ServerboundChatSessionUpdatePacket,
|
||||
0x21: serverbound_recipe_book_change_settings_packet::ServerboundRecipeBookChangeSettingsPacket,
|
||||
0x22: serverbound_recipe_book_seen_recipe_packet::ServerboundRecipeBookSeenRecipePacket,
|
||||
0x23: serverbound_rename_item_packet::ServerboundRenameItemPacket,
|
||||
0x24: serverbound_resource_pack_packet::ServerboundResourcePackPacket,
|
||||
0x25: serverbound_seen_advancements_packet::ServerboundSeenAdvancementsPacket,
|
||||
0x26: serverbound_select_trade_packet::ServerboundSelectTradePacket,
|
||||
0x27: serverbound_set_beacon_packet::ServerboundSetBeaconPacket,
|
||||
0x28: serverbound_set_carried_item_packet::ServerboundSetCarriedItemPacket,
|
||||
0x29: serverbound_set_command_block_packet::ServerboundSetCommandBlockPacket,
|
||||
0x2a: serverbound_set_command_minecart_packet::ServerboundSetCommandMinecartPacket,
|
||||
0x2b: serverbound_set_creative_mode_slot_packet::ServerboundSetCreativeModeSlotPacket,
|
||||
0x2c: serverbound_set_jigsaw_block_packet::ServerboundSetJigsawBlockPacket,
|
||||
0x2d: serverbound_set_structure_block_packet::ServerboundSetStructureBlockPacket,
|
||||
0x2e: serverbound_sign_update_packet::ServerboundSignUpdatePacket,
|
||||
0x2f: serverbound_swing_packet::ServerboundSwingPacket,
|
||||
0x30: serverbound_teleport_to_entity_packet::ServerboundTeleportToEntityPacket,
|
||||
0x31: serverbound_use_item_on_packet::ServerboundUseItemOnPacket,
|
||||
0x32: serverbound_use_item_packet::ServerboundUseItemPacket,
|
||||
},
|
||||
Clientbound => {
|
||||
0x00: clientbound_add_entity_packet::ClientboundAddEntityPacket,
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
use azalea_buf::McBuf;
|
||||
use azalea_protocol_macros::ServerboundGamePacket;
|
||||
|
||||
#[derive(Clone, Debug, McBuf, ServerboundGamePacket)]
|
||||
pub struct ServerboundChatSessionUpdatePacket {
|
||||
// TODO: {'field': 'a.a', 'operation': 'write', 'type': 'uuid'}
|
||||
// TODO: {'field': 'a.b.b.toEpochMilli()', 'operation': 'write', 'type': 'long'}
|
||||
// TODO: {'field': 'a.b.c.getEncoded().length', 'operation': 'write', 'type': 'varint'}
|
||||
// TODO: {'field': 'a.b.c.getEncoded()', 'operation': 'write', 'type': 'byte[]'}
|
||||
// TODO: {'field': 'a.b.d.length', 'operation': 'write', 'type': 'varint'}
|
||||
// TODO: {'field': 'a.b.d', 'operation': 'write', 'type': 'byte[]'}
|
||||
}
|
|
@ -5,23 +5,9 @@ use uuid::Uuid;
|
|||
#[derive(Clone, Debug, PartialEq, Eq, McBuf, ServerboundLoginPacket)]
|
||||
pub struct ServerboundHelloPacket {
|
||||
pub name: String,
|
||||
pub chat_session: RemoteChatSessionData,
|
||||
pub profile_id: Option<Uuid>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, McBuf)]
|
||||
pub struct RemoteChatSessionData {
|
||||
pub session_id: Uuid,
|
||||
pub profile_public_key: Option<ProfilePublicKeyData>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, McBuf, PartialEq, Eq)]
|
||||
pub struct ProfilePublicKeyData {
|
||||
pub expires_at: u64,
|
||||
pub key: Vec<u8>,
|
||||
pub key_signature: Vec<u8>,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use std::io::Cursor;
|
||||
|
@ -33,10 +19,6 @@ mod tests {
|
|||
fn test_read_write() {
|
||||
let packet = ServerboundHelloPacket {
|
||||
name: "test".to_string(),
|
||||
chat_session: RemoteChatSessionData {
|
||||
session_id: Uuid::nil(),
|
||||
profile_public_key: None,
|
||||
},
|
||||
profile_id: Some(Uuid::nil()),
|
||||
};
|
||||
let mut buf: Vec<u8> = Vec::new();
|
||||
|
|
|
@ -1,47 +1,8 @@
|
|||
use azalea_buf::{BufReadError, McBuf};
|
||||
use azalea_crypto::SaltSignaturePair;
|
||||
use azalea_buf::McBuf;
|
||||
use azalea_protocol_macros::ServerboundLoginPacket;
|
||||
use std::io::{Cursor, Write};
|
||||
|
||||
use azalea_buf::{McBufReadable, McBufWritable};
|
||||
|
||||
#[derive(Clone, Debug, McBuf, ServerboundLoginPacket)]
|
||||
pub struct ServerboundKeyPacket {
|
||||
pub key_bytes: Vec<u8>,
|
||||
pub nonce_or_salt_signature: NonceOrSaltSignature,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum NonceOrSaltSignature {
|
||||
Nonce(Vec<u8>),
|
||||
SaltSignature(SaltSignaturePair),
|
||||
}
|
||||
|
||||
impl McBufReadable for NonceOrSaltSignature {
|
||||
fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
|
||||
let is_nonce = bool::read_from(buf)?;
|
||||
if is_nonce {
|
||||
Ok(NonceOrSaltSignature::Nonce(Vec::<u8>::read_from(buf)?))
|
||||
} else {
|
||||
Ok(NonceOrSaltSignature::SaltSignature(
|
||||
SaltSignaturePair::read_from(buf)?,
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl McBufWritable for NonceOrSaltSignature {
|
||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
match self {
|
||||
NonceOrSaltSignature::Nonce(nonce) => {
|
||||
bool::write_into(&true, buf)?;
|
||||
nonce.write_into(buf)?;
|
||||
}
|
||||
NonceOrSaltSignature::SaltSignature(salt_signature) => {
|
||||
bool::write_into(&false, buf)?;
|
||||
salt_signature.write_into(buf)?;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
pub encrypted_challenge: Vec<u8>,
|
||||
}
|
||||
|
|
|
@ -9,7 +9,7 @@ use std::io::{Cursor, Write};
|
|||
|
||||
// TODO: rename the packet files to just like clientbound_add_entity instead of clientbound_add_entity_packet
|
||||
|
||||
pub const PROTOCOL_VERSION: u32 = 1073741928;
|
||||
pub const PROTOCOL_VERSION: u32 = 1073741929;
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
||||
pub enum ConnectionProtocol {
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
use azalea_buf::{BufReadError, McBufVarReadable};
|
||||
use azalea_block::BlockState;
|
||||
use azalea_buf::{BufReadError, McBufVarReadable, McBufVarWritable};
|
||||
use azalea_buf::{McBuf, McBufReadable, McBufWritable};
|
||||
use azalea_chat::Component;
|
||||
use azalea_core::{BlockPos, Direction, GlobalPos, Particle, Slot};
|
||||
|
@ -12,7 +13,7 @@ pub struct EntityMetadata(Vec<EntityDataItem>);
|
|||
pub struct EntityDataItem {
|
||||
// we can't identify what the index is for here because we don't know the
|
||||
// entity type
|
||||
pub index: u8,
|
||||
pub id: u8,
|
||||
pub value: EntityDataValue,
|
||||
}
|
||||
|
||||
|
@ -20,12 +21,12 @@ impl McBufReadable for EntityMetadata {
|
|||
fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
|
||||
let mut metadata = Vec::new();
|
||||
loop {
|
||||
let index = u8::read_from(buf)?;
|
||||
if index == 0xff {
|
||||
let id = u8::read_from(buf)?;
|
||||
if id == 0xff {
|
||||
break;
|
||||
}
|
||||
let value = EntityDataValue::read_from(buf)?;
|
||||
metadata.push(EntityDataItem { index, value });
|
||||
metadata.push(EntityDataItem { id, value });
|
||||
}
|
||||
Ok(EntityMetadata(metadata))
|
||||
}
|
||||
|
@ -34,7 +35,7 @@ impl McBufReadable for EntityMetadata {
|
|||
impl McBufWritable for EntityMetadata {
|
||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
for item in &self.0 {
|
||||
item.index.write_into(buf)?;
|
||||
item.id.write_into(buf)?;
|
||||
item.value.write_into(buf)?;
|
||||
}
|
||||
0xffu8.write_into(buf)?;
|
||||
|
@ -42,11 +43,12 @@ impl McBufWritable for EntityMetadata {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
#[derive(Clone, Debug, McBuf)]
|
||||
pub enum EntityDataValue {
|
||||
Byte(u8),
|
||||
// varint
|
||||
Int(i32),
|
||||
Long(i64),
|
||||
Float(f32),
|
||||
String(String),
|
||||
Component(Component),
|
||||
|
@ -60,78 +62,37 @@ pub enum EntityDataValue {
|
|||
OptionalUuid(Option<Uuid>),
|
||||
// 0 for absent (implies air); otherwise, a block state ID as per the global palette
|
||||
// this is a varint
|
||||
OptionalBlockState(Option<i32>),
|
||||
BlockState(BlockState),
|
||||
CompoundTag(azalea_nbt::Tag),
|
||||
Particle(Particle),
|
||||
VillagerData(VillagerData),
|
||||
// 0 for absent; 1 + actual value otherwise. Used for entity IDs.
|
||||
OptionalUnsignedInt(Option<u32>),
|
||||
OptionalUnsignedInt(OptionalUnsignedInt),
|
||||
Pose(Pose),
|
||||
CatVariant(azalea_registry::CatVariant),
|
||||
FrogVariant(azalea_registry::FrogVariant),
|
||||
GlobalPos(GlobalPos),
|
||||
OptionalGlobalPos(Option<GlobalPos>),
|
||||
PaintingVariant(azalea_registry::PaintingVariant),
|
||||
}
|
||||
|
||||
impl McBufReadable for EntityDataValue {
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct OptionalUnsignedInt {
|
||||
pub value: Option<u32>,
|
||||
}
|
||||
impl McBufReadable for OptionalUnsignedInt {
|
||||
fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> {
|
||||
let data_type = u32::var_read_from(buf)?;
|
||||
Ok(match data_type {
|
||||
0 => EntityDataValue::Byte(u8::read_from(buf)?),
|
||||
1 => EntityDataValue::Int(i32::var_read_from(buf)?),
|
||||
2 => EntityDataValue::Float(f32::read_from(buf)?),
|
||||
3 => EntityDataValue::String(String::read_from(buf)?),
|
||||
4 => EntityDataValue::Component(Component::read_from(buf)?),
|
||||
5 => EntityDataValue::OptionalComponent(Option::<Component>::read_from(buf)?),
|
||||
6 => EntityDataValue::ItemStack(Slot::read_from(buf)?),
|
||||
7 => EntityDataValue::Boolean(bool::read_from(buf)?),
|
||||
8 => EntityDataValue::Rotations {
|
||||
x: f32::read_from(buf)?,
|
||||
y: f32::read_from(buf)?,
|
||||
z: f32::read_from(buf)?,
|
||||
},
|
||||
9 => EntityDataValue::BlockPos(BlockPos::read_from(buf)?),
|
||||
10 => EntityDataValue::OptionalBlockPos(Option::<BlockPos>::read_from(buf)?),
|
||||
11 => EntityDataValue::Direction(Direction::read_from(buf)?),
|
||||
12 => EntityDataValue::OptionalUuid(Option::<Uuid>::read_from(buf)?),
|
||||
13 => EntityDataValue::OptionalBlockState({
|
||||
let val = i32::var_read_from(buf)?;
|
||||
if val == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(val)
|
||||
}
|
||||
}),
|
||||
14 => EntityDataValue::CompoundTag(azalea_nbt::Tag::read_from(buf)?),
|
||||
15 => EntityDataValue::Particle(Particle::read_from(buf)?),
|
||||
16 => EntityDataValue::VillagerData(VillagerData::read_from(buf)?),
|
||||
17 => EntityDataValue::OptionalUnsignedInt({
|
||||
let val = u32::var_read_from(buf)?;
|
||||
if val == 0 {
|
||||
None
|
||||
} else {
|
||||
Some(val - 1)
|
||||
}
|
||||
}),
|
||||
18 => EntityDataValue::Pose(Pose::read_from(buf)?),
|
||||
19 => EntityDataValue::CatVariant(azalea_registry::CatVariant::read_from(buf)?),
|
||||
20 => EntityDataValue::FrogVariant(azalea_registry::FrogVariant::read_from(buf)?),
|
||||
21 => EntityDataValue::GlobalPos(GlobalPos::read_from(buf)?),
|
||||
22 => {
|
||||
EntityDataValue::PaintingVariant(azalea_registry::PaintingVariant::read_from(buf)?)
|
||||
}
|
||||
_ => {
|
||||
return Err(BufReadError::UnexpectedEnumVariant {
|
||||
id: data_type as i32,
|
||||
})
|
||||
}
|
||||
let val = u32::var_read_from(buf)?;
|
||||
Ok(OptionalUnsignedInt {
|
||||
value: if val == 0 { None } else { Some(val - 1) },
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
impl McBufWritable for EntityDataValue {
|
||||
fn write_into(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
todo!();
|
||||
impl McBufWritable for OptionalUnsignedInt {
|
||||
fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> {
|
||||
match self.value {
|
||||
Some(val) => (val + 1).var_write_into(buf),
|
||||
None => 0u32.var_write_into(buf),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue