diff Comm.lua @ 91:5ade79caeece

Starting to add a global timestamp to allow for incremental updates.
author John@Yosemite-PC
date Mon, 16 Apr 2012 07:06:50 -0400
parents 22b37c800bc4
children a227f3b61cda
line wrap: on
line diff
--- a/Comm.lua	Mon Apr 16 07:06:27 2012 -0400
+++ b/Comm.lua	Mon Apr 16 07:06:50 2012 -0400
@@ -64,20 +64,54 @@
     end,
     ["CC"] = function(self,change,sender,isloop)
         if isloop then return end
+        table.insert(db.profile.changes,change)
         ProcessChange(change)
         changeListener:DataEvent()
     end,
     ["Push"] = function(self)
-        Send("PU",{db.profile.lists,db.profile.persons,db.profile.changes})
+        Send("PU",{db.profile.lists,db.profile.persons,db.profile.changes,db.profile.time})
     end,
     ["PU"] = function(self,packet,sender,isloop)
         if isloop then return end
-        db.profile.lists,db.profile.persons,db.profile.changes = unpack(packet)
+        db.profile.lists,db.profile.persons,db.profile.changes,db.profile.time = unpack(packet)
         CreateWorkingStateFromChanges(db.profile.changes)
         if changeListener then
             changeListener:DataEvent()
         end
     end,
+
+    ["TS"] = function(self,packet,sender,isloop)
+        if isloop then return end
+        if masterLooterIsMe and admin then
+            -- only non-admins will send this message, send them the present
+            -- working state
+            -- todo: if they send a timestamp that's somewhere along our
+            -- timeline, then just catch them up
+            local dbPersons = {toons=PersonList.toons,time=PersonList.time}
+            Send("CU",{dbPersons,LootLists.l,timestamp}) -- todo: send privately
+        end
+    end,
+
+    ["CU"] = function(self,packet,sender,isloop) -- blindly trust an admin loot master
+        if isloop then return end
+        print("CU")
+        db.profile.persons,db.profile.lists,db.profile.time = unpack(packet)
+        db.profile.changes = {}
+        CreateWorkingStateFromChanges(db.profile.changes)
+        if changeListener then
+            changeListener:DataEvent()
+        end
+
+    end,
+
+    ["RequestCatchup"] = function(self)
+        if not admin then
+            Send("TS", timestamp) -- todo: send privately to loot master
+        else
+            -- todo: admins talking to one another
+        end
+
+    end,
 }
 
 local function OnCommReceived(prefix, message, distribution, sender)