Skip to content

Commit

Permalink
Clippy: warn clippy::pedantic
Browse files Browse the repository at this point in the history
  • Loading branch information
Snowiiii committed Oct 21, 2024
1 parent 11a588b commit 12ab2c7
Show file tree
Hide file tree
Showing 26 changed files with 181 additions and 194 deletions.
4 changes: 2 additions & 2 deletions pumpkin/src/client/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ pub fn validate_textures(property: &Property, config: &TextureConfig) -> Result<
for texture in textures.textures {
let url =
Url::parse(&texture.1.url).map_err(|e| TextureError::InvalidURL(e.to_string()))?;
is_texture_url_valid(url, config)?
is_texture_url_valid(&url, config)?;
}
Ok(())
}

pub fn is_texture_url_valid(url: Url, config: &TextureConfig) -> Result<(), TextureError> {
pub fn is_texture_url_valid(url: &Url, config: &TextureConfig) -> Result<(), TextureError> {
let scheme = url.scheme();
if !config
.allowed_url_schemes
Expand Down
23 changes: 12 additions & 11 deletions pumpkin/src/client/client_packet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,11 @@ impl Client {
let profile = authentication::authenticate(username, &hash, &ip, auth_client).await?;
// Check if player should join
if let Some(actions) = &profile.profile_actions {
if !ADVANCED_CONFIG
if ADVANCED_CONFIG
.authentication
.player_profile
.allow_banned_players
{
if !actions.is_empty() {
return Err(AuthError::Banned);
}
} else {
for allowed in &ADVANCED_CONFIG
.authentication
.player_profile
Expand All @@ -210,6 +206,11 @@ impl Client {
return Err(AuthError::DisallowedAction);
}
}
if !actions.is_empty() {
return Err(AuthError::Banned);
}
} else if !actions.is_empty() {
return Err(AuthError::Banned);
}
}
// validate textures
Expand All @@ -234,7 +235,7 @@ impl Client {
Ok((profile, new_address)) => {
self.finish_login(&profile).await;
*self.gameprofile.lock().await = Some(profile);
*address = new_address
*address = new_address;
}
Err(error) => self.kick(&error.to_string()).await,
}
Expand All @@ -259,10 +260,10 @@ impl Client {
&resource_config.resource_pack_url,
&resource_config.resource_pack_sha1,
resource_config.force,
if !resource_config.prompt_message.is_empty() {
Some(TextComponent::text(&resource_config.prompt_message))
} else {
if resource_config.prompt_message.is_empty() {
None
} else {
Some(TextComponent::text(&resource_config.prompt_message))
},
);

Expand Down Expand Up @@ -298,7 +299,7 @@ impl Client {
server_listing: client_information.server_listing,
});
} else {
self.kick("Invalid hand or chat type").await
self.kick("Invalid hand or chat type").await;
}
}

Expand Down Expand Up @@ -328,7 +329,7 @@ impl Client {
self.send_packet(&CFinishConfig::new()).await;
}

