This commit is contained in:
zoe 2022-02-06 18:32:36 +01:00
parent d692ace55f
commit 58066c8abc

View file

@ -6,10 +6,14 @@ extern crate lazy_static;
use clap::Parser;
use rocket::fs::{relative, FileServer};
use rocket::response::stream::{Event, EventStream};
use rocket_dyn_templates::Template;
use rocket::response::stream::{EventStream, Event};
use std::{collections::HashMap, mem::drop, sync::Mutex};
use std::{
collections::HashMap,
mem::drop,
sync::{mpsc, Mutex, RwLock},
};
mod names;
mod rooms;
@ -22,7 +26,6 @@ lazy_static! {
static ref PLAYS: Mutex<HashMap<String, Vec<rooms::Board>>> = Mutex::new(HashMap::new());
}
/*
* Config options
*/
@ -45,7 +48,7 @@ fn rocket() -> _ {
rocket::custom(config)
.attach(Template::fairing())
.mount("/", FileServer::from(relative!("static")))
.mount("/", routes![index, room, stream])
.mount("/", routes![index, room, stream, play])
}
/*
@ -118,24 +121,20 @@ async fn room(roomname: &str, token: usize, player1: bool) -> Template {
//sends new board if there have been updates
//*
#[get("/stream/<roomname>/<token>")]
fn stream(roomname: String, token: usize) -> EventStream![]{
async fn stream(roomname: String, token: usize) -> EventStream![] {
let roomlist = ROOMS.lock().unwrap();
drop(roomlist);
EventStream! {
loop {
// TODO
// check if there are any new events, and then if the room token is correct
// if that's the case send the current playing board
// otherwise don't do anything
let mut i = 0;
if i == 0 {
let event = "something";
yield Event::json(&event);
}
i += 1
yield Event::json(&"oof".to_string());
}
}
}
//*
// adds new boards to the send queue after calculating move
//*