# HG changeset patch # User John@Yosemite-PC # Date 1331097485 18000 # Node ID b05fcb225c4aa53a937e8d538a8d677ae0d44418 # Parent 241986f7066cfc2e020c36e26eece9142b5ec08f player -> person fix trim bug when trimming all shortened IDs for persons list keys diff -r 241986f7066c -r b05fcb225c4a Core.lua --- a/Core.lua Tue Mar 06 09:33:04 2012 -0500 +++ b/Core.lua Wed Mar 07 00:18:05 2012 -0500 @@ -49,7 +49,7 @@ function bsk:HandleCommand(paramIn) local param = { strsplit(" ", paramIn) } - local FixPlayerName = function(p) + local FixPersonName = function(p) p = p:lower() -- next two lines from sylvanaar local MULTIBYTE_FIRST_CHAR = "^([\192-\255]?%a?[\128-\191]*)" @@ -60,8 +60,10 @@ bsk:Print("need args") return end - if param[1] == "players" then - bsk:PrintPlayers() + if param[1] == "persons" then + bsk:PrintPersons() + elseif param[1] == "changes" then + bsk:PrintChanges() elseif param[1] == "add" then if param[2] == nil or param[2] == "" then bsk:PrintTable(param) @@ -71,12 +73,12 @@ bsk:PrintTable(param) return end - if param[2] == "player" then + if param[2] == "person" then if param[3] == "all" then - bsk:AddMissingPlayers() + bsk:AddMissingPersons() else - local player = FixPlayerName(param[3]) - bsk:AddPlayer(player) + local person = FixPersonName(param[3]) + bsk:AddPerson(person) end elseif param[2] == "list" then bsk:CreateList(param[3]) @@ -96,9 +98,9 @@ bsk:PrintTable(param) return end - local player = FixPlayerName(param[2]) - bsk:Print(string.format("Fixed player name %s to %s",param[2],player)) - bsk:SuicidePlayer(player,param[3]) + local person = FixPersonName(param[2]) + bsk:Print(string.format("Fixed player name %s to %s",param[2],person)) + bsk:SuicidePerson(person,param[3]) elseif param[1] == "show" then if param[2] == nil or param[2] == "" then bsk:PrintTable(param) @@ -124,7 +126,7 @@ bsk.defaults = { profile = { - players = {}, + persons = {}, changes = {}, listBase = {} } diff -r 241986f7066c -r b05fcb225c4a Lists.lua --- a/Lists.lua Tue Mar 06 09:33:04 2012 -0500 +++ b/Lists.lua Wed Mar 07 00:18:05 2012 -0500 @@ -43,12 +43,14 @@ -- Handling conflicts: -- +-- todo: list-of-lists must not use int indices. those will lead to peril. bsk.lists = {} -bsk.players = {} +bsk.persons = {} -local RaidList = {} -local ReserveList = {} -local activeList = 0 -- temporary +local raidList = {} +local reserveList = {} +local activeListKey = 1 -- temporary +local personsReverse = {} local tinsert = table.insert local sformat = string.format @@ -77,8 +79,8 @@ function bsk:PrintChanges() bsk:PrintTable(bsk.db.profile.changes) end -function bsk:PrintPlayers() - bsk:PrintTable(bsk.players) +function bsk:PrintPersons() + bsk:PrintTable(bsk.persons) end function bsk:PrintTable(table, depth) depth = depth or "" @@ -102,14 +104,16 @@ --}}} function bsk:CreateWorkingStateFromChanges(changes) - local playerBase = self.db.profile.players + local personsBase = self.db.profile.persons local listBase = self.db.profile.listBase -- copy the base to the working state wipe(bsk.lists) - wipe(bsk.players) + wipe(bsk.persons) + wipe(personsReverse) + bsk:tcopy(bsk.lists,listBase) - bsk:tcopy(bsk.players,playerBase) + bsk:tcopy(bsk.persons,personsBase) -- now just go through the changes list applying each for i,v in ipairs(changes) do @@ -175,14 +179,14 @@ -- setting on all operating systems ... function bsk:ProcessChange(change) - if change.action == "AddPlayer" then - bsk:DoAddPlayer(change) + if change.action == "AddPerson" then + bsk:DoAddPerson(change) elseif change.action == "CreateList" then bsk:DoCreateList(change) - elseif change.action == "AddPlayerToList" then - bsk:DoAddPlayerToList(change) - elseif change.action == "SuicidePlayer" then - bsk:DoSuicidePlayer(change) + elseif change.action == "AddPersonToList" then + bsk:DoAddPersonToList(change) + elseif change.action == "SuicidePerson" then + bsk:DoSuicidePerson(change) else bsk:Print("Unknown message encountered") bsk:PrintTable(change) @@ -208,39 +212,43 @@ -- Note that "undo" has no special voodoo to it. It's basically a change that -- reverses the prior change on the stack. --- Players list -function bsk:DoAddPlayer(change) +-- persons list +function bsk:DoAddPerson(change) assert(change) - assert(change.arg.guid) + assert(change.arg.id) local arg = change.arg -- require admin - local players = bsk.players + local persons = bsk.persons local name = arg.name - local guid = arg.guid - assert(players[guid]==nil) - players[guid] = name - players.time=change.time + local id = arg.id + assert(persons[id]==nil) + persons[id] = {main=name} + persons.time=change.time + personsReverse[name] = id return true end -function bsk:AddPlayer(name) - local players = bsk.players +function bsk:AddPerson(name) + local persons = bsk.persons local guid = UnitGUID(name) -- TODO: check guid to be sure it's a player if not guid then self:Print(sformat("Could not add player %s - they must be in range or group",name)) return end - if players[guid] and players[guid] ~= name then - self:Print(sformat("Namechange detected for %s - new is %s, please rename the existing entry", players[guid], name)) + local id = string.sub(guid,6) -- skip at least 0x0580 ... + id = id:gsub("^0*(.*)","%1") -- nom all leading zeroes remaining + + if persons[id] and persons[id] ~= name then + self:Print(sformat("Namechange detected for %s - new is %s, please rename the existing entry", persons[id], name)) return end - if players[guid] ~= nil then - self:Print(sformat("%s is already in the players list; disregarding", name)) + if persons[id] ~= nil then + self:Print(sformat("%s is already in the persons list; disregarding", name)) return end - local change = {action="AddPlayer",arg={name=name,guid=guid}} - if bsk:DoAddPlayer(change) then + local change = {action="AddPerson",arg={name=name,id=id}} + if bsk:DoAddPerson(change) then bsk:CreateChange(change) end end @@ -268,7 +276,7 @@ end end -function bsk:DoAddPlayerToList(change) +function bsk:DoAddPersonToList(change) local listIndex = change.arg.listIndex local slist = change.arg.slist local list = bsk.lists[listIndex] @@ -283,27 +291,28 @@ return true end -function bsk:AddPlayerToList(name,list) +function bsk:AddPersonToList(name,list) -- require admin local listIndex = bsk:GetListIndex(list) - local slist = {name} -- TODO: support adding to elsewhere besides the end - local change = {action="AddPlayerToList",arg={name=name,listIndex=listIndex,slist=slist}} + local id = personsReverse[name] + local slist = {id} -- TODO: support adding to elsewhere besides the end + local change = {action="AddPersonToList",arg={id=id,listIndex=listIndex,slist=slist}} bsk:StartChange(change) - if bsk:DoAddPlayerToList(change) then + if bsk:DoAddPersonToList(change) then bsk:CommitChange(change) end end -function bsk:DoRemovePlayer(change) +function bsk:DoRemovePerson(change) -- return true end -function bsk:RemovePlayer(name) - -- from both players and lists +function bsk:RemovePerson(name) + -- from both persons and lists end -function bsk:DoSuicidePlayer(change) +function bsk:DoSuicidePerson(change) local listIndex = change.arg.listIndex local list = bsk.lists[listIndex] local slist = shallowCopy(change.arg.list) @@ -328,14 +337,14 @@ return true end -function bsk:SuicidePlayer(name,list) +function bsk:SuicidePerson(name,list) -- require admin bsk:PopulateRaidList() local listIndex = bsk:GetListIndex(list) local slist=bsk:GetSuicideList(name,bsk.lists[listIndex]) - local change = {action="SuicidePlayer",arg={names=names,list=slist,listIndex=listIndex}} + local change = {action="SuicidePerson",arg={names=names,list=slist,listIndex=listIndex}} bsk:StartChange(change) - if bsk:DoSuicidePlayer(change) then + if bsk:DoSuicidePerson(change) then bsk:CommitChange(change) end end @@ -365,9 +374,9 @@ bsk:CreateWorkingStateFromChanges(before) -- save this state permanently; trim the changes permanently - bsk:tcopy(bsk.db.profile.players,bsk.players) + bsk:tcopy(bsk.db.profile.persons,bsk.persons) bsk:tcopy(bsk.db.profile.listBase,bsk.lists) - while bsk.db.profile.changes[1].time <= time do + while bsk.db.profile.changes ~= nil and bsk.db.profile.changes[1] ~= nil and bsk.db.profile.changes[1].time <= time do table.remove(bsk.db.profile.changes,1) end @@ -377,16 +386,17 @@ --}}} -- Higher order actions (ie calls other Doers){{{ -function bsk:AddMissingPlayers() +function bsk:AddMissingPersons() bsk:PopulateRaidList() local t = {} - for i,v in pairs(bsk.players) do - t[v] = true + for _,v in pairs(bsk.persons) do + t[v.main] = true + -- TODO: also add alts here end - for i,v in pairs(RaidList) do + for i,_ in pairs(raidList) do if t[i] == nil then - bsk:Print(sformat("Player %s is missing from the players list - adding",i)) - bsk:AddPlayer(i) + bsk:Print(sformat("Person %s is missing from the persons list - adding",i)) + bsk:AddPerson(i) end end -- TODO: batch into a single op - no need to spam 25 messages in a row @@ -398,7 +408,7 @@ local t = {} --for i = 1,#list do - -- if not (RaidList(list[i]) or ReserveList(list[i])) then + -- if not (raidList(list[i]) or reserveList(list[i])) then -- tinsert(t,) -- end --end @@ -409,12 +419,12 @@ -- reserves function bsk:AddReserve(name) - ReserveList[name]=true + reserveList[name]=true -- TODO: communicate to others. don't store this in any way. end function bsk:RemoveReserve(name) - ReserveList[name]=false + reserveList[name]=false -- TODO: communicate to others. don't store this in any way. end @@ -439,20 +449,20 @@ local inParty = GetNumPartyMembers() local inRaid = GetNumRaidMembers() - wipe(RaidList) + wipe(raidList) if inRaid > 0 then for i = 1, inRaid do - RaidList[UnitName(rID[i])]=true + raidList[UnitName(rID[i])]=true end elseif inParty > 0 then for i = 1, inParty do - RaidList[UnitName(pID[i])]=true + raidList[UnitName(pID[i])]=true end -- Now add yourself as the last party member - RaidList[UnitName("player")]=true + raidList[UnitName("player")]=true else -- You're alone - RaidList[UnitName("player")]=true + raidList[UnitName("player")]=true end end @@ -475,7 +485,7 @@ if list[i] == name then pushing = true end - if pushing and (RaidList[list[i]] or ReserveList[list[i]]) then + if pushing and (raidList[list[i]] or reserveList[list[i]]) then tinsert(ret,list[i]) end end