aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIlion Beyst <ilion.beyst@gmail.com>2022-09-25 11:06:50 +0200
committerIlion Beyst <ilion.beyst@gmail.com>2022-09-25 11:06:50 +0200
commitb7bcbdd3a6b045692a1850d6b49128e312dffbe7 (patch)
treea9371c6fce0ddfd9e66827b65594de83bb6ff26a
parentf7261e165bda87dae49c879bdac850479cc20c19 (diff)
downloadplanetwars.dev-b7bcbdd3a6b045692a1850d6b49128e312dffbe7.tar.xz
planetwars.dev-b7bcbdd3a6b045692a1850d6b49128e312dffbe7.zip
propagate PlayerAction::Terminated
-rw-r--r--planetwars-matchrunner/src/match_log.rs2
-rw-r--r--planetwars-matchrunner/src/pw_match.rs6
2 files changed, 7 insertions, 1 deletions
diff --git a/planetwars-matchrunner/src/match_log.rs b/planetwars-matchrunner/src/match_log.rs
index 27443df..e6cf6c6 100644
--- a/planetwars-matchrunner/src/match_log.rs
+++ b/planetwars-matchrunner/src/match_log.rs
@@ -15,6 +15,8 @@ pub enum MatchLogMessage {
GameState(State),
#[serde(rename = "stderr")]
StdErr(StdErrMessage),
+ #[serde(rename = "bot_terminated")]
+ BotTerminated { player_id: u32 },
#[serde(rename = "timeout")]
Timeout { player_id: u32 },
#[serde(rename = "bad_command")]
diff --git a/planetwars-matchrunner/src/pw_match.rs b/planetwars-matchrunner/src/pw_match.rs
index 737aa00..62a07e5 100644
--- a/planetwars-matchrunner/src/pw_match.rs
+++ b/planetwars-matchrunner/src/pw_match.rs
@@ -1,3 +1,4 @@
+use crate::match_context::RequestError;
use crate::match_log::MatchLogMessage;
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 {
let data = match turn {
- Err(_timeout) => return PlayerAction::Timeout,
+ Err(RequestError::Timeout) => return PlayerAction::Timeout,
+ Err(RequestError::BotTerminated) => return PlayerAction::Terminated,
Ok(data) => data,
};
@@ -123,6 +125,7 @@ impl PwMatch {
PlayerAction::Timeout => self.match_ctx.log(MatchLogMessage::Timeout {
player_id: player_id as u32,
}),
+ PlayerAction::Terminated => (), // TODO: should something be logged here?
PlayerAction::ParseError { data, error } => {
// TODO: can this be handled better?
let command =
@@ -156,6 +159,7 @@ pub struct PlayerCommand {
// TODO: can we name this better? Is this a "play"?
pub enum PlayerAction {
Timeout,
+ Terminated,
ParseError {
data: Vec<u8>,
error: serde_json::Error,