diff --git a/server/src/game.rs b/server/src/game.rs index 6e5207dd..caeb1e61 100644 --- a/server/src/game.rs +++ b/server/src/game.rs @@ -1,3 +1,5 @@ +use std::fs::File; + use rand::prelude::*; use uuid::Uuid; @@ -864,7 +866,12 @@ pub fn game_update(tx: &mut Transaction, game: &Game) -> Result<(), Error> { result.iter().next().ok_or(format_err!("game {:?} could not be written", game))?; if game.finished() { - info!("game finished state={:?}", game); + info!("finished id={:?}", game.id); + + match game_json_file_write(&game) { + Ok(dest) => info!("wrote dest={:?}", dest), + Err(e) => error!("json write error={:?}", e), + }; if let Some(i) = game.instance { instance_game_finished(tx, &game, i)?; @@ -874,6 +881,12 @@ pub fn game_update(tx: &mut Transaction, game: &Game) -> Result<(), Error> { return Ok(()); } +fn game_json_file_write(g: &Game) -> Result { + let dest = format!("/var/lib/mnml/data/games/{}.mnml.game.json", g.id); + serde_json::to_writer(File::create(&dest)?, g)?; + Ok(dest) +} + pub fn game_skill(tx: &mut Transaction, account: &Account, game_id: Uuid, construct_id: Uuid, target_construct_id: Option, skill: Skill) -> Result { let mut game = game_get(tx, game_id)?; diff --git a/server/src/instance.rs b/server/src/instance.rs index 4d69927a..92812673 100644 --- a/server/src/instance.rs +++ b/server/src/instance.rs @@ -1,3 +1,5 @@ +use std::fs::File; + use uuid::Uuid; use serde_cbor::{from_slice, to_vec}; @@ -547,15 +549,26 @@ pub fn instance_update(tx: &mut Transaction, instance: Instance) -> Result info!("wrote dest={:?}", dest), + Err(e) => error!("json write error={:?}", e), + }; } return Ok(instance); } +fn instance_json_file_write(g: &Instance) -> Result { + let dest = format!("/var/lib/mnml/data/instances/{}.mnml.instance.json", g.id); + serde_json::to_writer(File::create(&dest)?, g)?; + Ok(dest) +} + pub fn instance_get(tx: &mut Transaction, instance_id: Uuid) -> Result { let query = " SELECT *