From 781951be42b4c31feba8660e43f4c591c992fbe9 Mon Sep 17 00:00:00 2001 From: Erb3 <49862976+Erb3@users.noreply.github.com> Date: Mon, 3 Jun 2024 21:43:27 +0200 Subject: [PATCH] Don't send packets unless joined Fixes #47 --- src/game.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/game.rs b/src/game.rs index 1ccfd25..bf82d53 100644 --- a/src/game.rs +++ b/src/game.rs @@ -64,6 +64,9 @@ pub fn on_connect(socket: SocketRef) { }, ) .unwrap(); + + socket.join("PRIMARY").unwrap(); + info!( "🪪 Client with ID {} set username to {}", socket.id, data.username @@ -120,7 +123,8 @@ pub async fn game_loop( leaderboard: state.leaderboard.clone(), }; - io.emit("solution", solution) + io.to("PRIMARY") + .emit("solution", solution) .expect("Unable to broadcast solution"); } @@ -134,7 +138,8 @@ pub async fn game_loop( info!("📍 New location: {}, {}", &city.name, &city.country); game_state.lock().unwrap().guesses.clear(); - io.emit("newTarget", target_message) + io.to("PRIMARY") + .emit("newTarget", target_message) .expect("Unable to broadcast new target"); last_city = Some(city);