Skip to content

Commit

Permalink
Rename Connection::configuration to config and add some clientbound f…
Browse files Browse the repository at this point in the history
…unctions that already existed serverbound

taken from Shay's fork: Shays-Forks@b0ca607
  • Loading branch information
mat-1 committed Jan 25, 2025
1 parent b6ddde9 commit fe42341
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 6 deletions.
2 changes: 1 addition & 1 deletion azalea-client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ impl Client {
p.game_profile
);
conn.write(ServerboundLoginAcknowledged {}).await?;
break (conn.configuration(), p.game_profile);
break (conn.config(), p.game_profile);
}
ClientboundLoginPacket::LoginDisconnect(p) => {
debug!("Got disconnect {:?}", p);
Expand Down
11 changes: 9 additions & 2 deletions azalea-protocol/azalea-protocol-macros/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ pub fn declare_state_packets(input: TokenStream) -> TokenStream {
}
}

/// Read a packet by its id, ConnectionProtocol, and flow
/// Read a packet by its id, ConnectionProtocol, and flow.
fn read(
id: u32,
buf: &mut std::io::Cursor<&[u8]>,
Expand Down Expand Up @@ -408,7 +408,7 @@ pub fn declare_state_packets(input: TokenStream) -> TokenStream {
}
}

/// Read a packet by its id, ConnectionProtocol, and flow
/// Read a packet by its id, ConnectionProtocol, and flow.
fn read(
id: u32,
buf: &mut std::io::Cursor<&[u8]>,
Expand All @@ -422,6 +422,13 @@ pub fn declare_state_packets(input: TokenStream) -> TokenStream {
})
}
}

impl crate::packets::Packet<#clientbound_state_name> for #clientbound_state_name {
/// No-op, exists so you can pass a packet enum when a Packet<> is expected.
fn into_variant(self) -> #clientbound_state_name {
self
}
}
});

contents.into()
Expand Down
13 changes: 10 additions & 3 deletions azalea-protocol/src/connect.rs
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ impl Connection<ClientboundLoginPacket, ServerboundLoginPacket> {
/// Change our state from login to configuration. This is the state where
/// the server sends us the registries and resource pack and stuff.
#[must_use]
pub fn configuration(self) -> Connection<ClientboundConfigPacket, ServerboundConfigPacket> {
pub fn config(self) -> Connection<ClientboundConfigPacket, ServerboundConfigPacket> {
Connection::from(self)
}

Expand Down Expand Up @@ -493,7 +493,7 @@ impl Connection<ServerboundLoginPacket, ClientboundLoginPacket> {

/// Change our state back to configuration.
#[must_use]
pub fn configuration(self) -> Connection<ServerboundConfigPacket, ClientboundConfigPacket> {
pub fn config(self) -> Connection<ServerboundConfigPacket, ClientboundConfigPacket> {
Connection::from(self)
}
}
Expand All @@ -519,7 +519,14 @@ impl Connection<ClientboundConfigPacket, ServerboundConfigPacket> {
impl Connection<ClientboundGamePacket, ServerboundGamePacket> {
/// Change our state back to configuration.
#[must_use]
pub fn configuration(self) -> Connection<ClientboundConfigPacket, ServerboundConfigPacket> {
pub fn config(self) -> Connection<ClientboundConfigPacket, ServerboundConfigPacket> {
Connection::from(self)
}
}
impl Connection<ServerboundGamePacket, ClientboundGamePacket> {
/// Change our state back to configuration.
#[must_use]
pub fn config(self) -> Connection<ServerboundConfigPacket, ClientboundConfigPacket> {
Connection::from(self)
}
}
Expand Down

0 comments on commit fe42341

Please sign in to comment.