pub async fn handle_config_acknowledged(&self, _config_acknowledged: SAcknowledgeFinishConfig) {
pub fn handle_config_acknowledged(&self, _config_acknowledged: &SAcknowledgeFinishConfig) {
dbg!("config acknowledged");
self.connection_state.store(ConnectionState::Play);
self.make_player
Expand Down
19 changes: 10 additions & 9 deletions pumpkin/src/client/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ impl Player {
.carried_item
.load()
.as_ref()
.map_or_else(Slot::empty, |item| item.into());
.map_or_else(Slot::empty, std::convert::Into::into);

// Gets the previous value
let i = inventory
Expand All @@ -92,7 +92,7 @@ impl Player {
inventory.total_opened_containers += 1;
self.client
.send_packet(&CCloseContainer::new(inventory.total_opened_containers))
.await
.await;
}

pub async fn set_container_property<T: WindowPropertyTrait>(
Expand Down Expand Up @@ -270,7 +270,7 @@ impl Player {
slots.skip(36).rev().find_map(find_condition)
};
if let Some(slot) = slots {
let mut item_slot = container.all_slots()[slot].map(|i| i.to_owned());
let mut item_slot = container.all_slots()[slot].map(|i| i);
container.handle_item_change(&mut item_slot, slot, MouseClick::Left)?;
*container.all_slots()[slot] = item_slot;
}
Expand Down Expand Up @@ -363,13 +363,14 @@ impl Player {
let player_id = self.entity_id();
let container_id = opened_container
.as_ref()
.map(|container| container.internal_pumpkin_id())
.unwrap_or(player_id as u64);
.map_or(player_id as u64, |container| {
container.internal_pumpkin_id()
});
match mouse_drag_state {
MouseDragState::Start(drag_type) => {
if drag_type == MouseDragType::Middle && self.gamemode.load() != GameMode::Creative
{
Err(InventoryError::PermissionError)?
Err(InventoryError::PermissionError)?;
}
drag_handler
.new_drag(container_id, player_id, drag_type)
Expand Down Expand Up @@ -417,15 +418,15 @@ impl Player {
.await
.iter()
.filter_map(|(token, player)| {
if *token != player_token {
if *token == player_token {
None
} else {
let entity_id = player.entity_id();
if player_ids.contains(&entity_id) {
Some(player.clone())
} else {
None
}
} else {
None
}
})
.collect_vec();
Expand Down
53 changes: 19 additions & 34 deletions pumpkin/src/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ impl Client {
gameprofile: Mutex::new(None),
config: Mutex::new(None),
brand: Mutex::new(None),
server_address: Mutex::new("".to_string()),
server_address: Mutex::new(String::new()),
id,
address: Mutex::new(address),
connection_state: AtomicCell::new(ConnectionState::HandShake),
Expand Down Expand Up @@ -211,9 +211,9 @@ impl Client {
while let Some(mut packet) = self.client_packets_queue.lock().await.pop_front() {
if let Err(error) = self.handle_packet(server, &mut packet).await {
dbg!("{:?}", packet.id);
let text = format!("Error while reading incoming packet {}", error);
let text = format!("Error while reading incoming packet {error}");
log::error!("{}", text);
self.kick(&text).await
self.kick(&text).await;
};
}
}
Expand All @@ -239,7 +239,7 @@ impl Client {
pumpkin_protocol::ConnectionState::Config => {
self.handle_config_packet(server, packet).await
}
_ => {
pumpkin_protocol::ConnectionState::Play => {
log::error!("Invalid Connection state {:?}", self.connection_state);
Ok(())
}
Expand All @@ -251,19 +251,15 @@ impl Client {
packet: &mut RawPacket,
) -> Result<(), DeserializerError> {
let bytebuf = &mut packet.bytebuf;
match packet.id.0 {
SHandShake::PACKET_ID => {
self.handle_handshake(SHandShake::read(bytebuf)?).await;
Ok(())
}
_ => {
log::error!(
"Failed to handle packet id {} while in Handshake state",
packet.id.0
);
Ok(())
}
if packet.id.0 == SHandShake::PACKET_ID {
self.handle_handshake(SHandShake::read(bytebuf)?).await;
} else {
log::error!(
"Failed to handle packet id {} while in Handshake state",
packet.id.0
);
}
Ok(())
}

async fn handle_status_packet(
Expand All @@ -276,21 +272,19 @@ impl Client {
SStatusRequest::PACKET_ID => {
self.handle_status_request(server, SStatusRequest::read(bytebuf)?)
.await;
Ok(())
}
SStatusPingRequest::PACKET_ID => {
self.handle_ping_request(SStatusPingRequest::read(bytebuf)?)
.await;
Ok(())
}
_ => {
log::error!(
"Failed to handle packet id {} while in Status state",
packet.id.0
);
Ok(())
}
}
Ok(())
}

async fn handle_login_packet(
Expand All @@ -303,31 +297,27 @@ impl Client {
SLoginStart::PACKET_ID => {
self.handle_login_start(server, SLoginStart::read(bytebuf)?)
.await;
Ok(())
}
SEncryptionResponse::PACKET_ID => {
self.handle_encryption_response(server, SEncryptionResponse::read(bytebuf)?)
.await;
Ok(())
}
SLoginPluginResponse::PACKET_ID => {
self.handle_plugin_response(SLoginPluginResponse::read(bytebuf)?)
.await;
Ok(())
}
SLoginAcknowledged::PACKET_ID => {
self.handle_login_acknowledged(server, SLoginAcknowledged::read(bytebuf)?)
.await;
Ok(())
}
_ => {
log::error!(
"Failed to handle packet id {} while in Login state",
packet.id.0
);
Ok(())
}
}
Ok(())
}

async fn handle_config_packet(
Expand All @@ -340,31 +330,26 @@ impl Client {
SClientInformationConfig::PACKET_ID => {
self.handle_client_information_config(SClientInformationConfig::read(bytebuf)?)
.await;
Ok(())
}
SPluginMessage::PACKET_ID => {
self.handle_plugin_message(SPluginMessage::read(bytebuf)?)
.await;
Ok(())
}
SAcknowledgeFinishConfig::PACKET_ID => {
self.handle_config_acknowledged(SAcknowledgeFinishConfig::read(bytebuf)?)
.await;
Ok(())
self.handle_config_acknowledged(&SAcknowledgeFinishConfig::read(bytebuf)?);
}
SKnownPacks::PACKET_ID => {
self.handle_known_packs(server, SKnownPacks::read(bytebuf)?)
.await;
Ok(())
}
_ => {
log::error!(
"Failed to handle packet id {} while in Config state",
packet.id.0
);
Ok(())
}
}
Ok(())
}

/// Reads the connection until our buffer of len 4096 is full, then decode
Expand Down Expand Up @@ -406,7 +391,7 @@ impl Client {
match self.connection_state.load() {
ConnectionState::Login => {
self.try_send_packet(&CLoginDisconnect::new(
&serde_json::to_string_pretty(&reason).unwrap_or_else(|_| "".into()),
&serde_json::to_string_pretty(&reason).unwrap_or_else(|_| String::new()),
))
.await
.unwrap_or_else(|_| self.close());
Expand All @@ -423,10 +408,10 @@ impl Client {
.unwrap_or_else(|_| self.close());
}
_ => {
log::warn!("Can't kick in {:?} State", self.connection_state)
log::warn!("Can't kick in {:?} State", self.connection_state);
}
}
self.close()
self.close();
}

/// You should prefer to use `kick` when you can
Expand Down
Loading

0 comments on commit 12ab2c7

Please sign in to comment.