aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2021-12-10 16:16:59 +0000
committermat <github@matdoes.dev>2021-12-10 16:16:59 +0000
commitf6a3f088ac1cd9526e6b93e03ea9929658478565 (patch)
treecbed70ca68f6009a7efe4c958e730ec9229ee4cf
parentbe762fc5d37ba48386996afb4c5ba0c94aaf5883 (diff)
downloadazalea-drasl-f6a3f088ac1cd9526e6b93e03ea9929658478565.tar.xz
it compiles
-rw-r--r--minecraft-protocol/src/connection.rs2
-rw-r--r--minecraft-protocol/src/packets/handshake/client_intention_packet.rs14
-rw-r--r--minecraft-protocol/src/packets/mod.rs13
-rw-r--r--minecraft-protocol/src/packets/status/clientbound_status_response_packet.rs9
-rw-r--r--minecraft-protocol/src/packets/status/serverbound_status_request_packet.rs8
-rw-r--r--minecraft-protocol/src/server_status_pinger.rs2
6 files changed, 24 insertions, 24 deletions
diff --git a/minecraft-protocol/src/connection.rs b/minecraft-protocol/src/connection.rs
index ba27cdad..d5cee708 100644
--- a/minecraft-protocol/src/connection.rs
+++ b/minecraft-protocol/src/connection.rs
@@ -72,7 +72,7 @@ impl Connection {
}
/// 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
// packet structure:
diff --git a/minecraft-protocol/src/packets/handshake/client_intention_packet.rs b/minecraft-protocol/src/packets/handshake/client_intention_packet.rs
index 401dbbac..0f14ed48 100644
--- a/minecraft-protocol/src/packets/handshake/client_intention_packet.rs
+++ b/minecraft-protocol/src/packets/handshake/client_intention_packet.rs
@@ -8,19 +8,19 @@ use crate::{
packets::{ConnectionProtocol, Packet, PacketTrait},
};
-#[derive(Hash)]
-pub struct ClientIntentionPacket<'a> {
+#[derive(Hash, Clone)]
+pub struct ClientIntentionPacket {
pub protocol_version: u32,
- pub hostname: &'a String,
+ pub hostname: String,
pub port: u16,
/// 1 for status, 2 for login
pub intention: ConnectionProtocol,
}
#[async_trait]
-impl<'a> PacketTrait for ClientIntentionPacket<'a> {
- fn get(&self) -> Packet {
- Packet::ClientIntentionPacket(*self)
+impl PacketTrait for ClientIntentionPacket {
+ fn get(self) -> Packet {
+ Packet::ClientIntentionPacket(self)
}
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>(
buf: &mut BufReader<T>,
- ) -> Result<Packet<'_>, String> {
+ ) -> Result<Packet, String> {
Err("ClientIntentionPacket::parse not implemented".to_string())
// Ok(ClientIntentionPacket {}.get())
}
diff --git a/minecraft-protocol/src/packets/mod.rs b/minecraft-protocol/src/packets/mod.rs
index 76f9128e..0d8b6883 100644
--- a/minecraft-protocol/src/packets/mod.rs
+++ b/minecraft-protocol/src/packets/mod.rs
@@ -16,11 +16,12 @@ pub enum ConnectionProtocol {
Login = 2,
}
-pub enum Packet<'a> {
+#[derive(Clone)]
+pub enum Packet {
// game
// handshake
- ClientIntentionPacket(handshake::client_intention_packet::ClientIntentionPacket<'a>),
+ ClientIntentionPacket(handshake::client_intention_packet::ClientIntentionPacket),
// login
@@ -34,7 +35,7 @@ pub enum Packet<'a> {
}
// TODO: do all this with macros so it's less repetitive
-impl Packet<'_> {
+impl Packet {
fn get_inner_packet(&self) -> &dyn PacketTrait {
match self {
Packet::ClientIntentionPacket(packet) => packet,
@@ -57,7 +58,7 @@ impl Packet<'_> {
protocol: ConnectionProtocol,
flow: PacketFlow,
buf: &mut BufReader<T>,
- ) -> Result<Packet<'_>, String> {
+ ) -> Result<Packet, String> {
match protocol {
ConnectionProtocol::Handshake => match id {
0x00 => Ok(
@@ -96,11 +97,11 @@ impl Packet<'_> {
#[async_trait]
pub trait PacketTrait {
/// 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>) -> ();
async fn read<T: AsyncRead + std::marker::Unpin + std::marker::Send>(
buf: &mut BufReader<T>,
- ) -> Result<Packet<'_>, String>
+ ) -> Result<Packet, String>
where
Self: Sized;
}
diff --git a/minecraft-protocol/src/packets/status/clientbound_status_response_packet.rs b/minecraft-protocol/src/packets/status/clientbound_status_response_packet.rs
index 38747cc8..28ac9b16 100644
--- a/minecraft-protocol/src/packets/status/clientbound_status_response_packet.rs
+++ b/minecraft-protocol/src/packets/status/clientbound_status_response_packet.rs
@@ -14,18 +14,17 @@ pub struct ClientboundStatusResponsePacket {
#[async_trait]
impl PacketTrait for ClientboundStatusResponsePacket {
- fn get(&self) -> Packet {
- Packet::ClientboundStatusResponsePacket(self.clone())
+ fn get(self) -> Packet {
+ Packet::ClientboundStatusResponsePacket(self)
}
fn write(&self, _buf: &mut Vec<u8>) {}
async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
buf: &mut BufReader<T>,
- ) -> Result<Packet<'_>, String> {
+ ) -> Result<Packet, String> {
let status = mc_buf::read_utf(buf).await?;
// this.status = GsonHelper.fromJson(GSON, friendlyByteBuf.readUtf(32767), ServerStatus.class);
- let packet = ClientboundStatusResponsePacket { status }.get();
- Ok(packet)
+ Ok(ClientboundStatusResponsePacket { status }.get())
}
}
diff --git a/minecraft-protocol/src/packets/status/serverbound_status_request_packet.rs b/minecraft-protocol/src/packets/status/serverbound_status_request_packet.rs
index b3c87968..1a301a4d 100644
--- a/minecraft-protocol/src/packets/status/serverbound_status_request_packet.rs
+++ b/minecraft-protocol/src/packets/status/serverbound_status_request_packet.rs
@@ -7,19 +7,19 @@ use crate::{
packets::{Packet, PacketTrait},
};
-#[derive(Hash)]
+#[derive(Hash, Clone)]
pub struct ServerboundStatusRequestPacket {}
#[async_trait]
impl PacketTrait for ServerboundStatusRequestPacket {
- fn get(&self) -> Packet {
- Packet::ServerboundStatusRequestPacket(*self)
+ fn get(self) -> Packet {
+ Packet::ServerboundStatusRequestPacket(self)
}
fn write(&self, _buf: &mut Vec<u8>) {}
async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
buf: &mut BufReader<T>,
- ) -> Result<Packet<'_>, String> {
+ ) -> Result<Packet, String> {
Err("ServerboundStatusRequestPacket::read not implemented".to_string())
}
}
diff --git a/minecraft-protocol/src/server_status_pinger.rs b/minecraft-protocol/src/server_status_pinger.rs
index 1e523511..a86be553 100644
--- a/minecraft-protocol/src/server_status_pinger.rs
+++ b/minecraft-protocol/src/server_status_pinger.rs
@@ -20,7 +20,7 @@ pub async fn ping_server(address: &ServerAddress) -> Result<(), String> {
conn.send_packet(
ClientIntentionPacket {
protocol_version: 757,
- hostname: &address.host,
+ hostname: address.host.clone(),
port: address.port,
intention: ConnectionProtocol::Status,
}