comparison 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
comparison
equal deleted inserted replaced
90:dcbe1f04bb31 91:5ade79caeece
62 end 62 end
63 Send("CC",change) 63 Send("CC",change)
64 end, 64 end,
65 ["CC"] = function(self,change,sender,isloop) 65 ["CC"] = function(self,change,sender,isloop)
66 if isloop then return end 66 if isloop then return end
67 table.insert(db.profile.changes,change)
67 ProcessChange(change) 68 ProcessChange(change)
68 changeListener:DataEvent() 69 changeListener:DataEvent()
69 end, 70 end,
70 ["Push"] = function(self) 71 ["Push"] = function(self)
71 Send("PU",{db.profile.lists,db.profile.persons,db.profile.changes}) 72 Send("PU",{db.profile.lists,db.profile.persons,db.profile.changes,db.profile.time})
72 end, 73 end,
73 ["PU"] = function(self,packet,sender,isloop) 74 ["PU"] = function(self,packet,sender,isloop)
74 if isloop then return end 75 if isloop then return end
75 db.profile.lists,db.profile.persons,db.profile.changes = unpack(packet) 76 db.profile.lists,db.profile.persons,db.profile.changes,db.profile.time = unpack(packet)
76 CreateWorkingStateFromChanges(db.profile.changes) 77 CreateWorkingStateFromChanges(db.profile.changes)
77 if changeListener then 78 if changeListener then
78 changeListener:DataEvent() 79 changeListener:DataEvent()
79 end 80 end
81 end,
82
83 ["TS"] = function(self,packet,sender,isloop)
84 if isloop then return end
85 if masterLooterIsMe and admin then
86 -- only non-admins will send this message, send them the present
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 end
93 end,
94
95 ["CU"] = function(self,packet,sender,isloop) -- blindly trust an admin loot master
96 if isloop then return end
97 print("CU")
98 db.profile.persons,db.profile.lists,db.profile.time = unpack(packet)
99 db.profile.changes = {}
100 CreateWorkingStateFromChanges(db.profile.changes)
101 if changeListener then
102 changeListener:DataEvent()
103 end
104
105 end,
106
107 ["RequestCatchup"] = function(self)
108 if not admin then
109 Send("TS", timestamp) -- todo: send privately to loot master
110 else
111 -- todo: admins talking to one another
112 end
113
80 end, 114 end,
81 } 115 }
82 116
83 local function OnCommReceived(prefix, message, distribution, sender) 117 local function OnCommReceived(prefix, message, distribution, sender)
84 print("Received on", distribution) 118 print("Received on", distribution)