From c9878129274258a30dc3ee0ecbd064b4fcf9bc6e Mon Sep 17 00:00:00 2001 From: mat Date: Tue, 3 May 2022 18:20:24 +0000 Subject: [PATCH] clippy --- azalea-client/src/connect.rs | 19 +++++++++---------- azalea-client/src/player.rs | 1 - azalea-crypto/src/lib.rs | 14 +++++--------- azalea-nbt/src/encode.rs | 2 +- azalea-protocol/packet-macros/src/lib.rs | 13 ++++++------- azalea-protocol/src/mc_buf/read.rs | 6 +++--- azalea-protocol/src/mc_buf/write.rs | 8 ++++---- .../clientbound_declare_commands_packet.rs | 18 ++++++++---------- .../game/clientbound_light_update_packet.rs | 1 - .../clientbound_player_abilities_packet.rs | 8 ++++---- .../clientbound_player_position_packet.rs | 10 +++++----- .../packets/game/clientbound_recipe_packet.rs | 4 ++-- .../clientbound_set_entity_data_packet.rs | 4 ++-- .../game/clientbound_update_recipes_packet.rs | 2 +- .../packets/login/serverbound_key_packet.rs | 2 -- azalea-protocol/src/write.rs | 5 +---- azalea-world/src/palette.rs | 18 +++++++++--------- 17 files changed, 60 insertions(+), 75 deletions(-) diff --git a/azalea-client/src/connect.rs b/azalea-client/src/connect.rs index 984c5d86..3b880ea3 100755 --- a/azalea-client/src/connect.rs +++ b/azalea-client/src/connect.rs @@ -13,8 +13,8 @@ use azalea_protocol::{ }, resolver, ServerAddress, }; -use azalea_world::{Chunk, ChunkStorage, World}; -use std::{fmt::Debug, ops::Deref, sync::Arc}; +use azalea_world::{ChunkStorage, World}; +use std::{fmt::Debug, sync::Arc}; use tokio::sync::mpsc::{self, UnboundedReceiver, UnboundedSender}; use tokio::sync::Mutex; @@ -34,8 +34,8 @@ pub struct ClientState { /// A player that you can control that is currently in a Minecraft server. pub struct Client { event_receiver: UnboundedReceiver, - conn: Arc>, - state: Arc>, + pub conn: Arc>, + pub state: Arc>, // game_loop } @@ -133,10 +133,9 @@ impl Client { // just start up the game loop and we're ready! // tokio::spawn(Self::game_loop(conn, tx, handler, state)) - let game_loop_conn = conn.clone(); let game_loop_state = client.state.clone(); - tokio::spawn(Self::game_loop(game_loop_conn, tx, game_loop_state)); + tokio::spawn(Self::game_loop(conn, tx, game_loop_state)); Ok(client) } @@ -221,7 +220,7 @@ impl Client { GamePacket::ClientboundChangeDifficultyPacket(p) => { println!("Got difficulty packet {:?}", p); } - GamePacket::ClientboundDeclareCommandsPacket(p) => { + GamePacket::ClientboundDeclareCommandsPacket(_p) => { println!("Got declare commands packet"); } GamePacket::ClientboundPlayerAbilitiesPacket(p) => { @@ -230,19 +229,19 @@ impl Client { GamePacket::ClientboundSetCarriedItemPacket(p) => { println!("Got set carried item packet {:?}", p); } - GamePacket::ClientboundUpdateTagsPacket(p) => { + GamePacket::ClientboundUpdateTagsPacket(_p) => { println!("Got update tags packet"); } GamePacket::ClientboundDisconnectPacket(p) => { println!("Got disconnect packet {:?}", p); } - GamePacket::ClientboundUpdateRecipesPacket(p) => { + GamePacket::ClientboundUpdateRecipesPacket(_p) => { println!("Got update recipes packet"); } GamePacket::ClientboundEntityEventPacket(p) => { println!("Got entity event packet {:?}", p); } - GamePacket::ClientboundRecipePacket(p) => { + GamePacket::ClientboundRecipePacket(_p) => { println!("Got recipe packet"); } GamePacket::ClientboundPlayerPositionPacket(p) => { diff --git a/azalea-client/src/player.rs b/azalea-client/src/player.rs index 70ac1c76..fc54ff93 100644 --- a/azalea-client/src/player.rs +++ b/azalea-client/src/player.rs @@ -1,5 +1,4 @@ use crate::Entity; -use azalea_world::World; #[derive(Default)] pub struct Player { diff --git a/azalea-crypto/src/lib.rs b/azalea-crypto/src/lib.rs index dc2620cc..62a81de3 100644 --- a/azalea-crypto/src/lib.rs +++ b/azalea-crypto/src/lib.rs @@ -1,9 +1,6 @@ use aes::cipher::inout::InOutBuf; -use aes::cipher::BlockEncrypt; use aes::{ - cipher::{ - generic_array::GenericArray, AsyncStreamCipher, BlockDecryptMut, BlockEncryptMut, KeyIvInit, - }, + cipher::{BlockDecryptMut, BlockEncryptMut, KeyIvInit}, Aes128, }; use rand::{rngs::OsRng, RngCore}; @@ -15,7 +12,7 @@ fn generate_secret_key() -> [u8; 16] { key } -fn digest_data(server_id: &[u8], public_key: &[u8], private_key: &[u8]) -> Vec { +pub fn digest_data(server_id: &[u8], public_key: &[u8], private_key: &[u8]) -> Vec { let mut digest = Sha1::new(); digest.update(server_id); digest.update(public_key); @@ -23,7 +20,7 @@ fn digest_data(server_id: &[u8], public_key: &[u8], private_key: &[u8]) -> Vec String { +pub fn hex_digest(digest: &[u8]) -> String { // Note that the Sha1.hexdigest() method used by minecraft is non standard. // It doesn't match the digest method found in most programming languages // and libraries. It works by treating the sha1 output bytes as one large @@ -48,9 +45,8 @@ pub fn encrypt(public_key: &[u8], nonce: &[u8]) -> Result // this.keybytes = Crypt.encryptUsingKey(publicKey, secretKey.getEncoded()); // this.nonce = Crypt.encryptUsingKey(publicKey, arrby); - let encrypted_public_key: Vec = - rsa_public_encrypt_pkcs1::encrypt(&public_key, &secret_key)?; - let encrypted_nonce: Vec = rsa_public_encrypt_pkcs1::encrypt(&public_key, &nonce)?; + let encrypted_public_key: Vec = rsa_public_encrypt_pkcs1::encrypt(public_key, &secret_key)?; + let encrypted_nonce: Vec = rsa_public_encrypt_pkcs1::encrypt(public_key, nonce)?; Ok(EncryptResult { secret_key, diff --git a/azalea-nbt/src/encode.rs b/azalea-nbt/src/encode.rs index 20d13793..fb5585b3 100755 --- a/azalea-nbt/src/encode.rs +++ b/azalea-nbt/src/encode.rs @@ -98,7 +98,7 @@ fn write_compound( if end_tag { writer.write_u8(Tag::End.id())?; } - return Ok(()); + Ok(()) } #[inline] diff --git a/azalea-protocol/packet-macros/src/lib.rs b/azalea-protocol/packet-macros/src/lib.rs index 35abf642..dec153ec 100755 --- a/azalea-protocol/packet-macros/src/lib.rs +++ b/azalea-protocol/packet-macros/src/lib.rs @@ -232,13 +232,12 @@ struct PacketIdMap { impl Parse for PacketIdMap { fn parse(input: ParseStream) -> Result { let mut packets = vec![]; - loop { - // 0x0e: clientbound_change_difficulty_packet::ClientboundChangeDifficultyPacket, - // 0x0e - let packet_id: LitInt = match input.parse() { - Ok(i) => i, - Err(_) => break, - }; + + // example: + // 0x0e: clientbound_change_difficulty_packet::ClientboundChangeDifficultyPacket, + + // 0x0e + while let Ok(packet_id) = input.parse::() { let packet_id = packet_id.base10_parse::()?; // : input.parse::()?; diff --git a/azalea-protocol/src/mc_buf/read.rs b/azalea-protocol/src/mc_buf/read.rs index 68c9cb3f..e1ae321c 100755 --- a/azalea-protocol/src/mc_buf/read.rs +++ b/azalea-protocol/src/mc_buf/read.rs @@ -1,10 +1,10 @@ -use super::{BitSet, UnsizedByteArray, MAX_STRING_LENGTH}; +use super::{UnsizedByteArray, MAX_STRING_LENGTH}; use azalea_chat::component::Component; use azalea_core::{ difficulty::Difficulty, game_type::GameType, resource_location::ResourceLocation, serializable_uuid::SerializableUuid, BlockPos, Direction, Slot, SlotData, }; -use byteorder::{ReadBytesExt, WriteBytesExt, BE}; +use byteorder::{ReadBytesExt, BE}; use serde::Deserialize; use std::io::Read; use tokio::io::{AsyncRead, AsyncReadExt}; @@ -421,7 +421,7 @@ impl McBufReadable for Component { fn read_into(buf: &mut impl Read) -> Result { let string = buf.read_utf()?; let json: serde_json::Value = serde_json::from_str(string.as_str()) - .map_err(|e| "Component isn't valid JSON".to_string())?; + .map_err(|_| "Component isn't valid JSON".to_string())?; let component = Component::deserialize(json).map_err(|e| e.to_string())?; Ok(component) } diff --git a/azalea-protocol/src/mc_buf/write.rs b/azalea-protocol/src/mc_buf/write.rs index 34bcafeb..3a4a02f8 100755 --- a/azalea-protocol/src/mc_buf/write.rs +++ b/azalea-protocol/src/mc_buf/write.rs @@ -20,8 +20,8 @@ pub trait Writable: Write { Ok(()) } - fn write_int_id_list(&mut self, list: &Vec) -> Result<(), std::io::Error> { - self.write_list(&list, |buf, n| buf.write_varint(*n)) + fn write_int_id_list(&mut self, list: &[i32]) -> Result<(), std::io::Error> { + self.write_list(list, |buf, n| buf.write_varint(*n)) } fn write_map( @@ -47,7 +47,7 @@ pub trait Writable: Write { } fn write_bytes(&mut self, bytes: &[u8]) -> Result<(), std::io::Error> { - self.write_all(bytes); + self.write_all(bytes)?; Ok(()) } @@ -333,7 +333,7 @@ impl McBufWritable for Component { // let component = Component::deserialize(json).map_err(|e| e.to_string())?; // Ok(component) // } - fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { + fn write_into(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> { // component doesn't have serialize implemented yet todo!() } diff --git a/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs b/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs index 27f4fb16..6743c3af 100755 --- a/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_declare_commands_packet.rs @@ -281,7 +281,7 @@ impl McBufReadable for BrigadierParser { } } -// azalea_brigadier::tree::CommandNode +// TODO: BrigadierNodeStub should have more stuff impl McBufReadable for BrigadierNodeStub { fn read_into(buf: &mut impl Read) -> Result { let flags = u8::read_into(buf)?; @@ -292,20 +292,18 @@ impl McBufReadable for BrigadierNodeStub { } let node_type = flags & 0x03; - let is_executable = flags & 0x04 != 0; + let _is_executable = flags & 0x04 != 0; let has_redirect = flags & 0x08 != 0; let has_suggestions_type = flags & 0x10 != 0; - let children = buf.read_int_id_list()?; - let redirect_node = if has_redirect { buf.read_varint()? } else { 0 }; + let _children = buf.read_int_id_list()?; + let _redirect_node = if has_redirect { buf.read_varint()? } else { 0 }; // argument node if node_type == 2 { - let name = buf.read_utf()?; - - let parser = BrigadierParser::read_into(buf)?; - - let suggestions_type = if has_suggestions_type { + let _name = buf.read_utf()?; + let _parser = BrigadierParser::read_into(buf)?; + let _suggestions_type = if has_suggestions_type { Some(buf.read_resource_location()?) } else { None @@ -314,7 +312,7 @@ impl McBufReadable for BrigadierNodeStub { } // literal node if node_type == 1 { - let name = buf.read_utf()?; + let _name = buf.read_utf()?; return Ok(BrigadierNodeStub {}); } Ok(BrigadierNodeStub {}) diff --git a/azalea-protocol/src/packets/game/clientbound_light_update_packet.rs b/azalea-protocol/src/packets/game/clientbound_light_update_packet.rs index c97eacff..e83d1e87 100644 --- a/azalea-protocol/src/packets/game/clientbound_light_update_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_light_update_packet.rs @@ -1,5 +1,4 @@ use crate::mc_buf::BitSet; -use azalea_core::{game_type::GameType, resource_location::ResourceLocation}; use packet_macros::{GamePacket, McBufReadable, McBufWritable}; #[derive(Clone, Debug, GamePacket)] diff --git a/azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs index cd645fe6..ed27ecf3 100755 --- a/azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_player_abilities_packet.rs @@ -34,16 +34,16 @@ impl McBufWritable for PlayerAbilitiesFlags { fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let mut byte = 0; if self.invulnerable { - byte = byte | 1; + byte |= 0b1; } if self.flying { - byte = byte | 2; + byte |= 0b10; } if self.can_fly { - byte = byte | 4; + byte |= 0b100; } if self.instant_break { - byte = byte | 8; + byte |= 0b1000; } u8::write_into(&byte, buf) } diff --git a/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs index cac4665d..c2bef8fa 100644 --- a/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_player_position_packet.rs @@ -43,19 +43,19 @@ impl McBufWritable for RelativeArguments { fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { let mut byte = 0; if self.x { - byte = byte | 0b1; + byte |= 0b1; } if self.y { - byte = byte | 0b10; + byte |= 0b10; } if self.z { - byte = byte | 0b100; + byte |= 0b100; } if self.y_rot { - byte = byte | 0b1000; + byte |= 0b1000; } if self.x_rot { - byte = byte | 0b10000; + byte |= 0b10000; } u8::write_into(&byte, buf) } diff --git a/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs b/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs index 543fb64c..fa0d58f0 100644 --- a/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_recipe_packet.rs @@ -1,5 +1,5 @@ use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable}; -use azalea_core::{resource_location::ResourceLocation, Slot}; +use azalea_core::resource_location::ResourceLocation; use packet_macros::{GamePacket, McBufReadable, McBufWritable}; use std::io::{Read, Write}; @@ -41,7 +41,7 @@ impl McBufWritable for State { } impl McBufReadable for State { fn read_into(buf: &mut impl Read) -> Result { - let state = buf.read_varint()?.try_into().unwrap(); + let state = buf.read_varint()?; Ok(match state { 0 => State::Init, 1 => State::Add, diff --git a/azalea-protocol/src/packets/game/clientbound_set_entity_data_packet.rs b/azalea-protocol/src/packets/game/clientbound_set_entity_data_packet.rs index 5d288518..ca726c39 100644 --- a/azalea-protocol/src/packets/game/clientbound_set_entity_data_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_set_entity_data_packet.rs @@ -123,7 +123,7 @@ impl McBufReadable for EntityDataValue { } impl McBufWritable for EntityDataValue { - fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { + fn write_into(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> { todo!(); } } @@ -398,7 +398,7 @@ impl McBufReadable for ParticleData { } impl McBufWritable for ParticleData { - fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { + fn write_into(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> { todo!() } } diff --git a/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs index d15e10c3..9bdea26e 100644 --- a/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_update_recipes_packet.rs @@ -122,7 +122,7 @@ pub struct Ingredient { } impl McBufWritable for Recipe { - fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { + fn write_into(&self, _buf: &mut impl Write) -> Result<(), std::io::Error> { todo!() } } diff --git a/azalea-protocol/src/packets/login/serverbound_key_packet.rs b/azalea-protocol/src/packets/login/serverbound_key_packet.rs index f402d357..2ff8dda6 100644 --- a/azalea-protocol/src/packets/login/serverbound_key_packet.rs +++ b/azalea-protocol/src/packets/login/serverbound_key_packet.rs @@ -1,5 +1,3 @@ -use super::LoginPacket; -use crate::mc_buf::Writable; use packet_macros::LoginPacket; use std::hash::Hash; diff --git a/azalea-protocol/src/write.rs b/azalea-protocol/src/write.rs index 345829c5..9291681c 100755 --- a/azalea-protocol/src/write.rs +++ b/azalea-protocol/src/write.rs @@ -2,10 +2,7 @@ use crate::{mc_buf::Writable, packets::ProtocolPacket, read::MAXIMUM_UNCOMPRESSE use async_compression::tokio::bufread::ZlibEncoder; use azalea_crypto::Aes128CfbEnc; use std::fmt::Debug; -use tokio::{ - io::{AsyncReadExt, AsyncWrite, AsyncWriteExt}, - net::TcpStream, -}; +use tokio::io::{AsyncReadExt, AsyncWrite, AsyncWriteExt}; fn frame_prepender(data: &mut Vec) -> Result, String> { let mut buf = Vec::new(); diff --git a/azalea-world/src/palette.rs b/azalea-world/src/palette.rs index a8ec50c9..69900fe6 100644 --- a/azalea-world/src/palette.rs +++ b/azalea-world/src/palette.rs @@ -35,9 +35,9 @@ impl McBufWritable for PalettedContainer { pub enum Palette { /// ID of the corresponding entry in its global palette SingleValue(u32), - LinearPalette(Vec), - HashmapPalette(Vec), - GlobalPalette, + Linear(Vec), + Hashmap(Vec), + Global, } impl Palette { @@ -47,9 +47,9 @@ impl Palette { ) -> Result { Ok(match bits_per_entry { 0 => Palette::SingleValue(u32::read_into(buf)?), - 1..=4 => Palette::LinearPalette(Vec::::read_into(buf)?), - 5..=8 => Palette::HashmapPalette(Vec::::read_into(buf)?), - _ => Palette::GlobalPalette, + 1..=4 => Palette::Linear(Vec::::read_into(buf)?), + 5..=8 => Palette::Hashmap(Vec::::read_into(buf)?), + _ => Palette::Global, }) } } @@ -60,13 +60,13 @@ impl McBufWritable for Palette { Palette::SingleValue(value) => { value.write_into(buf)?; } - Palette::LinearPalette(values) => { + Palette::Linear(values) => { values.write_into(buf)?; } - Palette::HashmapPalette(values) => { + Palette::Hashmap(values) => { values.write_into(buf)?; } - Palette::GlobalPalette => {} + Palette::Global => {} } Ok(()) }