comparison Comm.lua @ 94:2058d86778b4

Corrections on the receiver end of an incremental update.
author John@Yosemite-PC
date Sun, 22 Apr 2012 23:13:43 -0400
parents df94161e6d7c
children 082ff877c443
comparison
equal deleted inserted replaced
93:df94161e6d7c 94:2058d86778b4
83 ["TS"] = function(self,packet,sender,isloop) 83 ["TS"] = function(self,packet,sender,isloop)
84 if isloop then return end 84 if isloop then return end
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
89 -- timeline, then just catch them up
90 --local dbPersons = {toons=PersonList.toons,time=PersonList.time}
91 --Send("CU",{dbPersons,LootLists.l,timestamp}) -- todo: send privately
92 88
93 local t = packet 89 local t = packet
94 local remoteBase = table.remove(t,1) 90 local remoteBase = table.remove(t,1)
95 91
96 -- if their base is older than ours, this is easy - send them our 92 -- if their base is older than ours, this is easy - send them our
143 local nc = getn(c) 139 local nc = getn(c)
144 140
145 if no == 0 then 141 if no == 0 then
146 db.profile.changes = c 142 db.profile.changes = c
147 else 143 else
148 while op <= no and cp <= nc do 144 while op <= no or cp <= nc do -- lists are pre-sorted. insertion merge them
149 if c[cp].time == old[op].time then 145 if cp > nc then -- inelegant
146 table.insert(new,old[op])
147 op = op + 1
148 elseif op > no then
149 table.insert(new,c[cp])
150 cp = cp + 1
151 elseif c[cp].time < old[op].time then
152 table.insert(new,c[cp])
153 cp = cp + 1
154 elseif c[cp].time > old[op].time then
155 table.insert(new,old[op])
156 op = op + 1
157 else
150 error("Bad update received from ",sender) 158 error("Bad update received from ",sender)
151 end 159 end
152 if c[cp].time < old[op].time then
153 table.insert(new,c[cp])
154 cp = cp + 1
155 else
156 table.inert(new,old[cp])
157 op = op + 1
158 end
159 end 160 end
161 print("Updating changes - ",getn(new), "entries")
160 db.profile.changes = new 162 db.profile.changes = new
161 end 163 end
162 164
163 CreateWorkingStateFromChanges(db.profile.changes) 165 CreateWorkingStateFromChanges(db.profile.changes)
164 if changeListener then 166 if changeListener then