comparison Comm.lua @ 99:5914125bb4ea

Admin comms (partially implemented)
author John@Yosemite-PC
date Sun, 29 Apr 2012 15:54:32 -0400
parents 19fd02bff870
children 21567b74fcc7
comparison
equal deleted inserted replaced
98:0cd1d46e7b66 99:5914125bb4ea
25 25
26 local function SendMessage(str) 26 local function SendMessage(str)
27 --commlib:SendCommMessage("BSKADDON"..commversion,str,"GUILD") 27 --commlib:SendCommMessage("BSKADDON"..commversion,str,"GUILD")
28 commlib:SendCommMessage("BSKADDON"..commversion,str,"RAID") 28 commlib:SendCommMessage("BSKADDON"..commversion,str,"RAID")
29 end 29 end
30 local function SendAdminMessage(str)
31 --commlib:SendCommMessage("BSKADMIN"..commversion,str,"GUILD")
32 commlib:SendCommMessage("BSKADMIN"..commversion,str,"RAID")
33 end
30 34
31 local function Send(handler,message) 35 local function Send(handler,message)
32 local p,str = BuildPacket(handler,message) 36 local p,str = BuildPacket(handler,message)
33 SendMessage(str) 37 SendMessage(str)
38 end
39
40 local function SendAdmin(handler,message)
41 local p,str = BuildPacket(handler,message)
42 SendAdminMessage(str)
34 end 43 end
35 44
36 -- todo: ActivateList and AddReserve -> state 45 -- todo: ActivateList and AddReserve -> state
37 Comm = 46 Comm =
38 { 47 {
117 end, 126 end,
118 127
119 ["RequestCatchup"] = function(self) 128 ["RequestCatchup"] = function(self)
120 if not admin then 129 if not admin then
121 --local string = _g.tostring(timestamp) 130 --local string = _g.tostring(timestamp)
122 --for i,v in pairs(db.profile.changes) do -- append all change timestamps 131 --for i,v in ipairs(db.profile.changes) do -- append all change timestamps
123 -- string = string .. "|" .. _g.tostring(v.time) 132 -- string = string .. "|" .. _g.tostring(v.time)
124 --end 133 --end
125 local t = {db.profile.time} 134 local t = {db.profile.time}
126 for i,v in pairs(db.profile.changes) do -- append all change timestamps 135 for i,v in ipairs(db.profile.changes) do -- append all change timestamps
127 table.insert(t,v.time) 136 table.insert(t,v.time)
128 end 137 end
129 Send("TS", t) -- todo: send privately to loot master 138 Send("TS", t) -- todo: send privately to loot master
130 else 139 else
131 -- todo: admins talking to one another 140 -- todo: admins talking to one another
132 end 141 end
133 142
134 end, 143 end,
144
145 ["SR"] = function(self,packet,sender,isloop)
146 if isloop then return end
147 if admin then
148 RemoteAdminUpdateReceived(sender,packet)
149 end
150 end,
151
152 ["SA"] = function(self,packet,sender,isloop)
153 print("SA")
154 if isloop then return end
155 if admin then
156 SendAdmin("SR",onloadAdminStatus) -- SR ... prevent infinite loop please
157 RemoteAdminUpdateReceived(sender,packet)
158 end
159 end,
160
161 ["SendAdminStatusTable"] = function(self)
162 if admin and onloadAdminStatus and _G.next(onloadAdminStatus) then
163 SendAdmin("SA",onloadAdminStatus) -- only send onload status, since that's the only data you're guaranteed to have safely safed
164 end
165 end,
135 } 166 }
136 167
137 local function OnCommReceived(prefix, message, distribution, sender) 168 local function OnCommReceived(prefix, message, distribution, sender)
138 print("Received on", distribution) 169 print("Received on", distribution)
170 local success,packet = s:Deserialize(message)
171 local isloop = _G.UnitName("player") == sender
172
173 print("received",message)
174
175 Comm[packet[1]](Comm,packet[2],sender,isloop)
176 end
177
178 local function OnAdminCommReceived(prefix, message, distribution, sender)
179 print("Received (admin) on", distribution)
139 local success,packet = s:Deserialize(message) 180 local success,packet = s:Deserialize(message)
140 local isloop = _G.UnitName("player") == sender 181 local isloop = _G.UnitName("player") == sender
141 182
142 print("received",message) 183 print("received",message)
143 184
168 commlib:RegisterComm("BSKADDON"..i,OnNewerCommReceived) 209 commlib:RegisterComm("BSKADDON"..i,OnNewerCommReceived)
169 end 210 end
170 end 211 end
171 212
172 function DeinitializeComm() 213 function DeinitializeComm()
173 214 -- todo
174 end 215 end
216
217 local adminregistered = false
218 function RegisterAdminChannels()
219 if not adminregistered then
220 for i = 0,commversion-1 do
221 commlib:RegisterComm("BSKADMIN"..i,OnOlderCommReceived)
222 end
223 commlib:RegisterComm("BSKADMIN"..commversion,OnAdminCommReceived)
224 for i = commversion+1,commversion+5 do -- some sensible number
225 commlib:RegisterComm("BSKADMIN"..i,OnNewerCommReceived)
226 end
227 adminregistered = true
228
229 -- now that we're set up, tell the other admins our status
230 Comm:SendAdminStatusTable()
231 end
232 end
233
234 function UnregisterAdminChannels()
235 -- todo
236 end
237