Skip to content

Commit b1ad365

Browse files
committed
feat: game reporting id, game replay command
1 parent bbae80f commit b1ad365

4 files changed

Lines changed: 40 additions & 5 deletions

File tree

src/services/game/mod.rs

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ use crate::{
1010
GameSetupContext, GameSetupResponse, GameState, GetGameDetails,
1111
HostMigrateFinished, HostMigrateStart, JoinComplete, PlayerJoining,
1212
PlayerNetConnectionStatus, PlayerRemoved, PlayerState, PlayerStateChange,
13-
RemoveReason, SettingChange, SlotType, StateChange, UNSPECIFIED_TEAM_INDEX,
13+
RemoveReason, ReportingIdChange, SettingChange, SlotType, StateChange,
14+
UNSPECIFIED_TEAM_INDEX,
1415
},
1516
util::LOCALE_NZ,
1617
NetworkAddress,
@@ -252,6 +253,15 @@ impl Game {
252253
}
253254
}
254255

256+
/// Handle a "replay", game resetting its state back to pre-game
257+
/// updates game reporting id
258+
pub fn replay(&mut self) {
259+
self.set_state(GameState::PreGame);
260+
261+
// TODO: Rotate game reporting ID to a new ID
262+
self.set_game_reporting_id(18014398695176361);
263+
}
264+
255265
pub fn game_data(&self) -> RawBlaze {
256266
let data = GetGameDetails { game: self };
257267
data.into()
@@ -459,6 +469,21 @@ impl Game {
459469
));
460470
}
461471

472+
pub fn set_game_reporting_id(&mut self, reporting_id: u64) {
473+
self.reporting_id = reporting_id;
474+
475+
debug!("Updated game reporting id (Value: {:?})", &reporting_id);
476+
477+
self.notify_all(Packet::notify(
478+
game_manager::COMPONENT,
479+
game_manager::GAME_REPORTING_ID_CHANGE,
480+
ReportingIdChange {
481+
id: self.id,
482+
grid: reporting_id,
483+
},
484+
));
485+
}
486+
462487
pub fn set_settings(&mut self, settings: GameSettings) {
463488
self.settings = settings;
464489

src/session/models/game_manager.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,17 @@ pub struct StateChange {
538538
pub state: GameState,
539539
}
540540

541+
/// Message for a game reporting ID changing
542+
#[derive(TdfSerialize)]
543+
pub struct ReportingIdChange {
544+
/// The ID of the game
545+
#[tdf(tag = "GID")]
546+
pub id: GameID,
547+
/// The new game reporting ID
548+
#[tdf(tag = "GRID")]
549+
pub grid: u64,
550+
}
551+
541552
/// Message for a game setting changing
542553
#[derive(TdfSerialize)]
543554
pub struct SettingChange {

src/session/routes/game_manager.rs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,16 +544,14 @@ pub async fn handle_cancel_matchmaking(
544544
/// "GID": 2,
545545
/// }
546546
/// ```
547-
#[allow(unused)]
548547
pub async fn handle_replay_game(
549-
session: SessionLink,
550-
SessionAuth(player): SessionAuth,
551548
Extension(games): Extension<Arc<Games>>,
552-
553549
Blaze(ReplayGameRequest { game_id }): Blaze<ReplayGameRequest>,
554550
) -> ServerResult<()> {
555551
let game_ref = games
556552
.get_by_id(game_id)
557553
.ok_or(GameManagerError::InvalidGameId)?;
554+
555+
game_ref.write().replay();
558556
Ok(())
559557
}

src/session/routes/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ pub fn router() -> BlazeRouterBuilder {
5656
builder.route(g::COMPONENT, g::CANCEL_MATCHMAKING,handle_cancel_matchmaking);
5757
builder.route(g::COMPONENT, g::GET_GAME_DATA_FROM_ID, handle_get_game_data);
5858
builder.route(g::COMPONENT, g::JOIN_GAME, handle_join_game);
59+
builder.route(g::COMPONENT, g::REPLAY_GAME, handle_replay_game);
5960
}
6061

6162
// Stats

0 commit comments

Comments
 (0)