From: Nathaniel Wesley Filardo Date: Fri, 10 Feb 2017 07:00:11 +0000 (-0500) Subject: examples/ctfws: improve message handling X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=469d32da21a130d1d4b0d0b3d6a7ed706e28a9d1;p=acmetensortoys-esp-lua_ctfws examples/ctfws: improve message handling --- diff --git a/README.rst b/README.rst index c2ded1c..346ee5d 100644 --- a/README.rst +++ b/README.rst @@ -43,7 +43,10 @@ Centrally-set topics: forced game end. If this is larger than the last ``starttime`` gotten in a ``config`` message, then the game is considered over. -* ``ctfws/game/message`` -- Message to be displayed everywhere +* ``ctfws/game/message`` -- Message to be displayed everywhere. This, and + all other messages have a NTP-seconds timestamp followed by whitespace + before the message body. These permit messages from previous games to + be suppressed, should they end up resident on the MQTT broker. * ``ctfws/game/message/player`` -- Message to be displayed specifically to players, if they ever come to have their own devices (e.g. apps) @@ -112,10 +115,10 @@ get the latest messages automatically. mosquitto_pub "$M[@]" -t ctfws/game/flags -r -m '0 0' mosquitto_pub "$M[@]" -t ctfws/game/config -r -m `date +%s`' 900 3 900 10' -* To post information:: +* To post information (The messages must have date stamps on the front!):: mosquitto_pub "$M[@]" -t ctfws/game/flags -r -m '1 2' - mosquitto_pub "$M[@]" -t ctfws/game/message -r -m 'Red team captured a flag!' + mosquitto_pub "$M[@]" -t ctfws/game/message -r -m `date +%s`' Red team captured a flag!' * Note that you can deliberately hide the flag scores, if you like, by publishing ``?`` to the ``/flags`` topic:: diff --git a/init3.lua b/init3.lua index f27c874..582d269 100644 --- a/init3.lua +++ b/init3.lua @@ -107,7 +107,19 @@ nwfnet.onmqtt["init"] = function(c,t,m) end elseif t:match("^ctfws/game/message") then boot_message_hack = nil - ctfws_lcd:drawMessage(m) + local mt, ms = m:match("^%s*(%d+)%s*(.*)$") + if mt == nil then -- maybe they forgot a timestamp? + lastMsgTime = rtctime.get() - 30 -- subtract some wiggle room + ctfws_lcd:drawMessage(m) + else + mt = tonumber(mt) + if (ctfws.startT == nil or ctfws.startT <= mt) + and (lastMsgTime == nil or lastMsgTime <= mt) + then + lastMsgTime = mt + ctfws_lcd:drawMessage(ms) + end + end end end