aboutsummaryrefslogtreecommitdiff
path: root/server/src
diff options
context:
space:
mode:
authornokoe <nokoe@mailbox.org>2026-02-26 05:15:54 +0100
committernokoe <nokoe@mailbox.org>2026-02-27 19:31:14 +0100
commita859bceeddc8e746bba630b3cc197532b68adbcb (patch)
treef8e033595d21e4de34774e4caed8b483c7eba5c6 /server/src
parent6419d8c8139d697af309b7db2e698effa8290582 (diff)
downloadhurrycurry-a859bceeddc8e746bba630b3cc197532b68adbcb.tar
hurrycurry-a859bceeddc8e746bba630b3cc197532b68adbcb.tar.bz2
hurrycurry-a859bceeddc8e746bba630b3cc197532b68adbcb.tar.zst
use stable rust toolchainstable-rust
Diffstat (limited to 'server/src')
-rw-r--r--server/src/entity/customers.rs9
-rw-r--r--server/src/entity/pedestrians.rs7
-rw-r--r--server/src/entity/tag_minigame.rs5
-rw-r--r--server/src/lib.rs9
-rw-r--r--server/src/network/mdns.rs5
-rw-r--r--server/src/network/register.rs17
-rw-r--r--server/src/server.rs3
-rw-r--r--server/src/state.rs5
8 files changed, 32 insertions, 28 deletions
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 {