diff options
| author | mat <github@matdoes.dev> | 2021-12-10 22:01:16 +0000 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2021-12-10 22:01:16 +0000 |
| commit | 5039f9668f3512240af22ac6bb49140012885509 (patch) | |
| tree | 5300ef44f66345a82b0a568be20db67384707d27 /minecraft-protocol/src | |
| parent | 01a059c20cf3cf9330404d9e408a586500757fe6 (diff) | |
| download | azalea-drasl-5039f9668f3512240af22ac6bb49140012885509.tar.xz | |
clippy
Diffstat (limited to 'minecraft-protocol/src')
8 files changed, 19 insertions, 18 deletions
diff --git a/minecraft-protocol/src/connection.rs b/minecraft-protocol/src/connection.rs index a8319fe1..cfca403c 100644 --- a/minecraft-protocol/src/connection.rs +++ b/minecraft-protocol/src/connection.rs @@ -54,10 +54,10 @@ impl Connection { // the first thing minecraft sends us is the length as a varint, which can be up to 5 bytes long let mut buf = BufReader::with_capacity(4 * 1024 * 1024, &mut self.stream); println!("reading length varint"); - let (packet_size, packet_size_varint_size) = mc_buf::read_varint(&mut buf).await?; + let (_packet_size, _packet_size_varint_size) = mc_buf::read_varint(&mut buf).await?; // then, minecraft tells us the packet id as a varint println!("reading id varint"); - let (packet_id, packet_id_size) = mc_buf::read_varint(&mut buf).await?; + let (packet_id, _packet_id_size) = mc_buf::read_varint(&mut buf).await?; // if we recognize the packet id, parse it diff --git a/minecraft-protocol/src/mc_buf.rs b/minecraft-protocol/src/mc_buf.rs index 68ce6de4..a9ad1642 100644 --- a/minecraft-protocol/src/mc_buf.rs +++ b/minecraft-protocol/src/mc_buf.rs @@ -1,8 +1,8 @@ //! Utilities for reading and writing for the Minecraft protocol -use std::io::{Cursor, Write}; +use std::io::Write; -use byteorder::{BigEndian, ReadBytesExt, WriteBytesExt}; +use byteorder::{BigEndian, WriteBytesExt}; use tokio::io::{AsyncRead, AsyncReadExt, BufReader}; // const DEFAULT_NBT_QUOTA: u32 = 2097152; @@ -37,8 +37,8 @@ pub async fn read_varint<T: AsyncRead + std::marker::Unpin>( for i in 0..4 { buf.read_exact(&mut buffer) .await - .or_else(|_| Err("Invalid VarInt".to_string()))?; - ans |= ((buffer[0] & 0b0111_1111) as i32) << 7 * i; + .map_err(|_| "Invalid VarInt".to_string())?; + ans |= ((buffer[0] & 0b0111_1111) as i32) << (7 * i); if buffer[0] & 0b1000_0000 == 0 { return Ok((ans, i + 1)); } @@ -64,6 +64,8 @@ pub fn write_varint(buf: &mut Vec<u8>, mut value: i32) { #[cfg(test)] mod tests { use super::*; + use std::io::Cursor; + #[test] fn test_write_varint() { let mut buf = Vec::new(); @@ -98,7 +100,7 @@ pub async fn read_utf_with_len<T: AsyncRead + std::marker::Unpin>( buf: &mut BufReader<T>, max_length: u32, ) -> Result<String, String> { - let (length, length_varint_length) = read_varint(buf).await?; + let (length, _length_varint_length) = read_varint(buf).await?; // i don't know why it's multiplied by 4 but it's like that in mojang's code so if length < 0 { return Err( @@ -119,7 +121,7 @@ pub async fn read_utf_with_len<T: AsyncRead + std::marker::Unpin>( let mut buffer = vec![0; length as usize]; buf.read_exact(&mut buffer) .await - .or_else(|_| Err("Invalid UTF-8".to_string()))?; + .map_err(|_| "Invalid UTF-8".to_string())?; string.push_str(std::str::from_utf8(&buffer).unwrap()); if string.len() > length as usize { diff --git a/minecraft-protocol/src/packets/handshake/client_intention_packet.rs b/minecraft-protocol/src/packets/handshake/client_intention_packet.rs index c6a940e3..f3416f4c 100644 --- a/minecraft-protocol/src/packets/handshake/client_intention_packet.rs +++ b/minecraft-protocol/src/packets/handshake/client_intention_packet.rs @@ -31,7 +31,7 @@ impl PacketTrait for ClientIntentionPacket { } async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>( - buf: &mut BufReader<T>, + _buf: &mut BufReader<T>, ) -> 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 1fac2a3b..bacd0c27 100644 --- a/minecraft-protocol/src/packets/mod.rs +++ b/minecraft-protocol/src/packets/mod.rs @@ -46,9 +46,9 @@ impl Packet { pub fn id(&self) -> u32 { match self { - Packet::ClientIntentionPacket(packet) => 0x00, - Packet::ServerboundStatusRequestPacket(packet) => 0x00, - Packet::ClientboundStatusResponsePacket(packet) => 0x00, + Packet::ClientIntentionPacket(_packet) => 0x00, + Packet::ServerboundStatusRequestPacket(_packet) => 0x00, + Packet::ClientboundStatusResponsePacket(_packet) => 0x00, } } @@ -98,7 +98,7 @@ impl Packet { pub trait PacketTrait { /// Return a version of the packet that you can actually use for stuff 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>( buf: &mut BufReader<T>, ) -> Result<Packet, String> 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 5099952c..20db9fe1 100644 --- a/minecraft-protocol/src/packets/status/clientbound_status_response_packet.rs +++ b/minecraft-protocol/src/packets/status/clientbound_status_response_packet.rs @@ -52,7 +52,7 @@ impl PacketTrait for ClientboundStatusResponsePacket { // this.status = GsonHelper.fromJson(GSON, friendlyByteBuf.readUtf(32767), ServerStatus.class); Ok(ClientboundStatusResponsePacket { // version: status_json.get("version"), - description: Component::new(&description_string)?, + description: Component::new(description_string)?, } .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 a08ffdff..56799677 100644 --- a/minecraft-protocol/src/packets/status/serverbound_status_request_packet.rs +++ b/minecraft-protocol/src/packets/status/serverbound_status_request_packet.rs @@ -3,7 +3,6 @@ use std::hash::Hash; use tokio::io::BufReader; use crate::{ - mc_buf, packets::{Packet, PacketTrait}, }; @@ -18,7 +17,7 @@ impl PacketTrait for ServerboundStatusRequestPacket { fn write(&self, _buf: &mut Vec<u8>) {} async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>( - buf: &mut BufReader<T>, + _buf: &mut BufReader<T>, ) -> Result<Packet, String> { Err("ServerboundStatusRequestPacket::read not implemented".to_string()) } diff --git a/minecraft-protocol/src/resolver.rs b/minecraft-protocol/src/resolver.rs index 5dc6df8b..b751e05f 100644 --- a/minecraft-protocol/src/resolver.rs +++ b/minecraft-protocol/src/resolver.rs @@ -14,7 +14,7 @@ pub async fn resolve_address(address: &ServerAddress) -> Result<ServerIpAddress, // If the address.host is already in the format of an ip address, return it. if let Ok(ip) = address.host.parse::<IpAddr>() { return Ok(ServerIpAddress { - ip: ip, + ip, port: address.port, }); } diff --git a/minecraft-protocol/src/server_status_pinger.rs b/minecraft-protocol/src/server_status_pinger.rs index a86be553..0e12a6a7 100644 --- a/minecraft-protocol/src/server_status_pinger.rs +++ b/minecraft-protocol/src/server_status_pinger.rs @@ -9,7 +9,7 @@ use crate::{ }; pub async fn ping_server(address: &ServerAddress) -> Result<(), String> { - let resolved_address = resolver::resolve_address(&address).await?; + let resolved_address = resolver::resolve_address(address).await?; let mut conn = Connection::new(&resolved_address).await?; |
