comparison Admin.lua @ 103:d3ea0ab1428d

Bad commit, ignore. Just want a (failed) path to be on record.
author John@Doomsday
date Thu, 03 May 2012 09:05:40 -0400
parents 5914125bb4ea
children c6c748a5823b
comparison
equal deleted inserted replaced
102:21567b74fcc7 103:d3ea0ab1428d
31 end 31 end
32 end 32 end
33 end 33 end
34 end 34 end
35 35
36 if me == "Breuemama" then -- todo: strictly debugging ...
37 newAdminList[me] = true
38 newAdminList["Breue"] = true
39 end
40
36 if _G.next(adminList) ~= nil then -- had old admins. don't want to spam on initial load 41 if _G.next(adminList) ~= nil then -- had old admins. don't want to spam on initial load
37 -- diff new vs old 42 -- diff new vs old
38 for a in pairs(adminList) do 43 for a in pairs(adminList) do
39 if not newAdminList[a] then 44 if not newAdminList[a] then
40 print("Admin removed:", a) 45 print("Admin removed:", a)
46 end 51 end
47 end 52 end
48 end 53 end
49 adminList = newAdminList 54 adminList = newAdminList
50 55
51 if adminList[_G.UnitName("player")] then -- I'm an admin! 56 if adminList[me] then -- I'm an admin!
52 admin = true 57 admin = true
53 bsk.db.profile.admin = true 58 bsk.db.profile.admin = true
54 RegisterAdminChannels() 59 RegisterAdminChannels()
55 else 60 else
56 admin = false 61 admin = false
61 66
62 function RemoteAdminUpdateReceived(sender,remoteAdminStatusTable) 67 function RemoteAdminUpdateReceived(sender,remoteAdminStatusTable)
63 if not admin then return end 68 if not admin then return end
64 69
65 local rs = remoteAdminStatusTable 70 local rs = remoteAdminStatusTable
71 local events = {} -- record all timestamps seen in this update
66 for i,_ in pairs(adminList) do -- update each admin's entry in your own DB 72 for i,_ in pairs(adminList) do -- update each admin's entry in your own DB
67 73
68 -- grab the db copy and the incoming copy for that admin 74 -- grab the db copy and the incoming copy for that admin
69 local dbs = db.profile.adminStatus[i] or {} 75 if not db.profile.adminStatus then db.profile.adminStatus = {} end
70 local ics = packet[i] or {} 76 local dbs = db.profile.adminStatus[i] or {base=0, changes={}}
77 local ics = rs[i] or {base=0, changes={}}
71 78
72 -- figure out which is better and keep that one 79 -- figure out which is better and keep that one
73 -- winning criteria: 80 -- winning criteria:
74 -- * broadcast was actually from that person (ie best 81 -- * broadcast was actually from that person (ie best
75 -- verification possible) 82 -- verification possible)
81 db.profile.adminStatus[i] = ics 88 db.profile.adminStatus[i] = ics
82 elseif ics.base > dbs.base or (ics.base==dbs.base and getn(ics.changes) > getn(dbs.changes)) then 89 elseif ics.base > dbs.base or (ics.base==dbs.base and getn(ics.changes) > getn(dbs.changes)) then
83 db.profile.adminStatus[i] = ics 90 db.profile.adminStatus[i] = ics
84 end 91 end
85 end 92 end
93
94 local rss = rs[sender]
95
96 -- now figure out what I'm missing - and ask for it!
97
98 -- construct a hash table of all entries that the sender has / should have
99 local entries = {}
100 for i,v in pairs(rs) do
101 if v.changes then
102 for j,k in pairs(v.changes) do
103 entries[k.time] = true
104 end
105 end
106 end
107 -- now go back and scrub my own keys from that list
108 for i,v in ipairs(db.profile.changes) do
109 entries[v.time] = nil
110 end
111 -- what's left is what I need to ask for
112 local request = {}
113 for i,v in pairs(entries) do
114 if v then table.insert(request,i) end
115 end
116 table.sort(request)
117 Comm:RequestSpecificChanges(request,sender)
118
119 for
120 -- specifically leaving this broken. note to self.
121 -- this still isn't good enough. it doesn't communicate an admin's
122 -- present working state. like if they had put in new changes since
123 -- loading up. or learned of some changes to fill in an old gap
86 end 124 end
87 125
88 function InitializeAdmin() 126 function InitializeAdmin()
89 if not event then 127 if not event then
90 _G.error("BSK: Improper order of initialization") 128 _G.error("BSK: Improper order of initialization")
91 end 129 end
130 me = _G.UnitName("player")
92 131
93 if admin then -- if at last login I was an admin ... 132 if admin then -- if at last login I was an admin ...
94 133
95 -- note that we're not transmitting anything here. we'll do that once we 134 -- note that we're not transmitting anything here. we'll do that once we
96 -- know for certain we're an admin 135 -- know for certain we're an admin
98 -- cache the onload status in case it changes in memory later 137 -- cache the onload status in case it changes in memory later
99 onloadAdminStatus = {} 138 onloadAdminStatus = {}
100 tcopy(onloadAdminStatus,db.profile.adminStatus) 139 tcopy(onloadAdminStatus,db.profile.adminStatus)
101 140
102 -- update our own entry - safe because comms shouldn't have happened yet 141 -- update our own entry - safe because comms shouldn't have happened yet
103 me = _G.UnitName("player")
104 if not onloadAdminStatus then onloadAdminStatus = {} end 142 if not onloadAdminStatus then onloadAdminStatus = {} end
105 if not onloadAdminStatus[me] then onloadAdminStatus[me] = {} end 143 if not onloadAdminStatus[me] then onloadAdminStatus[me] = {} end
106 onloadAdminStatus[me].base = db.profile.time or 0 144 onloadAdminStatus[me].base = db.profile.time or 0
107 onloadAdminStatus[me].changes= {} 145 onloadAdminStatus[me].changes= {}
108 for _,v in ipairs(db.profile.changes) do 146 for _,v in ipairs(db.profile.changes) do
112 else -- otherwise store a blank slate 150 else -- otherwise store a blank slate
113 onloadAdminStatus = {} 151 onloadAdminStatus = {}
114 db.profile.adminStatus = nil 152 db.profile.adminStatus = nil
115 end 153 end
116 154
117
118 event:RegisterEvent("GUILD_ROSTER_UPDATE",GuildRosterUpdate) 155 event:RegisterEvent("GUILD_ROSTER_UPDATE",GuildRosterUpdate)
119 _G.GuildRoster() -- will eventually force the event to fire 156 _G.GuildRoster() -- will eventually force the event to fire
157
158 if me == "Breuemama" then -- debugging only
159 GuildRosterUpdate()
160 end
120 end 161 end
121 162
122 163