propagate PlayerAction::Terminated

This commit is contained in:
Ilion Beyst 2022-09-25 11:06:50 +02:00
parent f7261e165b
commit b7bcbdd3a6
2 changed files with 7 additions and 1 deletions

View file

@ -15,6 +15,8 @@ pub enum MatchLogMessage {
GameState(State), GameState(State),
#[serde(rename = "stderr")] #[serde(rename = "stderr")]
StdErr(StdErrMessage), StdErr(StdErrMessage),
#[serde(rename = "bot_terminated")]
BotTerminated { player_id: u32 },
#[serde(rename = "timeout")] #[serde(rename = "timeout")]
Timeout { player_id: u32 }, Timeout { player_id: u32 },
#[serde(rename = "bad_command")] #[serde(rename = "bad_command")]

View file

@ -1,3 +1,4 @@
use crate::match_context::RequestError;
use crate::match_log::MatchLogMessage; use crate::match_log::MatchLogMessage;
use super::match_context::{MatchCtx, RequestResult}; use super::match_context::{MatchCtx, RequestResult};
@ -89,7 +90,8 @@ impl PwMatch {
fn execute_action(&mut self, player_num: usize, turn: RequestResult<Vec<u8>>) -> PlayerAction { fn execute_action(&mut self, player_num: usize, turn: RequestResult<Vec<u8>>) -> PlayerAction {
let data = match turn { let data = match turn {
Err(_timeout) => return PlayerAction::Timeout, Err(RequestError::Timeout) => return PlayerAction::Timeout,
Err(RequestError::BotTerminated) => return PlayerAction::Terminated,
Ok(data) => data, Ok(data) => data,
}; };
@ -123,6 +125,7 @@ impl PwMatch {
PlayerAction::Timeout => self.match_ctx.log(MatchLogMessage::Timeout { PlayerAction::Timeout => self.match_ctx.log(MatchLogMessage::Timeout {
player_id: player_id as u32, player_id: player_id as u32,
}), }),
PlayerAction::Terminated => (), // TODO: should something be logged here?
PlayerAction::ParseError { data, error } => { PlayerAction::ParseError { data, error } => {
// TODO: can this be handled better? // TODO: can this be handled better?
let command = let command =
@ -156,6 +159,7 @@ pub struct PlayerCommand {
// TODO: can we name this better? Is this a "play"? // TODO: can we name this better? Is this a "play"?
pub enum PlayerAction { pub enum PlayerAction {
Timeout, Timeout,
Terminated,
ParseError { ParseError {
data: Vec<u8>, data: Vec<u8>,
error: serde_json::Error, error: serde_json::Error,