Thread Tools Display Modes
07-20-10, 05:30 PM   #1
Geneticus
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: May 2007
Posts: 15
Question Forced Item Server Query

So, Carbonite and atlasloot apparently can force server queries for item data.
Does this include quality and type(s) data? If so, how is this accomplished? I tried poking around in them a bit, but between the number of files and libs, it's a bit like looking for a cheeseburger in fat camp.....
  Reply With Quote
07-20-10, 05:31 PM   #2
yssaril
A Warpwood Thunder Caller
 
yssaril's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2007
Posts: 96
you have to add the item to a tooltip and then once the tooltip gets populated you have all the info about the item

this is what i use in YssBossLoot

Code:
local _, YssBossLoot = ...

local L = LibStub("AceLocale-3.0"):GetLocale("YssBossLoot", true)

local timerFrame = CreateFrame("Frame")
local animationGroup = timerFrame:CreateAnimationGroup()
local animation = animationGroup:CreateAnimation("Animation")
animation:SetDuration(7) -- increase this number if this Scanner starts disconnecting people without outside interference 6 seams to be the minimum lets use 7 to keep a little buffer
animationGroup:SetLooping("NONE")

local Scanner = CreateFrame("GameTooltip", "YssBossLoot_ScannerTooltip", nil, "GameTooltipTemplate")
Scanner:SetOwner(UIParent, "ANCHOR_NONE")

local itemlist = {}
local query_item
local function QueryNextItem()
	if next(itemlist) then
		query_item = tremove(itemlist, 1) -- always pull from bottom of table (its expensive but ensures order also makes adding items inexpensive and spreads out the expensive operation)
		if GetItemInfo(query_item) then -- if we already know item no need to query for it we just move on to the next item on the list
			YssBossLoot:UpdateLoot(#itemlist, query_item)
			return QueryNextItem()
		else
			YssBossLoot:UpdateLoot(#itemlist)
		end
		Scanner:SetHyperlink('item:'..query_item)
	else
		query_item = nil
		YssBossLoot:UpdateLoot(0)
	end
end

local function OnTooltipSetItem()
	if not query_item then return end
	if GetItemInfo(query_item) then -- if we already know item no need to query for it we just move on to the next item on the list
		YssBossLoot:UpdateLoot(#itemlist, query_item)
		if animationGroup:IsPlaying() then
			animationGroup:Stop()
		end
		QueryNextItem()
	else
		animationGroup:Play()
	end
end

animationGroup:SetScript("OnFinished", QueryNextItem)
Scanner:SetScript('OnTooltipSetItem', OnTooltipSetItem)

local PopupDisplayed = false
YssBossLoot.QuerryStopped = nil
StaticPopupDialogs["YssBossLoot_UnsafeQuery_DIALOG"] = {
	text = L["UNSAVE_QUERY_MSG"],
	button1 = YES,
	button2 = NO,
	OnAccept = function (self)
		YssBossLoot.db.global.badLogout = nil
		QueryNextItem()
		clicked = true
	end,
	OnCancel = function (self, data, reason)
		if reason == "clicked" then
			YssBossLoot.QuerryStopped = true
		end
	end,
	OnHide = function()
		if YssBossLoot.db.global.badLogout then
			if not YssBossLoot.QuerryStopped then
				PopupDisplayed = false
			end
			YssBossLoot:UpdateLoot(0)
		end
	end,
	timeout = 0,
	hideOnEscape = 1,
	noCancelOnEscape = 1,
	whileDead = 1,
}

function YssBossLoot:QueryItemInfo(item)
	if GetItemInfo(item) then -- do a preliminary check if we already know the item
		return nil
	end
	for i, listitem in ipairs(itemlist) do -- check if this item is already in our list
		if item == listitem then
			return nil
		end
	end
	itemlist[#itemlist+1] = item
	if not query_item then
		if self.db.global.badLogout and time() - self.db.global.badLogout < 900 then
			if YssBossLoot.QuerryStopped then
				YssBossLoot:UpdateLoot(0)
			elseif not PopupDisplayed then
				PopupDisplayed = true
				local popup = StaticPopup_Show("YssBossLoot_UnsafeQuery_DIALOG")
				popup:SetFrameStrata("TOOLTIP")
			end
		else
			self.db.global.badLogout = nil
			QueryNextItem()
		end
	end
end

function YssBossLoot:CancelAllQueries()
	wipe(itemlist)
	query_item = nil
	if YssBossLoot.queries then
		wipe(YssBossLoot.queries)
	end
	animationGroup:Stop()
end

local logoutFunctions = {
	["Logout"] = true,
	["Quit"] = true,
	["ForceQuit"] = true,
	["ReloadUI"] = true,
}
local cancelLogoutFunctions = {
	["CancelLogout"] = true,
}

local function logoutHook()
	YssBossLoot.isValidLogout = true
end
local function logoutHook_cancel()
	YssBossLoot.isValidLogout = nil
end

local function consoleHook(func, ...)
	for f in pairs(logoutFunctions) do
		if string.lower(f) == string.lower(func) then
			return logoutHook()
		end
	end
	for f in pairs(cancelLogoutFunctions) do
		if string.lower(f) == string.lower(func) then
			return logoutHook_cancel()
		end
	end
end

-- Setup our Logout Hooks
hooksecurefunc("ConsoleExec", consoleHook)
for func in pairs(logoutFunctions) do
	hooksecurefunc(func, logoutHook)
end
for func in pairs(cancelLogoutFunctions) do
	hooksecurefunc(func, logoutHook_cancel)
end

function YssBossLoot:PLAYER_LOGOUT()
	if not self.isValidLogout and query_item then
		self.db.global.badLogout = time()
	elseif self.db.global.badLogout and time() - self.db.global.badLogout > 900 then
		self.db.global.badLogout = nil
	end
end
YssBossLoot.frame:RegisterEvent("PLAYER_LOGOUT")

--[[ dc test function (this will DC the client)
--/script YssBossLootTest()
function YssBossLootTest()
	animation:SetDuration(.1)
	for i=1,100 do
		YssBossLoot:QueryItemInfo(i)
	end
end
]]
i add items to a request queue with: YssBossLoot:QueryItemInfo(item)
every item is requested sequentially (it waits for data before it moves on to the next one)
In The OnTooltipSetItem() function it calls YssBossLoot:UpdateLoot(#itemlist, query_item) with the item that was found and how many items remain in the queue
function QueryNextItem does the same thing if for some reason we already know the item (before we request if from the server)


all the other stuff is there to ensure that we do not query the server too fast and get disconnected (can easily happen)

Last edited by yssaril : 07-20-10 at 05:43 PM.
  Reply With Quote
07-20-10, 06:05 PM   #3
Geneticus
A Deviate Faerie Dragon
AddOn Author - Click to view addons
Join Date: May 2007
Posts: 15
Originally Posted by yssaril View Post
you have to add the item to a tooltip and then once the tooltip gets populated you have all the info about the item
Hmmm, interesting.
Does the tooltip get rendered or can it be hidden from view?
  Reply With Quote
07-20-10, 06:25 PM   #4
yssaril
A Warpwood Thunder Caller
 
yssaril's Avatar
AddOn Author - Click to view addons
Join Date: Jan 2007
Posts: 96
stays hidden
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » Forced Item Server Query


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off