157 lines
11 KiB
Lua
157 lines
11 KiB
Lua
local source=assert(arg[1])
|
|
local now,tasks,clients,sent=0,{},{},{}
|
|
local function after(delay,fn) tasks[#tasks+1]={at=now+delay,fn=fn} end
|
|
local function advance(delta)
|
|
local finish=now+delta
|
|
while true do
|
|
local best
|
|
for i,t in ipairs(tasks) do if t.at<=finish and (not best or t.at<tasks[best].at) then best=i end end
|
|
if not best then break end
|
|
local t=table.remove(tasks,best);now=t.at;t.fn()
|
|
end
|
|
now=finish
|
|
end
|
|
local function check(v,msg) if not v then error(msg,2) end end
|
|
local function client(name,guid,ids)
|
|
local c={name=name,guid=guid,ids=ids or {},base=197,filters={},original=0,opens=0}
|
|
local env=setmetatable({}, {__index=_G}); c.env=env
|
|
local methods={}
|
|
function methods:SetText(t) self.text=t end
|
|
function methods:SetTexture(t) self.texture=t end
|
|
function methods:SetScript(event,fn) self.scripts[event]=fn end
|
|
function methods:RegisterEvent(event) c.events=self end
|
|
function methods:Show() self.shown=true end
|
|
function methods:Hide() self.shown=false;if self.scripts.OnHide then self.scripts.OnHide(self) end end
|
|
local function frame(kind,n,parent)
|
|
local f={scripts={},kind=kind,parent=parent}
|
|
setmetatable(f,{__index=function(_,key) return methods[key] or function() end end})
|
|
function f:CreateFontString() return frame('Font') end
|
|
function f:CreateTexture() return frame('Texture') end
|
|
if n then env[n]=f end
|
|
return f
|
|
end
|
|
env.CreateFrame=frame;env.UIParent=frame('Root');env.GameTooltip=frame('Tooltip')
|
|
env.GetTime=function() return now end;env.C_Timer={After=after}
|
|
env.UnitGUID=function() return guid end;env.GetNormalizedRealmName=function() return 'Local' end
|
|
env.GetPlayerInfoByGUID=function(g) for n,p in pairs(clients) do if p.guid==g then return nil,nil,nil,nil,nil,n,'' end end end
|
|
env.SetItemRef=function() c.original=c.original+1 end
|
|
env.hooksecurefunc=function(n,f) local orig=env[n]; env[n]=function(...) local r=orig(...); f(...); return r end end
|
|
env.ChatFrame_AddMessageEventFilter=function(event,fn) c.filters[event]=fn end
|
|
env.InCombatLockdown=function() return c.combat end
|
|
env.C_Spell={GetSpellInfo=function(id) return {name='Spell '..id,iconID=id} end}
|
|
env.C_Item={GetItemNameByID=function(id) return 'Item '..id end}
|
|
env.C_ChatInfo={RegisterAddonMessagePrefix=function(p) c.prefix=p end,
|
|
SendAddonMessage=function(prefix,full,channel,target)
|
|
check(prefix=='OCTO_TS' and channel=='GUILD' and target==nil,'guild channel, no whisper (Turtle drops addon whispers)')
|
|
check(#prefix+1+#full<=254,'Source message bound')
|
|
local to,text=full:match('^(%S+) (.*)$');check(to,'addressed message')
|
|
sent[#sent+1]={from=name,to=to,text=text}
|
|
-- every guild member receives it; only the addressee may act on it
|
|
if not c.drop then for n,p in pairs(clients) do if n~=name then after(.01,function() p:raw(full,name) end) end end end
|
|
end}
|
|
env.UnitName=function() return name end
|
|
env.IsInGuild=function() return not c.noguild end
|
|
env.C_TradeSkillUI={
|
|
GetProfessionInfoBySkillLineID=function(skill) if skill==197 then return {professionID=197,professionName='Tailoring',skillLevel=300} end end,
|
|
GetAllProfessionTradeSkillLines=function() return {197} end,
|
|
GetBaseProfessionInfo=function() return {professionID=c.base} end,
|
|
OpenTradeSkill=function(skill) c.opens=c.opens+1;c.base=skill;return true end,
|
|
IsTradeSkillReady=function() return c.ready~=false end,
|
|
IsTradeSkillLinked=function() return c.linked end,
|
|
IsTradeSkillGuild=function() return c.guild end,
|
|
GetAllRecipeIDs=function() return c.ids end,
|
|
GetRecipeInfo=function(id) return {name='Recipe '..id,learned=id%7~=0} end,
|
|
IsRecipeInBaseSkillLine=function(id) return id%11~=0 end,
|
|
GetRecipeSchematic=function(id) return {reagentSlotSchematics={{quantityRequired=2,reagents={{itemID=2320}}}}} end,
|
|
}
|
|
function c:raw(full,sender,channel) self.events.scripts.OnEvent(self.events,'CHAT_MSG_ADDON','OCTO_TS',full,channel or 'GUILD',sender) end
|
|
function c:message(text,sender,channel) self:raw(self.name..' '..text,sender,channel) end
|
|
function c:click(link) self.env.SetItemRef(link,'label','LeftButton') end
|
|
function c:window() return self.env.OctoTradeLinkFrame end
|
|
clients[name]=c
|
|
local chunk=assert(loadfile(source));setfenv(chunk,env);chunk()
|
|
c.events.scripts.OnEvent(c.events,'PLAYER_LOGIN')
|
|
check(c.prefix=='OCTO_TS','prefix registered')
|
|
return c
|
|
end
|
|
local ids={};local expected=0
|
|
for i=4000,4499 do ids[#ids+1]=i;if i%7~=0 and i%11~=0 then expected=expected+1 end end
|
|
ids[#ids+1]=4000 -- duplicate recipe does not duplicate output
|
|
local owner=client('Raider','Player-70-000011A2',ids)
|
|
local asker=client('Owner','Player-70-000011A7')
|
|
asker:click('item:123');asker:click('trade:'..asker.guid..':12180:197')
|
|
check(asker.original==2 and #sent==0,'own/nontrade links retain native handling')
|
|
-- Owner opened Tailoring once earlier: list cached per character; now another profession is open.
|
|
owner.base=197;owner.events.scripts.OnEvent(owner.events,'TRADE_SKILL_LIST_UPDATE');owner.base=164
|
|
asker:click('trade:'..owner.guid..':12180:197')
|
|
check(asker.original==3 and sent[1].text=='REQ 197','native link skill parsed; post-hook keeps native handler (no global write)')
|
|
advance(3)
|
|
check(#asker:window().recipeIDs==expected,'two-client learned-only chunked list')
|
|
check(owner.opens==0,'owner profession window never opened by a remote click')
|
|
local ownChunks={};for _,m in ipairs(sent) do if m.from=='Raider' then ownChunks[#ownChunks+1]=m.text end end
|
|
check(asker:window().title.text=="Raider's Tailoring (?)",'native link never invents remote rank')
|
|
check(asker:window().rows[1].reagents.text=='2 x Item 2320','read-only reagent display')
|
|
check(asker:window().rows[1].scripts.OnClick==nil,'no crafting action')
|
|
local before=#sent;asker:click('trade:'..owner.guid..':197:300');advance(.2)
|
|
check(#sent==before,'request cooldown')
|
|
owner:message('REQ 197','Owner');advance(.2);check(#sent==before,'reply cooldown')
|
|
advance(11)
|
|
asker.drop=true
|
|
asker:click('trade:'..owner.guid..':197:300')
|
|
asker:message('LST 1/1 999','Stranger');check(#asker:window().recipeIDs==0,'foreign sender ignored')
|
|
asker:message('LST 1/1 999','Raider','WHISPER');check(#asker:window().recipeIDs==0,'wrong channel ignored')
|
|
asker:raw('Someone LST 1/1 999','Raider');check(#asker:window().recipeIDs==0,'message for another player ignored')
|
|
for _,bad in ipairs({'LST 0/1 1','LST 1/999 1','LST 1/1 1,,2','LST 1/1 0','LST 1/1 2147483648'}) do asker:message(bad,'Raider') end
|
|
check(#asker:window().recipeIDs==0,'malformed replies ignored')
|
|
asker:message('LST 2/2 4002,4003','Raider');asker:message('LST 2/2 4002,4003','Raider')
|
|
asker:message('LST 1/2 4001,4002','Raider')
|
|
check(#asker:window().recipeIDs==3,'out-of-order duplicate chunks and IDs handled')
|
|
check(asker:window().title.text=="Raider's Tailoring (300)",'explicit rank retained')
|
|
advance(11);asker:click('trade:'..owner.guid..':12180:197');advance(5.1)
|
|
check(asker:window().status.text=='No reply (player offline, not in your group or guild, or not using OctoWoW)','five second timeout')
|
|
asker:message('LST 1/1 4001','Raider');check(#asker:window().recipeIDs==0,'late response ignored')
|
|
advance(11);asker:click('trade:'..owner.guid..':12180:197')
|
|
asker:message('LST 1/2 4001','Raider');asker:message('LST 1/2 4002','Raider')
|
|
check(asker:window().status.text=='Invalid recipe reply','conflicting duplicate aborts')
|
|
advance(11);asker:click('trade:'..owner.guid..':12180:197');asker:message('LST 1/1 ','Raider')
|
|
check(#asker:window().recipeIDs==0 and asker:window().status.text:find('0 learned'),'empty learned list supported')
|
|
-- Chat sender attribution must match the link GUID; forwarded/spoofed links do not supply identity.
|
|
local unknown=client('Third','Player-70-00000003');unknown.env.GetPlayerInfoByGUID=nil
|
|
local filter=unknown.filters.CHAT_MSG_SAY
|
|
filter(nil,nil,'|Htrade:'..owner.guid..':12180:197|h[Tailoring]|h','Raider',nil,nil,nil,nil,nil,nil,nil,nil,1,'Player-70-00000099')
|
|
unknown:click('trade:'..owner.guid..':12180:197');check(unknown:window().status.text:find('Owner name unavailable'),'spoofed sender does not resolve owner')
|
|
filter(nil,nil,'|Htrade:'..owner.guid..':12180:197|h[Tailoring]|h','Raider',nil,nil,nil,nil,nil,nil,nil,nil,1,owner.guid)
|
|
unknown.drop=true;unknown:click('trade:'..owner.guid..':12180:197');check(sent[#sent].to=='Raider','matching chat sender resolves GUID')
|
|
local function replyTo(to,from) local t={};for i=from+1,#sent do if sent[i].to==to then t[#t+1]=sent[i].text end end;return table.concat(t,'|') end
|
|
advance(11);owner.linked=true;owner.ids={9001,9002};before=#sent;owner:message('REQ 197','Third');advance(3)
|
|
check(replyTo('Third',before)==table.concat(ownChunks,'|'),'linked recipes never shared as own (cached own list sent)')
|
|
owner.linked=false;owner.guild=true;advance(11);before=#sent;owner:message('REQ 197','Third');advance(3)
|
|
check(replyTo('Third',before)==table.concat(ownChunks,'|'),'guild recipes never shared as own (cached own list sent)')
|
|
-- An owner who never opened the profession answers NONE; the asker gets a clear message.
|
|
local fresh=client('Fresh','Player-70-00000005',{});local asker2=client('Asker','Player-70-00000006')
|
|
asker2.env.GetPlayerInfoByGUID=function(g) if g==fresh.guid then return nil,nil,nil,nil,nil,'Fresh','' end end
|
|
fresh.base=164;asker2:click('trade:'..fresh.guid..':12180:197');advance(.5)
|
|
check(sent[#sent].text=='NONE' and asker2:window().status.text:find('open this profession once'),'no cache -> NONE message')
|
|
check(fresh.opens==0,'fresh owner window not opened')
|
|
-- No shared group or guild: tell the asker instead of sending into the void.
|
|
local lone=client('Lone','Player-70-00000007');lone.noguild=true
|
|
lone.env.GetPlayerInfoByGUID=function(g) if g==owner.guid then return nil,nil,nil,nil,nil,'Raider','' end end
|
|
before=#sent;lone:click('trade:'..owner.guid..':12180:197')
|
|
check(#sent==before and lone:window().status.text:find('Join a group or guild'),'no shared channel -> clear message, nothing sent')
|
|
-- 70334 live shapes (LOCAL 11-29): recipes on a child skill line, profession missing from
|
|
-- GetAllProfessionTradeSkillLines, party member found by unit walk (UnitInParty(name) is false).
|
|
local kid=client('Kid','Player-70-00000008',{5001,5002});local ask3=client('Askr','Player-70-00000009')
|
|
kid.env.C_TradeSkillUI.IsRecipeInBaseSkillLine=function() return false end
|
|
kid.env.C_TradeSkillUI.GetProfessionInfoByRecipeID=function() return {professionID=2942,parentProfessionID=197} end
|
|
kid.events.scripts.OnEvent(kid.events,'TRADE_SKILL_LIST_UPDATE')
|
|
kid.env.C_TradeSkillUI.GetAllProfessionTradeSkillLines=function() return {2942} end
|
|
ask3.env.GetPlayerInfoByGUID=function(g) if g==kid.guid then return nil,nil,nil,nil,nil,'Kid','' end end
|
|
local sentChannel;local origSend=ask3.env.C_ChatInfo.SendAddonMessage
|
|
ask3.noguild=true;ask3.env.GetNumGroupMembers=function() return 2 end;ask3.env.IsInRaid=function() return false end
|
|
ask3.env.UnitName=function(u) if u=='party1' then return 'Kid' end return 'Askr' end
|
|
ask3.env.C_ChatInfo.SendAddonMessage=function(p,t,c) sentChannel=c;return origSend(p,t,'GUILD') end
|
|
advance(11);ask3:click('trade:'..kid.guid..':12180:197');advance(1)
|
|
check(sentChannel=='PARTY','party member found by unit walk')
|
|
check(#ask3:window().recipeIDs==2,'child skill line recipes shared; cached list proves profession')
|
|
print('PASS two-client tradeskill links, learned ownership, chunks, rate limits, timeout and read-only display')
|