This commit is contained in:
Adam 2024-05-04 21:28:42 -04:00
parent 880bab0ae2
commit 30d4388063
5 changed files with 6 additions and 6 deletions

View file

@ -31,7 +31,7 @@ pub async fn websocket(stream: WebSocket, state: Arc<AppState>, who: SocketAddr)
let mut rx = state.tx.subscribe(); let mut rx = state.tx.subscribe();
// ANNOUNCE THY PRESENCE // ANNOUNCE THY PRESENCE
let msg = format!("{who} is here, bitches!"); let msg = format!("{who} joined.");
tracing::debug!("{msg}"); tracing::debug!("{msg}");
let _ = state.tx.send(msg); let _ = state.tx.send(msg);

View file

@ -31,12 +31,11 @@ pub async fn message_handler(message: Message, state: &Arc<AppState>, who: Socke
match message { match message {
Message::Text(text) => { Message::Text(text) => {
tracing::debug!("{who}: {}", text);
if let Ok(new_game) = serde_json::from_str::<NewGameRequest>(&text) { if let Ok(new_game) = serde_json::from_str::<NewGameRequest>(&text) {
tracing::debug!("{:#?}", &new_game); tracing::debug!("{:#?}", &new_game);
// create game // create game
if let Ok(new_game_object) = CAHGame::new(new_game) { if let Ok(new_game_object) = CAHGame::new(new_game) {
let _ = tx.send(format!("{:#?}", &new_game_object.players[0].white));
state.games.lock().unwrap().push(new_game_object); state.games.lock().unwrap().push(new_game_object);
let _update = tx.send(greeting(&state)); let _update = tx.send(greeting(&state));
} else { } else {

View file

@ -17,12 +17,13 @@ use crate::message_handler::*;
/// Parse json for card data /// Parse json for card data
fn load_json(path: &str) -> Result<Vec<CAHCardSet>, Box<dyn Error>> { fn load_json(path: &str) -> Result<Vec<CAHCardSet>, Box<dyn Error>> {
let data: String = fs::read_to_string(path).expect("Error reading file"); let data: String = fs::read_to_string(path)?;
let jayson: Vec<CAHCardSet> = serde_json::from_str(&data)?; let jayson: Vec<CAHCardSet> = serde_json::from_str(&data)?;
Ok(jayson) Ok(jayson)
} }
// this is still around just for reference
#[allow(dead_code)] #[allow(dead_code)]
fn test() -> Result<(), Box<dyn Error>> { fn test() -> Result<(), Box<dyn Error>> {
// choose decks // choose decks
@ -88,10 +89,10 @@ pub struct AppState {
// Include utf-8 files at **compile** time. // Include utf-8 files at **compile** time.
async fn index() -> Html<&'static str> { async fn index() -> Html<&'static str> {
Html(std::include_str!("../test_client.html")) Html(std::include_str!("../public/test_client.html"))
} }
async fn spawnclients() -> Html<&'static str> { async fn spawnclients() -> Html<&'static str> {
Html(std::include_str!("../spawnclients.html")) Html(std::include_str!("../public/spawnclients.html"))
} }
#[tokio::main] #[tokio::main]