From 0642a9980a85435c637e7ebdce461e5b3cafb4c2 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Sun, 21 Jan 2024 14:01:28 -0700 Subject: [PATCH] Changed to use game topic for score, need to add arena topic still --- src/main.rs | 27 ++++++--------------------- 1 file changed, 6 insertions(+), 21 deletions(-) diff --git a/src/main.rs b/src/main.rs index f4c4dae..e448b4f 100644 --- a/src/main.rs +++ b/src/main.rs @@ -18,12 +18,11 @@ use std::net::TcpStream; use std::sync::mpsc; // MQTT Topics: -// - division/{division_id} +// - division/{division_id}/{round}/{match}/score // - division/{division_id}/ranking // - arena/{arena_id}/score // - arena/{arena_id}/state // - arena/{arena_id} -// - game/{division_id}/{game_id}/score // - team/{team_string} pub mod tm { @@ -712,14 +711,16 @@ fn on_score_change(notice: tm::Notice, event: Event, _connection: &TMConnection) match get_affected_match(¬ice) { None => (Vec::new(), event), Some(tuple) => { + // Use `event` to figure out which arena topic to publish to + // Also add the match score topic based on the tuple match get_game_score(¬ice) { None => (Vec::new(), event), Some(score) => { let serialized = serde_json::to_string(&score).unwrap(); - let arena_topic = String::from("arena/TEST/score"); + let game_topic = format!("division/{}/{:?}/{}/score", tuple.division, tuple.round, tuple.match_num); let mut out = Vec::new(); out.push(MQTTMessage{ - topic: arena_topic, + topic: game_topic, payload: serialized, }); return (out, event); @@ -796,28 +797,12 @@ fn on_match_list_update(_notice: tm::Notice, _event: Event, connection: &TMConne return _on_match_list_update(connection); } -fn on_match_score_update(notice: tm::Notice, event: Event, _connection: &TMConnection) -> (Vec, Event) { - match get_game_score(¬ice) { - None => (Vec::new(), event), - Some(score) => { - let serialized = serde_json::to_string(&score).unwrap(); - let arena_topic = String::from("arena/TEST/score"); - let mut out = Vec::new(); - out.push(MQTTMessage{ - topic: arena_topic, - payload: serialized, - }); - return (out, event); - }, - } -} - fn main() { env_logger::init(); let mut callbacks: HashMap = HashMap::new(); callbacks.insert(tm::NoticeId::NoticeRealtimeScoreChanged, on_score_change); - callbacks.insert(tm::NoticeId::NoticeMatchScoreUpdated, on_match_score_update); + callbacks.insert(tm::NoticeId::NoticeMatchScoreUpdated, on_score_change); callbacks.insert(tm::NoticeId::NoticeFieldTimerStarted, on_match_start); callbacks.insert(tm::NoticeId::NoticeFieldTimerStopped, on_match_cancel); callbacks.insert(tm::NoticeId::NoticeFieldResetTimer, on_match_reset);