diff --git a/backend/Cargo.toml b/backend/Cargo.toml index f81c602..97c39c5 100644 --- a/backend/Cargo.toml +++ b/backend/Cargo.toml @@ -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"] } diff --git a/backend/src/main.rs b/backend/src/main.rs index 74f2ef8..5f68259 100644 --- a/backend/src/main.rs +++ b/backend/src/main.rs @@ -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) -> tera::Result )); } -struct HostNameFilter(String); +#[async_std::main] +async fn main(){ + let rocket = rocket().await; + rocket.launch().await.expect("ROCKET CRASHED"); +} -impl tera::Filter for HostNameFilter { - fn filter(&self, _: &Value, _: &HashMap) -> tera::Result { - Ok(Value::String(self.0.clone())) - } +fn get_host_name(host_name: &str) -> impl Fn(&HashMap) -> tera::Result + 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::().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"); diff --git a/backend/src/routes/lobby.rs b/backend/src/routes/lobby.rs index e31646a..23636fd 100644 --- a/backend/src/routes/lobby.rs +++ b/backend/src/routes/lobby.rs @@ -77,7 +77,7 @@ async fn post_game( state: State<'_, Games>, ) -> Result, String> { let game = build_builder( - tp.clone(), + tp.inner().clone(), game_req.nop, game_req.max_turns, &game_req.map,