diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-09-18 13:00:32 +0200 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-09-18 13:00:32 +0200 |
commit | 3be0cfa0ea61a3c56e0efc7169be5f3e0d7009d3 (patch) | |
tree | 7bda2b3c75ea5c6c8aa2730bc9f8ecc38136daa5 | |
parent | f5fe1c4f2918561d70a56d196aaf1b13c97a2bf1 (diff) | |
download | planetwars.dev-3be0cfa0ea61a3c56e0efc7169be5f3e0d7009d3.tar.xz planetwars.dev-3be0cfa0ea61a3c56e0efc7169be5f3e0d7009d3.zip |
log dispatches and timeouts
-rw-r--r-- | planetwars-matchrunner/src/match_log.rs | 9 | ||||
-rw-r--r-- | planetwars-matchrunner/src/pw_match.rs | 12 |
2 files changed, 19 insertions, 2 deletions
diff --git a/planetwars-matchrunner/src/match_log.rs b/planetwars-matchrunner/src/match_log.rs index 087f2a9..27443df 100644 --- a/planetwars-matchrunner/src/match_log.rs +++ b/planetwars-matchrunner/src/match_log.rs @@ -6,6 +6,8 @@ use tokio::{fs::File, io::AsyncWriteExt}; use planetwars_rules::protocol::State; use tokio::sync::mpsc; +use crate::pw_match::PlayerCommand; + #[derive(Serialize, Deserialize, Debug)] #[serde(tag = "type")] pub enum MatchLogMessage { @@ -13,12 +15,19 @@ pub enum MatchLogMessage { GameState(State), #[serde(rename = "stderr")] StdErr(StdErrMessage), + #[serde(rename = "timeout")] + Timeout { player_id: u32 }, #[serde(rename = "bad_command")] BadCommand { player_id: u32, command: String, error: String, }, + #[serde(rename = "dispatches")] + Dispatches { + player_id: u32, + dispatches: Vec<PlayerCommand>, + }, } #[derive(Serialize, Deserialize, Debug)] diff --git a/planetwars-matchrunner/src/pw_match.rs b/planetwars-matchrunner/src/pw_match.rs index 03dd37c..4af215e 100644 --- a/planetwars-matchrunner/src/pw_match.rs +++ b/planetwars-matchrunner/src/pw_match.rs @@ -117,6 +117,9 @@ impl PwMatch { fn log_player_action(&mut self, player_id: usize, player_action: PlayerAction) { match player_action { + PlayerAction::Timeout => self.match_ctx.log(MatchLogMessage::Timeout { + player_id: player_id as u32, + }), PlayerAction::ParseError { data, error } => { // TODO: can this be handled better? let command = @@ -128,14 +131,19 @@ impl PwMatch { error: error.to_string(), }); } - // TODO: handle other action types - _ => {} + PlayerAction::Commands(dispatches) => { + self.match_ctx.log(MatchLogMessage::Dispatches { + player_id: player_id as u32, + dispatches, + }); + } } } } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct PlayerCommand { + #[serde(flatten)] pub command: proto::Command, #[serde(skip_serializing_if = "Option::is_none")] pub error: Option<proto::CommandError>, |