# HG changeset patch # User John@Yosemite-PC # Date 1335067393 14400 # Node ID a227f3b61cda96110c2ddc29ed0d2a5e2baae5bc # Parent 5ade79caeece79f0982df3aaca5247ccf3c3e02e Starting to integrate differential updating diff -r 5ade79caeece -r a227f3b61cda Comm.lua --- a/Comm.lua Mon Apr 16 07:06:50 2012 -0400 +++ b/Comm.lua Sun Apr 22 00:03:13 2012 -0400 @@ -87,8 +87,40 @@ -- 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 + --local dbPersons = {toons=PersonList.toons,time=PersonList.time} + --Send("CU",{dbPersons,LootLists.l,timestamp}) -- todo: send privately + + local t = packet + local remoteBase = table.remove(t,1) + + -- if their base is older than ours, this is easy - send them our + -- base and all the changes + -- if their base is equal to ours, then diff their changes vs ours + -- and send them the remainder - it's ok if they have changes we + -- don't + -- if their base is newer, then we have a problem - it means another + -- admin rebased and we aren't aware of that. but the other admin + -- wouldn't have done that if they didn't believe all the admins + -- were synced up to the release point. So do we trust that and use + -- this as a rebase opportunity? print an error? just reply that we + -- don't have anything new to share with them? only send them + -- + + if remoteBase == db.profile.time then + local j = 1 -- index in foreign list + local n = getn(t) + local o = {} + for i,v in pairs(db.profile.changes) do -- for each timestamp in our list + if t and t[j] < v.time then + table.insert(o,v) + end + while j=n ? add because the remote hit end of road. lt? add because it's a missing stamp + print("Received request at timebase",remoteBase,"and returning:") + PrintTable(o) + else + print("Received request at differing timebase",remoteBase,db.profile.time) + end end end, @@ -101,12 +133,19 @@ if changeListener then changeListener:DataEvent() end - end, ["RequestCatchup"] = function(self) if not admin then - Send("TS", timestamp) -- todo: send privately to loot master + --local string = _g.tostring(timestamp) + --for i,v in pairs(db.profile.changes) do -- append all change timestamps + -- string = string .. "|" .. _g.tostring(v.time) + --end + local t = {db.profile.time} + for i,v in pairs(db.profile.changes) do -- append all change timestamps + table.insert(t,v.time) + end + Send("TS", t) -- todo: send privately to loot master else -- todo: admins talking to one another end