diff options
-rw-r--r-- | server/protocol/src/lib.rs | 1 | ||||
-rw-r--r-- | server/src/commands.rs | 3 | ||||
-rw-r--r-- | server/src/entity/environment_effect.rs | 13 | ||||
-rw-r--r-- | server/src/entity/mod.rs | 1 | ||||
-rw-r--r-- | server/src/main.rs | 2 | ||||
-rw-r--r-- | server/src/network/mdns.rs | 2 | ||||
-rw-r--r-- | server/src/server.rs | 15 | ||||
-rw-r--r-- | server/src/state.rs | 5 |
8 files changed, 31 insertions, 11 deletions
diff --git a/server/protocol/src/lib.rs b/server/protocol/src/lib.rs index 082a9f10..12b9dfb7 100644 --- a/server/protocol/src/lib.rs +++ b/server/protocol/src/lib.rs @@ -321,6 +321,7 @@ pub enum PacketC { pub enum Menu { Document(DocumentElement), Score(Score), + AnnounceStart, } #[derive(Debug, Clone, Copy, Serialize, Deserialize, Encode, Decode, Default)] diff --git a/server/src/commands.rs b/server/src/commands.rs index 02562c87..91d81c12 100644 --- a/server/src/commands.rs +++ b/server/src/commands.rs @@ -156,6 +156,9 @@ impl Server { .await .map_err(|e| TrError::Plain(e.to_string()))?; self.load(data, timer.map(Duration::from_secs)); + self.start_pause_timer = 3.; + self.packet_out + .push_back(PacketC::Menu(Menu::AnnounceStart)); } Command::End => { self.tx diff --git a/server/src/entity/environment_effect.rs b/server/src/entity/environment_effect.rs index 0a7087c0..95040954 100644 --- a/server/src/entity/environment_effect.rs +++ b/server/src/entity/environment_effect.rs @@ -74,13 +74,10 @@ impl Entity for EnvironmentEffectController { #[derive(Debug, Clone)] pub struct EnvironmentController(pub Vec<String>); impl Entity for EnvironmentController { - fn tick(&mut self, c: EntityContext) -> anyhow::Result<()> { - if c.game.environment_effects.is_empty() { - c.game.environment_effects.extend(self.0.clone()); - c.packet_out.push_back(PacketC::Environment { - effects: c.game.environment_effects.clone(), - }) - } - Ok(()) + fn constructor(&mut self, c: EntityContext) { + c.game.environment_effects.extend(self.0.clone()); + c.packet_out.push_back(PacketC::Environment { + effects: c.game.environment_effects.clone(), + }) } } diff --git a/server/src/entity/mod.rs b/server/src/entity/mod.rs index c5a24e55..c42ebd65 100644 --- a/server/src/entity/mod.rs +++ b/server/src/entity/mod.rs @@ -75,6 +75,7 @@ pub trait Entity: Any { fn finished(&self) -> bool { false } + fn constructor(&mut self, _c: EntityContext<'_>) {} fn destructor(&mut self, _c: EntityContext<'_>) {} fn interact( &mut self, diff --git a/server/src/main.rs b/server/src/main.rs index 97952fc7..3cc6785a 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -87,7 +87,7 @@ pub(crate) struct Args { fn main() -> Result<()> { env_logger::builder() - .filter_level(LevelFilter::Warn) + .filter_level(LevelFilter::Info) .parse_env("LOG") .init(); diff --git a/server/src/network/mdns.rs b/server/src/network/mdns.rs index 018de4b3..b15a197a 100644 --- a/server/src/network/mdns.rs +++ b/server/src/network/mdns.rs @@ -34,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!("hks-{}.local.", random::<u64>()); + 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/server.rs b/server/src/server.rs index 8d04cf57..2fe0be17 100644 --- a/server/src/server.rs +++ b/server/src/server.rs @@ -44,6 +44,7 @@ pub struct Server { pub tx: Sender<PacketC>, pub connections: HashMap<ConnectionID, (HashSet<PlayerID>, bool)>, pub paused: bool, + pub start_pause_timer: f32, pub game: Game, @@ -320,6 +321,7 @@ impl Server { .await .context("Failed to load data index")?, tx, + start_pause_timer: 0., packet_out: VecDeque::new(), connections: HashMap::new(), data: Serverdata::default().into(), @@ -367,6 +369,19 @@ impl Server { self.gamedata_index.update(&self.game.data); self.data = serverdata.into(); self.entities = entities; + for e in &mut self.entities { + e.constructor(EntityContext { + game: &mut self.game, + packet_out: &mut self.packet_out, + packet_in: &mut self.packet_loopback, + score_changed: &mut self.score_changed, + load_map: &mut None, + serverdata: &self.data, + scoreboard: &self.scoreboard, + replies: None, + dt: 0., + }); + } } pub fn packet_in( diff --git a/server/src/state.rs b/server/src/state.rs index f7bccf29..5eb4059a 100644 --- a/server/src/state.rs +++ b/server/src/state.rs @@ -22,7 +22,10 @@ use log::{debug, info, trace}; impl Server { pub async fn tick_outer(&mut self, dt: f32) -> anyhow::Result<()> { - let should_pause = self.connections.iter().all(|c| c.1 .1); + if self.start_pause_timer > 0. { + self.start_pause_timer -= dt + } + let should_pause = self.start_pause_timer > 0. || self.connections.iter().all(|c| c.1 .1); if should_pause != self.paused { info!("Game paused: {should_pause}"); self.paused = should_pause; |