This commit is contained in:
+47
-32
@@ -13,7 +13,10 @@ use record_daemon::{
|
||||
config::{self, Settings},
|
||||
error::Result,
|
||||
ipc::{self, IpcHandlers, IpcServer, IpcServerConfig},
|
||||
lqp::{GameEvent, LockfileWatcher, LqpClient},
|
||||
lqp::{
|
||||
describe_event, LockfileWatcher, LqpClient, EVENT_TYPE_CHAMPION_PICK,
|
||||
EVENT_TYPE_GAME_START, EVENT_TYPE_PHASE_CHANGE,
|
||||
},
|
||||
recording::RecordingEngine,
|
||||
state::{DaemonStateMachine, DaemonStatus, StateTransition},
|
||||
timeline::{EventMapper, TimelineStore, TimestampedEvent},
|
||||
@@ -226,25 +229,44 @@ impl Daemon {
|
||||
|
||||
/// Handle a game event.
|
||||
async fn handle_game_event(&self, parsed: record_daemon::lqp::ParsedEvent) -> Result<()> {
|
||||
let event = &parsed.event;
|
||||
info!("[EVENT_HANDLER] Game event received: {:?}", event);
|
||||
let event_type = &parsed.event_type;
|
||||
let raw_data = &parsed.raw_data;
|
||||
let description = describe_event(event_type, raw_data);
|
||||
|
||||
info!(
|
||||
"[EVENT_HANDLER] Game event received: type={}, desc={}",
|
||||
event_type, description
|
||||
);
|
||||
|
||||
// Handle pre-game data collection
|
||||
match event {
|
||||
GameEvent::PhaseChange(info) if info.phase == "ChampSelect" => {
|
||||
info!("[EVENT_HANDLER] Champion select started");
|
||||
match event_type.as_str() {
|
||||
EVENT_TYPE_PHASE_CHANGE => {
|
||||
let phase = raw_data
|
||||
.as_str()
|
||||
.or_else(|| raw_data.get("phase").and_then(|v| v.as_str()))
|
||||
.unwrap_or("");
|
||||
if phase == "ChampSelect" {
|
||||
info!("[EVENT_HANDLER] Champion select started");
|
||||
}
|
||||
}
|
||||
GameEvent::ChampionPick(pick) if pick.is_local_player => {
|
||||
info!(
|
||||
"[EVENT_HANDLER] Local player picked champion: {}",
|
||||
pick.champion_name
|
||||
);
|
||||
EVENT_TYPE_CHAMPION_PICK => {
|
||||
let is_local = raw_data
|
||||
.get("isLocalPlayer")
|
||||
.or_else(|| raw_data.get("is_local_player"))
|
||||
.and_then(|v| v.as_bool())
|
||||
.unwrap_or(false);
|
||||
if is_local {
|
||||
let champion = raw_data
|
||||
.get("championName")
|
||||
.or_else(|| raw_data.get("champion_name"))
|
||||
.and_then(|v| v.as_str())
|
||||
.unwrap_or("unknown");
|
||||
info!("[EVENT_HANDLER] Local player picked champion: {}", champion);
|
||||
}
|
||||
}
|
||||
GameEvent::GameStart(info) => {
|
||||
info!(
|
||||
"[EVENT_HANDLER] Game started with metadata: queue={:?}, mode={:?}, map={:?}",
|
||||
info.queue_type, info.game_mode, info.map_name
|
||||
);
|
||||
EVENT_TYPE_GAME_START => {
|
||||
let game_id = raw_data.get("gameId").and_then(|v| v.as_u64()).unwrap_or(0);
|
||||
info!("[EVENT_HANDLER] Game started with game_id: {}", game_id);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -252,7 +274,7 @@ impl Daemon {
|
||||
// Record event to timeline if recording (BEFORE state transition for GameEnd)
|
||||
// This ensures GameEnd events are recorded while still in recording state
|
||||
if self.state_machine.is_recording() {
|
||||
if let Some((video_ts, game_ts)) = self.event_mapper.write().handle_event(event) {
|
||||
if let Some((video_ts, game_ts)) = self.event_mapper.write().handle_event(event_type) {
|
||||
// Get the current recording ID
|
||||
if let Some(recording_id) = *self.current_recording_id.read() {
|
||||
// Create a timestamped event with raw data
|
||||
@@ -260,11 +282,10 @@ impl Daemon {
|
||||
video_timestamp: video_ts,
|
||||
game_timestamp: game_ts,
|
||||
timestamp: chrono::Utc::now(),
|
||||
event_type: event.event_type_name().to_string(),
|
||||
description: event.description(),
|
||||
event: event.clone(),
|
||||
raw_data: Some(parsed.raw_data.clone()),
|
||||
uri: Some(parsed.uri.clone()),
|
||||
event_type: event_type.clone(),
|
||||
description: description.clone(),
|
||||
raw_data: parsed.raw_data.clone(),
|
||||
uri: parsed.uri.clone(),
|
||||
};
|
||||
|
||||
// Add the event to the timeline store
|
||||
@@ -277,9 +298,7 @@ impl Daemon {
|
||||
} else {
|
||||
debug!(
|
||||
"Event added to timeline: video_ts={:?}, game_ts={:?}, type={}",
|
||||
video_ts,
|
||||
game_ts,
|
||||
event.event_type_name()
|
||||
video_ts, game_ts, event_type
|
||||
);
|
||||
}
|
||||
} else {
|
||||
@@ -289,7 +308,7 @@ impl Daemon {
|
||||
}
|
||||
|
||||
// Process state transitions
|
||||
if let Some(transition) = self.state_machine.process_event(event) {
|
||||
if let Some(transition) = self.state_machine.process_event(event_type, raw_data) {
|
||||
info!("[EVENT_HANDLER] State transition: {:?}", transition);
|
||||
|
||||
// Only process the transition if it's valid
|
||||
@@ -297,12 +316,8 @@ impl Daemon {
|
||||
// Handle recording start/stop
|
||||
match transition {
|
||||
StateTransition::GameStarted => {
|
||||
// Extract game_id from the GameStart event
|
||||
let game_id = if let GameEvent::GameStart(ref info) = event {
|
||||
info.game_id
|
||||
} else {
|
||||
0
|
||||
};
|
||||
// Extract game_id from raw_data
|
||||
let game_id = raw_data.get("gameId").and_then(|v| v.as_u64()).unwrap_or(0);
|
||||
|
||||
info!(
|
||||
"[EVENT_HANDLER] GameStarted transition - game_id: {}",
|
||||
|
||||
Reference in New Issue
Block a user