Skip to content

Commit 334958e

Browse files
committed
Simple changes to support user-supplied league data
The www.pathofexile.com/trade site 403s apparently due to CloudFlare spam protection (see PathOfBuildingCommunity#8384). If you're using POESESSID, this means you can't use the trade tool until you null-out the POESESSID, to use the static league data. This branch attempts to fall back to a new field that can be user-supplied, Misc->TradeLeagueData. This is intended to be grabbed from the source of www.pathofexile.com/trade by the user, rather than POB trying to grab it. If that doesn't exist, the tool will finally fall back to the static list. A UI entry isn't provided in this branch.
1 parent 78aa5c1 commit 334958e

File tree

3 files changed

+68
-26
lines changed

3 files changed

+68
-26
lines changed

src/Classes/TradeQuery.lua

Lines changed: 50 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,39 +1101,65 @@ function TradeQueryClass:UpdateRealms()
11011101
self.controls.realm.selIndex = nil
11021102
self.controls.realm:SetSel(self.pbRealmIndex)
11031103
end
1104-
1105-
if main.POESESSID and main.POESESSID ~= "" then
1106-
-- Fetch from trade page using POESESSID, includes private leagues
1107-
ConPrintf("Fetching realms and leagues using POESESSID")
1108-
self.tradeQueryRequests:FetchRealmsAndLeaguesHTML(function(data, errMsg)
1109-
if errMsg then
1110-
self:SetNotice(self.controls.pbNotice, "Error while fetching league list: "..errMsg)
1111-
return
1112-
end
1113-
local leagues = data.leagues
1114-
self.allLeagues = {}
1115-
for _, value in ipairs(leagues) do
1116-
if not self.allLeagues[value.realm] then self.allLeagues[value.realm] = {} end
1117-
t_insert(self.allLeagues[value.realm], value.id)
1104+
local function processLeagueData(leagueDataObject)
1105+
local leagues = leagueDataObject.leagues
1106+
self.allLeagues = {}
1107+
for _, value in ipairs(leagues) do
1108+
if not self.allLeagues[value.realm] then self.allLeagues[value.realm] = {} end
1109+
t_insert(self.allLeagues[value.realm], value.id)
1110+
end
1111+
ConPrintTable(self.allLeagues)
1112+
self.realmIds = {}
1113+
for _, value in pairs(leagueDataObject.realms) do
1114+
-- filter out only Path of Exile one realms, as poe2 is not supported yet
1115+
if value.text:match("PoE 1 ") then
1116+
self.realmIds[value.text:gsub("PoE 1 ", "")] = value.id
11181117
end
1119-
self.realmIds = {}
1120-
for _, value in pairs(data.realms) do
1121-
-- filter out only Path of Exile one realms, as poe2 is not supported yet
1122-
if value.text:match("PoE 1 ") then
1123-
self.realmIds[value.text:gsub("PoE 1 ", "")] = value.id
1118+
end
1119+
end
1120+
local function tryFallbacks()
1121+
if main.TradeLeagueData:len() > 0 then
1122+
-- full json state obj from HTML
1123+
local dataStr = main.TradeLeagueData:match('require%(%["main"%].+ t%((.+)%);}%);}%);')
1124+
if not dataStr then
1125+
ConPrintf("User-supplied league data is malformed: %s", main.TradeLeagueData)
1126+
else
1127+
local data, _, err = dkjson.decode(dataStr)
1128+
if err then
1129+
ConPrintf("Failed to parse JSON object. ".. err)
1130+
else
1131+
ConPrintf("Using user-supplied league data")
1132+
processLeagueData(data)
1133+
setRealmDropList()
1134+
self:SetNotice(self.controls.pbNotice, "Using user-supplied league data")
1135+
return
11241136
end
11251137
end
1126-
setRealmDropList()
1127-
1128-
end)
1129-
else
1130-
-- Fallback to static list
1138+
end
1139+
-- Finally, fallback to static list
11311140
ConPrintf("Using static realms list")
11321141
self.realmIds = {
11331142
["PC"] = "pc",
11341143
["PS4"] = "sony",
11351144
["Xbox"] = "xbox",
11361145
}
11371146
setRealmDropList()
1147+
self:SetNotice(self.controls.pbNotice, "Using static realms list")
1148+
end
1149+
1150+
if main.POESESSID and main.POESESSID ~= "" then
1151+
-- Fetch from trade page using POESESSID, includes private leagues
1152+
ConPrintf("Fetching realms and leagues using POESESSID")
1153+
self.tradeQueryRequests:FetchRealmsAndLeaguesHTML(function(data, errMsg)
1154+
if errMsg then
1155+
self:SetNotice(self.controls.pbNotice, "Error while fetching league list: "..errMsg)
1156+
tryFallbacks()
1157+
else
1158+
processLeagueData(data)
1159+
setRealmDropList()
1160+
end
1161+
end)
1162+
else
1163+
tryFallbacks()
11381164
end
11391165
end

src/Classes/TradeQueryRequests.lua

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -400,6 +400,8 @@ function TradeQueryRequestsClass:FetchRealmsAndLeaguesHTML(callback)
400400
-- full json state obj from HTML
401401
local dataStr = response.body:match('require%(%["main"%].+ t%((.+)%);}%);}%);')
402402
if not dataStr then
403+
-- the response.body can hide a lua error, so it doesn't hurt to dump it to the console if debugging
404+
ConPrintf("invalid response data: %s", response.body)
403405
return callback(nil, "JSON object not found on the page.")
404406
end
405407
local data, _, err = dkjson.decode(dataStr)

src/Modules/Main.lua

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ function main:Init()
103103
self.slotOnlyTooltips = true
104104
self.POESESSID = ""
105105
self.showPublicBuilds = true
106+
self.TradeLeagueData = ""
106107

107108
if self.userPath then
108109
self:ChangeUserPath(self.userPath, ignoreBuild)
@@ -617,6 +618,17 @@ function main:LoadSettings(ignoreBuild)
617618
if node.attrib.showPublicBuilds then
618619
self.showPublicBuilds = node.attrib.showPublicBuilds == "true"
619620
end
621+
-- If the Misc node has a child, and it's the "TradeLeagueData" node, parse the contents
622+
-- into the TradeLeagueData field, for use if grabbing the data from www.pathofexile.com/trade 403s
623+
-- when trying to search for items
624+
for _, child in ipairs(node) do
625+
if child.elem == "TradeLeagueData" then
626+
if #child == 1 and child[1]:len() > 0 then
627+
-- trim value
628+
self.TradeLeagueData = child[1]:match"^%s*(.*)":match"(.-)%s*$"
629+
end
630+
end
631+
end
620632
end
621633
end
622634
end
@@ -703,7 +715,7 @@ function main:SaveSettings()
703715
t_insert(sharedItemList, set)
704716
end
705717
t_insert(setXML, sharedItemList)
706-
t_insert(setXML, { elem = "Misc", attrib = {
718+
local misc = { elem = "Misc", attrib = {
707719
buildSortMode = self.buildSortMode,
708720
connectionProtocol = tostring(launch.connectionProtocol),
709721
proxyURL = launch.proxyURL,
@@ -728,7 +740,9 @@ function main:SaveSettings()
728740
invertSliderScrollDirection = tostring(self.invertSliderScrollDirection),
729741
disableDevAutoSave = tostring(self.disableDevAutoSave),
730742
showPublicBuilds = tostring(self.showPublicBuilds)
731-
} })
743+
} }
744+
t_insert(misc, { elem = "TradeLeagueData", [1] = self.TradeLeagueData:match"^%s*(.*)":match"(.-)%s*$"})
745+
t_insert(setXML, misc)
732746
local res, errMsg = common.xml.SaveXMLFile(setXML, self.userPath.."Settings.xml")
733747
if not res then
734748
launch:ShowErrMsg("Error saving 'Settings.xml': %s", errMsg)

0 commit comments

Comments
 (0)