vanilla-wow-addons – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 --[[
2 Auctioneer Addon for World of Warcraft(tm).
3 Version: 3.9.0.1000 (Kangaroo)
4 Revision: $Id: AHScanning.lua 970 2006-08-22 02:58:29Z mentalpower $
5  
6 AHScanning
7 Functions for scanning the AH
8 Thanks to Telo for the LootLink code from which this was based.
9  
10 License:
11 This program is free software; you can redistribute it and/or
12 modify it under the terms of the GNU General Public License
13 as published by the Free Software Foundation; either version 2
14 of the License, or (at your option) any later version.
15  
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20  
21 You should have received a copy of the GNU General Public License
22 along with this program(see GPL.txt); if not, write to the Free Software
23 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
24 ]]
25  
26 --Local function Prototypes
27 local nextIndex, stopAuctionScan, auctionSubmitQuery, auctionNextQuery, checkCompleteScan, queryAuctionItemsHook, scanAuction, canSendAuctionQuery, startAuctionScan, canScan, requestAuctionScan;
28  
29 -- local variables
30 local isScanningRequested = false;
31 local lCurrentAuctionPage;
32 local lMajorAuctionCategories;
33 local lCurrentCategoryIndex;
34 local lIsPageScanned;
35 local lScanInProgress;
36 local lFullScan;
37 local lScanStartedAt;
38 local lPageStartedAt;
39  
40 -- function hooks
41 local lOriginal_CanSendAuctionQuery;
42 local lOriginal_AuctionFrameBrowse_OnEvent;
43 local lOriginal_AuctionFrameBrowse_Update;
44  
45 -- TODO: If all categories are selected, then we should do a complete scan rather than a one-by-one scan.
46  
47 -- get the next category index to based on what categories have been configured to be scanned
48 function nextIndex() --Local
49 if (lCurrentCategoryIndex == nil) then lCurrentCategoryIndex = 0 end
50 for i = lCurrentCategoryIndex + 1, table.getn(lMajorAuctionCategories) do
51 if tostring(Auctioneer.Command.GetFilterVal("scan-class"..i)) == "on" then
52 return i;
53 end
54 end
55  
56 return nil;
57 end
58  
59 function stopAuctionScan()
60 Auctioneer.Event.StopAuctionScan();
61  
62 -- Unhook the scanning functions
63 if( lOriginal_CanSendAuctionQuery ) then
64 CanSendAuctionQuery = lOriginal_CanSendAuctionQuery;
65 lOriginal_CanSendAuctionQuery = nil;
66 end
67  
68 if( lOriginal_AuctionFrameBrowse_OnEvent ) then
69 AuctionFrameBrowse_OnEvent = lOriginal_AuctionFrameBrowse_OnEvent;
70 lOriginal_AuctionFrameBrowse_OnEvent = nil;
71 end
72  
73 if( lOriginal_AuctionFrameBrowse_Update ) then
74 AuctionFrameBrowse_Update = lOriginal_AuctionFrameBrowse_Update;
75 lOriginal_AuctionFrameBrowse_Update = nil;
76 end
77  
78 Auctioneer.Scanning.IsScanningRequested = false;
79 lScanInProgress = false;
80 lCurrentCategoryIndex = 0;
81 lPageStartedAt = nil;
82 lCurrentAuctionPage = nil;
83  
84 -- Unprotect AuctionFrame if we should
85 if (Auctioneer.Command.GetFilterVal('protect-window') == 1) then
86 Auctioneer.Util.ProtectAuctionFrame(false);
87 end
88 end
89  
90 function auctionSubmitQuery() --Local
91 if not lCurrentAuctionPage or lCurrentAuctionPage == 0 then
92 if not lCurrentAuctionPage then lCurrentAuctionPage = 0 end
93 if lFullScan then
94 BrowseNoResultsText:SetText(string.format(_AUCT('AuctionScanStart'), _AUCT('TextAuction')));
95 else
96 BrowseNoResultsText:SetText(string.format(_AUCT('AuctionScanStart'), lMajorAuctionCategories[lCurrentCategoryIndex]));
97 end
98 end
99 if (lFullScan) then
100 QueryAuctionItems("", "", "", nil, nil, nil, lCurrentAuctionPage, nil, nil);
101 else
102 QueryAuctionItems("", "", "", nil, lCurrentCategoryIndex, nil, lCurrentAuctionPage, nil, nil);
103 end
104 lPageStartedAt = time();
105  
106 lIsPageScanned = false;
107 Auctioneer.Event.AuctionQuery(lCurrentAuctionPage);
108 end
109  
110 local lCheckPage = nil;
111 function auctionNextQuery() --Local
112 lCheckPage = nil;
113 if lCurrentAuctionPage then
114 local numBatchAuctions, totalAuctions = GetNumAuctionItems("list");
115 local maxPages = floor(totalAuctions / NUM_AUCTION_ITEMS_PER_PAGE);
116  
117 local auctionsPerSecond = ( Auctioneer.Core.Variables.TotalAuctionsScannedCount / ( GetTime() - lScanStartedAt ) );
118 local auctionETA = ( ( totalAuctions - Auctioneer.Core.Variables.TotalAuctionsScannedCount ) / auctionsPerSecond );
119 auctionsPerSecond = floor( auctionsPerSecond * 100 ) / 100;
120 if ( type(auctionsPerSecond) ~= "number" ) then
121 auctionsPerSecond = "";
122 else
123 auctionsPerSecond = tostring(auctionsPerSecond);
124 end
125 local ETAString = SecondsToTime(auctionETA);
126  
127 if( lCurrentAuctionPage < maxPages ) then
128 lPageStartedAt = time();
129 lCurrentAuctionPage = lCurrentAuctionPage + 1;
130 if lFullScan then
131 BrowseNoResultsText:SetText(string.format(_AUCT('AuctionPageN'), _AUCT('TextAuction'), lCurrentAuctionPage + 1, maxPages + 1, auctionsPerSecond, ETAString));
132 else
133 BrowseNoResultsText:SetText(string.format(_AUCT('AuctionPageN'), lMajorAuctionCategories[lCurrentCategoryIndex],lCurrentAuctionPage + 1, maxPages + 1, auctionsPerSecond, ETAString));
134 end
135 elseif nextIndex() then
136 lPageStartedAt = time();
137 lCurrentCategoryIndex = nextIndex();
138 lCurrentAuctionPage = 0;
139 else
140 stopAuctionScan();
141 if( totalAuctions > 0 ) then
142 BrowseNoResultsText:SetText(_AUCT('AuctionScanDone'));
143 Auctioneer.Event.FinishedAuctionScan();
144 end
145 return;
146 end
147 end
148 auctionSubmitQuery();
149 end
150  
151 local lCheckStartTime = nil;
152 function checkCompleteScan()
153 lCheckStartTime = lCheckStartTime or time()
154 if (time() - lCheckStartTime > 10) then
155 -- Sometimes they never return an owner.
156 return true
157 end
158  
159 for index = 1, GetNumAuctionItems("list") do
160 local _,_,_,_,_,_,_,_,_,_,_, owner = GetAuctionItemInfo("list", index);
161 if (not owner) then
162 return false
163 end
164 end
165  
166 return true
167 end
168  
169 function queryAuctionItemsHook()
170 lCheckStartTime = nil;
171 end
172  
173 function scanAuction(nonScanUpdate)
174 local numBatchAuctions, totalAuctions = GetNumAuctionItems("list");
175 local auctionid;
176  
177 if( numBatchAuctions > 0 ) then
178 if (nonScanUpdate) then
179 for auctionid = 1, numBatchAuctions do
180 Auctioneer.Event.ScanAuction(nil, auctionid, nil, true);
181 end
182 else
183 for auctionid = 1, numBatchAuctions do
184 Auctioneer.Event.ScanAuction(lCurrentAuctionPage, auctionid, lCurrentCategoryIndex);
185 end
186 end
187 end
188  
189 lIsPageScanned = true;
190 end
191  
192 local retryCount = 0
193 function canSendAuctionQuery() --Local
194 local value = lOriginal_CanSendAuctionQuery();
195 if (value and lIsPageScanned) or (retryCount >= 3) then
196 auctionNextQuery();
197 retryCount = 0
198 return nil;
199 end
200 if (lPageStartedAt) then
201 local pageElapsed = time() - lPageStartedAt;
202 if (pageElapsed > 20) then
203 if (Auctioneer.Command.GetFilter('show-warning')) then
204 Auctioneer.Util.ChatPrint(string.format(_AUCT('AuctionScanRedo'), 20));
205 end
206 auctionSubmitQuery();
207 retryCount = retryCount + 1;
208 return nil;
209 end
210 return false;
211 end
212 end
213  
214 Auctioneer.AuctionFrameBrowse = {
215 OnEvent = function()
216 -- Intentionally empty; don't allow the auction UI to update while we're scanning
217 end,
218 Update = function()
219 -- Intentionally empty; don't allow the auction UI to update while we're scanning
220 end
221 };
222  
223 function startAuctionScan()
224 lMajorAuctionCategories = {GetAuctionItemClasses()};
225  
226 lFullScan = true;
227 for i = 1, table.getn(lMajorAuctionCategories) do
228 if tostring(Auctioneer.Command.GetFilterVal("scan-class"..i)) ~= "on" then
229 lFullScan = false;
230 end
231 end
232  
233 if (lFullScan) then
234 lCurrentCategoryIndex = table.getn(lMajorAuctionCategories);
235 else
236 -- first make sure that we have at least one category to scan
237 lCurrentCategoryIndex = nextIndex();
238 if not lCurrentCategoryIndex then
239 lCurrentCategoryIndex = 0;
240 Auctioneer.Util.ChatPrint(_AUCT('AuctionScanNocat'));
241 return;
242 end
243 end
244  
245 -- Start with the first page
246 lCurrentAuctionPage = nil;
247 lScanInProgress = true;
248  
249 -- Hook the functions that we need for the scan
250 if( not lOriginal_CanSendAuctionQuery ) then
251 lOriginal_CanSendAuctionQuery = CanSendAuctionQuery;
252 CanSendAuctionQuery = canSendAuctionQuery;
253 end
254  
255 if( not lOriginal_AuctionFrameBrowse_OnEvent ) then
256 lOriginal_AuctionFrameBrowse_OnEvent = AuctionFrameBrowse_OnEvent;
257 AuctionFrameBrowse_OnEvent = Auctioneer.AuctionFrameBrowse.OnEvent;
258 end
259  
260 if( not lOriginal_AuctionFrameBrowse_Update ) then
261 lOriginal_AuctionFrameBrowse_Update = AuctionFrameBrowse_Update;
262 AuctionFrameBrowse_Update = Auctioneer.AuctionFrameBrowse.Update;
263 end
264  
265 Auctioneer.Event.StartAuctionScan();
266  
267 lScanStartedAt = GetTime();
268 auctionNextQuery();
269 end
270  
271 function canScan()
272 if (lScanInProgress) then
273 return false;
274 end
275 if (not CanSendAuctionQuery()) then
276 return false;
277 end
278 if (AucBidManager.IsProcessingRequest()) then
279 return false;
280 end
281 return true;
282 end
283  
284 function requestAuctionScan(chatPrint)
285 Auctioneer.Scanning.IsScanningRequested = true;
286 if (AuctionFrame and AuctionFrame:IsVisible()) then
287 local iButton;
288 local button;
289  
290 -- Hide the UI from any current results, show the no results text so we can use it
291 BrowseNoResultsText:Show();
292 for iButton = 1, NUM_BROWSE_TO_DISPLAY do
293 button = getglobal("BrowseButton"..iButton);
294 button:Hide();
295 end
296 BrowsePrevPageButton:Hide();
297 BrowseNextPageButton:Hide();
298 BrowseSearchCountText:Hide();
299  
300 startAuctionScan();
301 else
302 if (chatPrint) then
303 Auctioneer.Util.ChatPrint(_AUCT('AuctionScanNexttime'));
304 end
305 end
306 end
307  
308 Auctioneer.Scanning = {
309 IsScanningRequested = isScanningRequested,
310 StopAuctionScan = stopAuctionScan,
311 CheckCompleteScan = checkCompleteScan,
312 QueryAuctionItemsHook = queryAuctionItemsHook,
313 ScanAuction = scanAuction,
314 StartAuctionScan = startAuctionScan,
315 CanScan = canScan,
316 RequestAuctionScan = requestAuctionScan,
317 }