diff options
author | Ilion Beyst <ilion.beyst@gmail.com> | 2022-02-23 21:08:56 +0100 |
---|---|---|
committer | Ilion Beyst <ilion.beyst@gmail.com> | 2022-02-23 21:08:56 +0100 |
commit | 54b9694f0d0d7e853592317d60ad262ae8c13568 (patch) | |
tree | b8842c884ee51cac97d6e39c68e3fd54f19f0bf8 /planetwars-matchrunner/src/match_context.rs | |
parent | e15944622d3741137f443e7fa0b5d193b4ce28d9 (diff) | |
download | planetwars.dev-54b9694f0d0d7e853592317d60ad262ae8c13568.tar.xz planetwars.dev-54b9694f0d0d7e853592317d60ad262ae8c13568.zip |
implement matchlogger
Diffstat (limited to 'planetwars-matchrunner/src/match_context.rs')
-rw-r--r-- | planetwars-matchrunner/src/match_context.rs | 17 |
1 files changed, 7 insertions, 10 deletions
diff --git a/planetwars-matchrunner/src/match_context.rs b/planetwars-matchrunner/src/match_context.rs index 8161ed9..6ea60c3 100644 --- a/planetwars-matchrunner/src/match_context.rs +++ b/planetwars-matchrunner/src/match_context.rs @@ -1,8 +1,6 @@ use futures::task::{Context, Poll}; use futures::{future::Future, task::AtomicWaker}; use serde::{Deserialize, Serialize}; -use std::fs::File; -use std::io::Write; use std::pin::Pin; use std::time::Duration; use std::{ @@ -10,6 +8,8 @@ use std::{ sync::{Arc, Mutex}, }; +use crate::match_log::{MatchLogMessage, MatchLogger}; + #[derive(Serialize, Deserialize, Debug)] pub struct RequestMessage { pub request_id: u32, @@ -20,16 +20,14 @@ pub struct RequestMessage { pub struct MatchCtx { event_bus: Arc<Mutex<EventBus>>, players: HashMap<u32, PlayerData>, - // output: MsgStreamHandle<String>, - log_sink: File, + match_logger: MatchLogger, } impl MatchCtx { pub fn new( event_bus: Arc<Mutex<EventBus>>, players: HashMap<u32, Box<dyn PlayerHandle>>, - log_file: File, - // log: MsgStreamHandle<String>, + match_logger: MatchLogger, ) -> Self { MatchCtx { event_bus, @@ -43,7 +41,7 @@ impl MatchCtx { (id, player_handle) }) .collect(), - log_sink: log_file, + match_logger, } } @@ -70,9 +68,8 @@ impl MatchCtx { self.players.keys().cloned().collect() } - // this method should be used to emit log states etc. - pub fn log_string(&mut self, message: String) { - write!(self.log_sink, "{}\n", message).expect("failed to write to log file"); + pub fn log(&mut self, message: MatchLogMessage) { + self.match_logger.send(message).expect("write failed"); } } |