aboutsummaryrefslogtreecommitdiff
path: root/server
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-10-08 23:33:59 +0200
committermetamuffin <metamuffin@disroot.org>2025-10-08 23:33:59 +0200
commitc768cd1240c272dad34f07b09340cfe1d11d67b6 (patch)
tree7a422e56ee6874a44aa5edba018cf0e902058db3 /server
parentb8af9f80385fa4d38bc2ac2109250fa9ea2a8080 (diff)
downloadhurrycurry-c768cd1240c272dad34f07b09340cfe1d11d67b6.tar
hurrycurry-c768cd1240c272dad34f07b09340cfe1d11d67b6.tar.bz2
hurrycurry-c768cd1240c272dad34f07b09340cfe1d11d67b6.tar.zst
merge all makefiles into one
Diffstat (limited to 'server')
-rw-r--r--server/book-export/src/main.rs3
-rw-r--r--server/data/src/index.rs33
-rw-r--r--server/locale-export/Cargo.toml2
-rw-r--r--server/makefile42
-rw-r--r--server/src/main.rs22
-rw-r--r--server/src/server.rs5
-rw-r--r--server/tools/src/graph.rs3
-rw-r--r--server/tools/src/graph_summary.rs3
-rw-r--r--server/tools/src/main.rs15
-rw-r--r--server/tools/src/map_linter.rs3
10 files changed, 38 insertions, 93 deletions
diff --git a/server/book-export/src/main.rs b/server/book-export/src/main.rs
index b57aa04f..9d3cb5dc 100644
--- a/server/book-export/src/main.rs
+++ b/server/book-export/src/main.rs
@@ -42,8 +42,7 @@ fn main() -> Result<()> {
env_logger::init_from_env("LOG");
let args = Args::parse();
- let mut index = DataIndex::default();
- index.reload()?;
+ let index = DataIndex::new("data".into())?;
let (data, serverdata) = index.generate(&args.map)?;
let book = book(&data, &serverdata)?;
diff --git a/server/data/src/index.rs b/server/data/src/index.rs
index a5ec8d97..9a44d202 100644
--- a/server/data/src/index.rs
+++ b/server/data/src/index.rs
@@ -23,35 +23,34 @@ use std::{
collections::{HashMap, HashSet},
fs::{File, read_to_string},
path::PathBuf,
- str::FromStr,
- sync::Mutex,
};
use crate::{MapDecl, Serverdata, book::book, build_data};
-#[derive(Debug, Deserialize, Default)]
+#[derive(Debug, Deserialize)]
pub struct DataIndex {
+ #[serde(skip)]
+ pub path: PathBuf,
pub maps: HashMap<String, MapMetadata>,
pub recipes: HashSet<String>,
}
-pub static DATA_DIR: Mutex<Option<PathBuf>> = Mutex::new(None);
-fn data_dir() -> PathBuf {
- DATA_DIR
- .lock()
- .unwrap()
- .to_owned()
- .unwrap_or_else(|| PathBuf::from_str("data").unwrap())
-}
-
impl DataIndex {
- pub fn load() -> Result<Self> {
- let mut s = Self::default();
+ pub fn new(path: PathBuf) -> Result<Self> {
+ let mut s = Self {
+ path,
+ maps: HashMap::new(),
+ recipes: HashSet::new(),
+ };
s.reload()?;
Ok(s)
}
pub fn reload(&mut self) -> Result<()> {
- *self = serde_yml::from_reader(File::open(data_dir().join("index.yaml"))?)?;
+ let path = self.path.clone();
+ *self = serde_yml::from_reader(
+ File::open(self.path.join("index.yaml")).context("Failed opening data index")?,
+ )?;
+ self.path = path;
Ok(())
}
@@ -60,14 +59,14 @@ impl DataIndex {
if name.contains("..") || name.starts_with("/") || name.contains("//") {
bail!("illegal map path");
}
- let path = data_dir().join(format!("maps/{name}.yaml"));
+ let path = self.path.join(format!("maps/{name}.yaml"));
Ok(read_to_string(path)?)
}
pub fn read_recipes(&self, name: &str) -> Result<String> {
if !self.recipes.contains(name) {
bail!("unknown recipes: {name:?}");
}
- let path = data_dir().join(format!("recipes/{name}.yaml"));
+ let path = self.path.join(format!("recipes/{name}.yaml"));
Ok(read_to_string(path)?)
}
pub fn generate(&self, map: &str) -> Result<(Gamedata, Serverdata)> {
diff --git a/server/locale-export/Cargo.toml b/server/locale-export/Cargo.toml
index 89543937..56067c7a 100644
--- a/server/locale-export/Cargo.toml
+++ b/server/locale-export/Cargo.toml
@@ -1,5 +1,5 @@
[package]
-name = "localetool"
+name = "hurrycurry-locale-export"
version = "0.1.0"
edition = "2021"
diff --git a/server/makefile b/server/makefile
deleted file mode 100644
index bff817db..00000000
--- a/server/makefile
+++ /dev/null
@@ -1,42 +0,0 @@
-# Hurry Curry! - a game about cooking
-# Copyright (C) 2025 Hurry Curry! contributors
-#
-# This program is free software: you can redistribute it and/or modify
-# it under the terms of the GNU Affero General Public License as published by
-# the Free Software Foundation, version 3 of the License only.
-#
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-# GNU Affero General Public License for more details.
-#
-# You should have received a copy of the GNU Affero General Public License
-# along with this program. If not, see <https://www.gnu.org/licenses/>.
-#
-
-SERVER = ../target/release/hurrycurry-server
-REPLAYTOOL = ../target/release/hurrycurry-replaytool
-DISCOVER = ../target/release/hurrycurry-discover
-BOT = ../target/release/hurrycurry-bot
-EDITOR = ../target/release/hurrycurry-editor
-
-.PHONY: all clean server replaytool discover bot editor
-all: server replaytool discover bot editor
-server: $(SERVER)
-replaytool: $(REPLAYTOOL)
-discover: $(DISCOVER)
-bot: $(BOT)
-editor: $(EDITOR)
-clean:
-
-$(SERVER): $(shell find protocol src -type f)
- cargo $(CARGOFLAGS) build --release
-$(REPLAYTOOL): $(shell find protocol replaytool -type f)
- { cd replaytool; cargo $(CARGOFLAGS) build --release; }
-$(BOT): $(shell find protocol bot client-lib -type f)
- { cd bot; cargo $(CARGOFLAGS) build --release; }
-$(DISCOVER): $(shell find protocol discover -type f)
- { cd discover; cargo $(CARGOFLAGS) build --release; }
-$(EDITOR): $(shell find protocol client-lib editor -type f)
- { cd editor; cargo $(CARGOFLAGS) build --release; }
-
diff --git a/server/src/main.rs b/server/src/main.rs
index b1265420..7ab19f30 100644
--- a/server/src/main.rs
+++ b/server/src/main.rs
@@ -18,7 +18,6 @@
use anyhow::{bail, Result};
use clap::Parser;
use futures_util::{SinkExt, StreamExt};
-use hurrycurry_data::index::DATA_DIR;
use hurrycurry_locale::trm;
use hurrycurry_protocol::{PacketC, PacketS};
use hurrycurry_server::{server::Server, ConnectionID};
@@ -92,7 +91,7 @@ fn main() -> Result<()> {
info!("Starting Hurry Curry! Server {version} ({distribution})");
- let data_dir = if let Some(d) = args.data_dir.clone() {
+ let data_path = if let Some(d) = args.data_dir.clone() {
d
} else {
let mut test_order = Vec::new();
@@ -134,22 +133,21 @@ fn main() -> Result<()> {
info!("Selected data dir {d:?}");
PathBuf::from_str(d)?
};
- *DATA_DIR.lock().unwrap() = Some(data_dir);
tokio::runtime::Builder::new_multi_thread()
.enable_all()
.build()?
- .block_on(run(args))?;
+ .block_on(run(data_path, args))?;
Ok(())
}
-async fn run(args: Args) -> anyhow::Result<()> {
+async fn run(data_path: PathBuf, args: Args) -> anyhow::Result<()> {
let ws_listener = TcpListener::bind(args.listen).await?;
info!("Listening for websockets on {}", ws_listener.local_addr()?);
let (tx, rx) = broadcast::channel::<PacketC>(128 * 1024);
- let mut state = Server::new(tx)?;
+ let mut state = Server::new(data_path, tx)?;
state.load(state.index.generate_with_book("lobby")?, None);
let state = Arc::new(RwLock::new(state));
@@ -315,14 +313,12 @@ async fn run(args: Args) -> anyhow::Result<()> {
#[cfg(test)]
mod test {
- use hurrycurry_data::index::DATA_DIR;
use hurrycurry_protocol::{Character, PacketS, PlayerClass, PlayerID};
use hurrycurry_server::{server::Server, ConnectionID};
use std::future::Future;
use tokio::sync::broadcast;
fn harness(body: impl Future) {
- *DATA_DIR.lock().unwrap() = Some("../data".into());
tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
@@ -332,26 +328,26 @@ mod test {
#[test]
fn run() {
- harness(async { Server::new(broadcast::channel(1024).0).unwrap() });
+ harness(async { Server::new("../data".into(), broadcast::channel(1024).0).unwrap() });
}
#[test]
fn map_load() {
harness(async {
- let mut s = Server::new(broadcast::channel(1024).0).unwrap();
+ let mut s = Server::new("../data".into(), broadcast::channel(1024).0).unwrap();
s.load(s.index.generate("5star").unwrap(), None);
});
}
#[test]
fn map_load_book() {
harness(async {
- let mut s = Server::new(broadcast::channel(1024).0).unwrap();
+ let mut s = Server::new("../data".into(), broadcast::channel(1024).0).unwrap();
s.load(s.index.generate_with_book("lobby").unwrap(), None);
});
}
#[test]
fn tick() {
harness(async {
- let mut s = Server::new(broadcast::channel(1024).0).unwrap();
+ let mut s = Server::new("../data".into(), broadcast::channel(1024).0).unwrap();
for _ in 0..100 {
s.tick(0.1);
}
@@ -360,7 +356,7 @@ mod test {
#[test]
fn packet_sender_verif() {
harness(async {
- let mut s = Server::new(broadcast::channel(1024).0).unwrap();
+ let mut s = Server::new("../data".into(), broadcast::channel(1024).0).unwrap();
for (conn, p) in [
PacketS::Effect {
diff --git a/server/src/server.rs b/server/src/server.rs
index 034fe67a..3f54fe38 100644
--- a/server/src/server.rs
+++ b/server/src/server.rs
@@ -35,6 +35,7 @@ use log::{info, warn};
use rand::random;
use std::{
collections::{HashMap, HashSet, VecDeque},
+ path::PathBuf,
sync::Arc,
time::{Duration, Instant},
};
@@ -333,10 +334,10 @@ impl GameServerExt for Game {
}
impl Server {
- pub fn new(tx: Sender<PacketC>) -> Result<Self> {
+ pub fn new(data_path: PathBuf, tx: Sender<PacketC>) -> Result<Self> {
Ok(Self {
game: Game::default(),
- index: DataIndex::load().context("Failed to load data index")?,
+ index: DataIndex::new(data_path).context("Failed to load data index")?,
tx,
announce_state: AnnounceState::Done,
packet_out: VecDeque::new(),
diff --git a/server/tools/src/graph.rs b/server/tools/src/graph.rs
index a65ffc97..343047da 100644
--- a/server/tools/src/graph.rs
+++ b/server/tools/src/graph.rs
@@ -20,8 +20,7 @@ use hurrycurry_data::index::DataIndex;
use hurrycurry_protocol::{Demand, ItemIndex, Recipe, RecipeIndex};
pub(crate) fn graph() -> Result<()> {
- let mut index = DataIndex::default();
- index.reload()?;
+ let index = DataIndex::new("data".into())?;
println!("digraph {{");
diff --git a/server/tools/src/graph_summary.rs b/server/tools/src/graph_summary.rs
index bfdcc955..c6db2678 100644
--- a/server/tools/src/graph_summary.rs
+++ b/server/tools/src/graph_summary.rs
@@ -22,8 +22,7 @@ use hurrycurry_protocol::{ItemIndex, Recipe, TileIndex};
use std::collections::HashSet;
pub(crate) fn graph_summary() -> Result<()> {
- let mut index = DataIndex::default();
- index.reload()?;
+ let index = DataIndex::new("data".into())?;
println!("digraph {{");
diff --git a/server/tools/src/main.rs b/server/tools/src/main.rs
index 07c5d45b..4af6b87f 100644
--- a/server/tools/src/main.rs
+++ b/server/tools/src/main.rs
@@ -65,8 +65,7 @@ fn main() -> Result<()> {
Action::Graph => graph()?,
Action::GraphSummary => graph_summary()?,
Action::GraphSingle { out, dot_out } => {
- let mut index = DataIndex::default();
- index.reload()?;
+ let index = DataIndex::new("data".into())?;
let (data, serverdata) = index.generate("5star")?;
let out = data.get_item_by_name(&out).unwrap();
let mut diagram = recipe_diagram(&data, &serverdata, &[out])?;
@@ -79,24 +78,21 @@ fn main() -> Result<()> {
println!("{out}");
}
Action::MapDemands { map } => {
- let mut index = DataIndex::default();
- index.reload()?;
+ let index = DataIndex::new("data".into())?;
let (data, _) = index.generate(&map)?;
for demand in &data.demands {
println!("{}", data.item_name(demand.input))
}
}
Action::MapItems { map } => {
- let mut index = DataIndex::default();
- index.reload()?;
+ let index = DataIndex::new("data".into())?;
let (data, _) = index.generate(&map)?;
for name in &data.item_names {
println!("{name}")
}
}
Action::MapTiles { map } => {
- let mut index = DataIndex::default();
- index.reload()?;
+ let index = DataIndex::new("data".into())?;
let (data, _) = index.generate(&map)?;
for name in &data.tile_names {
println!("{name}")
@@ -104,8 +100,7 @@ fn main() -> Result<()> {
}
Action::CheckMap { map } => {
if map == "all" {
- let mut index = DataIndex::default();
- index.reload()?;
+ let index = DataIndex::new("data".into())?;
for map in index.maps.keys() {
check_map(map)?;
}
diff --git a/server/tools/src/map_linter.rs b/server/tools/src/map_linter.rs
index 678f2930..94b57726 100644
--- a/server/tools/src/map_linter.rs
+++ b/server/tools/src/map_linter.rs
@@ -146,8 +146,7 @@ static TILE_MODE: LazyLock<HashMap<String, TileMode>> = LazyLock::new(|| {
pub fn check_map(map: &str) -> Result<()> {
let style = &COLORED;
let locale = &*FALLBACK_LOCALE;
- let mut index = DataIndex::default();
- index.reload()?;
+ let index = DataIndex::new("data".into())?;
let (data, serverdata) = index.generate(map)?;
let mut warnings = Vec::new();