make it compile, but can't run and break hostname config

This commit is contained in:
ajuvercr 2020-11-11 22:21:56 +01:00
parent dcf1173cb8
commit ba0b2c7655
3 changed files with 32 additions and 29 deletions

View file

@ -8,18 +8,18 @@ edition = "2018"
[dependencies]
mozaic = { git = "https://github.com/ZeusWPI/MOZAICP" }
rand = { version = "0.6.5", default-features = true }
rand = { version = "0.7.3", default-features = true }
async-std = { version = "1.5.0", features = ["attributes"] }
futures = { version = "0.3.1", features = ["executor", "thread-pool"] }
async-std = { version = "1.7.0", features = ["attributes"] }
futures = { version = "0.3.8", features = ["executor", "thread-pool"] }
serde = "1.0.100"
serde_derive = "1.0.100"
serde = "1.0.117"
serde_derive = "1.0.117"
serde_json = "1.0"
tracing = "0.1.9"
tracing-futures = "0.1.0"
tracing-subscriber = "0.1.5"
rocket = { git = "https://github.com/SergioBenitez/Rocket", branch = "async" }
rocket_contrib = { git = "https://github.com/SergioBenitez/Rocket", branch = "async", features = ["handlebars_templates", "tera_templates"] }
tracing = "0.1.21"
tracing-futures = "0.2.4"
tracing-subscriber = "0.2.15"
rocket = { git = "https://github.com/SergioBenitez/Rocket", branch = "master" }
rocket_contrib = { git = "https://github.com/SergioBenitez/Rocket", branch = "master", features = ["handlebars_templates", "tera_templates"] }
educe = { version = "0.4.2", features = ["Debug", "Default", "Hash", "Clone", "Copy"] }
educe = { version = "0.4.13", features = ["Debug", "Default", "Hash", "Clone", "Copy"] }

View file

@ -1,4 +1,4 @@
#![feature(proc_macro_hygiene, async_closure)]
#![feature(proc_macro_hygiene, async_closure, decl_macro)]
extern crate serde;
#[macro_use]
@ -86,16 +86,19 @@ fn get_colour(value: &Value, _: &HashMap<String, Value>) -> tera::Result<Value>
));
}
struct HostNameFilter(String);
impl tera::Filter for HostNameFilter {
fn filter(&self, _: &Value, _: &HashMap<String, Value>) -> tera::Result<Value> {
Ok(Value::String(self.0.clone()))
#[async_std::main]
async fn main(){
let rocket = rocket().await;
rocket.launch().await.expect("ROCKET CRASHED");
}
fn get_host_name(host_name: &str) -> impl Fn(&HashMap<String, Value>) -> tera::Result<Value> + Sync + Send {
let host_name = host_name.to_string();
move |_| Ok(Value::String(host_name.clone()))
}
/// Async main function, starting logger, graph and rocket
#[launch]
async fn rocket() -> rocket::Rocket {
let fut = graph::set_default();
@ -104,10 +107,11 @@ async fn rocket() -> rocket::Rocket {
.finish();
tracing::subscriber::set_global_default(sub).unwrap();
let pool = ThreadPool::new().unwrap();
let pool = ThreadPool::builder().create().unwrap();
pool.spawn_ok(fut.map(|_| ()));
let gm = create_game_manager("0.0.0.0:9142", pool.clone()).await;
async_std::task::sleep(std::time::Duration::from_millis(100)).await;
async_std::task::sleep(std::time::Duration::from_millis(200)).await;
let mut routes = Vec::new();
routes::fuel(&mut routes);
@ -116,17 +120,16 @@ async fn rocket() -> rocket::Rocket {
.manage(gm)
.manage(pool)
.manage(Games::new())
.attach(AdHoc::on_attach("Assets Config", async move |mut rocket| {
let host_name = rocket.config().await
.get_str("host_name")
.unwrap_or("mozaic.zeus.gent")
.to_string();
.attach(AdHoc::on_attach("Assets Config", async move |rocket| {
// let host_name = rocket.config()
// .get_string("host_name")
// .unwrap_or("mozaic.zeus.gent".to_string());
let host_name = "mozaic.zeus.gent".to_string();
let tera = Template::custom(move |engines: &mut Engines| {
let filter = HostNameFilter(host_name.clone());
engines.tera.register_filter("calc_viewbox", calc_viewbox);
engines.tera.register_filter("get_colour", get_colour);
engines.tera.register_filter("get_host_name", filter);
engines.tera.register_function("get_host_name", get_host_name(&host_name));
});
Ok(rocket.attach(tera))
@ -139,7 +142,7 @@ async fn rocket() -> rocket::Rocket {
async fn create_game_manager(tcp: &str, pool: ThreadPool) -> game::Manager {
let addr = tcp.parse::<SocketAddr>().unwrap();
let (gmb, handle) = game::Manager::builder(pool.clone());
pool.spawn_ok(handle.map(|_| ()));
pool.spawn_ok(handle.map(|_| {println!("I'm done")}));
let ep = TcpEndpoint::new(addr, pool.clone());
let gmb = gmb.add_endpoint(ep, "TCP endpoint");

View file

@ -77,7 +77,7 @@ async fn post_game(
state: State<'_, Games>,
) -> Result<Json<GameRes>, String> {
let game = build_builder(
tp.clone(),
tp.inner().clone(),
game_req.nop,
game_req.max_turns,
&game_req.map,