|
|
|
@ -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<MQTTMessage>, 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<tm::NoticeId, NoticeCallback> = 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);
|
|
|
|
|