1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00

delete packet-macros

This commit is contained in:
mat 2021-12-12 13:48:37 -06:00
parent 1286286e83
commit ec03abfe69
3 changed files with 0 additions and 159 deletions

View file

@ -11,7 +11,6 @@ async-trait = "0.1.51"
byteorder = "^1.4.3" byteorder = "^1.4.3"
bytes = "^1.1.0" bytes = "^1.1.0"
minecraft-chat = {path = "../minecraft-chat"} minecraft-chat = {path = "../minecraft-chat"}
packet-macros = {path = "./packet-macros"}
serde = {version = "1.0.130", features = ["serde_derive"]} serde = {version = "1.0.130", features = ["serde_derive"]}
serde_json = "^1.0.72" serde_json = "^1.0.72"
thiserror = "^1.0.30" thiserror = "^1.0.30"

View file

@ -1,13 +0,0 @@
[package]
edition = "2021"
name = "packet-macros"
version = "0.1.0"
[lib]
proc-macro = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
casey = "^0.3.3"
quote = "^1.0.10"
syn = "^1.0.82"

View file

@ -1,145 +0,0 @@
use casey::{pascal, snake};
extern crate proc_macro;
use proc_macro::TokenStream;
use quote::quote;
use syn::{
self,
parse::{Parse, ParseStream},
parse_macro_input, DeriveInput, Signature,
};
// #[derive(Clone, Debug)]
// pub enum Packet {
// // game
// // handshake
// ClientIntentionPacket(handshake::client_intention_packet::ClientIntentionPacket),
// // login
// // status
// ServerboundStatusRequestPacket(
// status::serverbound_status_request_packet::ServerboundStatusRequestPacket,
// ),
// ClientboundStatusResponsePacket(
// status::clientbound_status_response_packet::ClientboundStatusResponsePacket,
// ),
// }
// // TODO: do all this with macros so it's less repetitive
// impl Packet {
// fn get_inner_packet(&self) -> &dyn PacketTrait {
// match self {
// Packet::ClientIntentionPacket(packet) => packet,
// Packet::ServerboundStatusRequestPacket(packet) => packet,
// Packet::ClientboundStatusResponsePacket(packet) => packet,
// }
// }
// pub fn id(&self) -> u32 {
// match self {
// Packet::ClientIntentionPacket(_packet) => 0x00,
// Packet::ServerboundStatusRequestPacket(_packet) => 0x00,
// Packet::ClientboundStatusResponsePacket(_packet) => 0x00,
// }
// }
// /// Read a packet by its id, ConnectionProtocol, and flow
// pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
// id: u32,
// protocol: &ConnectionProtocol,
// flow: &PacketFlow,
// buf: &mut BufReader<T>,
// ) -> Result<Packet, String> {
// match protocol {
// ConnectionProtocol::Handshake => match id {
// 0x00 => Ok(
// handshake::client_intention_packet::ClientIntentionPacket::read(buf).await?,
// ),
// _ => Err(format!("Unknown packet id: {}", id)),
// },
// ConnectionProtocol::Game => Err("Game protocol not implemented yet".to_string()),
// ConnectionProtocol::Status => match flow {
// PacketFlow::ServerToClient => match id {
// 0x00 => Ok(
// status::clientbound_status_response_packet::ClientboundStatusResponsePacket
// ::read(buf)
// .await?,
// ),
// _ => Err(format!("Unknown packet id: {}", id)),
// },
// PacketFlow::ClientToServer => match id {
// 0x00 => Ok(
// status::serverbound_status_request_packet::ServerboundStatusRequestPacket
// ::read(buf)
// .await?,
// ),
// _ => Err(format!("Unknown packet id: {}", id)),
// },
// },
// ConnectionProtocol::Login => Err("Login protocol not implemented yet".to_string()),
// }
// }
// pub fn write(&self, buf: &mut Vec<u8>) {
// self.get_inner_packet().write(buf);
// }
// }
struct RegisterPacket {
name: syn::Ident,
connection_protocol: syn::Ident,
flow: syn::Ident,
}
struct RegisterPackets {
packets: Vec<RegisterPacket>,
}
impl Parse for RegisterPackets {
fn parse(input: ParseStream) -> syn::Result<Self> {
let packets = vec![];
loop {
let name: syn::Ident = input.parse()?;
input.parse::<syn::Token![=>]>()?;
let connection_protocol: syn::Ident = input.parse()?;
input.parse::<syn::Token![,]>()?;
let flow: syn::Ident = input.parse()?;
input.parse::<syn::Token![;]>()?;
packets.push(RegisterPacket {
name,
connection_protocol,
flow,
});
if input.is_empty() {
break;
}
}
Ok(RegisterPackets { packets })
}
}
#[proc_macro]
pub fn register_packets(input: TokenStream) -> TokenStream {
let RegisterPackets { packets } = syn::parse_macro_input!(input as RegisterPackets);
// ClientIntentionPacket(handshake::client_intention_packet::ClientIntentionPacket),
let gen = quote! {
// #[derive(Clone, Debug)]
// pub enum Packet {
// // ClientIntentionPacket(handshake::client_intention_packet::ClientIntentionPacket),
// // ClientboundStatusResponsePacket(
// // status::clientbound_status_response_packet::ClientboundStatusResponsePacket,
// // ),
// }
};
gen.into()
}