diff options
Diffstat (limited to 'server/src')
| -rw-r--r-- | server/src/benchmark.rs | 4 | ||||
| -rw-r--r-- | server/src/commands.rs | 14 | ||||
| -rw-r--r-- | server/src/entity/mod.rs | 4 | ||||
| -rw-r--r-- | server/src/main.rs | 14 | ||||
| -rw-r--r-- | server/src/server.rs | 55 | ||||
| -rw-r--r-- | server/src/state.rs | 12 |
6 files changed, 64 insertions, 39 deletions
diff --git a/server/src/benchmark.rs b/server/src/benchmark.rs index 6e9e4eb7..216cf0a8 100644 --- a/server/src/benchmark.rs +++ b/server/src/benchmark.rs @@ -22,7 +22,7 @@ use crate::{ }; use anyhow::Result; use hurrycurry_bot::algos::Simple; -use hurrycurry_data::build_data; +use hurrycurry_data::build_gamedata; use hurrycurry_protocol::{Character, PacketC, PlayerClass}; use log::debug; use std::{path::PathBuf, time::Instant}; @@ -37,7 +37,7 @@ pub fn benchmark(data_path: PathBuf) -> Result<()> { broadcast::channel(1024).0, )?; - server.load(build_data(&server.config.data_path, "junior", true)?, None); + server.load(build_gamedata(&server.config.data_path, "junior", true)?, None); server.entities.push(Box::new(BotDriver::new( "player".to_string(), diff --git a/server/src/commands.rs b/server/src/commands.rs index 0dc8b954..d2a7da2c 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_data::build_data; +use hurrycurry_data::build_gamedata; use hurrycurry_locale::{TrError, tre, trm}; use hurrycurry_protocol::{ Character, Hand, ItemLocation, Menu, Message, PacketC, PlayerClass, PlayerID, @@ -175,7 +175,7 @@ impl Server { }) .ok(); } - let mut data = build_data(&self.config.data_path, &name, true) + let mut data = build_gamedata(&self.config.data_path, &name, true) .map_err(|e| TrError::Plain(e.to_string()))?; if let Some(hand_count) = hand_count { @@ -206,7 +206,7 @@ impl Server { }) .ok(); self.load( - build_data(&self.config.data_path, &self.config.lobby, true) + build_gamedata(&self.config.data_path, &self.config.lobby, true) .map_err(|e| TrError::Plain(e.to_string()))?, None, ); @@ -216,7 +216,7 @@ impl Server { return Err(tre!("s.error.must_be_alone")); } self.load( - build_data(&self.config.data_path, &self.game.data.current_map, true) + build_gamedata(&self.config.data_path, &self.game.data.current_map, true) .map_err(|e| TrError::Plain(e.to_string()))?, None, ); @@ -233,7 +233,9 @@ impl Server { } self.update_paused(); } - Command::Book => replies.push(PacketC::Menu(Menu::Book(self.data.book.clone()))), + Command::Book => { + replies.push(PacketC::Menu(Menu::Book(self.priv_gamedata.book.clone()))) + } Command::Effect { name } => { self.broadcast .send(PacketC::Effect2 { @@ -289,7 +291,6 @@ impl Server { Command::Scoreboard { map, text } => { let mapname = map.as_ref().unwrap_or(&self.game.data.current_map); let mapname_pretty = &self - .game .data .maps .iter() @@ -327,7 +328,6 @@ impl Server { Command::Info { map } => { let mapname = map.as_ref().unwrap_or(&self.game.data.current_map); let info = &self - .game .data .maps .iter() diff --git a/server/src/entity/mod.rs b/server/src/entity/mod.rs index d10bee0c..8a78202b 100644 --- a/server/src/entity/mod.rs +++ b/server/src/entity/mod.rs @@ -44,7 +44,7 @@ use campaign::{Gate, Map}; use conveyor::Conveyor; use customers::Customers; use environment_effect::{EnvironmentController, EnvironmentEffectController}; -use hurrycurry_data::{Serverdata, entities::EntityDecl}; +use hurrycurry_data::{PrivateGamedata, entities::EntityDecl}; use hurrycurry_game_core::Game; use hurrycurry_locale::TrError; use hurrycurry_protocol::{Character, ItemLocation, PacketC, PacketS, PlayerID}; @@ -61,7 +61,7 @@ pub type Entities = Vec<DynEntity>; pub struct EntityContext<'a> { pub game: &'a mut Game, - pub serverdata: &'a Serverdata, + pub serverdata: &'a PrivateGamedata, pub packet_out: &'a mut VecDeque<PacketC>, pub packet_in: &'a mut VecDeque<PacketS>, pub score_changed: &'a mut bool, diff --git a/server/src/main.rs b/server/src/main.rs index cf133203..f1af7c54 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -68,10 +68,12 @@ pub(crate) struct Args { #[arg(long)] upnp: bool, /// Server name - #[cfg(any(feature = "register", feature = "mdns"))] #[arg(long, short = 'N', default_value = "A Hurry Curry! Server")] server_name: String, - /// Uri for connecting remotely for registry submission + /// Message of the day + #[arg(long, short = 'M')] + motd: Option<String>, + /// URI for connecting remotely for registry submission #[cfg(feature = "register")] #[arg(long)] register_uri: Option<String>, @@ -140,6 +142,8 @@ async fn run(data_path: PathBuf, args: Args) -> anyhow::Result<()> { inactivity_timeout: args.inactivity_timeout, lobby: args.lobby, data_path, + motd: args.motd, + name: args.server_name.clone(), }; let mut state = Server::new(config, tx)?; @@ -342,7 +346,7 @@ fn find_data_path() -> Result<PathBuf> { #[cfg(test)] mod test { - use hurrycurry_data::build_data; + use hurrycurry_data::build_gamedata; use hurrycurry_protocol::{Character, PacketS, PlayerClass, PlayerID}; use hurrycurry_server::{ ConnectionID, @@ -376,7 +380,7 @@ mod test { fn map_load() { let mut s = server(); s.load( - build_data(&s.config.data_path, "junior", false).unwrap(), + build_gamedata(&s.config.data_path, "junior", false).unwrap(), None, ); } @@ -384,7 +388,7 @@ mod test { fn map_load_book() { let mut s = server(); s.load( - build_data(&s.config.data_path, "junior", true).unwrap(), + build_gamedata(&s.config.data_path, "junior", true).unwrap(), None, ); } diff --git a/server/src/server.rs b/server/src/server.rs index 41156e6b..795192c5 100644 --- a/server/src/server.rs +++ b/server/src/server.rs @@ -21,7 +21,7 @@ use crate::{ scoreboard::ScoreboardStore, }; use anyhow::{Context, Result, anyhow}; -use hurrycurry_data::{Serverdata, build_data}; +use hurrycurry_data::{PrivateGamedata, build_gamedata, map_list}; use hurrycurry_game_core::{Game, Involvement, Item, Player, Tile}; use hurrycurry_locale::{ GLOBAL_LOCALE, TrError, @@ -30,7 +30,7 @@ use hurrycurry_locale::{ }; use hurrycurry_protocol::{ Character, Gamedata, Hand, ItemLocation, Menu, MessageTimeout, PacketC, PacketS, PlayerClass, - PlayerID, Score, glam::Vec2, movement::MovementBase, + PlayerID, Score, Serverdata, glam::Vec2, movement::MovementBase, }; use log::{info, warn}; use std::{ @@ -60,6 +60,8 @@ pub struct ServerConfig { pub inactivity_timeout: f32, pub lobby: String, pub data_path: PathBuf, + pub motd: Option<String>, + pub name: String, } pub struct Server { @@ -71,8 +73,8 @@ pub struct Server { pub announce_state: AnnounceState, pub game: Game, - - pub data: Arc<Serverdata>, + pub data: Box<Serverdata>, + pub priv_gamedata: Arc<PrivateGamedata>, pub entities: Entities, pub score_changed: bool, pub packet_loopback: VecDeque<PacketS>, @@ -86,6 +88,17 @@ pub struct Server { impl Server { pub fn new(config: ServerConfig, tx: broadcast::Sender<PacketC>) -> Result<Self> { Ok(Self { + data: Box::new(Serverdata { + bot_algos: vec![ + "waiter".to_string(), + "simple".to_string(), + "dishwasher".to_string(), + "frank".to_string(), + ], + maps: map_list(&config.data_path)?, + motd: config.motd.clone(), + name: config.name.clone(), + }), config, game: Game::default(), tick_perf: (Duration::ZERO, 0), @@ -93,7 +106,7 @@ impl Server { announce_state: AnnounceState::Done, packet_out: VecDeque::new(), connections: HashMap::new(), - data: Serverdata::default().into(), + priv_gamedata: PrivateGamedata::default().into(), entities: Vec::new(), score_changed: false, packet_loopback: VecDeque::new(), @@ -111,6 +124,8 @@ impl Default for ServerConfig { data_path: "data".into(), inactivity_timeout: 60., lobby: "lobby".to_string(), + name: "A Hurry Curry! Server".to_string(), + motd: None, } } } @@ -120,7 +135,7 @@ pub trait GameServerExt { fn load( &mut self, gamedata: Gamedata, - serverdata: &Serverdata, + serverdata: &PrivateGamedata, timer: Option<Duration>, packet_out: &mut VecDeque<PacketC>, is_lobby: bool, @@ -132,7 +147,7 @@ pub trait GameServerExt { name: String, character: Character, class: PlayerClass, - serverdata: &Serverdata, + serverdata: &PrivateGamedata, custom_position: Option<Vec2>, packet_out: Option<&mut VecDeque<PacketC>>, ); @@ -161,7 +176,7 @@ impl GameServerExt for Game { fn load( &mut self, gamedata: Gamedata, - serverdata: &Serverdata, + serverdata: &PrivateGamedata, timer: Option<Duration>, packet_out: &mut VecDeque<PacketC>, is_lobby: bool, @@ -213,7 +228,7 @@ impl GameServerExt for Game { fn prime_client(&self) -> Vec<PacketC> { let mut out = Vec::new(); - out.push(PacketC::Data { + out.push(PacketC::GameData { data: { let mut k = self.data.as_ref().to_owned(); k.recipes.clear(); @@ -309,7 +324,7 @@ impl GameServerExt for Game { name: String, character: Character, class: PlayerClass, - serverdata: &Serverdata, + serverdata: &PrivateGamedata, custom_position: Option<Vec2>, packet_out: Option<&mut VecDeque<PacketC>>, ) { @@ -348,7 +363,7 @@ impl GameServerExt for Game { impl Server { pub fn load_map(&mut self, name: &str) -> Result<()> { self.load( - build_data(&self.config.data_path, name, true) + build_gamedata(&self.config.data_path, name, true) .context(anyhow!("preparing gamedata for {:?}", name))?, None, ); @@ -356,7 +371,7 @@ impl Server { } pub fn load( &mut self, - (gamedata, serverdata): (Gamedata, Serverdata), + (gamedata, serverdata): (Gamedata, PrivateGamedata), timer: Option<Duration>, ) { info!("Changing map to {:?}", gamedata.current_map); @@ -367,7 +382,7 @@ impl Server { packet_in: &mut self.packet_loopback, score_changed: &mut self.score_changed, scoreboard: &self.scoreboard, - serverdata: self.data.as_ref(), + serverdata: self.priv_gamedata.as_ref(), replies: None, dt: 0., load_map: &mut None, @@ -391,7 +406,7 @@ impl Server { for ed in &serverdata.entity_decls { self.entities.push(construct_entity(ed)); } - self.data = serverdata.into(); + self.priv_gamedata = serverdata.into(); for e in &mut self.entities { e.constructor(EntityContext { game: &mut self.game, @@ -399,7 +414,7 @@ impl Server { packet_in: &mut self.packet_loopback, score_changed: &mut self.score_changed, load_map: &mut None, - serverdata: &self.data, + serverdata: &self.priv_gamedata, scoreboard: &self.scoreboard, replies: None, dt: 0., @@ -445,7 +460,7 @@ impl Server { name, character, class, - &self.data, + &self.priv_gamedata, position, Some(&mut self.packet_out), ); @@ -541,7 +556,7 @@ impl Server { packet_in: &mut self.packet_loopback, score_changed: &mut self.score_changed, load_map: &mut None, - serverdata: &self.data, + serverdata: &self.priv_gamedata, scoreboard: &self.scoreboard, replies: Some(replies), dt: 0., @@ -754,7 +769,7 @@ impl Server { score_changed: &mut self.score_changed, packet_in: &mut self.packet_loopback, scoreboard: &self.scoreboard, - serverdata: &self.data, + serverdata: &self.priv_gamedata, replies: None, dt, }) { @@ -770,7 +785,7 @@ impl Server { score_changed: &mut self.score_changed, packet_in: &mut self.packet_loopback, scoreboard: &self.scoreboard, - serverdata: &self.data, + serverdata: &self.priv_gamedata, replies: None, dt: 0., }); @@ -794,7 +809,7 @@ impl Server { self.game.score.time_remaining -= dt as f64; if self.game.score.time_remaining < 0. { let relative_score = - (self.game.score.points * 100) / self.data.score_baseline.max(1); + (self.game.score.points * 100) / self.priv_gamedata.score_baseline.max(1); self.game.score.stars = match relative_score { 100.. => 3, 70.. => 2, diff --git a/server/src/state.rs b/server/src/state.rs index 70c5b7f1..533c5a0c 100644 --- a/server/src/state.rs +++ b/server/src/state.rs @@ -20,7 +20,7 @@ use crate::{ server::{AnnounceState, ConnectionData, GameServerExt, Server}, }; use anyhow::Result; -use hurrycurry_data::build_data; +use hurrycurry_data::build_gamedata; use hurrycurry_locale::{TrError, tre, trm}; use hurrycurry_protocol::{KEEPALIVE_INTERVAL, Menu, Message, PacketC, PacketS, PlayerID, VERSION}; use log::{debug, info, trace, warn}; @@ -76,7 +76,7 @@ impl Server { } if let Some((name, timer)) = r { self.scoreboard.save()?; - self.load(build_data(&self.config.data_path, &name, true)?, timer); + self.load(build_gamedata(&self.config.data_path, &name, true)?, timer); } } @@ -128,6 +128,12 @@ impl Server { supports_bincode: true, }, ); + init.insert( + 1, + PacketC::ServerData { + data: self.data.clone(), + }, + ); self.connections.insert( id, ConnectionData { @@ -242,7 +248,7 @@ impl Server { }) .ok(); self.load( - build_data(&self.config.data_path, &self.config.lobby, true) + build_gamedata(&self.config.data_path, &self.config.lobby, true) .map_err(|m| tre!("s.error.map_load", s = format!("{m}")))?, None, ); |