record-daemon: add game start and end metadata
record-daemon / Build, check and test (push) Successful in 2m9s

This commit is contained in:
vhaudiquet committed 2026-03-24 18:16:53 +01:00
1 parent fc7ba40b30
commit f90e549b1e
9 files changed
+1878 -98

No files matched your search

+293 -2
View File
@@ -13,9 +13,17 @@ pub enum GameEvent {
#[serde(rename = "lcu-match-found")]
MatchFound(MatchInfo),
/// Champion select phase started.
#[serde(rename = "lcu-champ-select-start")]
ChampSelectStart(ChampSelectStartInfo),
/// Player picked a champion.
#[serde(rename = "lcu-champion-pick")]
ChampionPick(ChampionPickInfo),
/// Game has started.
#[serde(rename = "lcu-game-start")]
GameStart(GameStartInfo),
GameStart(Box<GameStartInfo>),
/// Player killed an enemy.
#[serde(rename = "lcu-kill")]
@@ -29,6 +37,10 @@ pub enum GameEvent {
#[serde(rename = "lcu-objective")]
Objective(ObjectiveEvent),
/// In-game stats update.
#[serde(rename = "lcu-stats-update")]
StatsUpdate(InGameStats),
/// Game has ended.
#[serde(rename = "lcu-game-end")]
GameEnd(GameEndInfo),
@@ -65,6 +77,10 @@ pub struct MatchInfo {
/// Queue type (ranked, normal, aram, etc.).
pub queue_type: String,
/// Queue ID (numeric identifier).
#[serde(default)]
pub queue_id: Option<u32>,
/// Map name.
pub map: String,
@@ -76,6 +92,87 @@ pub struct MatchInfo {
pub timestamp: DateTime<Utc>,
}
/// Champion select start event data.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ChampSelectStartInfo {
/// Session ID.
#[serde(default)]
pub session_id: Option<String>,
/// Team (100 = blue, 200 = red).
#[serde(default)]
pub team: Option<u32>,
/// Timestamp when champ select started.
#[serde(default = "Utc::now")]
pub timestamp: DateTime<Utc>,
}
/// Champion pick event data.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct ChampionPickInfo {
/// Player's summoner name.
pub summoner_name: String,
/// Champion ID.
pub champion_id: u32,
/// Champion name.
pub champion_name: String,
/// Whether this is the local player's pick.
#[serde(default)]
pub is_local_player: bool,
/// Skin ID selected.
#[serde(default)]
pub skin_id: Option<u32>,
/// Skin name.
#[serde(default)]
pub skin_name: Option<String>,
/// Timestamp when champion was picked.
#[serde(default = "Utc::now")]
pub timestamp: DateTime<Utc>,
}
/// In-game stats update.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct InGameStats {
/// Current kills.
pub kills: u32,
/// Current deaths.
pub deaths: u32,
/// Current assists.
pub assists: u32,
/// Current creep score.
#[serde(default)]
pub creep_score: u32,
/// Current gold.
#[serde(default)]
pub gold: u32,
/// Current level.
#[serde(default)]
pub level: u32,
/// Game time in seconds.
#[serde(default)]
pub game_time: f64,
/// Timestamp of the stats update.
#[serde(default = "Utc::now")]
pub timestamp: DateTime<Utc>,
}
/// Game start event data.
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "camelCase")]
@@ -99,6 +196,26 @@ pub struct GameStartInfo {
#[serde(default)]
pub team: Option<u32>,
/// Queue type (ranked, normal, aram, etc.).
#[serde(default)]
pub queue_type: Option<String>,
/// Queue ID.
#[serde(default)]
pub queue_id: Option<u32>,
/// Game mode.
#[serde(default)]
pub game_mode: Option<String>,
/// Map name.
#[serde(default, rename = "map")]
pub map_name: Option<String>,
/// Full gameflow session data (if available).
#[serde(default)]
pub session: Option<GameflowSession>,
/// Game start timestamp.
#[serde(default = "Utc::now")]
pub timestamp: DateTime<Utc>,
@@ -283,7 +400,7 @@ pub struct RawEvent {
#[serde(untagged)]
pub enum EventData {
/// Game event.
GameEvent(GameEvent),
GameEvent(Box<GameEvent>),
/// Raw JSON value.
Raw(serde_json::Value),
@@ -313,6 +430,12 @@ impl GameEvent {
GameEvent::MatchFound(info) => {
format!("Match found: {} ({})", info.game_mode, info.queue_type)
}
GameEvent::ChampSelectStart(info) => {
format!("Champion select started (team: {:?})", info.team)
}
GameEvent::ChampionPick(pick) => {
format!("{} picked {}", pick.summoner_name, pick.champion_name)
}
GameEvent::GameStart(info) => {
format!("Game started: ID {}", info.game_id)
}
@@ -326,6 +449,12 @@ impl GameEvent {
let team = if obj.team == 100 { "Blue" } else { "Red" };
format!("{} took {:?}", team, obj.objective_type)
}
GameEvent::StatsUpdate(stats) => {
format!(
"Stats: {}/{}/{} CS: {} Gold: {}",
stats.kills, stats.deaths, stats.assists, stats.creep_score, stats.gold
)
}
GameEvent::GameEnd(end) => {
let result = if end.victory { "Victory" } else { "Defeat" };
format!("Game ended: {} ({:.1}s)", result, end.duration)
@@ -336,6 +465,23 @@ impl GameEvent {
GameEvent::Unknown => "Unknown event".to_string(),
}
}
/// Get the event type name for categorization.
pub fn event_type_name(&self) -> &'static str {
match self {
GameEvent::MatchFound(_) => "match_found",
GameEvent::ChampSelectStart(_) => "champ_select_start",
GameEvent::ChampionPick(_) => "champion_pick",
GameEvent::GameStart(_) => "game_start",
GameEvent::Kill(_) => "kill",
GameEvent::Death(_) => "death",
GameEvent::Objective(_) => "objective",
GameEvent::StatsUpdate(_) => "stats_update",
GameEvent::GameEnd(_) => "game_end",
GameEvent::PhaseChange(_) => "phase_change",
GameEvent::Unknown => "unknown",
}
}
}
#[cfg(test)]
@@ -370,3 +516,148 @@ mod tests {
assert_eq!(obj, ObjectiveType::Dragon);
}
}
// ============================================================================
// GameFlow Session Data Structures
// ============================================================================
/// Full gameflow session data from /lol-gameflow/v1/session
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct GameflowSession {
pub game_id: u64,
pub game_name: String,
pub is_custom_game: bool,
pub password: String,
pub player_champion_selections: Vec<PlayerChampionSelection>,
pub queue: Option<QueueInfo>,
pub spectator_key: Option<String>,
pub spectators_allowed: bool,
pub team_one: Vec<TeamMember>,
pub team_two: Vec<TeamMember>,
#[serde(default)]
pub phase: Option<String>,
}
/// Player's champion selection info
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct PlayerChampionSelection {
pub champion_id: u32,
pub puuid: String,
pub selected_skin_index: u32,
pub spell1_id: u32,
pub spell2_id: u32,
}
/// Queue information
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct QueueInfo {
pub id: u32,
pub name: String,
pub short_name: Option<String>,
pub description: String,
pub detailed_description: Option<String>,
pub game_mode: String,
pub map_id: u32,
pub category: String,
#[serde(default)]
pub is_ranked: bool,
#[serde(default)]
pub is_custom: bool,
pub r#type: Option<String>,
pub num_players_per_team: u32,
pub maximum_participant_list_size: u32,
pub minimum_participant_list_size: u32,
pub champions_required_to_play: u32,
#[serde(default)]
pub are_free_champions_allowed: bool,
pub queue_availability: Option<String>,
pub spectator_enabled: Option<bool>,
}
/// Team member information
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
#[serde(rename_all = "camelCase")]
pub struct TeamMember {
pub champion_id: u32,
pub last_selected_skin_index: u32,
pub profile_icon_id: u32,
pub puuid: String,
pub selected_position: String,
pub selected_role: String,
pub summoner_id: u64,
pub summoner_internal_name: String,
pub summoner_name: String,
#[serde(default)]
pub team_owner: bool,
pub team_participant_id: u32,
}
impl GameflowSession {
/// Get a player's champion selection by puuid
pub fn get_player_selection(&self, puuid: &str) -> Option<&PlayerChampionSelection> {
self.player_champion_selections
.iter()
.find(|s| s.puuid == puuid)
}
/// Get a player's team member info by puuid (returns team member and team id)
pub fn get_player_team_member(&self, puuid: &str) -> Option<(&TeamMember, u32)> {
// Check team one
for member in &self.team_one {
if member.puuid == puuid {
return Some((member, 100));
}
}
// Check team two
for member in &self.team_two {
if member.puuid == puuid {
return Some((member, 200));
}
}
None
}
/// Get a player's champion ID by puuid
pub fn get_champion_id(&self, puuid: &str) -> Option<u32> {
self.get_player_selection(puuid).map(|s| s.champion_id)
}
/// Get a player's team (100 or 200) by puuid
pub fn get_team(&self, puuid: &str) -> Option<u32> {
self.get_player_team_member(puuid).map(|(_, team)| team)
}
/// Get a player's summoner name by puuid
pub fn get_summoner_name(&self, puuid: &str) -> Option<&str> {
self.get_player_team_member(puuid).and_then(|(member, _)| {
if member.summoner_name.is_empty() {
None
} else {
Some(member.summoner_name.as_str())
}
})
}
/// Get queue name
pub fn queue_name(&self) -> Option<&str> {
self.queue.as_ref().map(|q| q.name.as_str())
}
/// Get game mode
pub fn game_mode(&self) -> Option<&str> {
self.queue.as_ref().map(|q| q.game_mode.as_str())
}
/// Get map ID
pub fn map_id(&self) -> Option<u32> {
self.queue.as_ref().map(|q| q.map_id)
}
/// Get queue ID
pub fn queue_id(&self) -> Option<u32> {
self.queue.as_ref().map(|q| q.id)
}
}