Skip to content

Commit 205da71

Browse files
vaisestLocalIdentity
andauthored
Port PoB 2 Oauth API (#9812)
* Port PoB 2 Oauth API * Make Cspell happy * Fix stat fallback and also fix trade site used Was using the poe 2 trade site url and also there was an issue with sorting by currency when you didn't download the currency rates yet * Rename button variable Want to remove poesessid from the name as it now isn't relevant --------- Co-authored-by: LocalIdentity <localidentity2@gmail.com>
1 parent 92bc0df commit 205da71

21 files changed

Lines changed: 11731 additions & 792 deletions

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,5 @@ src/Data/TimelessJewelData/*.bin
3737
# Simplegraphic Debugging
3838
runtime/imgui.ini
3939
runtime/SimpleGraphic/SimpleGraphic.log
40+
41+
src/poe_api_response.json

runtime/lua/sha2.lua

Lines changed: 5675 additions & 0 deletions
Large diffs are not rendered by default.

runtime/lua/socket.lua

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
1+
-----------------------------------------------------------------------------
2+
-- LuaSocket helper module
3+
-- Author: Diego Nehab
4+
-----------------------------------------------------------------------------
5+
6+
-----------------------------------------------------------------------------
7+
-- Declare module and import dependencies
8+
-----------------------------------------------------------------------------
9+
local base = _G
10+
local string = require("string")
11+
local math = require("math")
12+
local socket = require("socket.core")
13+
14+
local _M = socket
15+
16+
-----------------------------------------------------------------------------
17+
-- Exported auxiliar functions
18+
-----------------------------------------------------------------------------
19+
function _M.connect4(address, port, laddress, lport)
20+
return socket.connect(address, port, laddress, lport, "inet")
21+
end
22+
23+
function _M.connect6(address, port, laddress, lport)
24+
return socket.connect(address, port, laddress, lport, "inet6")
25+
end
26+
27+
function _M.bind(host, port, backlog)
28+
if host == "*" then host = "0.0.0.0" end
29+
local addrinfo, err = socket.dns.getaddrinfo(host);
30+
if not addrinfo then return nil, err end
31+
local sock, res
32+
err = "no info on address"
33+
for i, alt in base.ipairs(addrinfo) do
34+
if alt.family == "inet" then
35+
sock, err = socket.tcp4()
36+
else
37+
sock, err = socket.tcp6()
38+
end
39+
if not sock then return nil, err end
40+
res, err = sock:bind(alt.addr, port)
41+
if not res then
42+
sock:close()
43+
else
44+
res, err = sock:listen(backlog)
45+
if not res then
46+
sock:close()
47+
else
48+
return sock
49+
end
50+
end
51+
end
52+
return nil, err
53+
end
54+
55+
_M.try = _M.newtry()
56+
57+
function _M.choose(table)
58+
return function(name, opt1, opt2)
59+
if base.type(name) ~= "string" then
60+
name, opt1, opt2 = "default", name, opt1
61+
end
62+
local f = table[name or "nil"]
63+
if not f then base.error("unknown key (".. base.tostring(name) ..")", 3)
64+
else return f(opt1, opt2) end
65+
end
66+
end
67+
68+
-----------------------------------------------------------------------------
69+
-- Socket sources and sinks, conforming to LTN12
70+
-----------------------------------------------------------------------------
71+
-- create namespaces inside LuaSocket namespace
72+
local sourcet, sinkt = {}, {}
73+
_M.sourcet = sourcet
74+
_M.sinkt = sinkt
75+
76+
_M.BLOCKSIZE = 2048
77+
78+
sinkt["close-when-done"] = function(sock)
79+
return base.setmetatable({
80+
getfd = function() return sock:getfd() end,
81+
dirty = function() return sock:dirty() end
82+
}, {
83+
__call = function(self, chunk, err)
84+
if not chunk then
85+
sock:close()
86+
return 1
87+
else return sock:send(chunk) end
88+
end
89+
})
90+
end
91+
92+
sinkt["keep-open"] = function(sock)
93+
return base.setmetatable({
94+
getfd = function() return sock:getfd() end,
95+
dirty = function() return sock:dirty() end
96+
}, {
97+
__call = function(self, chunk, err)
98+
if chunk then return sock:send(chunk)
99+
else return 1 end
100+
end
101+
})
102+
end
103+
104+
sinkt["default"] = sinkt["keep-open"]
105+
106+
_M.sink = _M.choose(sinkt)
107+
108+
sourcet["by-length"] = function(sock, length)
109+
return base.setmetatable({
110+
getfd = function() return sock:getfd() end,
111+
dirty = function() return sock:dirty() end
112+
}, {
113+
__call = function()
114+
if length <= 0 then return nil end
115+
local size = math.min(socket.BLOCKSIZE, length)
116+
local chunk, err = sock:receive(size)
117+
if err then return nil, err end
118+
length = length - string.len(chunk)
119+
return chunk
120+
end
121+
})
122+
end
123+
124+
sourcet["until-closed"] = function(sock)
125+
local done
126+
return base.setmetatable({
127+
getfd = function() return sock:getfd() end,
128+
dirty = function() return sock:dirty() end
129+
}, {
130+
__call = function()
131+
if done then return nil end
132+
local chunk, err, partial = sock:receive(socket.BLOCKSIZE)
133+
if not err then return chunk
134+
elseif err == "closed" then
135+
sock:close()
136+
done = 1
137+
return partial
138+
else return nil, err end
139+
end
140+
})
141+
end
142+
143+
144+
sourcet["default"] = sourcet["until-closed"]
145+
146+
_M.source = _M.choose(sourcet)
147+
148+
return _M

0 commit comments

Comments
 (0)