mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 06:16:04 +00:00
add macro for a couple more packets
This commit is contained in:
parent
a1afbb6031
commit
3ec7352da2
5 changed files with 5 additions and 65 deletions
|
@ -1,5 +1,5 @@
|
|||
use quote::{quote, quote_spanned, ToTokens};
|
||||
use syn::{self, parse_macro_input, spanned::Spanned, DeriveInput, FieldsNamed};
|
||||
use quote::{quote, ToTokens};
|
||||
use syn::{self, parse_macro_input, DeriveInput, FieldsNamed};
|
||||
|
||||
fn as_packet_derive(
|
||||
input: proc_macro::TokenStream,
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use crate::mc_buf::{Readable, Writable};
|
||||
use crate::packets::game::GamePacket;
|
||||
use azalea_core::resource_location::ResourceLocation;
|
||||
use packet_macros::GamePacket;
|
||||
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
// i don't know the actual name of this packet, i couldn't find it in the source code!
|
||||
|
||||
use super::GamePacket;
|
||||
use crate::mc_buf::{Readable, Writable};
|
||||
use packet_macros::GamePacket;
|
||||
|
||||
|
|
|
@ -14,35 +14,3 @@ pub struct ClientIntentionPacket {
|
|||
pub port: u16,
|
||||
pub intention: ConnectionProtocol,
|
||||
}
|
||||
|
||||
// impl ClientIntentionPacket {
|
||||
// pub fn get(self) -> HandshakePacket {
|
||||
// HandshakePacket::ClientIntentionPacket(self)
|
||||
// }
|
||||
|
||||
// pub fn write(&self, buf: &mut Vec<u8>) {
|
||||
// buf.write_varint(self.protocol_version as i32).unwrap();
|
||||
// buf.write_utf(&self.hostname).unwrap();
|
||||
// buf.write_short(self.port).unwrap();
|
||||
// buf.write_varint(self.intention.clone() as i32).unwrap();
|
||||
// }
|
||||
|
||||
// pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
|
||||
// buf: &mut T,
|
||||
// ) -> Result<HandshakePacket, String> {
|
||||
// let protocol_version = buf.read_varint().await? as u32;
|
||||
// let hostname = buf.read_utf().await?;
|
||||
// let port = buf.read_short().await? as u16;
|
||||
// let intention = buf.read_varint().await?;
|
||||
|
||||
// Ok(HandshakePacket::ClientIntentionPacket(
|
||||
// ClientIntentionPacket {
|
||||
// protocol_version,
|
||||
// hostname,
|
||||
// port,
|
||||
// intention: ConnectionProtocol::from_i32(intention)
|
||||
// .ok_or_else(|| "Invalid intention".to_string())?,
|
||||
// },
|
||||
// ))
|
||||
// }
|
||||
// }
|
||||
|
|
|
@ -1,38 +1,12 @@
|
|||
use super::LoginPacket;
|
||||
use crate::mc_buf::{Readable, Writable};
|
||||
use azalea_core::resource_location::ResourceLocation;
|
||||
use packet_macros::LoginPacket;
|
||||
use std::hash::Hash;
|
||||
|
||||
#[derive(Hash, Clone, Debug)]
|
||||
#[derive(Hash, Clone, Debug, LoginPacket)]
|
||||
pub struct ClientboundCustomQueryPacket {
|
||||
#[varint]
|
||||
pub transaction_id: u32,
|
||||
pub identifier: ResourceLocation,
|
||||
pub data: Vec<u8>,
|
||||
}
|
||||
|
||||
impl ClientboundCustomQueryPacket {
|
||||
pub fn get(self) -> LoginPacket {
|
||||
LoginPacket::ClientboundCustomQueryPacket(self)
|
||||
}
|
||||
|
||||
pub fn write(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
|
||||
buf.write_varint(self.transaction_id as i32).unwrap();
|
||||
buf.write_utf(self.identifier.to_string().as_str()).unwrap();
|
||||
buf.write_bytes(&self.data).unwrap();
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
|
||||
buf: &mut T,
|
||||
) -> Result<LoginPacket, String> {
|
||||
let transaction_id = buf.read_varint().await? as u32;
|
||||
let identifier = ResourceLocation::new(&buf.read_utf().await?)?;
|
||||
let data = buf.read_bytes_with_len(1048576).await?;
|
||||
Ok(ClientboundCustomQueryPacket {
|
||||
transaction_id,
|
||||
identifier,
|
||||
data,
|
||||
}
|
||||
.get())
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue