annotate Core.lua @ 99:5914125bb4ea

Admin comms (partially implemented)
author John@Yosemite-PC
date Sun, 29 Apr 2012 15:54:32 -0400
parents 0cd1d46e7b66
children
rev   line source
John@0 1 -- ideas: last attended data and/or remove people who haven't attended in X days
John@0 2
John@0 3 -- order of implementation
John@31 4 -- (*) lists fully functional (/script interface)
John@31 5 -- (*) lists single-user functional via command line interface
John@27 6 -- (*) all actions should reference the player list rather than player names
John@95 7 -- (x) player entries should persist as long as any list or change references
John@18 8 -- (*) lists store number slots rather than flat indexing
John@86 9 -- (*) database and comm versioning
John@77 10 -- (_) limited communication - everyone trusts the loot master
John@85 11 -- (*) single user + admin gui (manual suicides)
John@85 12 -- (*) single user + admin gui (master loot)
John@84 13 -- (*) whisper UI
John@85 14 -- (_) communication and list merging/trimming
John@85 15 -- (_) admins
John@77 16 -- (*) players gui
John@35 17 -- ( ) undo
John@0 18 -- ( ) crypto / protection against tampering
John@0 19 -- ( ) alt tracking
John@70 20 -- (*) reserves
John@91 21 -- ( ) comparison vs currently equipped item
John@32 22
John@95 23
John@95 24 -- Trimming.
John@95 25 -- * on login, check self state vs admin states
John@95 26 -- * trim up to the common point
John@95 27 -- * broadcast to other admins your present state (they will simply record this)
John@95 28
John@42 29 local _G=_G
John@42 30 local strsplit=strsplit
John@42 31 local string=string
John@42 32 local sformat=string.format
John@43 33 local bsk = LibStub("AceAddon-3.0"):NewAddon("bsk","AceConsole-3.0")
John@42 34 _G.bsk=bsk
John@42 35 local L = LibStub("AceLocale-3.0"):GetLocale("bsk", false)
John@42 36 setfenv(1,bsk)
John@42 37
John@34 38 local pkgrev = " @project-revision@ "
John@0 39
John@0 40 -- important things to remember:
John@1 41 -- 1) ipairs iterates from 1 until the first missing int index -> no gaps if int
John@1 42 -- indexing
John@0 43 -- 2) a.x === a["x"]
John@0 44 -- 3) a["1"] =/= a[1]
John@5 45 -- 4) table.remove() works ok if reverse iterating, terrible at anything else
John@5 46 -- 5) pairs() does not have a guaranteed iteration order
John@0 47
John@86 48 dbversion = 1
John@86 49 commversion = 1
John@86 50
John@42 51 function OnInitialize()
John@0 52
John@69 53 debug = true
John@69 54
John@42 55 db = _G.LibStub("AceDB-3.0"):New("BskDB", defaults, "Default")
John@0 56
John@42 57 options.args.profile = _G.LibStub("AceDBOptions-3.0"):GetOptionsTable(db)
John@42 58 _G.LibStub("AceConfig-3.0"):RegisterOptionsTable("bsk", options)
John@42 59 --optionsFrame = LibStub("AceConfigDialog-3.0"):AddToBlizOptions("bsk", "bsk")
John@0 60
John@74 61 admin = db.profile.admin
John@86 62 if not db.profile.dbversion or db.profile.dbversion < dbversion then
John@86 63 UpgradeDB()
John@86 64 end
John@74 65
John@42 66 local HandlePassThrough = function(...) HandleCommand(...) end
John@42 67 bsk:RegisterChatCommand("bsk", HandlePassThrough)
John@68 68 bsk:OnInitializeSetStaticData()
John@70 69 InitializeComm()
John@73 70 InitializeLooting()
John@98 71 InitializeAdmin()
John@0 72 end
John@0 73
John@42 74 function OnEnable()
John@42 75 CreateWorkingStateFromChanges(db.profile.changes)
John@73 76 InitializeState()
John@0 77 end
John@0 78
John@42 79 function HandleCommand(paramIn)
John@0 80 local param = { strsplit(" ", paramIn) }
John@8 81 local FixPersonName = function(p)
John@0 82 p = p:lower()
John@0 83 -- next two lines from sylvanaar
John@0 84 local MULTIBYTE_FIRST_CHAR = "^([\192-\255]?%a?[\128-\191]*)"
John@0 85 return string.gsub(p, MULTIBYTE_FIRST_CHAR, string.upper, 1)
John@0 86 end
John@49 87 action,arg1,arg2,arg3 = bsk:GetArgs(paramIn,4)
John@0 88
John@49 89 if not action then
John@43 90 print("need args")
John@0 91 return
John@0 92 end
John@49 93 if action == "persons" then
John@42 94 PrintPersons()
John@49 95 elseif action == "changes" then
John@42 96 PrintChanges()
John@49 97 elseif action == "selfdestruct" then
John@49 98 SelfDestruct()
John@49 99 elseif action == "delete" or action == "remove" then
John@49 100 if not arg1 or not arg2 then
John@42 101 PrintTable(param)
John@21 102 return
John@21 103 end
John@49 104 if arg1 == "list" then
John@49 105 DeleteList(arg2)
John@49 106 elseif arg1 == "personfromlist" or "fromlist" then
John@49 107 if not arg3 then
John@42 108 PrintTable(param)
John@22 109 return
John@22 110 end
John@49 111 local person = FixPersonName(arg2)
John@49 112 RemovePersonFromList(person, arg3)
John@49 113 elseif arg1 == "person" then
John@49 114 local person = FixPersonName(arg2)
John@42 115 RemovePerson(person)
John@21 116 else
John@49 117 printf("Deleting anything of type %s is not supported",arg1)
John@21 118 end
John@49 119 elseif action == "nuke" then
John@49 120 if not arg1 then
John@42 121 PrintTable(param)
John@30 122 return
John@30 123 end
John@49 124 local person = FixPersonName(arg1)
John@42 125 NukePerson(person)
John@49 126 elseif action == "add" or action == "create" then
John@49 127 if not arg1 or not arg2 then
John@42 128 PrintTable(param)
John@0 129 return
John@0 130 end
John@49 131 if arg1 == "person" then
John@49 132 if arg2 == "all" or arg2 == "missing" then
John@49 133 PersonList:AddMissing()
John@1 134 else
John@49 135 local person = FixPersonName(arg2)
John@42 136 AddPerson(person)
John@1 137 end
John@49 138 elseif arg1 == "list" then
John@49 139 CreateList(arg2)
John@49 140 elseif arg1 == "tolist" then
John@49 141 if not arg3 then
John@42 142 PrintTable(param)
John@9 143 return
John@9 144 end
John@49 145 local person = FixPersonName(arg2)
John@49 146 AddPersonToListEnd(person,arg3)
John@49 147 elseif arg1 == "tolistrandom" then
John@49 148 if not arg3 then
John@42 149 PrintTable(param)
John@11 150 return
John@11 151 end
John@49 152 local person = FixPersonName(arg2)
John@49 153 AddPersonToListRandom(person,arg3)
John@0 154 end
John@49 155 elseif action == "populate" then
John@49 156 if not arg1 then
John@42 157 PrintTable(param)
John@3 158 return
John@3 159 end
John@3 160 -- list = p2
John@49 161 PopulateListRandom(arg1)
John@49 162 elseif action == "suicide" then
John@49 163 if not arg1 or not arg2 then
John@42 164 PrintTable(param)
John@0 165 return
John@0 166 end
John@49 167 local person = FixPersonName(arg1)
John@49 168 SuicidePerson(person,arg2)
John@49 169 elseif action == "lists" then
John@49 170 if not arg1 then
John@42 171 PrettyPrintLists()
John@14 172 return
John@14 173 else
John@49 174 PrettyPrintList(arg1)
John@14 175 end
John@49 176 elseif action == "reserve" then
John@49 177 if not arg1 then
John@49 178 PrintTable(param)
John@49 179 return
John@49 180 end
John@49 181 local person = FixPersonName(arg1)
John@49 182 ReservePerson(person)
John@49 183 elseif action == "trim" then
John@49 184 if not arg1 then
John@42 185 printtable(param)
John@0 186 return
John@0 187 end
John@49 188 TrimLists(arg1)
John@49 189 elseif action == "rename" then
John@49 190 if not arg1 or not arg2 then
John@49 191 PrintTable(param)
John@5 192 return
John@5 193 end
John@49 194 RenameList(arg1,arg2)
John@66 195 elseif action == "generate" then
John@66 196 if not arg1 then
John@66 197 PrintTable(param)
John@66 198 return
John@66 199 end
John@66 200 PersonList:AddMissing()
John@66 201 CreateList(arg1)
John@66 202 PopulateListRandom(arg1)
John@77 203 elseif action == "liststatus" then
John@77 204 local lids = LootLists:GetAllIds()
John@77 205 for _,v in _G.pairs(lids) do
John@77 206 local lref = LootLists:Select(v)
John@77 207 printf("List %s, modified %s (%s)", lref:GetName(), _G.date("%m/%d/%y %H:%M:%S",lref:GetTime()), lref:GetTime())
John@77 208 end
John@72 209 elseif action == "push" then
John@72 210 Comm:Push()
John@72 211 elseif action == "state" then
John@72 212 print(state)
John@38 213 else
John@42 214 CreateGUI()
John@0 215 end
John@0 216 end
John@0 217
John@42 218 defaults = {
John@0 219 profile = {
John@91 220 time = 0,
John@8 221 persons = {},
John@0 222 changes = {},
John@34 223 lists = {}
John@0 224 }
John@0 225 }
John@0 226
John@86 227 function UpgradeDB()
John@86 228 local mydbver = db.profile.dbversion or 0
John@86 229
John@86 230 if mydbver == 0 then -- difference between 0 and 1 is whether this field is present
John@86 231 db.profile.dbversion = 1
John@86 232 mydbver = 1
John@86 233 end
John@86 234
John@86 235
John@86 236 end