diff options
| author | Luis <luis@lu15.dev> | 2024-04-27 07:03:20 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-04-27 01:03:20 -0500 |
| commit | 6553d9510ddc52469dd7557aa9675982cb5187ab (patch) | |
| tree | e2d0cc0e36be8b2d4be5857c2790cb79eb84dece /azalea-protocol/src/packets/mod.rs | |
| parent | 84f66a55a5e5b1618111e522c25704ac96d45806 (diff) | |
| download | azalea-drasl-6553d9510ddc52469dd7557aa9675982cb5187ab.tar.xz | |
Use ClientIntention over ConnectionProtocol for ClientIntentionPacket (#143)
* fix!: use ClientIntention over ConnectionProtocol for ClientIntentionPacket
* chore: remove McBufRead/Writable from ConnectionProtocol
* chore: use From over Into for ClientIntention to ConnectionProtocol conversion
* chore: organise imports in existing style
Diffstat (limited to 'azalea-protocol/src/packets/mod.rs')
| -rwxr-xr-x | azalea-protocol/src/packets/mod.rs | 37 |
1 files changed, 33 insertions, 4 deletions
diff --git a/azalea-protocol/src/packets/mod.rs b/azalea-protocol/src/packets/mod.rs index 63a0c1c9..044bb56c 100755 --- a/azalea-protocol/src/packets/mod.rs +++ b/azalea-protocol/src/packets/mod.rs @@ -50,15 +50,44 @@ where fn write(&self, buf: &mut impl Write) -> Result<(), std::io::Error>; } -impl azalea_buf::McBufReadable for ConnectionProtocol { +#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] +pub enum ClientIntention { + Status = 1, + Login = 2, + Transfer = 3 +} + +impl TryFrom<i32> for ClientIntention { + type Error = (); + + fn try_from(value: i32) -> Result<Self, Self::Error> { + match value { + 1 => Ok(ClientIntention::Status), + 2 => Ok(ClientIntention::Login), + 3 => Ok(ClientIntention::Transfer), + _ => Err(()), + } + } +} + +impl From<ClientIntention> for ConnectionProtocol { + fn from(intention: ClientIntention) -> Self { + match intention { + ClientIntention::Status => ConnectionProtocol::Status, + ClientIntention::Login | ClientIntention::Transfer => ConnectionProtocol::Login, + } + } +} + +impl azalea_buf::McBufReadable for ClientIntention { fn read_from(buf: &mut Cursor<&[u8]>) -> Result<Self, BufReadError> { let id = i32::var_read_from(buf)?; - ConnectionProtocol::from_i32(id).ok_or(BufReadError::UnexpectedEnumVariant { id }) + id.try_into().map_err(|_| BufReadError::UnexpectedEnumVariant { id }) } } -impl McBufWritable for ConnectionProtocol { +impl McBufWritable for ClientIntention { fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { (*self as i32).var_write_into(buf) } -} +}
\ No newline at end of file |
