Files

70 lines
3.4 KiB
Lua

-- aux's item-cache scan must not turn every login into a server crawl of item ids 1..99999.
-- On 70334 GetItemInfo of an id without client item data sends an ItemSparse DB query; ids the server
-- refuses come back as GET_ITEM_INFO_RECEIVED(id, false) and are never cached by the client, so aux must
-- remember them (and the items it cached) and not ask again on the next login, until the retry window ends.
assert(type(setfenv) == 'function' and type(getfenv) == 'function',
'aux cache fixture requires a Lua 5.1-compatible interpreter (lua5.1 or LuaJIT)')
local root = assert(arg[1], 'gateway directory required')
local exists = {[25] = true, [2589] = true, [99998] = true}
local asked, now = 0, 1000000
OctoAuxCompat = setmetatable({}, {__index = _G})
local C = OctoAuxCompat
C._G = C
C.module, C.require = false, false -- the client has no Lua 5.1 package library
dofile(root .. '/client_addons/aux-addon/libs/package.lua')
local queue, listeners, refused = {}, {}, {}
C.GetItemInfo = function(s)
local id = tonumber(s:match('^item:(%d+)'))
asked = asked + 1
if exists[id] then return 'Item ' .. id, s, 1, 1, 'Misc', 'Junk', 20, '', 'tex' end
refused[#refused + 1] = id -- the server answers invalid later
end
C.time = function() return now end
C.strlower, C.tinsert, C.sort, C.strlen = string.lower, table.insert, table.sort, string.len
C.CreateFrame = function() return {SetScript = function() end} end
C.tooltip = function() return {} end
C.auctionable = function() return true end
local loads = {}
local stub = setfenv(function()
module 'aux'
M.handle = setmetatable({}, {__newindex = function(_, k, v) if k == 'LOAD' then loads[#loads + 1] = v end end})
M.event_listener = function(event, cb) listeners[event] = listeners[event] or {} table.insert(listeners[event], cb) end
M.later = function() return true end
M.when = function(_, f, ...) return f(...) end
M.thread = function(f, ...) queue[#queue + 1] = {f, {...}} end
M.realm_data = {characters = {}}
M.account_data = {items = {}, item_ids = {}, auctionable_items = {}, merchant_buy = {}, merchant_sell = {}}
module 'T'
M.temp = setmetatable({}, {__sub = function(_, x) return x end})
M.map = function(...) return {...} end
module 'aux.util.persistence'
M.write = function(_, t) return t end
end, C)
stub()
local aux = C.require 'aux'
local function login() -- a fresh client session: listeners re-registered, saved variables kept
asked, queue, listeners, refused = 0, {}, {}, {}
loads[1]() -- the scan_wdb LOAD handler (first in cache.lua)
while #queue > 0 do local job = table.remove(queue, 1) job[1](unpack(job[2])) end
for _, id in ipairs(refused) do
C.arg1, C.arg2 = id, false
for _, cb in ipairs(listeners.GET_ITEM_INFO_RECEIVED or {}) do cb(function() end) end
end
C.arg1, C.arg2 = nil, nil
return asked
end
dofile(root .. '/client_addons/aux-addon/core/cache.lua')
local first = login()
assert(aux.account_data.item_ids['item 2589'] == 2589 and aux.account_data.item_ids['item 99998'] == 99998,
'scan must still cache every item the client has')
local second = login()
assert(second == 0, 'second login asked ' .. second .. ' item ids; cached and refused ids must not be asked again')
now = now + 4 * 24 * 60 * 60
local later = login()
assert(later == first - 3, 'after the retry window the refused ids are asked again (asked ' .. later .. ')')
print('aux item scan: first login ' .. first .. ' lookups, second login ' .. second .. ', after 4 days ' .. later)