Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide characters in POESESSID input box for privacy reasons #5314

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 39 additions & 6 deletions src/Classes/EditControl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
local m_max = math.max
local m_min = math.min
local m_floor = math.floor
local protected_replace = "*"

local function lastLine(str)
local lastLineIndex = 1
Expand Down Expand Up @@ -83,6 +84,7 @@ local EditClass = newClass("EditControl", "ControlHost", "Control", "UndoHandler
self.controls.scrollBarH.shown = false
self.controls.scrollBarV.shown = false
end
self.protected = false
end)

function EditClass:SetText(text, notify)
Expand All @@ -102,6 +104,13 @@ function EditClass:SetPlaceholder(text, notify)
end
end

function EditClass:SetProtected(bool)
self.protected = bool or false
-- set the font to be fixed to prevent strange
-- spacing
self.font = "FIXED"
end

function EditClass:IsMouseOver()
if not self:IsShown() then
return false
Expand Down Expand Up @@ -278,7 +287,11 @@ function EditClass:Draw(viewPort, noTooltip)
DrawString(-self.controls.scrollBarH.offset, -self.controls.scrollBarV.offset, "LEFT", textHeight, self.font, self.placeholder)
else
SetDrawColor(self.inactiveCol)
DrawString(-self.controls.scrollBarH.offset, -self.controls.scrollBarV.offset, "LEFT", textHeight, self.font, self.buf)
if self.protected then
DrawString(-self.controls.scrollBarH.offset, -self.controls.scrollBarV.offset, "LEFT", textHeight, self.font, string.rep(protected_replace, #self.buf))
else
DrawString(-self.controls.scrollBarH.offset, -self.controls.scrollBarV.offset, "LEFT", textHeight, self.font, self.buf)
end
end
SetViewport()
self:DrawControls(viewPort, noTooltip and self)
Expand Down Expand Up @@ -351,13 +364,25 @@ function EditClass:Draw(viewPort, noTooltip)
local pre = self.textCol .. self.buf:sub(1, left - 1)
local sel = self.selCol .. StripEscapes(self.buf:sub(left, right - 1))
local post = self.textCol .. self.buf:sub(right)
DrawString(textX, textY, "LEFT", textHeight, self.font, pre)
if self.protected then
DrawString(textX, textY, "LEFT", textHeight, self.font, string.rep(protected_replace, #pre-#self.textCol))
else
DrawString(textX, textY, "LEFT", textHeight, self.font, pre)
end
textX = textX + DrawStringWidth(textHeight, self.font, pre)
local selWidth = DrawStringWidth(textHeight, self.font, sel)
SetDrawColor(self.selBGCol)
DrawImage(nil, textX, textY, selWidth, textHeight)
DrawString(textX, textY, "LEFT", textHeight, self.font, sel)
DrawString(textX + selWidth, textY, "LEFT", textHeight, self.font, post)
if self.protected then
DrawString(textX, textY, "LEFT", textHeight, self.font, string.rep(protected_replace, #sel))
else
DrawString(textX, textY, "LEFT", textHeight, self.font, sel)
end
if self.protected and #post > 0 then
DrawString(textX, textY, "LEFT", textHeight, self.font, string.rep(protected_replace, #post-#self.textCol))
else
DrawString(textX + selWidth, textY, "LEFT", textHeight, self.font, post)
end
if (GetTime() - self.blinkStart) % 1000 < 500 then
local caretX = (self.caret > self.sel) and textX + selWidth or textX
SetDrawColor(self.textCol)
Expand All @@ -366,9 +391,17 @@ function EditClass:Draw(viewPort, noTooltip)
else
local pre = self.textCol .. self.buf:sub(1, self.caret - 1)
local post = self.buf:sub(self.caret)
DrawString(textX, textY, "LEFT", textHeight, self.font, pre)
if self.protected then
DrawString(textX, textY, "LEFT", textHeight, self.font, string.rep(protected_replace, #pre-#self.textCol))
else
DrawString(textX, textY, "LEFT", textHeight, self.font, pre)
end
textX = textX + DrawStringWidth(textHeight, self.font, pre)
DrawString(textX, textY, "LEFT", textHeight, self.font, post)
if self.protected and #post > 0 then
DrawString(textX, textY, "LEFT", textHeight, self.font, string.rep(protected_replace, #post))
else
DrawString(textX, textY, "LEFT", textHeight, self.font, post)
end
if (GetTime() - self.blinkStart) % 1000 < 500 then
SetDrawColor(self.textCol)
DrawImage(nil, textX, textY, 1, textHeight)
Expand Down
1 change: 1 addition & 0 deletions src/Classes/ImportTab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ You can get this from your web browser's cookies while logged into the Path of E
OpenURL('https://www.pathofexile.com/my-account/privacy')
end)
self.controls.sessionInput = new("EditControl", {"TOPLEFT",self.controls.sessionRetry,"BOTTOMLEFT"}, 0, 8, 350, 20, "", "POESESSID", "%X", 32)
self.controls.sessionInput:SetProtected(true)
self.controls.sessionGo = new("ButtonControl", {"LEFT",self.controls.sessionInput,"RIGHT"}, 8, 0, 60, 20, "Go", function()
self:DownloadCharacterList()
end)
Expand Down
7 changes: 4 additions & 3 deletions src/Classes/TradeQuery.lua
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ function TradeQueryClass:PriceItem()
self.controls.poesessidButton = new("ButtonControl", {"TOPLEFT", self.controls.setSelect, "BOTTOMLEFT"}, 0, 4, 200, row_height, function() return main.POESESSID ~= "" and "Change POESESSID" or colorCodes.WARNING.."Missing POESESSID" end, function()
local poesessid_controls = {}
poesessid_controls.sessionInput = new("EditControl", nil, 0, 18, 350, 18, main.POESESSID, nil, "%X", 32)
poesessid_controls.sessionInput:SetProtected(true)
poesessid_controls.sessionInput.placeholder = "Enter your session ID here"
poesessid_controls.sessionInput.tooltipText = "You can get this from your web browser's cookies while logged into the Path of Exile website."
poesessid_controls.save = new("ButtonControl", {"TOPRIGHT", poesessid_controls.sessionInput, "TOP"}, -8, 24, 90, row_height, "Save", function()
Expand Down Expand Up @@ -388,10 +389,9 @@ end
-- Method to set the current result return in the pane based of an index
function TradeQueryClass:SetFetchResultReturn(slotIndex, index)
if self.resultTbl[slotIndex] and self.resultTbl[slotIndex][index] then
local pb_index = self.sortedResultTbl[slotIndex][index].index
self.totalPrice[slotIndex] = {
currency = self.resultTbl[slotIndex][pb_index].currency,
amount = self.resultTbl[slotIndex][pb_index].amount,
currency = self.resultTbl[slotIndex][index].currency,
amount = self.resultTbl[slotIndex][index].amount,
}
self.controls.fullPrice.label = "Total Price: " .. self:GetTotalPriceString()
end
Expand All @@ -416,6 +416,7 @@ function TradeQueryClass:SortFetchResults(slotTbl, trade_index)
local newDPS = GlobalCache.useFullDPS and output.FullDPS or m_max(output.TotalDPS, m_max(output.TotalDot, output.CombinedAvg))
if self.pbSortSelectionIndex == 4 then
local chaosAmount = self:ConvertCurrencyToChaos(tbl.currency, tbl.amount)
--print(tbl.amount, tbl.currency, item.name)
if chaosAmount > 0 then
t_insert(newTbl, { outputAttr = newDPS / chaosAmount, index = index })
end
Expand Down
4 changes: 2 additions & 2 deletions src/Classes/TradeQueryGenerator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ local localOnlyModGroups = {
["DefencesPercentSuffix"] = true
}

local MAX_FILTERS = 36
local MAX_FILTERS = 35

local function logToFile(...)
ConPrintf(...)
Expand Down Expand Up @@ -637,7 +637,7 @@ function TradeQueryGeneratorClass:FinishQuery()
end
end

if options.maxPrice > 0 then
if options.maxPrice and options.maxPrice > 0 then
queryTable.query.filters.trade_filters = {
filters = {
price = {
Expand Down
8 changes: 4 additions & 4 deletions src/Classes/TradeQueryRequests.lua
Original file line number Diff line number Diff line change
Expand Up @@ -178,8 +178,8 @@ function TradeQueryRequestsClass:SearchWithURL(urlEditControl, callback)
if errMsg then
return callback(nil, errMsg)
end
urlEditControl:SetText("https://www.pathofexile.com/trade/search/" .. self.tradeQuery.pbLeagueRealName .. "/" .. queryId)
self:SearchWithQuery(self.tradeQuery.pbLeagueRealName, query, callback)
urlEditControl:SetText("https://www.pathofexile.com/trade/search/" .. self.tradeQuery.pbLeague .. "/" .. queryId)
self:SearchWithQuery(self.tradeQuery.pbLeague, query, callback)
end)
end

Expand All @@ -188,7 +188,7 @@ end
---@param league string
---@param callback fun(query:string, errMsg:string)
function TradeQueryRequestsClass:FetchSearchQuery(queryId, callback)
local url = "https://www.pathofexile.com/api/trade/search/" .. self.tradeQuery.pbLeagueRealName .. "/" .. queryId
local url = "https://www.pathofexile.com/api/trade/search/" .. self.tradeQuery.pbLeague .. "/" .. queryId
table.insert(self.requestQueue["search"], {
url = url,
callback = function(response, errMsg)
Expand Down Expand Up @@ -216,7 +216,7 @@ function TradeQueryRequestsClass:FetchSearchQueryHTML(queryId, callback)
end
local header = "Cookie: POESESSID=" .. main.POESESSID
-- the league doesn't affect query so we set it to Standard as it doesn't change
launch:DownloadPage("https://www.pathofexile.com/trade/search/" .. self.tradeQuery.pbLeagueRealName .. "/" .. queryId,
launch:DownloadPage("https://www.pathofexile.com/trade/search/" .. self.tradeQuery.pbLeague .. "/" .. queryId,
function(response, errMsg)
if errMsg then
return callback(nil, errMsg)
Expand Down