mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
.get() -> .into_packet()
This commit is contained in:
parent
eabb329085
commit
68e3d0104b
29 changed files with 139 additions and 135 deletions
|
@ -90,7 +90,7 @@ pub fn handle_attack_event(
|
||||||
action: s_interact::ActionType::Attack,
|
action: s_interact::ActionType::Attack,
|
||||||
using_secondary_action: **sneaking,
|
using_secondary_action: **sneaking,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
});
|
});
|
||||||
|
|
||||||
// we can't attack if we're in spectator mode but it still sends the attack
|
// we can't attack if we're in spectator mode but it still sends the attack
|
||||||
|
|
|
@ -274,10 +274,10 @@ pub fn handle_send_chat_kind_event(
|
||||||
signature: None,
|
signature: None,
|
||||||
last_seen_messages: LastSeenMessagesUpdate::default(),
|
last_seen_messages: LastSeenMessagesUpdate::default(),
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
ChatKind::Command => {
|
ChatKind::Command => {
|
||||||
// TODO: chat signing
|
// TODO: chat signing
|
||||||
ServerboundChatCommand { command: content }.get()
|
ServerboundChatCommand { command: content }.into_variant()
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -164,7 +164,7 @@ pub fn handle_chunk_batch_finished_event(
|
||||||
packet: ServerboundChunkBatchReceived {
|
packet: ServerboundChunkBatchReceived {
|
||||||
desired_chunks_per_tick,
|
desired_chunks_per_tick,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -356,7 +356,7 @@ impl Client {
|
||||||
port: address.port,
|
port: address.port,
|
||||||
intention: ClientIntention::Login,
|
intention: ClientIntention::Login,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
let mut conn = conn.login();
|
let mut conn = conn.login();
|
||||||
|
@ -377,7 +377,7 @@ impl Client {
|
||||||
// Uuid::default()
|
// Uuid::default()
|
||||||
profile_id: account.uuid.unwrap_or_default(),
|
profile_id: account.uuid.unwrap_or_default(),
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -443,7 +443,7 @@ impl Client {
|
||||||
key_bytes: e.encrypted_public_key,
|
key_bytes: e.encrypted_public_key,
|
||||||
encrypted_challenge: e.encrypted_challenge,
|
encrypted_challenge: e.encrypted_challenge,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
|
@ -458,7 +458,8 @@ impl Client {
|
||||||
"Got profile {:?}. handshake is finished and we're now switching to the configuration state",
|
"Got profile {:?}. handshake is finished and we're now switching to the configuration state",
|
||||||
p.game_profile
|
p.game_profile
|
||||||
);
|
);
|
||||||
conn.write(ServerboundLoginAcknowledged {}.get()).await?;
|
conn.write(ServerboundLoginAcknowledged {}.into_variant())
|
||||||
|
.await?;
|
||||||
break (conn.configuration(), p.game_profile);
|
break (conn.configuration(), p.game_profile);
|
||||||
}
|
}
|
||||||
ClientboundLoginPacket::LoginDisconnect(p) => {
|
ClientboundLoginPacket::LoginDisconnect(p) => {
|
||||||
|
@ -600,7 +601,7 @@ impl Client {
|
||||||
"Sending client information (already logged in): {:?}",
|
"Sending client information (already logged in): {:?}",
|
||||||
client_information
|
client_information
|
||||||
);
|
);
|
||||||
self.write_packet(azalea_protocol::packets::game::s_client_information::ServerboundClientInformation { information: client_information.clone() }.get())?;
|
self.write_packet(azalea_protocol::packets::game::s_client_information::ServerboundClientInformation { information: client_information.clone() }.into_variant())?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -37,7 +37,7 @@ fn handle_in_configuration_state(
|
||||||
identifier: ResourceLocation::new("brand"),
|
identifier: ResourceLocation::new("brand"),
|
||||||
data: brand_data.into(),
|
data: brand_data.into(),
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
});
|
});
|
||||||
|
|
||||||
send_packet_events.send(SendConfigurationEvent {
|
send_packet_events.send(SendConfigurationEvent {
|
||||||
|
@ -45,7 +45,7 @@ fn handle_in_configuration_state(
|
||||||
packet: ServerboundClientInformation {
|
packet: ServerboundClientInformation {
|
||||||
information: client_information.clone(),
|
information: client_information.clone(),
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -155,7 +155,7 @@ pub fn handle_block_interact_event(
|
||||||
block_hit,
|
block_hit,
|
||||||
sequence: sequence_number.0,
|
sequence: sequence_number.0,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -307,7 +307,7 @@ pub fn handle_swing_arm_event(
|
||||||
packet: ServerboundSwing {
|
packet: ServerboundSwing {
|
||||||
hand: InteractionHand::MainHand,
|
hand: InteractionHand::MainHand,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -632,7 +632,7 @@ fn handle_container_close_event(
|
||||||
packet: ServerboundContainerClose {
|
packet: ServerboundContainerClose {
|
||||||
container_id: inventory.id,
|
container_id: inventory.id,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
});
|
});
|
||||||
client_side_events.send(ClientSideCloseContainerEvent {
|
client_side_events.send(ClientSideCloseContainerEvent {
|
||||||
entity: event.entity,
|
entity: event.entity,
|
||||||
|
@ -706,7 +706,7 @@ pub fn handle_container_click_event(
|
||||||
changed_slots,
|
changed_slots,
|
||||||
carried_item: inventory.carried.clone(),
|
carried_item: inventory.carried.clone(),
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -768,7 +768,7 @@ fn handle_set_selected_hotbar_slot_event(
|
||||||
packet: ServerboundSetCarriedItem {
|
packet: ServerboundSetCarriedItem {
|
||||||
slot: event.slot as u16,
|
slot: event.slot as u16,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -260,7 +260,7 @@ fn handle_start_mining_block_with_direction_event(
|
||||||
direction: event.direction,
|
direction: event.direction,
|
||||||
sequence: 0,
|
sequence: 0,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -332,7 +332,7 @@ fn handle_start_mining_block_with_direction_event(
|
||||||
direction: event.direction,
|
direction: event.direction,
|
||||||
sequence: **sequence_number,
|
sequence: **sequence_number,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -502,7 +502,7 @@ pub fn handle_stop_mining_block_event(
|
||||||
direction: Direction::Down,
|
direction: Direction::Down,
|
||||||
sequence: 0,
|
sequence: 0,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
});
|
});
|
||||||
commands.entity(event.entity).remove::<Mining>();
|
commands.entity(event.entity).remove::<Mining>();
|
||||||
**mine_progress = 0.;
|
**mine_progress = 0.;
|
||||||
|
@ -576,7 +576,7 @@ pub fn continue_mining_block(
|
||||||
direction: mining.dir,
|
direction: mining.dir,
|
||||||
sequence: **sequence_number,
|
sequence: **sequence_number,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
});
|
});
|
||||||
swing_arm_events.send(SwingArmEvent { entity });
|
swing_arm_events.send(SwingArmEvent { entity });
|
||||||
} else if is_same_mining_target(
|
} else if is_same_mining_target(
|
||||||
|
@ -622,7 +622,7 @@ pub fn continue_mining_block(
|
||||||
direction: mining.dir,
|
direction: mining.dir,
|
||||||
sequence: **sequence_number,
|
sequence: **sequence_number,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
});
|
});
|
||||||
**mine_progress = 0.;
|
**mine_progress = 0.;
|
||||||
**mine_ticks = 0.;
|
**mine_ticks = 0.;
|
||||||
|
|
|
@ -196,7 +196,7 @@ pub fn send_position(
|
||||||
y_rot: direction.y_rot,
|
y_rot: direction.y_rot,
|
||||||
on_ground: physics.on_ground,
|
on_ground: physics.on_ground,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
)
|
)
|
||||||
} else if sending_position {
|
} else if sending_position {
|
||||||
Some(
|
Some(
|
||||||
|
@ -206,7 +206,7 @@ pub fn send_position(
|
||||||
z: position.z,
|
z: position.z,
|
||||||
on_ground: physics.on_ground,
|
on_ground: physics.on_ground,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
)
|
)
|
||||||
} else if sending_direction {
|
} else if sending_direction {
|
||||||
Some(
|
Some(
|
||||||
|
@ -215,14 +215,14 @@ pub fn send_position(
|
||||||
y_rot: direction.y_rot,
|
y_rot: direction.y_rot,
|
||||||
on_ground: physics.on_ground,
|
on_ground: physics.on_ground,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
)
|
)
|
||||||
} else if physics.last_on_ground != physics.on_ground {
|
} else if physics.last_on_ground != physics.on_ground {
|
||||||
Some(
|
Some(
|
||||||
ServerboundMovePlayerStatusOnly {
|
ServerboundMovePlayerStatusOnly {
|
||||||
on_ground: physics.on_ground,
|
on_ground: physics.on_ground,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -268,7 +268,7 @@ fn send_sprinting_if_needed(
|
||||||
action: sprinting_action,
|
action: sprinting_action,
|
||||||
data: 0,
|
data: 0,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
});
|
});
|
||||||
physics_state.was_sprinting = **sprinting;
|
physics_state.was_sprinting = **sprinting;
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,7 +107,7 @@ pub fn process_packet_events(ecs: &mut World) {
|
||||||
let mut raw_connection = query.get_mut(player_entity).unwrap();
|
let mut raw_connection = query.get_mut(player_entity).unwrap();
|
||||||
|
|
||||||
raw_connection
|
raw_connection
|
||||||
.write_packet(ServerboundFinishConfiguration {}.get())
|
.write_packet(ServerboundFinishConfiguration {}.into_variant())
|
||||||
.expect(
|
.expect(
|
||||||
"we should be in the right state and encoding this packet shouldn't fail",
|
"we should be in the right state and encoding this packet shouldn't fail",
|
||||||
);
|
);
|
||||||
|
@ -150,7 +150,7 @@ pub fn process_packet_events(ecs: &mut World) {
|
||||||
id: p.id,
|
id: p.id,
|
||||||
});
|
});
|
||||||
raw_connection
|
raw_connection
|
||||||
.write_packet(ServerboundKeepAlive { id: p.id }.get())
|
.write_packet(ServerboundKeepAlive { id: p.id }.into_variant())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
ClientboundConfigPacket::Ping(p) => {
|
ClientboundConfigPacket::Ping(p) => {
|
||||||
|
@ -161,7 +161,7 @@ pub fn process_packet_events(ecs: &mut World) {
|
||||||
let raw_connection = query.get_mut(player_entity).unwrap();
|
let raw_connection = query.get_mut(player_entity).unwrap();
|
||||||
|
|
||||||
raw_connection
|
raw_connection
|
||||||
.write_packet(config::s_pong::ServerboundPong { id: p.id }.get())
|
.write_packet(config::s_pong::ServerboundPong { id: p.id }.into_variant())
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
ClientboundConfigPacket::ResourcePackPush(p) => {
|
ClientboundConfigPacket::ResourcePackPush(p) => {
|
||||||
|
@ -178,7 +178,7 @@ pub fn process_packet_events(ecs: &mut World) {
|
||||||
id: p.id,
|
id: p.id,
|
||||||
action: config::s_resource_pack::Action::Accepted,
|
action: config::s_resource_pack::Action::Accepted,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -216,7 +216,7 @@ pub fn process_packet_events(ecs: &mut World) {
|
||||||
ServerboundSelectKnownPacks {
|
ServerboundSelectKnownPacks {
|
||||||
known_packs: vec![],
|
known_packs: vec![],
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
|
@ -340,7 +340,7 @@ pub fn process_packet_events(ecs: &mut World) {
|
||||||
);
|
);
|
||||||
send_packet_events.send(SendPacketEvent {
|
send_packet_events.send(SendPacketEvent {
|
||||||
entity: player_entity,
|
entity: player_entity,
|
||||||
packet: azalea_protocol::packets::game::s_client_information::ServerboundClientInformation { information: client_information.clone() }.get(),
|
packet: azalea_protocol::packets::game::s_client_information::ServerboundClientInformation { information: client_information.clone() }.into_variant(),
|
||||||
});
|
});
|
||||||
|
|
||||||
system_state.apply(ecs);
|
system_state.apply(ecs);
|
||||||
|
@ -493,7 +493,7 @@ pub fn process_packet_events(ecs: &mut World) {
|
||||||
|
|
||||||
send_packet_events.send(SendPacketEvent {
|
send_packet_events.send(SendPacketEvent {
|
||||||
entity: player_entity,
|
entity: player_entity,
|
||||||
packet: ServerboundAcceptTeleportation { id: p.id }.get(),
|
packet: ServerboundAcceptTeleportation { id: p.id }.into_variant(),
|
||||||
});
|
});
|
||||||
send_packet_events.send(SendPacketEvent {
|
send_packet_events.send(SendPacketEvent {
|
||||||
entity: player_entity,
|
entity: player_entity,
|
||||||
|
@ -506,7 +506,7 @@ pub fn process_packet_events(ecs: &mut World) {
|
||||||
// this is always false
|
// this is always false
|
||||||
on_ground: false,
|
on_ground: false,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ClientboundGamePacket::PlayerInfoUpdate(p) => {
|
ClientboundGamePacket::PlayerInfoUpdate(p) => {
|
||||||
|
@ -983,7 +983,7 @@ pub fn process_packet_events(ecs: &mut World) {
|
||||||
});
|
});
|
||||||
send_packet_events.send(SendPacketEvent {
|
send_packet_events.send(SendPacketEvent {
|
||||||
entity: player_entity,
|
entity: player_entity,
|
||||||
packet: ServerboundKeepAlive { id: p.id }.get(),
|
packet: ServerboundKeepAlive { id: p.id }.into_variant(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ClientboundGamePacket::RemoveEntities(p) => {
|
ClientboundGamePacket::RemoveEntities(p) => {
|
||||||
|
@ -1279,7 +1279,7 @@ pub fn process_packet_events(ecs: &mut World) {
|
||||||
|
|
||||||
send_packet_events.send(SendPacketEvent {
|
send_packet_events.send(SendPacketEvent {
|
||||||
entity: player_entity,
|
entity: player_entity,
|
||||||
packet: ServerboundPong { id: p.id }.get(),
|
packet: ServerboundPong { id: p.id }.into_variant(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
ClientboundGamePacket::PlaceGhostRecipe(_) => {}
|
ClientboundGamePacket::PlaceGhostRecipe(_) => {}
|
||||||
|
@ -1423,7 +1423,7 @@ pub fn process_packet_events(ecs: &mut World) {
|
||||||
|
|
||||||
packet_events.send(SendPacketEvent {
|
packet_events.send(SendPacketEvent {
|
||||||
entity: player_entity,
|
entity: player_entity,
|
||||||
packet: ServerboundConfigurationAcknowledged {}.get(),
|
packet: ServerboundConfigurationAcknowledged {}.into_variant(),
|
||||||
});
|
});
|
||||||
|
|
||||||
commands
|
commands
|
||||||
|
|
|
@ -92,7 +92,7 @@ pub fn process_packet_events(ecs: &mut World) {
|
||||||
transaction_id: p.transaction_id,
|
transaction_id: p.transaction_id,
|
||||||
data: None,
|
data: None,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
_ => {}
|
_ => {}
|
||||||
|
|
|
@ -81,13 +81,14 @@ pub async fn ping_server_with_connection(
|
||||||
port: address.port,
|
port: address.port,
|
||||||
intention: ClientIntention::Status,
|
intention: ClientIntention::Status,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
let mut conn = conn.status();
|
let mut conn = conn.status();
|
||||||
|
|
||||||
// send the empty status request packet
|
// send the empty status request packet
|
||||||
conn.write(ServerboundStatusRequest {}.get()).await?;
|
conn.write(ServerboundStatusRequest {}.into_variant())
|
||||||
|
.await?;
|
||||||
|
|
||||||
let packet = conn.read().await?;
|
let packet = conn.read().await?;
|
||||||
|
|
||||||
|
|
|
@ -29,7 +29,7 @@ pub fn perform_respawn(
|
||||||
packet: ServerboundClientCommand {
|
packet: ServerboundClientCommand {
|
||||||
action: s_client_command::Action::PerformRespawn,
|
action: s_client_command::Action::PerformRespawn,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -699,10 +699,10 @@ mod tests {
|
||||||
let block_state = world_lock.write().chunks.set_block_state(
|
let block_state = world_lock.write().chunks.set_block_state(
|
||||||
&BlockPos { x: 0, y: 69, z: 0 },
|
&BlockPos { x: 0, y: 69, z: 0 },
|
||||||
azalea_block::blocks::CobblestoneWall {
|
azalea_block::blocks::CobblestoneWall {
|
||||||
east: azalea_block::properties::EastWall::Low,
|
east: azalea_block::properties::WallEast::Low,
|
||||||
north: azalea_block::properties::NorthWall::Low,
|
north: azalea_block::properties::WallNorth::Low,
|
||||||
south: azalea_block::properties::SouthWall::Low,
|
south: azalea_block::properties::WallSouth::Low,
|
||||||
west: azalea_block::properties::WestWall::Low,
|
west: azalea_block::properties::WallWest::Low,
|
||||||
up: false,
|
up: false,
|
||||||
waterlogged: false,
|
waterlogged: false,
|
||||||
}
|
}
|
||||||
|
@ -761,10 +761,10 @@ mod tests {
|
||||||
z: -8,
|
z: -8,
|
||||||
},
|
},
|
||||||
azalea_block::blocks::CobblestoneWall {
|
azalea_block::blocks::CobblestoneWall {
|
||||||
east: azalea_block::properties::EastWall::Low,
|
east: azalea_block::properties::WallEast::Low,
|
||||||
north: azalea_block::properties::NorthWall::Low,
|
north: azalea_block::properties::WallNorth::Low,
|
||||||
south: azalea_block::properties::SouthWall::Low,
|
south: azalea_block::properties::WallSouth::Low,
|
||||||
west: azalea_block::properties::WestWall::Low,
|
west: azalea_block::properties::WallWest::Low,
|
||||||
up: false,
|
up: false,
|
||||||
waterlogged: false,
|
waterlogged: false,
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,10 +20,6 @@ fn as_packet_derive(input: TokenStream, state: proc_macro2::TokenStream) -> Toke
|
||||||
|
|
||||||
let contents = quote! {
|
let contents = quote! {
|
||||||
impl #ident {
|
impl #ident {
|
||||||
pub fn get(self) -> #state {
|
|
||||||
#state::#variant_name(self)
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
|
pub fn write(&self, buf: &mut impl std::io::Write) -> Result<(), std::io::Error> {
|
||||||
azalea_buf::McBufWritable::write_into(self, buf)
|
azalea_buf::McBufWritable::write_into(self, buf)
|
||||||
}
|
}
|
||||||
|
@ -32,7 +28,12 @@ fn as_packet_derive(input: TokenStream, state: proc_macro2::TokenStream) -> Toke
|
||||||
buf: &mut std::io::Cursor<&[u8]>,
|
buf: &mut std::io::Cursor<&[u8]>,
|
||||||
) -> Result<#state, azalea_buf::BufReadError> {
|
) -> Result<#state, azalea_buf::BufReadError> {
|
||||||
use azalea_buf::McBufReadable;
|
use azalea_buf::McBufReadable;
|
||||||
Ok(Self::read_from(buf)?.get())
|
Ok(Self::read_from(buf)?.into_variant())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Convert this packet into an variant for the enum of the state and direction.
|
||||||
|
pub fn into_variant(self) -> #state {
|
||||||
|
#state::#variant_name(self)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,7 +7,7 @@ use azalea_protocol::{
|
||||||
connect::Connection,
|
connect::Connection,
|
||||||
packets::{
|
packets::{
|
||||||
handshake::{
|
handshake::{
|
||||||
client_intention::ClientIntention, ClientboundHandshakePacket,
|
s_client_intention::ServerboundClientIntention, ClientboundHandshakePacket,
|
||||||
ServerboundHandshakePacket,
|
ServerboundHandshakePacket,
|
||||||
},
|
},
|
||||||
login::{s_hello::ServerboundHello, ServerboundLoginPacket},
|
login::{s_hello::ServerboundHello, ServerboundLoginPacket},
|
||||||
|
@ -108,12 +108,12 @@ async fn handle_connection(stream: TcpStream) -> anyhow::Result<()> {
|
||||||
version: PROXY_VERSION.clone(),
|
version: PROXY_VERSION.clone(),
|
||||||
enforces_secure_chat: PROXY_SECURE_CHAT,
|
enforces_secure_chat: PROXY_SECURE_CHAT,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
}
|
}
|
||||||
ServerboundStatusPacket::PingRequest(p) => {
|
ServerboundStatusPacket::PingRequest(p) => {
|
||||||
conn.write(ClientboundPongResponse { time: p.time }.get())
|
conn.write(ClientboundPongResponse { time: p.time }.into_variant())
|
||||||
.await?;
|
.await?;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -178,7 +178,7 @@ async fn handle_connection(stream: TcpStream) -> anyhow::Result<()> {
|
||||||
|
|
||||||
async fn transfer(
|
async fn transfer(
|
||||||
mut inbound: TcpStream,
|
mut inbound: TcpStream,
|
||||||
intent: ClientIntention,
|
intent: ServerboundClientIntention,
|
||||||
hello: ServerboundHello,
|
hello: ServerboundHello,
|
||||||
) -> Result<(), Box<dyn Error>> {
|
) -> Result<(), Box<dyn Error>> {
|
||||||
let outbound = TcpStream::connect(PROXY_ADDR).await?;
|
let outbound = TcpStream::connect(PROXY_ADDR).await?;
|
||||||
|
@ -189,10 +189,10 @@ async fn transfer(
|
||||||
// received earlier to the proxy target
|
// received earlier to the proxy target
|
||||||
let mut outbound_conn: Connection<ClientboundHandshakePacket, ServerboundHandshakePacket> =
|
let mut outbound_conn: Connection<ClientboundHandshakePacket, ServerboundHandshakePacket> =
|
||||||
Connection::wrap(outbound);
|
Connection::wrap(outbound);
|
||||||
outbound_conn.write(intent.get()).await?;
|
outbound_conn.write(intent.into_variant()).await?;
|
||||||
|
|
||||||
let mut outbound_conn = outbound_conn.login();
|
let mut outbound_conn = outbound_conn.login();
|
||||||
outbound_conn.write(hello.get()).await?;
|
outbound_conn.write(hello.into_variant()).await?;
|
||||||
|
|
||||||
let mut outbound = outbound_conn.unwrap()?;
|
let mut outbound = outbound_conn.unwrap()?;
|
||||||
|
|
||||||
|
|
|
@ -139,3 +139,51 @@ impl McBufWritable for ModelCustomization {
|
||||||
set.write_into(buf)
|
set.write_into(buf)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use std::io::Cursor;
|
||||||
|
|
||||||
|
use azalea_buf::{McBufReadable, McBufWritable};
|
||||||
|
|
||||||
|
use super::*;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_client_information() {
|
||||||
|
{
|
||||||
|
let data = ClientInformation::default();
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
data.write_into(&mut buf).unwrap();
|
||||||
|
let mut data_cursor: Cursor<&[u8]> = Cursor::new(&buf);
|
||||||
|
|
||||||
|
let read_data = ClientInformation::read_from(&mut data_cursor).unwrap();
|
||||||
|
assert_eq!(read_data, data);
|
||||||
|
}
|
||||||
|
|
||||||
|
let data = ClientInformation {
|
||||||
|
language: "en_gb".to_string(),
|
||||||
|
view_distance: 24,
|
||||||
|
chat_visibility: ChatVisibility::Hidden,
|
||||||
|
chat_colors: false,
|
||||||
|
model_customization: ModelCustomization {
|
||||||
|
cape: false,
|
||||||
|
jacket: false,
|
||||||
|
left_sleeve: true,
|
||||||
|
right_sleeve: false,
|
||||||
|
left_pants: true,
|
||||||
|
right_pants: false,
|
||||||
|
hat: true,
|
||||||
|
},
|
||||||
|
main_hand: HumanoidArm::Left,
|
||||||
|
text_filtering_enabled: true,
|
||||||
|
allows_listing: true,
|
||||||
|
particle_status: ParticleStatus::Decreased,
|
||||||
|
};
|
||||||
|
let mut buf = Vec::new();
|
||||||
|
data.write_into(&mut buf).unwrap();
|
||||||
|
let mut data_cursor: Cursor<&[u8]> = Cursor::new(&buf);
|
||||||
|
|
||||||
|
let read_data = ClientInformation::read_from(&mut data_cursor).unwrap();
|
||||||
|
assert_eq!(read_data, data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ pub struct WriteConnection<W: ProtocolPacket> {
|
||||||
/// port: resolved_address.port(),
|
/// port: resolved_address.port(),
|
||||||
/// intention: ClientIntention::Login,
|
/// intention: ClientIntention::Login,
|
||||||
/// }
|
/// }
|
||||||
/// .get(),
|
/// .into_variant(),
|
||||||
/// )
|
/// )
|
||||||
/// .await?;
|
/// .await?;
|
||||||
///
|
///
|
||||||
|
@ -96,7 +96,7 @@ pub struct WriteConnection<W: ProtocolPacket> {
|
||||||
/// name: "bot".to_string(),
|
/// name: "bot".to_string(),
|
||||||
/// profile_id: uuid::Uuid::nil(),
|
/// profile_id: uuid::Uuid::nil(),
|
||||||
/// }
|
/// }
|
||||||
/// .get(),
|
/// .into_variant(),
|
||||||
/// )
|
/// )
|
||||||
/// .await?;
|
/// .await?;
|
||||||
///
|
///
|
||||||
|
@ -111,7 +111,7 @@ pub struct WriteConnection<W: ProtocolPacket> {
|
||||||
/// key_bytes: e.encrypted_public_key,
|
/// key_bytes: e.encrypted_public_key,
|
||||||
/// encrypted_challenge: e.encrypted_challenge,
|
/// encrypted_challenge: e.encrypted_challenge,
|
||||||
/// }
|
/// }
|
||||||
/// .get(),
|
/// .into_variant(),
|
||||||
/// )
|
/// )
|
||||||
/// .await?;
|
/// .await?;
|
||||||
/// conn.set_encryption_key(e.secret_key);
|
/// conn.set_encryption_key(e.secret_key);
|
||||||
|
@ -414,7 +414,7 @@ impl Connection<ClientboundLoginPacket, ServerboundLoginPacket> {
|
||||||
/// ServerboundKeyPacket {
|
/// ServerboundKeyPacket {
|
||||||
/// key_bytes: e.encrypted_public_key,
|
/// key_bytes: e.encrypted_public_key,
|
||||||
/// encrypted_challenge: e.encrypted_challenge,
|
/// encrypted_challenge: e.encrypted_challenge,
|
||||||
/// }.get()
|
/// }.into_variant()
|
||||||
/// ).await?;
|
/// ).await?;
|
||||||
/// conn.set_encryption_key(e.secret_key);
|
/// conn.set_encryption_key(e.secret_key);
|
||||||
/// }
|
/// }
|
||||||
|
|
|
@ -122,7 +122,7 @@ mod tests {
|
||||||
name: "test".to_string(),
|
name: "test".to_string(),
|
||||||
profile_id: Uuid::nil(),
|
profile_id: Uuid::nil(),
|
||||||
}
|
}
|
||||||
.get();
|
.into_variant();
|
||||||
let mut stream = Vec::new();
|
let mut stream = Vec::new();
|
||||||
write_packet(&packet, &mut stream, None, &mut None)
|
write_packet(&packet, &mut stream, None, &mut None)
|
||||||
.await
|
.await
|
||||||
|
@ -130,10 +130,14 @@ mod tests {
|
||||||
|
|
||||||
let mut stream = Cursor::new(stream);
|
let mut stream = Cursor::new(stream);
|
||||||
|
|
||||||
let _ =
|
let _ = read_packet::<ServerboundLoginPacket, _>(
|
||||||
read::<ServerboundLoginPacket, _>(&mut stream, &mut BytesMut::new(), None, &mut None)
|
&mut stream,
|
||||||
.await
|
&mut BytesMut::new(),
|
||||||
.unwrap();
|
None,
|
||||||
|
&mut None,
|
||||||
|
)
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
@ -142,7 +146,7 @@ mod tests {
|
||||||
name: "test".to_string(),
|
name: "test".to_string(),
|
||||||
profile_id: Uuid::nil(),
|
profile_id: Uuid::nil(),
|
||||||
}
|
}
|
||||||
.get();
|
.into_variant();
|
||||||
let mut stream = Vec::new();
|
let mut stream = Vec::new();
|
||||||
write_packet(&packet, &mut stream, None, &mut None)
|
write_packet(&packet, &mut stream, None, &mut None)
|
||||||
.await
|
.await
|
||||||
|
@ -154,10 +158,10 @@ mod tests {
|
||||||
|
|
||||||
let mut buffer = BytesMut::new();
|
let mut buffer = BytesMut::new();
|
||||||
|
|
||||||
let _ = read::<ServerboundLoginPacket, _>(&mut stream, &mut buffer, None, &mut None)
|
let _ = read_packet::<ServerboundLoginPacket, _>(&mut stream, &mut buffer, None, &mut None)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
let _ = read::<ServerboundLoginPacket, _>(&mut stream, &mut buffer, None, &mut None)
|
let _ = read_packet::<ServerboundLoginPacket, _>(&mut stream, &mut buffer, None, &mut None)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
}
|
}
|
||||||
|
@ -174,7 +178,7 @@ mod tests {
|
||||||
signature: None,
|
signature: None,
|
||||||
last_seen_messages: LastSeenMessagesUpdate::default(),
|
last_seen_messages: LastSeenMessagesUpdate::default(),
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
)
|
)
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
|
|
@ -7,53 +7,3 @@ use crate::common::ClientInformation;
|
||||||
pub struct ServerboundClientInformation {
|
pub struct ServerboundClientInformation {
|
||||||
pub information: ClientInformation,
|
pub information: ClientInformation,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
|
||||||
mod tests {
|
|
||||||
use std::io::Cursor;
|
|
||||||
|
|
||||||
use azalea_buf::{McBufReadable, McBufWritable};
|
|
||||||
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_client_information_packet() {
|
|
||||||
{
|
|
||||||
let data = ClientInformation::default();
|
|
||||||
let mut buf = Vec::new();
|
|
||||||
data.write_into(&mut buf).unwrap();
|
|
||||||
let mut data_cursor: Cursor<&[u8]> = Cursor::new(&buf);
|
|
||||||
|
|
||||||
let read_data = ClientInformation::read_from(&mut data_cursor).unwrap();
|
|
||||||
assert_eq!(read_data, data);
|
|
||||||
}
|
|
||||||
|
|
||||||
{
|
|
||||||
let data = ClientInformation {
|
|
||||||
language: "en_gb".to_string(),
|
|
||||||
view_distance: 24,
|
|
||||||
chat_visibility: ChatVisibility::Hidden,
|
|
||||||
chat_colors: false,
|
|
||||||
model_customization: ModelCustomization {
|
|
||||||
cape: false,
|
|
||||||
jacket: false,
|
|
||||||
left_sleeve: true,
|
|
||||||
right_sleeve: false,
|
|
||||||
left_pants: true,
|
|
||||||
right_pants: false,
|
|
||||||
hat: true,
|
|
||||||
},
|
|
||||||
main_hand: HumanoidArm::Left,
|
|
||||||
text_filtering_enabled: true,
|
|
||||||
allows_listing: true,
|
|
||||||
particle_status: ParticleStatus::Decreased,
|
|
||||||
};
|
|
||||||
let mut buf = Vec::new();
|
|
||||||
data.write_into(&mut buf).unwrap();
|
|
||||||
let mut data_cursor: Cursor<&[u8]> = Cursor::new(&buf);
|
|
||||||
|
|
||||||
let read_data = ClientInformation::read_from(&mut data_cursor).unwrap();
|
|
||||||
assert_eq!(read_data, data);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -128,8 +128,8 @@ pub enum BrigadierParser {
|
||||||
ScoreHolder { allows_multiple: bool },
|
ScoreHolder { allows_multiple: bool },
|
||||||
Swizzle,
|
Swizzle,
|
||||||
Team,
|
Team,
|
||||||
ItemStack,
|
ItemSlot,
|
||||||
ItemStacks,
|
ItemSlots,
|
||||||
ResourceLocation,
|
ResourceLocation,
|
||||||
Function,
|
Function,
|
||||||
EntityAnchor,
|
EntityAnchor,
|
||||||
|
|
|
@ -160,7 +160,7 @@ mod tests {
|
||||||
};
|
};
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
packet.write_into(&mut buf).unwrap();
|
packet.write_into(&mut buf).unwrap();
|
||||||
let packet2 = ClientboundExplodePacket::read_from(&mut Cursor::new(&buf)).unwrap();
|
let packet2 = ClientboundExplode::read_from(&mut Cursor::new(&buf)).unwrap();
|
||||||
assert_eq!(packet, packet2);
|
assert_eq!(packet, packet2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -33,7 +33,7 @@ mod tests {
|
||||||
][..];
|
][..];
|
||||||
let mut bytes = Cursor::new(slice);
|
let mut bytes = Cursor::new(slice);
|
||||||
|
|
||||||
let _packet = ClientboundLevelParticlesPacket::read_from(&mut bytes).unwrap();
|
let _packet = ClientboundLevelParticles::read_from(&mut bytes).unwrap();
|
||||||
assert_eq!(bytes.position(), slice.len() as u64);
|
assert_eq!(bytes.position(), slice.len() as u64);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -308,6 +308,6 @@ mod tests {
|
||||||
0,
|
0,
|
||||||
][..],
|
][..],
|
||||||
);
|
);
|
||||||
let _packet = ClientboundPlayerInfoUpdatePacket::read_from(&mut bytes).unwrap();
|
let _packet = ClientboundPlayerInfoUpdate::read_from(&mut bytes).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,7 +22,7 @@ mod tests {
|
||||||
let mut bytes = Cursor::new(&[
|
let mut bytes = Cursor::new(&[
|
||||||
10, 9, 0, 5, 101, 120, 116, 114, 97, 10, 0, 0, 0, 3, 1, 0, 4, 98, 111, 108, 100, 1, 8, 0, 4, 116, 101, 120, 116, 0, 16, 50, 66, 85, 73, 76, 68, 69, 82, 83, 50, 84, 79, 79, 76, 83, 10, 8, 0, 5, 99, 111, 108, 111, 114, 0, 4, 103, 114, 97, 121, 0, 8, 0, 0, 0, 1, 10, 0, 8, 0, 5, 99, 111, 108, 111, 114, 0, 4, 103, 111, 108, 100, 8, 0, 4, 116, 101, 120, 116, 0, 27, 80, 101, 110, 100, 105, 110, 103, 32, 99, 111, 110, 110, 101, 99, 116, 105, 111, 110, 32, 116, 111, 32, 50, 98, 50, 116, 10, 0, 8, 0, 4, 116, 101, 120, 116, 0, 1, 10, 0, 10, 9, 0, 5, 101, 120, 116, 114, 97, 10, 0, 0, 0, 1, 8, 0, 5, 99, 111, 108, 111, 114, 0, 4, 103, 111, 108, 100, 8, 0, 4, 116, 101, 120, 116, 0, 72, 84, 104, 105, 115, 32, 97, 99, 99, 111, 117, 110, 116, 32, 104, 97, 115, 32, 112, 114, 105, 111, 114, 105, 116, 121, 32, 115, 116, 97, 116, 117, 115, 32, 97, 110, 100, 32, 119, 105, 108, 108, 32, 98, 101, 32, 112, 108, 97, 99, 101, 100, 32, 105, 110, 32, 97, 32, 115, 104, 111, 114, 116, 101, 114, 32, 113, 117, 101, 117, 101, 46, 10, 0, 8, 0, 4, 116, 101, 120, 116, 0, 1, 10, 0
|
10, 9, 0, 5, 101, 120, 116, 114, 97, 10, 0, 0, 0, 3, 1, 0, 4, 98, 111, 108, 100, 1, 8, 0, 4, 116, 101, 120, 116, 0, 16, 50, 66, 85, 73, 76, 68, 69, 82, 83, 50, 84, 79, 79, 76, 83, 10, 8, 0, 5, 99, 111, 108, 111, 114, 0, 4, 103, 114, 97, 121, 0, 8, 0, 0, 0, 1, 10, 0, 8, 0, 5, 99, 111, 108, 111, 114, 0, 4, 103, 111, 108, 100, 8, 0, 4, 116, 101, 120, 116, 0, 27, 80, 101, 110, 100, 105, 110, 103, 32, 99, 111, 110, 110, 101, 99, 116, 105, 111, 110, 32, 116, 111, 32, 50, 98, 50, 116, 10, 0, 8, 0, 4, 116, 101, 120, 116, 0, 1, 10, 0, 10, 9, 0, 5, 101, 120, 116, 114, 97, 10, 0, 0, 0, 1, 8, 0, 5, 99, 111, 108, 111, 114, 0, 4, 103, 111, 108, 100, 8, 0, 4, 116, 101, 120, 116, 0, 72, 84, 104, 105, 115, 32, 97, 99, 99, 111, 117, 110, 116, 32, 104, 97, 115, 32, 112, 114, 105, 111, 114, 105, 116, 121, 32, 115, 116, 97, 116, 117, 115, 32, 97, 110, 100, 32, 119, 105, 108, 108, 32, 98, 101, 32, 112, 108, 97, 99, 101, 100, 32, 105, 110, 32, 97, 32, 115, 104, 111, 114, 116, 101, 114, 32, 113, 117, 101, 117, 101, 46, 10, 0, 8, 0, 4, 116, 101, 120, 116, 0, 1, 10, 0
|
||||||
][..]);
|
][..]);
|
||||||
let _packet = ClientboundTabListPacket::read_from(&mut bytes).unwrap();
|
let _packet = ClientboundTabList::read_from(&mut bytes).unwrap();
|
||||||
assert!(bytes.get_ref()[bytes.position() as usize..].is_empty());
|
assert!(bytes.get_ref()[bytes.position() as usize..].is_empty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1504,8 +1504,8 @@ enum CommandArgumentKind {
|
||||||
ScoreHolder => "minecraft:score_holder",
|
ScoreHolder => "minecraft:score_holder",
|
||||||
Swizzle => "minecraft:swizzle",
|
Swizzle => "minecraft:swizzle",
|
||||||
Team => "minecraft:team",
|
Team => "minecraft:team",
|
||||||
ItemStack => "minecraft:item_slot",
|
ItemSlot => "minecraft:item_slot",
|
||||||
ItemStacks => "minecraft:item_slots",
|
ItemSlots => "minecraft:item_slots",
|
||||||
ResourceLocation => "minecraft:resource_location",
|
ResourceLocation => "minecraft:resource_location",
|
||||||
Function => "minecraft:function",
|
Function => "minecraft:function",
|
||||||
EntityAnchor => "minecraft:entity_anchor",
|
EntityAnchor => "minecraft:entity_anchor",
|
||||||
|
|
|
@ -36,7 +36,7 @@ fn accept_resource_pack(
|
||||||
id: event.id,
|
id: event.id,
|
||||||
action: s_resource_pack::Action::Accepted,
|
action: s_resource_pack::Action::Accepted,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
});
|
});
|
||||||
send_packet_events.send(SendPacketEvent {
|
send_packet_events.send(SendPacketEvent {
|
||||||
entity: event.entity,
|
entity: event.entity,
|
||||||
|
@ -44,7 +44,7 @@ fn accept_resource_pack(
|
||||||
id: event.id,
|
id: event.id,
|
||||||
action: s_resource_pack::Action::SuccessfullyLoaded,
|
action: s_resource_pack::Action::SuccessfullyLoaded,
|
||||||
}
|
}
|
||||||
.get(),
|
.into_variant(),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue