mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
it compiles
This commit is contained in:
parent
be762fc5d3
commit
f6a3f088ac
6 changed files with 24 additions and 24 deletions
|
@ -72,7 +72,7 @@ impl Connection {
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Write a packet to the server
|
/// Write a packet to the server
|
||||||
pub async fn send_packet(&mut self, packet: Packet<'_>) {
|
pub async fn send_packet(&mut self, packet: Packet) {
|
||||||
// TODO: implement compression
|
// TODO: implement compression
|
||||||
|
|
||||||
// packet structure:
|
// packet structure:
|
||||||
|
|
|
@ -8,19 +8,19 @@ use crate::{
|
||||||
packets::{ConnectionProtocol, Packet, PacketTrait},
|
packets::{ConnectionProtocol, Packet, PacketTrait},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Hash)]
|
#[derive(Hash, Clone)]
|
||||||
pub struct ClientIntentionPacket<'a> {
|
pub struct ClientIntentionPacket {
|
||||||
pub protocol_version: u32,
|
pub protocol_version: u32,
|
||||||
pub hostname: &'a String,
|
pub hostname: String,
|
||||||
pub port: u16,
|
pub port: u16,
|
||||||
/// 1 for status, 2 for login
|
/// 1 for status, 2 for login
|
||||||
pub intention: ConnectionProtocol,
|
pub intention: ConnectionProtocol,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl<'a> PacketTrait for ClientIntentionPacket<'a> {
|
impl PacketTrait for ClientIntentionPacket {
|
||||||
fn get(&self) -> Packet {
|
fn get(self) -> Packet {
|
||||||
Packet::ClientIntentionPacket(*self)
|
Packet::ClientIntentionPacket(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write(&self, buf: &mut Vec<u8>) {
|
fn write(&self, buf: &mut Vec<u8>) {
|
||||||
|
@ -32,7 +32,7 @@ impl<'a> PacketTrait for ClientIntentionPacket<'a> {
|
||||||
|
|
||||||
async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
|
async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
|
||||||
buf: &mut BufReader<T>,
|
buf: &mut BufReader<T>,
|
||||||
) -> Result<Packet<'_>, String> {
|
) -> Result<Packet, String> {
|
||||||
Err("ClientIntentionPacket::parse not implemented".to_string())
|
Err("ClientIntentionPacket::parse not implemented".to_string())
|
||||||
// Ok(ClientIntentionPacket {}.get())
|
// Ok(ClientIntentionPacket {}.get())
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,11 +16,12 @@ pub enum ConnectionProtocol {
|
||||||
Login = 2,
|
Login = 2,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub enum Packet<'a> {
|
#[derive(Clone)]
|
||||||
|
pub enum Packet {
|
||||||
// game
|
// game
|
||||||
|
|
||||||
// handshake
|
// handshake
|
||||||
ClientIntentionPacket(handshake::client_intention_packet::ClientIntentionPacket<'a>),
|
ClientIntentionPacket(handshake::client_intention_packet::ClientIntentionPacket),
|
||||||
|
|
||||||
// login
|
// login
|
||||||
|
|
||||||
|
@ -34,7 +35,7 @@ pub enum Packet<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: do all this with macros so it's less repetitive
|
// TODO: do all this with macros so it's less repetitive
|
||||||
impl Packet<'_> {
|
impl Packet {
|
||||||
fn get_inner_packet(&self) -> &dyn PacketTrait {
|
fn get_inner_packet(&self) -> &dyn PacketTrait {
|
||||||
match self {
|
match self {
|
||||||
Packet::ClientIntentionPacket(packet) => packet,
|
Packet::ClientIntentionPacket(packet) => packet,
|
||||||
|
@ -57,7 +58,7 @@ impl Packet<'_> {
|
||||||
protocol: ConnectionProtocol,
|
protocol: ConnectionProtocol,
|
||||||
flow: PacketFlow,
|
flow: PacketFlow,
|
||||||
buf: &mut BufReader<T>,
|
buf: &mut BufReader<T>,
|
||||||
) -> Result<Packet<'_>, String> {
|
) -> Result<Packet, String> {
|
||||||
match protocol {
|
match protocol {
|
||||||
ConnectionProtocol::Handshake => match id {
|
ConnectionProtocol::Handshake => match id {
|
||||||
0x00 => Ok(
|
0x00 => Ok(
|
||||||
|
@ -96,11 +97,11 @@ impl Packet<'_> {
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
pub trait PacketTrait {
|
pub trait PacketTrait {
|
||||||
/// Return a version of the packet that you can actually use for stuff
|
/// Return a version of the packet that you can actually use for stuff
|
||||||
fn get(&self) -> Packet;
|
fn get(self) -> Packet;
|
||||||
fn write(&self, buf: &mut Vec<u8>) -> ();
|
fn write(&self, buf: &mut Vec<u8>) -> ();
|
||||||
async fn read<T: AsyncRead + std::marker::Unpin + std::marker::Send>(
|
async fn read<T: AsyncRead + std::marker::Unpin + std::marker::Send>(
|
||||||
buf: &mut BufReader<T>,
|
buf: &mut BufReader<T>,
|
||||||
) -> Result<Packet<'_>, String>
|
) -> Result<Packet, String>
|
||||||
where
|
where
|
||||||
Self: Sized;
|
Self: Sized;
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,18 +14,17 @@ pub struct ClientboundStatusResponsePacket {
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl PacketTrait for ClientboundStatusResponsePacket {
|
impl PacketTrait for ClientboundStatusResponsePacket {
|
||||||
fn get(&self) -> Packet {
|
fn get(self) -> Packet {
|
||||||
Packet::ClientboundStatusResponsePacket(self.clone())
|
Packet::ClientboundStatusResponsePacket(self)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write(&self, _buf: &mut Vec<u8>) {}
|
fn write(&self, _buf: &mut Vec<u8>) {}
|
||||||
|
|
||||||
async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
|
async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
|
||||||
buf: &mut BufReader<T>,
|
buf: &mut BufReader<T>,
|
||||||
) -> Result<Packet<'_>, String> {
|
) -> Result<Packet, String> {
|
||||||
let status = mc_buf::read_utf(buf).await?;
|
let status = mc_buf::read_utf(buf).await?;
|
||||||
// this.status = GsonHelper.fromJson(GSON, friendlyByteBuf.readUtf(32767), ServerStatus.class);
|
// this.status = GsonHelper.fromJson(GSON, friendlyByteBuf.readUtf(32767), ServerStatus.class);
|
||||||
let packet = ClientboundStatusResponsePacket { status }.get();
|
Ok(ClientboundStatusResponsePacket { status }.get())
|
||||||
Ok(packet)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,19 +7,19 @@ use crate::{
|
||||||
packets::{Packet, PacketTrait},
|
packets::{Packet, PacketTrait},
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Hash)]
|
#[derive(Hash, Clone)]
|
||||||
pub struct ServerboundStatusRequestPacket {}
|
pub struct ServerboundStatusRequestPacket {}
|
||||||
|
|
||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl PacketTrait for ServerboundStatusRequestPacket {
|
impl PacketTrait for ServerboundStatusRequestPacket {
|
||||||
fn get(&self) -> Packet {
|
fn get(self) -> Packet {
|
||||||
Packet::ServerboundStatusRequestPacket(*self)
|
Packet::ServerboundStatusRequestPacket(self)
|
||||||
}
|
}
|
||||||
fn write(&self, _buf: &mut Vec<u8>) {}
|
fn write(&self, _buf: &mut Vec<u8>) {}
|
||||||
|
|
||||||
async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
|
async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
|
||||||
buf: &mut BufReader<T>,
|
buf: &mut BufReader<T>,
|
||||||
) -> Result<Packet<'_>, String> {
|
) -> Result<Packet, String> {
|
||||||
Err("ServerboundStatusRequestPacket::read not implemented".to_string())
|
Err("ServerboundStatusRequestPacket::read not implemented".to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,7 +20,7 @@ pub async fn ping_server(address: &ServerAddress) -> Result<(), String> {
|
||||||
conn.send_packet(
|
conn.send_packet(
|
||||||
ClientIntentionPacket {
|
ClientIntentionPacket {
|
||||||
protocol_version: 757,
|
protocol_version: 757,
|
||||||
hostname: &address.host,
|
hostname: address.host.clone(),
|
||||||
port: address.port,
|
port: address.port,
|
||||||
intention: ConnectionProtocol::Status,
|
intention: ConnectionProtocol::Status,
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue