-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce a separate
server-config
crate for server configs (#194)
* Introduce new server-config crate with new config prototypes * Mark the validator examples as requiring the script feature
- Loading branch information
1 parent
b9b587f
commit 85df9d9
Showing
17 changed files
with
1,380 additions
and
23 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
[package] | ||
name = "server-config" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[features] | ||
script = [ "rlua", "serde-rlua" ] | ||
|
||
[dependencies] | ||
serde = { version = "1.0", features = [ "derive" ] } | ||
serde-value = "0.7" | ||
serde_path_to_error = "0.1.7" | ||
nalgebra = { version = "0.31", features = ["serde-serialize"] } | ||
doc-cfg = "0.1" | ||
|
||
rlua = { version = "0.19", optional = true } | ||
serde-rlua = { path = "../utils/serde-rlua", optional = true } | ||
|
||
[dependencies.protocol] | ||
version = "0.5" | ||
package = "airmash-protocol" | ||
features = [ "serde" ] | ||
|
||
[dev-dependencies] | ||
serde_json = "1.0" | ||
anyhow = "1.0" | ||
|
||
[[example]] | ||
name = "export" | ||
required-features = ["script"] | ||
|
||
[[example]] | ||
name = "validate" | ||
required-features = ["script"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
-- Empty LUA file means no edits to the config |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
|
||
-- Set the firing delay and energy for all planes to 0. | ||
for key, plane in pairs(data.planes) do | ||
plane.fire_delay = 0 | ||
plane.fire_energy = 0 | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
use std::io::Write; | ||
|
||
use serde::Deserialize; | ||
use server_config::GamePrototype; | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let args = std::env::args().skip(1).collect::<Vec<_>>(); | ||
// let args = vec!["server-prototypes/configs/infinite-fire.lua"]; | ||
|
||
let mut prototype = GamePrototype::default(); | ||
|
||
let lua = rlua::Lua::new(); | ||
lua.context(|lua| -> Result<(), Box<dyn std::error::Error>> { | ||
for file in args { | ||
let contents = std::fs::read_to_string(file)?; | ||
let value = prototype.patch_direct(lua, &contents)?; | ||
|
||
let mut track = serde_path_to_error::Track::new(); | ||
let de = serde_rlua::Deserializer::new(value); | ||
let de = serde_path_to_error::Deserializer::new(de, &mut track); | ||
|
||
match GamePrototype::deserialize(de) { | ||
Ok(proto) => prototype = proto, | ||
Err(e) => Err(format!( | ||
"Error while deserializing field {}: {}", | ||
track.path(), | ||
e | ||
))?, | ||
} | ||
} | ||
|
||
Ok(()) | ||
})?; | ||
|
||
let mut stdout = std::io::stdout().lock(); | ||
serde_json::to_writer_pretty(&mut stdout, &prototype)?; | ||
stdout.write_all(b"\n")?; | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.