aboutsummaryrefslogtreecommitdiff
path: root/server/src/state.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/src/state.rs')
-rw-r--r--server/src/state.rs40
1 files changed, 28 insertions, 12 deletions
diff --git a/server/src/state.rs b/server/src/state.rs
index 1d2af247..45e928aa 100644
--- a/server/src/state.rs
+++ b/server/src/state.rs
@@ -17,30 +17,38 @@
*/
use crate::{
message::TrError,
- server::{ConnectionData, GameServerExt, Server},
+ server::{AnnounceState, ConnectionData, GameServerExt, Server},
tre, trm, ConnectionID,
};
use anyhow::Result;
-use hurrycurry_protocol::{Message, PacketC, PacketS, PlayerID, VERSION};
+use hurrycurry_protocol::{Menu, Message, PacketC, PacketS, PlayerID, VERSION};
use log::{debug, info, trace};
impl Server {
pub fn tick_outer(&mut self, dt: f32) -> anyhow::Result<()> {
- let should_pause = self.announce_timer > 0.;
- if should_pause != self.paused {
- self.paused = should_pause;
- }
if !self.paused {
let r = self.tick(dt);
if let Some((name, timer)) = r {
self.scoreboard.save()?;
self.load(self.index.generate_with_book(&name)?, timer);
}
- } else if self.announce_timer > 0. {
- self.announce_timer -= dt;
- if self.announce_timer <= 0. {
+ }
+
+ match &mut self.announce_state {
+ AnnounceState::Queued if !self.paused => {
+ self.announce_state = AnnounceState::Running(3.5);
+ self.packet_out
+ .push_back(PacketC::Menu(Menu::AnnounceStart));
self.update_paused();
}
+ AnnounceState::Running(timer) => {
+ *timer -= dt;
+ if *timer <= 0. {
+ self.announce_state = AnnounceState::Done;
+ self.update_paused();
+ }
+ }
+ _ => (),
}
while let Some(p) = self.packet_out.pop_front() {
@@ -166,8 +174,12 @@ impl Server {
pub fn update_paused(&mut self) {
let all_idle = self.connections.values().all(|c| c.idle);
- let not_ready = self.connections.values().filter(|c| !c.ready).count();
- let announcing = self.announce_timer > 0.;
+ let mut not_ready = self.connections.values().filter(|c| !c.ready).count();
+ let announcing = matches!(self.announce_state, AnnounceState::Running(_));
+
+ if self.game.lobby {
+ not_ready = 0; // not waiting for players in lobby
+ }
let should_pause = all_idle || not_ready > 0 || announcing;
@@ -178,7 +190,11 @@ impl Server {
s = not_ready.to_string()
))
} else if all_idle {
- info!("Game paused: All players idle");
+ if self.connections.is_empty() {
+ info!("Game paused: Server empty");
+ } else {
+ info!("Game paused: All players idle");
+ }
Some(trm!("s.state.paused.all_idle"))
} else if announcing {
info!("Game paused: Waiting for announcement");