diff options
| -rw-r--r-- | Cargo.lock | 216 | ||||
| -rw-r--r-- | rust-toolchain | 2 | ||||
| -rw-r--r-- | server/Cargo.toml | 1 | ||||
| -rw-r--r-- | server/bot/Cargo.toml | 1 | ||||
| -rw-r--r-- | server/bot/src/algos/customer.rs | 11 | ||||
| -rw-r--r-- | server/bot/src/algos/frank.rs | 6 | ||||
| -rw-r--r-- | server/bot/src/lib.rs | 9 | ||||
| -rw-r--r-- | server/discover/src/main.rs | 9 | ||||
| -rw-r--r-- | server/registry/src/lobby.rs | 4 | ||||
| -rw-r--r-- | server/registry/src/main.rs | 2 | ||||
| -rw-r--r-- | server/replaytool/Cargo.toml | 1 | ||||
| -rw-r--r-- | server/replaytool/src/main.rs | 1 | ||||
| -rw-r--r-- | server/replaytool/src/render.rs | 16 | ||||
| -rw-r--r-- | server/src/entity/customers.rs | 9 | ||||
| -rw-r--r-- | server/src/entity/pedestrians.rs | 7 | ||||
| -rw-r--r-- | server/src/entity/tag_minigame.rs | 5 | ||||
| -rw-r--r-- | server/src/lib.rs | 9 | ||||
| -rw-r--r-- | server/src/network/mdns.rs | 5 | ||||
| -rw-r--r-- | server/src/network/register.rs | 17 | ||||
| -rw-r--r-- | server/src/server.rs | 3 | ||||
| -rw-r--r-- | server/src/state.rs | 5 |
21 files changed, 281 insertions, 58 deletions
@@ -310,6 +310,17 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724" [[package]] +name = "chacha20" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6f8d983286843e49675a4b7a2d174efe136dc93a18d69130dd18198a6c167601" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.0", + "rand_core 0.10.0", +] + +[[package]] name = "clang-sys" version = "1.8.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -439,6 +450,15 @@ dependencies = [ ] [[package]] +name = "cpufeatures" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b2a41393f66f16b0823bb79094d54ac5fbd34ab292ddafb9a0456ac9f87d201" +dependencies = [ + "libc", +] + +[[package]] name = "crypto-common" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -642,6 +662,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" [[package]] +name = "foldhash" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9c4f5dac5e15c24eb999c26181a6ca40b39fe946cbe4c263c7209467bc83af2" + +[[package]] name = "form_urlencoded" version = "1.2.2" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -824,6 +850,20 @@ dependencies = [ ] [[package]] +name = "getrandom" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "139ef39800118c7683f2fd3c98c1b23c09ae076556b435f8e9064ae108aaeeec" +dependencies = [ + "cfg-if", + "libc", + "r-efi", + "rand_core 0.10.0", + "wasip2", + "wasip3", +] + +[[package]] name = "gimli" version = "0.31.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -887,6 +927,9 @@ name = "hashbrown" version = "0.15.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" +dependencies = [ + "foldhash", +] [[package]] name = "heck" @@ -993,6 +1036,7 @@ dependencies = [ "hurrycurry-game-core", "hurrycurry-protocol", "log", + "rand 0.10.0", "rustls", ] @@ -1117,6 +1161,7 @@ dependencies = [ "futures-util", "hurrycurry-protocol", "log", + "rand 0.10.0", "rustls", "serde", "serde_json", @@ -1143,6 +1188,7 @@ dependencies = [ "log", "mdns-sd", "pollster", + "rand 0.10.0", "reqwest", "serde", "serde_json", @@ -1343,6 +1389,12 @@ dependencies = [ ] [[package]] +name = "id-arena" +version = "2.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d3067d79b975e8844ca9eb072e16b31c3c1c36928edf9c6789548c524d0d954" + +[[package]] name = "idna" version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -1519,6 +1571,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe" [[package]] +name = "leb128fmt" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09edd9e8b54e49e587e4f6295a7d29c3ea94d469cb40ab8ca70b288248a81db2" + +[[package]] name = "libc" version = "0.2.175" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2002,6 +2060,17 @@ dependencies = [ ] [[package]] +name = "rand" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc266eb313df6c5c09c1c7b1fbe2510961e5bcd3add930c1e31f7ed9da0feff8" +dependencies = [ + "chacha20", + "getrandom 0.4.1", + "rand_core 0.10.0", +] + +[[package]] name = "rand_chacha" version = "0.3.1" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2040,6 +2109,12 @@ dependencies = [ ] [[package]] +name = "rand_core" +version = "0.10.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c8d0fd677905edcbeedbf2edb6494d676f0e98d54d5cf9bda0b061cb8fb8aba" + +[[package]] name = "redox_syscall" version = "0.5.17" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2376,6 +2451,12 @@ dependencies = [ ] [[package]] +name = "semver" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d767eb0aabc880b29956c35734170f26ed551a859dbd361d140cdbeca61ab1e2" + +[[package]] name = "serde" version = "1.0.228" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -2459,7 +2540,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3bf829a2d51ab4a5ddf1352d8470c140cadc8301b2ae1789db023f01cedd6ba" dependencies = [ "cfg-if", - "cpufeatures", + "cpufeatures 0.2.17", "digest", ] @@ -3099,7 +3180,16 @@ version = "1.0.1+wasi-0.2.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0562428422c63773dad2c345a1882263bbf4d65cf3f42e90921f787ef5ad58e7" dependencies = [ - "wit-bindgen", + "wit-bindgen 0.46.0", +] + +[[package]] +name = "wasip3" +version = "0.4.0+wasi-0.3.0-rc-2026-01-06" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" +dependencies = [ + "wit-bindgen 0.51.0", ] [[package]] @@ -3175,6 +3265,40 @@ dependencies = [ ] [[package]] +name = "wasm-encoder" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +dependencies = [ + "leb128fmt", + "wasmparser", +] + +[[package]] +name = "wasm-metadata" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" +dependencies = [ + "anyhow", + "indexmap", + "wasm-encoder", + "wasmparser", +] + +[[package]] +name = "wasmparser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" +dependencies = [ + "bitflags", + "hashbrown", + "indexmap", + "semver", +] + +[[package]] name = "web-sys" version = "0.3.78" source = "registry+https://github.com/rust-lang/crates.io-index" @@ -3523,6 +3647,94 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f17a85883d4e6d00e8a97c586de764dabcc06133f7f1d55dce5cdc070ad7fe59" [[package]] +name = "wit-bindgen" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" +dependencies = [ + "wit-bindgen-rust-macro", +] + +[[package]] +name = "wit-bindgen-core" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" +dependencies = [ + "anyhow", + "heck", + "wit-parser", +] + +[[package]] +name = "wit-bindgen-rust" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" +dependencies = [ + "anyhow", + "heck", + "indexmap", + "prettyplease", + "syn", + "wasm-metadata", + "wit-bindgen-core", + "wit-component", +] + +[[package]] +name = "wit-bindgen-rust-macro" +version = "0.51.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" +dependencies = [ + "anyhow", + "prettyplease", + "proc-macro2", + "quote", + "syn", + "wit-bindgen-core", + "wit-bindgen-rust", +] + +[[package]] +name = "wit-component" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" +dependencies = [ + "anyhow", + "bitflags", + "indexmap", + "log", + "serde", + "serde_derive", + "serde_json", + "wasm-encoder", + "wasm-metadata", + "wasmparser", + "wit-parser", +] + +[[package]] +name = "wit-parser" +version = "0.244.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" +dependencies = [ + "anyhow", + "id-arena", + "indexmap", + "log", + "semver", + "serde", + "serde_derive", + "serde_json", + "unicode-xid", + "wasmparser", +] + +[[package]] name = "writeable" version = "0.6.1" source = "registry+https://github.com/rust-lang/crates.io-index" diff --git a/rust-toolchain b/rust-toolchain index 455c5a51..d8ac93be 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2025-10-09 +1.93.1 diff --git a/server/Cargo.toml b/server/Cargo.toml index f74854d6..724d571b 100644 --- a/server/Cargo.toml +++ b/server/Cargo.toml @@ -31,6 +31,7 @@ hurrycurry-protocol = { path = "protocol" } hurrycurry-game-core = { path = "game-core" } hurrycurry-bot = { path = "bot" } hurrycurry-data = { path = "data" } +rand = "0.10.0" [target.'cfg(windows)'.dependencies] windows-registry = "0.6" diff --git a/server/bot/Cargo.toml b/server/bot/Cargo.toml index c78410b3..e73be6e9 100644 --- a/server/bot/Cargo.toml +++ b/server/bot/Cargo.toml @@ -11,6 +11,7 @@ anyhow = "1.0.99" env_logger = "0.11.8" rustls = { version = "0.23.31", features = ["ring"] } clap = { version = "4.5.47", features = ["derive"] } +rand = "0.10.0" [features] # default = ["debug_events"] diff --git a/server/bot/src/algos/customer.rs b/server/bot/src/algos/customer.rs index fe665f47..ba4d43a8 100644 --- a/server/bot/src/algos/customer.rs +++ b/server/bot/src/algos/customer.rs @@ -17,8 +17,7 @@ */ use crate::{ BotAlgo, PacketSink, - pathfinding::{Path, find_path}, - random_float, + pathfinding::{Path, find_path}, random_usize, }; use hurrycurry_game_core::Game; use hurrycurry_protocol::{ @@ -26,7 +25,7 @@ use hurrycurry_protocol::{ glam::{IVec2, Vec2}, }; use log::debug; -use std::random::random; +use rand::{random, seq::IndexedRandom}; #[derive(Debug, Clone)] pub struct Customer { @@ -107,7 +106,7 @@ 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(&chair) = chairs.choose(&mut rand::rng()) && let Some(path) = find_path(game, pos.as_ivec2(), chair) { debug!("{me:?} -> entering"); @@ -129,10 +128,10 @@ impl CustomerState { *ticks += 1; let check = *ticks % 10 == 0; if path.is_done() { - let demand = DemandIndex(random::<usize>(..) % game.data.demands.len()); + let demand = DemandIndex(random_usize(&mut rand::rng()) % game.data.demands.len()); let requested_item = game.data.demands[demand.0].input; debug!("{me:?} -> waiting"); - let timeout = 90. + random_float() * 60.; + let timeout = 90. + random::<f32>() * 60.; let mut facing = Vec2::ZERO; for off in [IVec2::NEG_X, IVec2::NEG_Y, IVec2::X, IVec2::Y] { if game.tiles.get(&(off + *chair)).is_some_and(|t| { diff --git a/server/bot/src/algos/frank.rs b/server/bot/src/algos/frank.rs index 8bd6d17b..156d655d 100644 --- a/server/bot/src/algos/frank.rs +++ b/server/bot/src/algos/frank.rs @@ -21,7 +21,7 @@ use crate::{ }; use hurrycurry_game_core::Game; use hurrycurry_protocol::{Message, PacketS, PlayerClass, PlayerID, glam::Vec2}; -use std::random::random; +use rand::{random, seq::IndexedRandom}; pub struct Frank { me: PlayerID, @@ -86,7 +86,7 @@ impl BotAlgo for Frank { out.push(PacketS::Communicate { player: self.me, message: Some(Message::Translation { - id: format!("s.bot.frank.line.{}", random::<u32>(..) % 8), + id: format!("s.bot.frank.line.{}", random::<u32>() % 8), params: vec![Message::Text(player.name.clone())], }), timeout: Some(3.), @@ -122,5 +122,5 @@ fn find_chef(game: &Game, me: PlayerID) -> Option<PlayerID> { .filter(|(i, p)| p.class == PlayerClass::Chef && **i != me) .map(|(i, _)| *i) .collect::<Vec<_>>(); - chefs.get(random::<usize>(..) % chefs.len().max(1)).copied() + chefs.choose(&mut rand::rng()).copied() } diff --git a/server/bot/src/lib.rs b/server/bot/src/lib.rs index 078314b1..31f2132a 100644 --- a/server/bot/src/lib.rs +++ b/server/bot/src/lib.rs @@ -15,7 +15,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#![feature(random)] + pub mod algos; pub mod pathfinding; pub mod step; @@ -24,7 +24,8 @@ use hurrycurry_game_core::Game; use hurrycurry_protocol::PacketS; #[cfg(feature = "debug_events")] use hurrycurry_protocol::{PlayerID, glam::Vec3}; -use std::{collections::VecDeque, random::random}; +use rand::{Rng, RngExt}; +use std::{collections::VecDeque}; pub struct PacketSink<'a> { buf: &'a mut VecDeque<PacketS>, @@ -54,8 +55,8 @@ impl<T: BotAlgo + ?Sized> BotAlgo for Box<T> { } } -fn random_float() -> f32 { - random::<u32>(..) as f32 / u32::MAX as f32 +fn random_usize<T: Rng>(rng: &mut T) -> usize { + usize::from_ne_bytes(rng.random()) } #[cfg(feature = "debug_events")] diff --git a/server/discover/src/main.rs b/server/discover/src/main.rs index 3dcb96bf..8b86af74 100644 --- a/server/discover/src/main.rs +++ b/server/discover/src/main.rs @@ -15,7 +15,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#![feature(never_type)] use anyhow::Result; use clap::Parser; use http_body_util::Full; @@ -37,7 +36,7 @@ struct Args { version: bool, } -fn main() -> Result<()> { +fn main() -> anyhow::Result<()> { let args = Args::parse(); if args.version { println!("{}", env!("CARGO_PKG_VERSION")); @@ -49,8 +48,10 @@ fn main() -> Result<()> { .enable_all() .build()? .block_on(async_main())?; + Ok(()) } -async fn async_main() -> Result<!> { + +async fn async_main() -> Result<anyhow::Error /*TODO: never type*/> { let mdns = ServiceDaemon::new()?; let mdns_events = mdns.browse("_hurrycurry._tcp.local.")?; @@ -113,7 +114,7 @@ async fn async_main() -> Result<!> { service_fn(move |_req| { let entries = entries.clone(); async move { - Ok::<_, !>(match _req.uri().path() { + anyhow::Ok(match _req.uri().path() { "/" => Response::new(Full::new(Bytes::from( "Hurry Curry! local discovery service", ))), diff --git a/server/registry/src/lobby.rs b/server/registry/src/lobby.rs index 8492fac6..753fdf1c 100644 --- a/server/registry/src/lobby.rs +++ b/server/registry/src/lobby.rs @@ -23,13 +23,13 @@ use tokio::{ use tokio_tungstenite::tungstenite::Message; pub(crate) async fn lobby_wrapper(registry: Arc<RwLock<Registry>>, saddr: SocketAddr) { - let Err(e) = lobby(registry, saddr).await; + let Err(e) = lobby(registry, saddr).await else { unreachable!() }; error!("lobby crashed: {e}"); } const TILES: &[(&str, bool)] = &[("grass", false), ("black-hole", false)]; -async fn lobby(registry: Arc<RwLock<Registry>>, saddr: SocketAddr) -> Result<!> { +async fn lobby(registry: Arc<RwLock<Registry>>, saddr: SocketAddr) -> Result<()> { let ws_listener = TcpListener::bind(saddr).await?; loop { diff --git a/server/registry/src/main.rs b/server/registry/src/main.rs index 3cd252d9..0ccee7f3 100644 --- a/server/registry/src/main.rs +++ b/server/registry/src/main.rs @@ -15,7 +15,7 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#![feature(never_type)] + pub mod conn_test; pub mod list; pub mod lobby; diff --git a/server/replaytool/Cargo.toml b/server/replaytool/Cargo.toml index cc13b4a9..b3055704 100644 --- a/server/replaytool/Cargo.toml +++ b/server/replaytool/Cargo.toml @@ -19,3 +19,4 @@ async-compression = { version = "0.4.30", features = ["zstd", "tokio"] } rustls = { version = "0.23.31", features = ["ring"] } hurrycurry-protocol = { path = "../protocol" } +rand = "0.10.0" diff --git a/server/replaytool/src/main.rs b/server/replaytool/src/main.rs index 7f60287f..8dde133d 100644 --- a/server/replaytool/src/main.rs +++ b/server/replaytool/src/main.rs @@ -15,7 +15,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#![feature(exit_status_error, random)] pub mod record; pub mod render; diff --git a/server/replaytool/src/render.rs b/server/replaytool/src/render.rs index b3290e07..9654256d 100644 --- a/server/replaytool/src/render.rs +++ b/server/replaytool/src/render.rs @@ -17,9 +17,9 @@ */ use crate::replay::replay; -use anyhow::{Context, Result, anyhow}; +use anyhow::{Context, Result, anyhow, bail}; use log::info; -use std::{path::PathBuf, random::random, str::FromStr}; +use std::{path::PathBuf, str::FromStr}; use tokio::{ fs::{File, create_dir_all, remove_dir, remove_file}, io::AsyncWriteExt, @@ -58,9 +58,10 @@ pub struct RenderArgs { pub async fn render(a: RenderArgs) -> Result<()> { let ws_listener = TcpListener::bind(("127.0.0.1", a.port)).await?; - let cwd = PathBuf::from_str("/tmp") - .unwrap() - .join(format!("hurrycurry-render-cfg-{:016x}", random::<u64>(..))); + let cwd = PathBuf::from_str("/tmp").unwrap().join(format!( + "hurrycurry-render-cfg-{:016x}", + rand::random::<u64>() + )); let config = { let (width, height) = a @@ -130,7 +131,10 @@ window/size/viewport_height={height} info!("listening for websockets on {}", ws_listener.local_addr()?); replay(&ws_listener, &a.input).await?; - client.wait().await?.exit_ok()?; + let e = client.wait().await?; + if !e.success() { + bail!("failed with code {:?}", e.code()) + } remove_file(cwd.join("override.cfg")).await?; remove_file(cwd.join("client.pck")).await?; diff --git a/server/src/entity/customers.rs b/server/src/entity/customers.rs index c1bfb525..f6a50fa8 100644 --- a/server/src/entity/customers.rs +++ b/server/src/entity/customers.rs @@ -16,12 +16,11 @@ */ use super::{Entity, EntityContext, bot::BotDriver}; -use crate::random_float; use anyhow::Result; use hurrycurry_bot::algos::Customer; use hurrycurry_locale::TrError; use hurrycurry_protocol::{Character, PlayerClass}; -use std::random::random; +use rand::random; pub struct Customers { customers: Vec<BotDriver<Customer>>, @@ -58,12 +57,12 @@ impl Entity for Customers { self.current_spawn_cooldown = self.current_spawn_cooldown.max(0.); if self.customers.len() < max_count && self.current_spawn_cooldown <= 0. { self.current_spawn_cooldown = - self.spawn_cooldown + random_float() * self.spawn_cooldown; + self.spawn_cooldown + random::<f32>() * self.spawn_cooldown; let bot = BotDriver::new( "".to_string(), Character { - color: random(..), - hairstyle: random(..), + color: random(), + hairstyle: random(), headwear: 0, }, PlayerClass::Customer, diff --git a/server/src/entity/pedestrians.rs b/server/src/entity/pedestrians.rs index 0d33bfd0..4fe91464 100644 --- a/server/src/entity/pedestrians.rs +++ b/server/src/entity/pedestrians.rs @@ -21,7 +21,8 @@ use super::{Entity, EntityContext}; use anyhow::Result; use hurrycurry_locale::TrError; use hurrycurry_protocol::{Character, PacketS, PlayerClass, PlayerID, glam::Vec2}; -use std::{collections::HashMap, random::random}; +use rand::random; +use std::collections::HashMap; pub struct Pedestrians { pub players: HashMap<PlayerID, usize>, @@ -44,8 +45,8 @@ impl Entity for Pedestrians { id: Some(id), name: "Pedestrian".to_string(), character: Character { - color: random(..), - hairstyle: random(..), + color: random(), + hairstyle: random(), headwear: 0, }, class: PlayerClass::Customer, diff --git a/server/src/entity/tag_minigame.rs b/server/src/entity/tag_minigame.rs index e45422b7..f1975f22 100644 --- a/server/src/entity/tag_minigame.rs +++ b/server/src/entity/tag_minigame.rs @@ -22,7 +22,8 @@ use hurrycurry_locale::TrError; use hurrycurry_protocol::{ Hand, ItemIndex, ItemLocation, Message, PacketC, PlayerID, TileIndex, glam::IVec2, }; -use std::{collections::HashMap, fmt::Write, random::random}; +use rand::RngExt; +use std::{collections::HashMap, fmt::Write}; #[derive(Debug, Clone)] pub struct TagMinigame { @@ -60,7 +61,7 @@ impl Entity for TagMinigame { if player_ids.is_empty() { break; } - let id = player_ids[random::<usize>(..) % player_ids.len()]; + let id = player_ids[usize::from_ne_bytes(rand::rng().random())]; let player = c.game.players.get_mut(&id).expect("just got the ids"); if let Some(slot) = player.items.get_mut(0) { *slot = Some(Item { diff --git a/server/src/lib.rs b/server/src/lib.rs index 042fcb6c..79cdbeb3 100644 --- a/server/src/lib.rs +++ b/server/src/lib.rs @@ -15,7 +15,6 @@ along with this program. If not, see <https://www.gnu.org/licenses/>. */ -#![feature(if_let_guard, iterator_try_collect, stmt_expr_attributes, random)] pub mod commands; pub mod entity; pub mod network; @@ -24,7 +23,8 @@ pub mod server; pub mod state; use hurrycurry_protocol::glam::Vec2; -use std::{fmt::Display, random::random}; +use rand::random; +use std::fmt::Display; #[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct ConnectionID(pub i64); @@ -49,9 +49,6 @@ impl InterpolateExt for f32 { } } -fn random_float() -> f32 { - random::<u32>(..) as f32 / u32::MAX as f32 -} fn random_gauss() -> f32 { - [(); 12].map(|()| random_float()).iter().sum::<f32>() - 6. + [(); 12].map(|()| random::<f32>()).iter().sum::<f32>() - 6. } diff --git a/server/src/network/mdns.rs b/server/src/network/mdns.rs index 590ad656..b15a197a 100644 --- a/server/src/network/mdns.rs +++ b/server/src/network/mdns.rs @@ -21,7 +21,8 @@ use get_if_addrs::get_if_addrs; use hurrycurry_protocol::VERSION; use log::{info, warn}; use mdns_sd::{ServiceDaemon, ServiceInfo}; -use std::{collections::HashMap, net::SocketAddr, random::random, sync::Arc, time::Duration}; +use rand::random; +use std::{collections::HashMap, net::SocketAddr, sync::Arc, time::Duration}; use tokio::{sync::RwLock, time::interval}; pub async fn mdns_loop(name: String, listen_addr: SocketAddr, state: Arc<RwLock<Server>>) { @@ -33,7 +34,7 @@ pub async fn mdns_loop(name: String, listen_addr: SocketAddr, state: Arc<RwLock< } }; let mut interval = interval(Duration::from_secs(60)); - let hostname = format!("hurrycurry-{}.local.", random::<u64>(..)); // TODO use system hostname + let hostname = format!("hurrycurry-{}.local.", random::<u64>()); // TODO use system hostname loop { interval.tick().await; if let Err(e) = update_service(&d, &state, &name, &hostname, listen_addr).await { diff --git a/server/src/network/register.rs b/server/src/network/register.rs index 060994fe..101d96d1 100644 --- a/server/src/network/register.rs +++ b/server/src/network/register.rs @@ -19,10 +19,10 @@ use crate::server::Server; use anyhow::{Result, bail}; use hurrycurry_protocol::{VERSION, registry::Submission}; use log::{debug, error, info, warn}; +use rand::random; use reqwest::{Client, Url, header::USER_AGENT}; use std::{ net::{IpAddr, Ipv4Addr, Ipv6Addr}, - random::random, str::FromStr, sync::Arc, time::Duration, @@ -57,7 +57,7 @@ impl Register { registry_uri, players: 0, port, - secret: random(..), + secret: random(), state, ip4_client: if no4 { None @@ -108,7 +108,6 @@ impl Register { None } }); - #[rustfmt::skip] match tokio::join!(v4, v6) { (None, None) => info!("no registration sent"), (Some(Ok(())), None) => info!("Registration successful (IPv4)"), @@ -116,9 +115,15 @@ impl Register { (Some(Ok(())), Some(Ok(()))) => info!("Registration successful (IPv4 + IPv6)"), (Some(Err(e)), None) => error!("Registration failed (IPv4): {e}"), (None, Some(Err(e))) => error!("Registration failed (IPv6): {e}"), - (Some(Err(e1)), Some(Err(e2))) => error!("Registration failed (IPv4 + IPv6): {e1}, {e2}"), - (Some(Ok(())), Some(Err(e))) => warn!("Registration partially failed (IPv4 ok, IPv6 fail): {e}"), - (Some(Err(e)), Some(Ok(()))) => warn!("Registration partially failed (IPv4 fail, IPv6 ok): {e}"), + (Some(Err(e1)), Some(Err(e2))) => { + error!("Registration failed (IPv4 + IPv6): {e1}, {e2}") + } + (Some(Ok(())), Some(Err(e))) => { + warn!("Registration partially failed (IPv4 ok, IPv6 fail): {e}") + } + (Some(Err(e)), Some(Ok(()))) => { + warn!("Registration partially failed (IPv4 fail, IPv6 ok): {e}") + } } Ok(()) } diff --git a/server/src/server.rs b/server/src/server.rs index b2597bc6..30f70bcb 100644 --- a/server/src/server.rs +++ b/server/src/server.rs @@ -18,7 +18,6 @@ use crate::{ ConnectionID, entity::{Entities, EntityContext, construct_entity}, - random_float, scoreboard::ScoreboardStore, }; use anyhow::{Context, Result}; @@ -329,7 +328,7 @@ impl GameServerExt for Game { PlayerClass::Customer => serverdata.customer_spawn.unwrap_or(serverdata.chef_spawn), PlayerClass::Bot | PlayerClass::Chef => serverdata.chef_spawn, PlayerClass::Tram => Vec2::ZERO, // should always have custom location - }) + (Vec2::new(random_float(), random_float()) - 0.5); + }) + (Vec2::new(rand::random::<f32>(), rand::random::<f32>()) - 0.5); self.players.insert( id, Player { diff --git a/server/src/state.rs b/server/src/state.rs index 1bddf33c..937d5a24 100644 --- a/server/src/state.rs +++ b/server/src/state.rs @@ -174,8 +174,9 @@ impl Server { timeout: None, player, .. - } if let Some(command) = text.strip_prefix("/") => { - match self.handle_command_parse(*player, command) { + } if text.strip_prefix("/").is_some() => { + // TODO: replace this by if let guard when stable + match self.handle_command_parse(*player, text.strip_prefix("/").unwrap()) { Ok(packets) => return Ok(packets), Err(e) => { return Ok(vec![PacketC::ServerMessage { |