diff options
| author | metamuffin <metamuffin@disroot.org> | 2025-10-11 00:24:11 +0200 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2025-10-11 00:24:11 +0200 |
| commit | e68a9eb5e9e15372313f9017be4a2d58fb690bfc (patch) | |
| tree | 690287a2c71d87c2955e992f1e9575166237188a /server | |
| parent | 3fe8ba7f1b9fa7e38fa03f55fd898c8ca2a0e996 (diff) | |
| download | hurrycurry-e68a9eb5e9e15372313f9017be4a2d58fb690bfc.tar hurrycurry-e68a9eb5e9e15372313f9017be4a2d58fb690bfc.tar.bz2 hurrycurry-e68a9eb5e9e15372313f9017be4a2d58fb690bfc.tar.zst | |
clippy + fmt; start using if let chains
Diffstat (limited to 'server')
39 files changed, 277 insertions, 287 deletions
diff --git a/server/book-export/src/book_html.rs b/server/book-export/src/book_html.rs index 08a12e88..9d4e41ac 100644 --- a/server/book-export/src/book_html.rs +++ b/server/book-export/src/book_html.rs @@ -80,7 +80,7 @@ markup::define! { } MessageR<'a>(data: &'a Gamedata, locale: &'a Locale, message: &'a Message) { - @message.display_message(*locale, *data, &PLAIN) + @message.display_message(locale, data, &PLAIN) } DiagramR<'a>(data: &'a Gamedata, diagram: &'a Diagram) { diff --git a/server/bot/src/algos/customer.rs b/server/bot/src/algos/customer.rs index 17ade544..010ef48a 100644 --- a/server/bot/src/algos/customer.rs +++ b/server/bot/src/algos/customer.rs @@ -111,16 +111,16 @@ impl CustomerState { .filter(|(_, t)| game.data.tile_name(t.kind) == "chair") .map(|(p, _)| *p) .collect::<Vec<_>>(); - if let Some(&chair) = chairs.get(random::<usize>(..) % chairs.len().max(1)) { - if let Some(path) = find_path(&game.walkable, pos.as_ivec2(), chair) { - debug!("{me:?} -> entering"); - *self = CustomerState::Entering { - path, - chair, - origin: pos.as_ivec2(), - ticks: 0, - }; - } + if let Some(&chair) = chairs.get(random::<usize>(..) % chairs.len().max(1)) + && let Some(path) = find_path(&game.walkable, pos.as_ivec2(), chair) + { + debug!("{me:?} -> entering"); + *self = CustomerState::Entering { + path, + chair, + origin: pos.as_ivec2(), + ticks: 0, + }; } } BotInput::default() diff --git a/server/bot/src/algos/dishwasher.rs b/server/bot/src/algos/dishwasher.rs index cbeedab9..94368558 100644 --- a/server/bot/src/algos/dishwasher.rs +++ b/server/bot/src/algos/dishwasher.rs @@ -16,9 +16,9 @@ */ use super::simple::State; -use crate::{algos::simple::Context, pathfinding::Path, BotAlgo, BotInput}; +use crate::{BotAlgo, BotInput, algos::simple::Context, pathfinding::Path}; use hurrycurry_client_lib::Game; -use hurrycurry_protocol::{glam::IVec2, ItemIndex, PlayerID}; +use hurrycurry_protocol::{ItemIndex, PlayerID, glam::IVec2}; #[derive(Default)] pub struct DishWasher { diff --git a/server/bot/src/algos/simple.rs b/server/bot/src/algos/simple.rs index 914e8809..f8d01b3a 100644 --- a/server/bot/src/algos/simple.rs +++ b/server/bot/src/algos/simple.rs @@ -16,12 +16,12 @@ */ use crate::{ - pathfinding::{find_path_to_neighbour, Path}, BotAlgo, BotInput, + pathfinding::{Path, find_path_to_neighbour}, }; use hurrycurry_client_lib::Game; use hurrycurry_protocol::{ - glam::IVec2, ItemIndex, Message, PlayerID, Recipe, RecipeIndex, TileIndex, + ItemIndex, Message, PlayerID, Recipe, RecipeIndex, TileIndex, glam::IVec2, }; use log::{debug, warn}; diff --git a/server/bot/src/algos/test.rs b/server/bot/src/algos/test.rs index 5ef11553..361cf4ea 100644 --- a/server/bot/src/algos/test.rs +++ b/server/bot/src/algos/test.rs @@ -16,11 +16,11 @@ */ use crate::{ - pathfinding::{find_path_to_neighbour, Path}, BotAlgo, BotInput, + pathfinding::{Path, find_path_to_neighbour}, }; use hurrycurry_client_lib::Game; -use hurrycurry_protocol::{glam::IVec2, ItemIndex, Message, PlayerID}; +use hurrycurry_protocol::{ItemIndex, Message, PlayerID, glam::IVec2}; use log::info; #[derive(Default)] diff --git a/server/bot/src/algos/waiter.rs b/server/bot/src/algos/waiter.rs index bde87f94..8fccd34a 100644 --- a/server/bot/src/algos/waiter.rs +++ b/server/bot/src/algos/waiter.rs @@ -16,9 +16,9 @@ */ use super::simple::State; -use crate::{algos::simple::Context, pathfinding::Path, BotAlgo, BotInput}; +use crate::{BotAlgo, BotInput, algos::simple::Context, pathfinding::Path}; use hurrycurry_client_lib::Game; -use hurrycurry_protocol::{glam::IVec2, ItemIndex, PlayerID}; +use hurrycurry_protocol::{ItemIndex, PlayerID, glam::IVec2}; use log::debug; #[derive(Default)] diff --git a/server/bot/src/main.rs b/server/bot/src/main.rs index b1b8bb84..d2bd10c5 100644 --- a/server/bot/src/main.rs +++ b/server/bot/src/main.rs @@ -17,8 +17,8 @@ */ use anyhow::Result; use clap::Parser; -use hurrycurry_bot::{algos::ALGO_CONSTRUCTORS, BotAlgo, BotInput}; -use hurrycurry_client_lib::{network::sync::Network, Game}; +use hurrycurry_bot::{BotAlgo, BotInput, algos::ALGO_CONSTRUCTORS}; +use hurrycurry_client_lib::{Game, network::sync::Network}; use hurrycurry_protocol::{Character, Hand, PacketC, PacketS, PlayerClass, PlayerID}; use log::warn; use std::{thread::sleep, time::Duration}; diff --git a/server/bot/src/pathfinding.rs b/server/bot/src/pathfinding.rs index 211f1890..41bc79c7 100644 --- a/server/bot/src/pathfinding.rs +++ b/server/bot/src/pathfinding.rs @@ -70,7 +70,7 @@ pub fn find_path(walkable: &HashSet<IVec2>, from: IVec2, to: IVec2) -> Option<Pa struct Open(i32, IVec2, IVec2, i32); impl PartialOrd for Open { fn partial_cmp(&self, other: &Self) -> Option<Ordering> { - Some(self.0.cmp(&other.0)) + Some(self.cmp(other)) } } impl Ord for Open { diff --git a/server/client-lib/src/lib.rs b/server/client-lib/src/lib.rs index b3939388..1922576f 100644 --- a/server/client-lib/src/lib.rs +++ b/server/client-lib/src/lib.rs @@ -20,8 +20,8 @@ pub mod network; pub mod spatial_index; use hurrycurry_protocol::{ - glam::IVec2, movement::MovementBase, Character, Gamedata, Hand, ItemIndex, ItemLocation, - Message, MessageTimeout, PacketC, PlayerClass, PlayerID, RecipeIndex, Score, TileIndex, + Character, Gamedata, Hand, ItemIndex, ItemLocation, Message, MessageTimeout, PacketC, + PlayerClass, PlayerID, RecipeIndex, Score, TileIndex, glam::IVec2, movement::MovementBase, }; use spatial_index::SpatialIndex; use std::{ @@ -222,10 +222,10 @@ impl Game { } } for tile in self.tiles.values_mut() { - if let Some(item) = &mut tile.item { - if let Some(active) = &mut item.active { - active.position += active.speed; - } + if let Some(item) = &mut tile.item + && let Some(active) = &mut item.active + { + active.position += active.speed; } } diff --git a/server/client-lib/src/network/sync.rs b/server/client-lib/src/network/sync.rs index 4d6919c9..9854b58e 100644 --- a/server/client-lib/src/network/sync.rs +++ b/server/client-lib/src/network/sync.rs @@ -20,12 +20,12 @@ use hurrycurry_protocol::{PacketC, PacketS, VERSION}; use log::{debug, info, warn}; use std::{collections::VecDeque, net::TcpStream}; use tungstenite::{ - client::{uri_mode, IntoClientRequest}, + Message, WebSocket, + client::{IntoClientRequest, uri_mode}, client_tls_with_config, handshake::client::Request, stream::{MaybeTlsStream, Mode}, util::NonBlockingError, - Message, WebSocket, }; pub struct Network { @@ -91,11 +91,12 @@ impl Network { major, supports_bincode, } = &packet + && *minor == VERSION.0 + && *major == VERSION.1 + && *supports_bincode { - if *minor == VERSION.0 && *major == VERSION.1 && *supports_bincode { - info!("Binary protocol format enabled."); - self.use_bincode = true; - } + info!("Binary protocol format enabled."); + self.use_bincode = true; } Some(packet) } diff --git a/server/client-lib/src/network/tokio.rs b/server/client-lib/src/network/tokio.rs index d42d0fc1..6e7f0902 100644 --- a/server/client-lib/src/network/tokio.rs +++ b/server/client-lib/src/network/tokio.rs @@ -15,21 +15,21 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use futures_util::{ - stream::{SplitSink, SplitStream, StreamExt}, SinkExt, TryStreamExt, + stream::{SplitSink, SplitStream, StreamExt}, }; use hurrycurry_protocol::{PacketC, PacketS, VERSION}; use log::{debug, info, warn}; use std::sync::atomic::{AtomicBool, Ordering}; use tokio::{net::TcpStream, sync::RwLock}; -use tokio_tungstenite::{client_async_tls_with_config, MaybeTlsStream, WebSocketStream}; +use tokio_tungstenite::{MaybeTlsStream, WebSocketStream, client_async_tls_with_config}; use tungstenite::{ - client::{uri_mode, IntoClientRequest}, + Message, + client::{IntoClientRequest, uri_mode}, http::Request, stream::Mode, - Message, }; pub struct Network { @@ -98,11 +98,12 @@ impl Network { major, supports_bincode, } = &packet + && *minor == VERSION.0 + && *major == VERSION.1 + && *supports_bincode { - if *minor == VERSION.0 && *major == VERSION.1 && *supports_bincode { - info!("Binary protocol format enabled."); - self.use_binary.store(true, Ordering::Relaxed); - } + info!("Binary protocol format enabled."); + self.use_binary.store(true, Ordering::Relaxed); } return Ok(Some(packet)); } diff --git a/server/client-lib/src/spatial_index.rs b/server/client-lib/src/spatial_index.rs index faa1c7f4..8b717ca3 100644 --- a/server/client-lib/src/spatial_index.rs +++ b/server/client-lib/src/spatial_index.rs @@ -15,7 +15,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -use hurrycurry_protocol::glam::{ivec2, IVec2, Vec2}; +use hurrycurry_protocol::glam::{IVec2, Vec2, ivec2}; use std::{collections::HashMap, hash::Hash}; pub struct SpatialIndex<T> { diff --git a/server/data/src/book/recipe_diagram.rs b/server/data/src/book/recipe_diagram.rs index 6ec9965f..b6639657 100644 --- a/server/data/src/book/recipe_diagram.rs +++ b/server/data/src/book/recipe_diagram.rs @@ -75,7 +75,7 @@ pub fn recipe_diagram( .collect(), index: ri, }; - need.extend(gr.inputs.iter().filter(|i| !have.contains(&i))); + need.extend(gr.inputs.iter().filter(|i| !have.contains(i))); have.extend(&gr.outputs); recipes.insert(gr); found_recipe = true; @@ -104,7 +104,8 @@ pub fn recipe_diagram( let index = diag.nodes.len(); let recipe = data.recipe(r.index); - if matches!(recipe, Recipe::Instant { .. }) && r.inputs.len() >= 1 && r.outputs.len() >= 1 { + if matches!(recipe, Recipe::Instant { .. }) && !r.inputs.is_empty() && !r.outputs.is_empty() + { for i in r.inputs { diag.edges.push(DiagramEdge { src: item_index[&i], diff --git a/server/data/src/filter_demands.rs b/server/data/src/filter_demands.rs index 99246252..406c6b09 100644 --- a/server/data/src/filter_demands.rs +++ b/server/data/src/filter_demands.rs @@ -32,7 +32,7 @@ pub fn filter_demands_and_recipes( ); // Remove tile-bound recipes that cant be performed - recipes.retain(|r| r.tile().map_or(true, |t| map_tiles.contains(&t))); + recipes.retain(|r| r.tile().is_none_or(|t| map_tiles.contains(&t))); let mut producable = HashMap::new(); diff --git a/server/data/src/lib.rs b/server/data/src/lib.rs index a5e8ac68..dd462e3b 100644 --- a/server/data/src/lib.rs +++ b/server/data/src/lib.rs @@ -286,6 +286,7 @@ fn build_data( Ok((data, serverdata)) } +#[allow(clippy::type_complexity)] fn load_recipes( recipes_in: Vec<RecipeDecl>, reg: &ItemTileRegistry, @@ -313,10 +314,10 @@ fn load_recipes( let mut inputs = r.inputs.into_iter().map(|i| reg.register_item(i)); let mut outputs = r.outputs.into_iter().map(|o| reg.register_item(o)); let tile = r.tile.map(|t| reg.register_tile(t)); - if let Some(g) = r.group { - if !r.group_hidden { - recipe_groups.entry(g).or_default().extend(inputs.clone()); - } + if let Some(g) = r.group + && !r.group_hidden + { + recipe_groups.entry(g).or_default().extend(inputs.clone()); } match r.action { RecipeDeclAction::Never => {} diff --git a/server/data/src/registry.rs b/server/data/src/registry.rs index 7d56567d..952a2e29 100644 --- a/server/data/src/registry.rs +++ b/server/data/src/registry.rs @@ -128,10 +128,8 @@ pub(crate) fn filter_unused_tiles_and_items(data: &mut Gamedata, serverdata: &mu *tile = tile_map[tile] } *input = item_map[input]; - for output in outputs { - if let Some(output) = output { - *output = item_map[output]; - } + for output in outputs.iter_mut().flatten() { + *output = item_map[output]; } } Recipe::Instant { @@ -143,15 +141,11 @@ pub(crate) fn filter_unused_tiles_and_items(data: &mut Gamedata, serverdata: &mu if let Some(tile) = tile { *tile = tile_map[tile] } - for input in inputs { - if let Some(input) = input { - *input = item_map[input]; - } + for input in inputs.iter_mut().flatten() { + *input = item_map[input]; } - for output in outputs { - if let Some(output) = output { - *output = item_map[output]; - } + for output in outputs.iter_mut().flatten() { + *output = item_map[output]; } } } diff --git a/server/discover/src/main.rs b/server/discover/src/main.rs index 7247854d..3dcb96bf 100644 --- a/server/discover/src/main.rs +++ b/server/discover/src/main.rs @@ -21,8 +21,8 @@ use clap::Parser; use http_body_util::Full; use hurrycurry_protocol::registry::Entry; use hyper::{ - body::Bytes, header::HeaderValue, server::conn::http1, service::service_fn, Response, - StatusCode, + Response, StatusCode, body::Bytes, header::HeaderValue, server::conn::http1, + service::service_fn, }; use hyper_util::rt::TokioIo; use log::warn; diff --git a/server/locale-export/src/main.rs b/server/locale-export/src/main.rs index 23823716..50cfe9eb 100644 --- a/server/locale-export/src/main.rs +++ b/server/locale-export/src/main.rs @@ -1,9 +1,9 @@ -use anyhow::{anyhow, Context, Result}; +use anyhow::{Context, Result, anyhow}; use clap::Parser; use std::{ collections::BTreeMap, fmt::Write as W2, - fs::{read_to_string, File}, + fs::{File, read_to_string}, io::Write, path::{Path, PathBuf}, }; @@ -105,10 +105,10 @@ msgstr "" .to_string_lossy(), ini.into_iter() .try_fold(String::new(), |mut a, (mut key, value)| { - if let Some(id_map) = &id_map { - if let Some(new_id) = id_map.get(&key) { - key = new_id.to_owned() - } + if let Some(id_map) = &id_map + && let Some(new_id) = id_map.get(&key) + { + key = new_id.to_owned() } let key = serde_json::to_string(&key)?; let value = serde_json::to_string(&value)?; diff --git a/server/protocol/src/movement.rs b/server/protocol/src/movement.rs index 6945aa5d..daa8c421 100644 --- a/server/protocol/src/movement.rs +++ b/server/protocol/src/movement.rs @@ -16,8 +16,8 @@ */ use crate::{ - glam::{IVec2, Vec2}, PacketC, PacketS, PlayerID, + glam::{IVec2, Vec2}, }; use std::collections::HashSet; diff --git a/server/registry/src/conn_test.rs b/server/registry/src/conn_test.rs index 553d1fff..809abc78 100644 --- a/server/registry/src/conn_test.rs +++ b/server/registry/src/conn_test.rs @@ -16,7 +16,7 @@ */ use crate::MAX_ADDR_CACHE; -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use hurrycurry_client_lib::network::tokio::Network; use hurrycurry_protocol::PacketC; use log::info; diff --git a/server/registry/src/list.rs b/server/registry/src/list.rs index 619700f7..05c2eeab 100644 --- a/server/registry/src/list.rs +++ b/server/registry/src/list.rs @@ -19,15 +19,13 @@ use crate::Registry; use anyhow::Result; use hurrycurry_protocol::registry::Entry; use rocket::{ - get, + Either, Request, State, get, http::{Header, MediaType}, request::{self, FromRequest, Outcome}, response::{ - self, + self, Responder, content::{RawHtml, RawJson}, - Responder, }, - Either, Request, State, }; use std::sync::Arc; use tokio::sync::RwLock; diff --git a/server/registry/src/lobby.rs b/server/registry/src/lobby.rs index 4be2cabd..8492fac6 100644 --- a/server/registry/src/lobby.rs +++ b/server/registry/src/lobby.rs @@ -1,10 +1,10 @@ use crate::Registry; use anyhow::Result; use hurrycurry_protocol::{ - glam::{ivec2, vec2, IVec2, Vec2}, + Gamedata, PacketC, PacketS, PlayerClass, PlayerID, TileIndex, VERSION, + glam::{IVec2, Vec2, ivec2, vec2}, movement::MovementBase, registry::Entry, - Gamedata, PacketC, PacketS, PlayerClass, PlayerID, TileIndex, VERSION, }; use log::{error, info, warn}; use rocket::futures::{SinkExt, StreamExt}; diff --git a/server/registry/src/main.rs b/server/registry/src/main.rs index da7f404b..24ce6621 100644 --- a/server/registry/src/main.rs +++ b/server/registry/src/main.rs @@ -26,7 +26,7 @@ use list::{generate_html_list, generate_json_list, r_list}; use lobby::lobby_wrapper; use log::{error, info}; use register::r_register; -use rocket::{fairing::AdHoc, get, http::Header, routes, shield::Shield, Config}; +use rocket::{Config, fairing::AdHoc, get, http::Header, routes, shield::Shield}; use std::{ cmp::Reverse, collections::HashMap, diff --git a/server/registry/src/register.rs b/server/registry/src/register.rs index 893b2a1d..473e958a 100644 --- a/server/registry/src/register.rs +++ b/server/registry/src/register.rs @@ -15,11 +15,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -use crate::{conn_test::test_connect, Registry, MAX_SERVERS}; +use crate::{MAX_SERVERS, Registry, conn_test::test_connect}; use anyhow::Result; use hurrycurry_protocol::registry::Submission; use log::{debug, info}; -use rocket::{http::hyper::Uri, post, serde::json::Json, State}; +use rocket::{State, http::hyper::Uri, post, serde::json::Json}; use std::{ net::{IpAddr, SocketAddr}, str::FromStr, diff --git a/server/replaytool/src/replay.rs b/server/replaytool/src/replay.rs index d442f599..958760ba 100644 --- a/server/replaytool/src/replay.rs +++ b/server/replaytool/src/replay.rs @@ -17,7 +17,7 @@ */ use crate::Event; -use anyhow::{anyhow, Result}; +use anyhow::{Result, anyhow}; use async_compression::tokio::bufread::ZstdDecoder; use futures_util::{SinkExt, StreamExt}; use hurrycurry_protocol::{Message, PacketC, PacketS}; diff --git a/server/src/commands.rs b/server/src/commands.rs index 5eda53b6..0a7b7643 100644 --- a/server/src/commands.rs +++ b/server/src/commands.rs @@ -22,7 +22,7 @@ use crate::{ use anyhow::Result; use clap::{Parser, ValueEnum}; use hurrycurry_bot::algos::ALGO_CONSTRUCTORS; -use hurrycurry_locale::{tre, trm, TrError}; +use hurrycurry_locale::{TrError, tre, trm}; use hurrycurry_protocol::{Character, Menu, Message, PacketC, PlayerClass, PlayerID}; use std::{fmt::Write, time::Duration}; diff --git a/server/src/entity/book.rs b/server/src/entity/book.rs index 4b87aa44..8daec972 100644 --- a/server/src/entity/book.rs +++ b/server/src/entity/book.rs @@ -18,7 +18,7 @@ use super::{Entity, EntityContext}; use anyhow::Result; use hurrycurry_locale::TrError; -use hurrycurry_protocol::{glam::IVec2, Menu, PacketC, PlayerID}; +use hurrycurry_protocol::{Menu, PacketC, PlayerID, glam::IVec2}; #[derive(Debug, Clone)] pub struct Book(pub IVec2); diff --git a/server/src/entity/campaign.rs b/server/src/entity/campaign.rs index fdc169d1..33baf631 100644 --- a/server/src/entity/campaign.rs +++ b/server/src/entity/campaign.rs @@ -19,10 +19,10 @@ use super::{Entity, EntityContext}; use crate::{scoreboard::ScoreboardStore, server::GameServerExt}; use anyhow::Result; use hurrycurry_data::entities::GateCondition; -use hurrycurry_locale::{trm, TrError}; +use hurrycurry_locale::{TrError, trm}; use hurrycurry_protocol::{ - glam::{IVec2, Vec2}, Message, PacketC, PlayerID, TileIndex, + glam::{IVec2, Vec2}, }; #[derive(Debug, Default, Clone)] diff --git a/server/src/entity/conveyor.rs b/server/src/entity/conveyor.rs index e31410e3..9534b045 100644 --- a/server/src/entity/conveyor.rs +++ b/server/src/entity/conveyor.rs @@ -17,8 +17,8 @@ */ use super::{Entity, EntityContext}; use crate::interaction::interact; -use anyhow::{anyhow, bail, Result}; -use hurrycurry_protocol::{glam::IVec2, ItemLocation}; +use anyhow::{Result, anyhow, bail}; +use hurrycurry_protocol::{ItemLocation, glam::IVec2}; #[derive(Debug, Clone)] pub struct Conveyor { diff --git a/server/src/entity/item_portal.rs b/server/src/entity/item_portal.rs index 6035331b..f0472802 100644 --- a/server/src/entity/item_portal.rs +++ b/server/src/entity/item_portal.rs @@ -17,8 +17,8 @@ */ use super::{Entity, EntityContext}; use crate::interaction::interact; -use anyhow::{bail, Result}; -use hurrycurry_protocol::{glam::IVec2, ItemLocation}; +use anyhow::{Result, bail}; +use hurrycurry_protocol::{ItemLocation, glam::IVec2}; #[derive(Debug, Default, Clone)] pub struct ItemPortal { diff --git a/server/src/entity/player_portal.rs b/server/src/entity/player_portal.rs index f70a2f95..1717002a 100644 --- a/server/src/entity/player_portal.rs +++ b/server/src/entity/player_portal.rs @@ -16,8 +16,8 @@ */ use super::{Entity, EntityContext}; -use anyhow::{anyhow, Result}; -use hurrycurry_protocol::{glam::Vec2, PacketC}; +use anyhow::{Result, anyhow}; +use hurrycurry_protocol::{PacketC, glam::Vec2}; #[derive(Debug, Default, Clone)] pub struct PlayerPortal { diff --git a/server/src/entity/tutorial.rs b/server/src/entity/tutorial.rs index bc4e3e7d..69086165 100644 --- a/server/src/entity/tutorial.rs +++ b/server/src/entity/tutorial.rs @@ -19,7 +19,7 @@ use super::{Entity, EntityContext}; use anyhow::Result; use hurrycurry_locale::{TrError, trm}; use hurrycurry_protocol::{ - glam::IVec2, ItemIndex, Message, PacketC, PlayerID, Recipe, RecipeIndex, TileIndex, + ItemIndex, Message, PacketC, PlayerID, Recipe, RecipeIndex, TileIndex, glam::IVec2, }; use log::{debug, warn}; @@ -297,10 +297,10 @@ impl StepContext<'_> { .. } => { for (pos, tile) in self.ent.game.tiles.iter().filter(|(_, t)| t.kind == *tile) { - if let Some(item) = &tile.item { - if item.kind == *input { - return Err((Some(*pos), trm!("s.tutorial.hold_interact"))); - } + if let Some(item) = &tile.item + && item.kind == *input + { + return Err((Some(*pos), trm!("s.tutorial.hold_interact"))); } } if let Some(pos) = self.find_tile(*tile) { @@ -322,10 +322,10 @@ impl StepContext<'_> { } => { for (_pos, tile) in self.ent.game.tiles.iter().filter(|(_, t)| t.kind == *tile) { - if let Some(item) = &tile.item { - if item.kind == *input { - return Err((None, trm!("s.tutorial.wait_finish"))); - } + if let Some(item) = &tile.item + && item.kind == *input + { + return Err((None, trm!("s.tutorial.wait_finish"))); } } if let Some(pos) = self.find_tile(*tile) { diff --git a/server/src/interaction.rs b/server/src/interaction.rs index fef1ca40..5dd7099b 100644 --- a/server/src/interaction.rs +++ b/server/src/interaction.rs @@ -15,7 +15,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -use hurrycurry_client_lib::{gamedata_index::GamedataIndex, Involvement, Item}; +use hurrycurry_client_lib::{Involvement, Item, gamedata_index::GamedataIndex}; use hurrycurry_protocol::{Gamedata, ItemLocation, PacketC, PlayerID, Recipe, Score, TileIndex}; use log::info; use std::collections::VecDeque; @@ -36,46 +36,45 @@ pub fn interact( packet_out: &mut VecDeque<PacketC>, ) { let _ = automated; //? what was this used for?? - if other.is_none() { - if let Some(item) = this { - if let Some(active) = &mut item.active { - let recipe = &data.recipe(active.recipe); - if recipe.supports_tile(tile) { - if let Recipe::Active { outputs, speed, .. } = recipe { - if edge { - active.speed += speed; - } else { - active.speed -= speed; - active.speed = active.speed.max(0.); // in case of "release without press" when items cool on active tile - } - if active.position >= 1. { - let this_had_item = this.is_some(); - let other_had_item = other.is_some(); - *other = outputs[0].map(|kind| Item { kind, active: None }); - *this = outputs[1].map(|kind| Item { kind, active: None }); - produce( - this_had_item, - other_had_item, - this, - this_loc, - other, - other_loc, - score_changed, - packet_out, - ); - } else { - packet_out.push_back(PacketC::SetProgress { - player, - item: this_loc, - position: active.position, - speed: active.speed, - warn: active.warn, - }); - } - return; - } - } + if other.is_none() + && let Some(item) = this + && let Some(active) = &mut item.active + { + let recipe = &data.recipe(active.recipe); + if recipe.supports_tile(tile) + && let Recipe::Active { outputs, speed, .. } = recipe + { + if edge { + active.speed += speed; + } else { + active.speed -= speed; + active.speed = active.speed.max(0.); // in case of "release without press" when items cool on active tile } + if active.position >= 1. { + let this_had_item = this.is_some(); + let other_had_item = other.is_some(); + *other = outputs[0].map(|kind| Item { kind, active: None }); + *this = outputs[1].map(|kind| Item { kind, active: None }); + produce( + this_had_item, + other_had_item, + this, + this_loc, + other, + other_loc, + score_changed, + packet_out, + ); + } else { + packet_out.push_back(PacketC::SetProgress { + player, + item: this_loc, + position: active.position, + speed: active.speed, + warn: active.warn, + }); + } + return; } } if !edge { @@ -87,48 +86,48 @@ pub fn interact( } match recipe { Recipe::Active { input, speed, .. } => { - if other.is_none() { - if let Some(item) = this { - if item.kind == *input && item.active.is_none() { - info!("start active recipe {ri:?}"); - item.active = Some(Involvement { - player, - recipe: ri, - speed: *speed, - position: 0., - warn: false, - }); - } - } + if other.is_none() + && let Some(item) = this + && item.kind == *input + && item.active.is_none() + { + info!("start active recipe {ri:?}"); + item.active = Some(Involvement { + player, + recipe: ri, + speed: *speed, + position: 0., + warn: false, + }); } - if this.is_none() { - if let Some(item) = &other { - if item.kind == *input && item.active.is_none() { - let mut item = other.take().unwrap(); - info!("start active recipe {ri:?}"); - item.active = Some(Involvement { - player, - recipe: ri, - speed: *speed, - position: 0., - warn: false, - }); - *this = Some(item); - score.active_recipes += 1; - packet_out.push_back(PacketC::MoveItem { - from: other_loc, - to: this_loc, - }); - packet_out.push_back(PacketC::SetProgress { - player, - item: this_loc, - position: 0., - speed: *speed, - warn: false, - }); - return; - } - } + if this.is_none() + && let Some(item) = &other + && item.kind == *input + && item.active.is_none() + { + let mut item = other.take().unwrap(); + info!("start active recipe {ri:?}"); + item.active = Some(Involvement { + player, + recipe: ri, + speed: *speed, + position: 0., + warn: false, + }); + *this = Some(item); + score.active_recipes += 1; + packet_out.push_back(PacketC::MoveItem { + from: other_loc, + to: this_loc, + }); + packet_out.push_back(PacketC::SetProgress { + player, + item: this_loc, + position: 0., + speed: *speed, + warn: false, + }); + return; } } Recipe::Instant { @@ -176,24 +175,25 @@ pub fn interact( }) }); - if can_place && this.is_none() { - if let Some(item) = other.take() { - *this = Some(item); - packet_out.push_back(PacketC::MoveItem { - from: other_loc, - to: this_loc, - }); - return; - } + if can_place + && this.is_none() + && let Some(item) = other.take() + { + *this = Some(item); + packet_out.push_back(PacketC::MoveItem { + from: other_loc, + to: this_loc, + }); + return; } - if other.is_none() { - if let Some(item) = this.take() { - *other = Some(item); - packet_out.push_back(PacketC::MoveItem { - from: this_loc, - to: other_loc, - }); - } + if other.is_none() + && let Some(item) = this.take() + { + *other = Some(item); + packet_out.push_back(PacketC::MoveItem { + from: this_loc, + to: other_loc, + }); } } @@ -225,10 +225,10 @@ pub fn tick_slot( let prev_speed = a.speed; if r.supports_tile(tile) { - if a.speed <= 0. { - if let Recipe::Passive { speed, .. } = &data.recipe(a.recipe) { - a.speed = *speed; - } + if a.speed <= 0. + && let Recipe::Passive { speed, .. } = &data.recipe(a.recipe) + { + a.speed = *speed; } } else if let Some(revert_speed) = r.revert_speed() { a.speed = -revert_speed @@ -241,25 +241,25 @@ pub fn tick_slot( packet_out.push_back(PacketC::ClearProgress { item: slot_loc }); return; } - if a.position >= 1. { - if let Recipe::Passive { output, warn, .. } = &data.recipe(a.recipe) { - *slot = output.map(|kind| Item { kind, active: None }); - score.passive_recipes += 1; - *score_changed = true; - packet_out.push_back(PacketC::SetProgress { - player: None, - warn: *warn, - item: slot_loc, - position: 1., - speed: 0., - }); - packet_out.push_back(PacketC::SetItem { - location: slot_loc, - item: slot.as_ref().map(|i| i.kind), - }); - return; - }; - } + if a.position >= 1. + && let Recipe::Passive { output, warn, .. } = &data.recipe(a.recipe) + { + *slot = output.map(|kind| Item { kind, active: None }); + score.passive_recipes += 1; + *score_changed = true; + packet_out.push_back(PacketC::SetProgress { + player: None, + warn: *warn, + item: slot_loc, + position: 1., + speed: 0., + }); + packet_out.push_back(PacketC::SetItem { + location: slot_loc, + item: slot.as_ref().map(|i| i.kind), + }); + return; + }; a.position += dt * a.speed; a.position = a.position.min(1.); @@ -276,29 +276,27 @@ pub fn tick_slot( } else if let Some(recipes) = data_index.recipe_passive_by_input.get(&item.kind) { for &ri in recipes { let recipe = data.recipe(ri); - if recipe.supports_tile(tile) { - if let Recipe::Passive { + if recipe.supports_tile(tile) + && let Recipe::Passive { input, warn, speed, .. } = recipe - { - if *input == item.kind { - item.active = Some(Involvement { - player: None, - recipe: ri, - position: 0., - warn: *warn, - speed: *speed, - }); - packet_out.push_back(PacketC::SetProgress { - player: None, - position: 0., - speed: *speed, - warn: *warn, - item: slot_loc, - }); - return; - } - } + && *input == item.kind + { + item.active = Some(Involvement { + player: None, + recipe: ri, + position: 0., + warn: *warn, + speed: *speed, + }); + packet_out.push_back(PacketC::SetProgress { + player: None, + position: 0., + speed: *speed, + warn: *warn, + item: slot_loc, + }); + return; } } } diff --git a/server/src/main.rs b/server/src/main.rs index be0bb005..93147d45 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -15,13 +15,13 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use clap::Parser; use futures_util::{SinkExt, StreamExt}; use hurrycurry_locale::trm; use hurrycurry_protocol::{PacketC, PacketS}; -use hurrycurry_server::{server::Server, ConnectionID}; -use log::{debug, info, trace, warn, LevelFilter}; +use hurrycurry_server::{ConnectionID, server::Server}; +use log::{LevelFilter, debug, info, trace, warn}; use std::{ env::var, net::SocketAddr, path::PathBuf, process::exit, str::FromStr, sync::Arc, time::Duration, @@ -29,7 +29,7 @@ use std::{ use tokio::{ net::TcpListener, spawn, - sync::{broadcast, mpsc::channel, RwLock}, + sync::{RwLock, broadcast, mpsc::channel}, time::interval, }; use tokio_tungstenite::tungstenite::Message; @@ -315,7 +315,7 @@ async fn run(data_path: PathBuf, args: Args) -> anyhow::Result<()> { #[cfg(test)] mod test { use hurrycurry_protocol::{Character, PacketS, PlayerClass, PlayerID}; - use hurrycurry_server::{server::Server, ConnectionID}; + use hurrycurry_server::{ConnectionID, server::Server}; use std::future::Future; use tokio::sync::broadcast; diff --git a/server/src/network/upnp.rs b/server/src/network/upnp.rs index 8ad79588..a443a223 100644 --- a/server/src/network/upnp.rs +++ b/server/src/network/upnp.rs @@ -15,11 +15,11 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -use anyhow::{bail, Result}; +use anyhow::{Result, bail}; use get_if_addrs::get_if_addrs; use igd::{ - aio::{search_gateway, Gateway}, PortMappingProtocol, SearchOptions, + aio::{Gateway, search_gateway}, }; use log::{error, info}; use std::{ @@ -61,11 +61,11 @@ async fn upnp_setup() -> Result<(Gateway, Ipv4Addr)> { info!("IGD address is {}", gateway.addr); for i in get_if_addrs()? { let a = i.addr.ip(); - if !a.is_loopback() { - if let IpAddr::V4(a) = a { - info!("local v4 address is {a}"); - return Ok((gateway, a)); - } + if !a.is_loopback() + && let IpAddr::V4(a) = a + { + info!("local v4 address is {a}"); + return Ok((gateway, a)); } } bail!("no good local address found") diff --git a/server/src/scoreboard.rs b/server/src/scoreboard.rs index e97e22b2..86616c1f 100644 --- a/server/src/scoreboard.rs +++ b/server/src/scoreboard.rs @@ -23,7 +23,7 @@ use serde::{Deserialize, Serialize}; use std::{ cmp::Reverse, collections::HashMap, - fs::{create_dir_all, read_to_string, rename, File}, + fs::{File, create_dir_all, read_to_string, rename}, io::Write, }; diff --git a/server/src/server.rs b/server/src/server.rs index 48439b5f..9141bc4e 100644 --- a/server/src/server.rs +++ b/server/src/server.rs @@ -461,14 +461,14 @@ impl Server { // TODO if holding two, one is destroyed for item in p.items.into_iter().flatten() { let pos = p.movement.position.floor().as_ivec2(); - if let Some(tile) = self.game.tiles.get_mut(&pos) { - if tile.item.is_none() { - self.packet_out.push_back(PacketC::SetItem { - location: ItemLocation::Tile(pos), - item: Some(item.kind), - }); - tile.item = Some(item); - } + if let Some(tile) = self.game.tiles.get_mut(&pos) + && tile.item.is_none() + { + self.packet_out.push_back(PacketC::SetItem { + location: ItemLocation::Tile(pos), + item: Some(item.kind), + }); + tile.item = Some(item); } } self.packet_out @@ -725,10 +725,10 @@ impl Server { self.game .players_spatial_index .query(pos1, 2., |p2, _pos2| { - if p1 != p2 { - if let [Some(a), Some(b)] = self.game.players.get_disjoint_mut([&p1, &p2]) { - a.movement.collide(&mut b.movement, dt) - } + if p1 != p2 + && let [Some(a), Some(b)] = self.game.players.get_disjoint_mut([&p1, &p2]) + { + a.movement.collide(&mut b.movement, dt) } }) }); @@ -765,16 +765,13 @@ impl Server { player.communicate_persist = None; } } - if let Some((pos, hand)) = player.interacting { - if let Some(tile) = self.game.tiles.get(&pos) { - if let Some(item) = &tile.item { - if let Some(involvement) = &item.active { - if involvement.position >= 1. { - players_auto_release.push((*pid, hand)); - } - } - } - } + if let Some((pos, hand)) = player.interacting + && let Some(tile) = self.game.tiles.get(&pos) + && let Some(item) = &tile.item + && let Some(involvement) = &item.active + && involvement.position >= 1. + { + players_auto_release.push((*pid, hand)); } } for (player, hand) in players_auto_release.drain(..) { diff --git a/server/src/state.rs b/server/src/state.rs index 6cdaa8f1..49b2467a 100644 --- a/server/src/state.rs +++ b/server/src/state.rs @@ -16,11 +16,11 @@ */ use crate::{ - server::{AnnounceState, ConnectionData, GameServerExt, Server}, ConnectionID, + server::{AnnounceState, ConnectionData, GameServerExt, Server}, }; use anyhow::Result; -use hurrycurry_locale::{tre, trm, TrError}; +use hurrycurry_locale::{TrError, tre, trm}; use hurrycurry_protocol::{Menu, Message, PacketC, PacketS, PlayerID, VERSION}; use log::{debug, info, trace}; @@ -92,16 +92,15 @@ impl Server { conn: ConnectionID, packet: PacketS, ) -> Result<Vec<PacketC>, TrError> { - if let Some(p) = get_packet_player(&packet) { - if !self + if let Some(p) = get_packet_player(&packet) + && !self .connections .entry(conn) .or_default() .players .contains(&p) - { - return Err(tre!("s.error.packet_sender_invalid")); - } + { + return Err(tre!("s.error.packet_sender_invalid")); } let mut replies = Vec::new(); match &packet { diff --git a/server/tools/src/diagram_dot.rs b/server/tools/src/diagram_dot.rs index 1701f4ab..307fa470 100644 --- a/server/tools/src/diagram_dot.rs +++ b/server/tools/src/diagram_dot.rs @@ -52,7 +52,7 @@ pub fn diagram_dot(data: &Gamedata, diagram: &Diagram, use_position: bool) -> Re if use_position { attrs.push(format!("pos=\"{},{}!\"", n.position.x, n.position.y)); } - node_style(&mut attrs, &n); + node_style(&mut attrs, n); match &n.label { Message::Text(text) => { attrs.push(format!("label=\"{text}\"")); |