comparison Comm.lua @ 92:a227f3b61cda

Starting to integrate differential updating
author John@Yosemite-PC
date Sun, 22 Apr 2012 00:03:13 -0400
parents 5ade79caeece
children df94161e6d7c
comparison
equal deleted inserted replaced
91:5ade79caeece 92:a227f3b61cda
85 if masterLooterIsMe and admin then 85 if masterLooterIsMe and admin then
86 -- only non-admins will send this message, send them the present 86 -- only non-admins will send this message, send them the present
87 -- working state 87 -- working state
88 -- todo: if they send a timestamp that's somewhere along our 88 -- todo: if they send a timestamp that's somewhere along our
89 -- timeline, then just catch them up 89 -- timeline, then just catch them up
90 local dbPersons = {toons=PersonList.toons,time=PersonList.time} 90 --local dbPersons = {toons=PersonList.toons,time=PersonList.time}
91 Send("CU",{dbPersons,LootLists.l,timestamp}) -- todo: send privately 91 --Send("CU",{dbPersons,LootLists.l,timestamp}) -- todo: send privately
92
93 local t = packet
94 local remoteBase = table.remove(t,1)
95
96 -- if their base is older than ours, this is easy - send them our
97 -- base and all the changes
98 -- if their base is equal to ours, then diff their changes vs ours
99 -- and send them the remainder - it's ok if they have changes we
100 -- don't
101 -- if their base is newer, then we have a problem - it means another
102 -- admin rebased and we aren't aware of that. but the other admin
103 -- wouldn't have done that if they didn't believe all the admins
104 -- were synced up to the release point. So do we trust that and use
105 -- this as a rebase opportunity? print an error? just reply that we
106 -- don't have anything new to share with them? only send them
107 --
108
109 if remoteBase == db.profile.time then
110 local j = 1 -- index in foreign list
111 local n = getn(t)
112 local o = {}
113 for i,v in pairs(db.profile.changes) do -- for each timestamp in our list
114 if t and t[j] < v.time then
115 table.insert(o,v)
116 end
117 while j<n and t[j] <= v.time do j = j+1 end -- advance the foreign pointer past our current entry
118 end -- j>=n ? add because the remote hit end of road. lt? add because it's a missing stamp
119 print("Received request at timebase",remoteBase,"and returning:")
120 PrintTable(o)
121 else
122 print("Received request at differing timebase",remoteBase,db.profile.time)
123 end
92 end 124 end
93 end, 125 end,
94 126
95 ["CU"] = function(self,packet,sender,isloop) -- blindly trust an admin loot master 127 ["CU"] = function(self,packet,sender,isloop) -- blindly trust an admin loot master
96 if isloop then return end 128 if isloop then return end
99 db.profile.changes = {} 131 db.profile.changes = {}
100 CreateWorkingStateFromChanges(db.profile.changes) 132 CreateWorkingStateFromChanges(db.profile.changes)
101 if changeListener then 133 if changeListener then
102 changeListener:DataEvent() 134 changeListener:DataEvent()
103 end 135 end
104
105 end, 136 end,
106 137
107 ["RequestCatchup"] = function(self) 138 ["RequestCatchup"] = function(self)
108 if not admin then 139 if not admin then
109 Send("TS", timestamp) -- todo: send privately to loot master 140 --local string = _g.tostring(timestamp)
141 --for i,v in pairs(db.profile.changes) do -- append all change timestamps
142 -- string = string .. "|" .. _g.tostring(v.time)
143 --end
144 local t = {db.profile.time}
145 for i,v in pairs(db.profile.changes) do -- append all change timestamps
146 table.insert(t,v.time)
147 end
148 Send("TS", t) -- todo: send privately to loot master
110 else 149 else
111 -- todo: admins talking to one another 150 -- todo: admins talking to one another
112 end 151 end
113 152
114 end, 153 end,