comparison Admin.lua @ 99:5914125bb4ea

Admin comms (partially implemented)
author John@Yosemite-PC
date Sun, 29 Apr 2012 15:54:32 -0400
parents 0cd1d46e7b66
children d3ea0ab1428d
comparison
equal deleted inserted replaced
98:0cd1d46e7b66 99:5914125bb4ea
20 local newAdminList = {} 20 local newAdminList = {}
21 for line in guildInfoText:gmatch("[^\r\n]+") do 21 for line in guildInfoText:gmatch("[^\r\n]+") do
22 local l,r = line:match("(.*):(.*)") -- could use wow strsplit had I known about it before writing this 22 local l,r = line:match("(.*):(.*)") -- could use wow strsplit had I known about it before writing this
23 l = string.trim(l or "") 23 l = string.trim(l or "")
24 r = string.trim(r or "") 24 r = string.trim(r or "")
25 if l == "BSKADMIN" then -- found a juicy line. may contain multiple, comma delimited 25 if l == "BSKADMIN" then -- found a juicy line. may contain multiple, comma or space delimited
26 local admins = {strsplit(", ",r)} 26 local admins = {strsplit(", ",r)}
27 for _,a in pairs(admins) do 27 for _,a in pairs(admins) do
28 a = string.trim(a or "") 28 a = string.trim(a or "")
29 if a ~= "" then 29 if a ~= "" then
30 newAdminList[a] = true 30 newAdminList[a] = true
45 print("Admin added:",a) 45 print("Admin added:",a)
46 end 46 end
47 end 47 end
48 end 48 end
49 adminList = newAdminList 49 adminList = newAdminList
50
51 if adminList[_G.UnitName("player")] then -- I'm an admin!
52 admin = true
53 bsk.db.profile.admin = true
54 RegisterAdminChannels()
55 else
56 admin = false
57 bsk.db.profile.admin = false
58 UnregisterAdminChannels()
59 end
60 end
61
62 function RemoteAdminUpdateReceived(sender,remoteAdminStatusTable)
63 if not admin then return end
64
65 local rs = remoteAdminStatusTable
66 for i,_ in pairs(adminList) do -- update each admin's entry in your own DB
67
68 -- grab the db copy and the incoming copy for that admin
69 local dbs = db.profile.adminStatus[i] or {}
70 local ics = packet[i] or {}
71
72 -- figure out which is better and keep that one
73 -- winning criteria:
74 -- * broadcast was actually from that person (ie best
75 -- verification possible)
76 -- * newer base
77 -- * same base, more entries
78 -- * todo: see if date last observed is a better option
79
80 if i==sender then
81 db.profile.adminStatus[i] = ics
82 elseif ics.base > dbs.base or (ics.base==dbs.base and getn(ics.changes) > getn(dbs.changes)) then
83 db.profile.adminStatus[i] = ics
84 end
85 end
50 end 86 end
51 87
52 function InitializeAdmin() 88 function InitializeAdmin()
53 if not event then 89 if not event then
54 _G.error("BSK: Improper order of initialization") 90 _G.error("BSK: Improper order of initialization")
55 end 91 end
92
93 if admin then -- if at last login I was an admin ...
94
95 -- note that we're not transmitting anything here. we'll do that once we
96 -- know for certain we're an admin
97
98 -- cache the onload status in case it changes in memory later
99 onloadAdminStatus = {}
100 tcopy(onloadAdminStatus,db.profile.adminStatus)
101
102 -- update our own entry - safe because comms shouldn't have happened yet
103 me = _G.UnitName("player")
104 if not onloadAdminStatus then onloadAdminStatus = {} end
105 if not onloadAdminStatus[me] then onloadAdminStatus[me] = {} end
106 onloadAdminStatus[me].base = db.profile.time or 0
107 onloadAdminStatus[me].changes= {}
108 for _,v in ipairs(db.profile.changes) do
109 table.insert(onloadAdminStatus[me].changes,v.time) -- only timestamps
110 end
111
112 else -- otherwise store a blank slate
113 onloadAdminStatus = {}
114 db.profile.adminStatus = nil
115 end
116
117
56 event:RegisterEvent("GUILD_ROSTER_UPDATE",GuildRosterUpdate) 118 event:RegisterEvent("GUILD_ROSTER_UPDATE",GuildRosterUpdate)
57 _G.GuildRoster() -- will eventually force the event to fire 119 _G.GuildRoster() -- will eventually force the event to fire
58 end 120 end
59 121
60 122