And the associated config.
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
save_dir = "."
command_socket = "@command_socket@"
template_dir = "@src@/templates"
+specs_dir = "@src@/specs"
nwtemplate_dir = "@src@/nwtemplates"
bundled_sources = "@target@/bundled-sources"
wasm_dir = "@target@/packed-wasm"
Ok(LogEntry { html })
}))?
}
+
+ MGI::ResetFromNamedSpec { spec } => {
+ reset_game_from_spec(cs,ag,ig,who, Box::new(move |ig| {
+ let (mut spec_f, what) = bundles::load_spec_to_read(ig,&spec)?;
+ let mut buf = String::new();
+ spec_f.read_to_string(&mut buf).map_err(|e| match e.kind() {
+ ErrorKind::InvalidData => ME::GameSpecInvalidData,
+ ErrorKind::UnexpectedEof => ME::BadBundle(e.to_string()),
+ _ => IE::from(
+ AE::from(e).context(what).context("read spec")
+ ).into()
+ })?;
+ Ok::<_,ME>(buf)
+ }))?
+ }
+
MGI::ResetFromGameSpec { spec_toml: spec } => {
reset_game_from_spec(cs,ag,ig,who, Box::new(|_| Ok::<_,ME>(spec)))?
}
command_socket = "/home/rustcargo/Rustup/Game/server/command.socket"
template_dir = "/home/ian/Rustup/Game/server/templates"
nwtemplate_dir = "/home/ian/Rustup/Game/server/nwtemplates"
+specs_dir = "/home/ian/Rustup/Game/server/specs"
bundled_sources = "/home/rustcargo/Rustup/Game/server/target/bundled-sources"
wasm_dir = "/home/rustcargo/Rustup/Game/server/target/packed-wasm"
libexec_dir = "/home/rustcargo/Rustup/Game/server/target/debug"
}
}
+//---------- specs ----------
+
+#[throws(MgmtError)]
+pub fn load_spec_to_read(ig: &Instance, spec_name: &str)
+ -> (Box<dyn Read>, String)
+{
+ let spec_leaf = format!("{}.game.toml", spec_name);
+
+ // todo: game specs from bundles
+
+ if spec_name.chars().all(
+ |c| c.is_ascii_alphanumeric() || c=='-' || c =='_'
+ ) {
+ let path = format!("{}/{}", config().specs_dir, &spec_leaf);
+ debug!("{}: trying to loading builtin spec from {}",
+ &ig.name, &path);
+ match File::open(&path) {
+ Ok(f) => return (Box::new(f) as _, path),
+ Err(e) if e.kind() == ErrorKind::NotFound => { },
+ Err(e) => throw!(IE::from(
+ AE::from(e).context(path).context("try open game spec")
+ )),
+ }
+ }
+
+ Err(ME::GameSpecNotFound)?
+}
+
//---------- scanning/incorporating/uploading ----------
#[throws(InternalError)]
DefinePieceAlias { alias: String, target: Box<dyn PieceSpec> },
ClearGame { },
+ ResetFromNamedSpec { spec: String },
ResetFromGameSpec { spec_toml: String },
ResetPlayerAccess(PlayerId),
#[error("bad bundle: {0}")] BadBundle(String),
#[error("bundle not found")] BundleNotFound,
#[error("bundle(s) in use, cannot clear ({0})")] BundlesInUse(String),
+ #[error("game spec not found")] GameSpecNotFound,
+ #[error("game contains invalid UTF-8")] GameSpecInvalidData,
#[error("idle timeout waiting for mgmt command")] IdleTimeout,
#[error("upload took too long (timed out)")] UploadTimeout,
}
pub log: Option<toml::Value>,
pub bundled_sources: Option<String>,
pub shapelibs: Option<Vec<shapelib::Config1>>,
+ pub specs_dir: Option<String>,
pub sendmail: Option<String>,
pub debug_js_inject_file: Option<String>,
#[serde(default)] pub fake_rng: FakeRngSpec,
pub usvg_bin: String,
pub bundled_sources: String,
pub shapelibs: Vec<shapelib::Config1>,
+ pub specs_dir: String,
pub sendmail: String,
pub debug_js_inject: Arc<String>,
pub check_bundled_sources: bool,
let ServerConfigSpec {
change_directory, base_dir, save_dir, command_socket, debug,
http_port, public_url, sse_wildcard_url, rocket_workers,
- template_dir, nwtemplate_dir, wasm_dir, libexec_dir, usvg_bin,
+ template_dir, specs_dir, nwtemplate_dir, wasm_dir, libexec_dir, usvg_bin,
log, bundled_sources, shapelibs, sendmail,
debug_js_inject_file, check_bundled_sources, fake_rng,
} = self;
};
let save_dir = defpath(save_dir, "save" );
+ let specs_dir = defpath(specs_dir, "specs" );
let command_socket = defpath(command_socket, "var/command.socket");
let template_dir = defpath(template_dir, "assets" );
let wasm_dir = defpath(wasm_dir, "assets" );
let server = ServerConfig {
save_dir, command_socket, debug,
http_port, public_url, sse_wildcard_url, rocket_workers,
- template_dir, nwtemplate_dir, wasm_dir, libexec_dir,
+ template_dir, specs_dir, nwtemplate_dir, wasm_dir, libexec_dir,
bundled_sources, shapelibs, sendmail, usvg_bin,
debug_js_inject, check_bundled_sources, game_rng, prctx,
};