diff options
| author | metamuffin <metamuffin@disroot.org> | 2025-10-08 23:33:59 +0200 |
|---|---|---|
| committer | metamuffin <metamuffin@disroot.org> | 2025-10-08 23:33:59 +0200 |
| commit | c768cd1240c272dad34f07b09340cfe1d11d67b6 (patch) | |
| tree | 7a422e56ee6874a44aa5edba018cf0e902058db3 /server/src | |
| parent | b8af9f80385fa4d38bc2ac2109250fa9ea2a8080 (diff) | |
| download | hurrycurry-c768cd1240c272dad34f07b09340cfe1d11d67b6.tar hurrycurry-c768cd1240c272dad34f07b09340cfe1d11d67b6.tar.bz2 hurrycurry-c768cd1240c272dad34f07b09340cfe1d11d67b6.tar.zst | |
merge all makefiles into one
Diffstat (limited to 'server/src')
| -rw-r--r-- | server/src/main.rs | 22 | ||||
| -rw-r--r-- | server/src/server.rs | 5 |
2 files changed, 12 insertions, 15 deletions
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(), |