]> hydra-www.ietfng.org Git - acmetensortoys-esp-lua_ctfws/commitdiff
examples/ctfws: improve message handling
authorNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Fri, 10 Feb 2017 07:00:11 +0000 (02:00 -0500)
committerNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Fri, 10 Feb 2017 07:08:48 +0000 (02:08 -0500)
README.rst
init3.lua

index c2ded1ca6ba36d46db440a1e9fc94f70f8cb084c..346ee5d066b6a170fe668f1ee2bc0abc0e4491fd 100644 (file)
@@ -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::
index f27c874812ff52c3cbce79f6b8e7a3326b47adbb..582d269267b95a78640d5d4f58b1542c2c614da1 100644 (file)
--- 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