Skip to content

Commit

Permalink
fix(resource): improve sv_main join check error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed Mar 15, 2023
1 parent 421cbd3 commit 0d9e6c9
Showing 1 changed file with 23 additions and 20 deletions.
43 changes: 23 additions & 20 deletions resource/sv_main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -342,26 +342,29 @@ function handleConnections(name, setKickReason, d)
attempts = attempts + 1
d.update("\n[txAdmin] Checking banlist/whitelist... ("..attempts.."/10)")
PerformHttpRequest(url, function(httpCode, rawData, resultHeaders)
-- Validating response
local respStr = tostring(rawData)
if httpCode ~= 200 then
logError("\n[txAdmin] Checking banlist/whitelist failed with code "..httpCode.." and message: "..respStr)
end
local respObj = json.decode(respStr)
if not respObj or type(respObj.allow) ~= "boolean" then
logError("\n[txAdmin] Checking banlist/whitelist failed with invalid response: "..respStr)
end

if respObj.allow == true then
if not isDone then
d.done()
isDone = true
end
else
if not isDone then
local reason = respObj.reason or "\n[txAdmin] no reason provided"
d.done("\n"..reason)
isDone = true
-- rawData = nil
-- httpCode = 408

if not rawData or httpCode ~= 200 then
logError("Checking banlist/whitelist failed with code "..httpCode.." and message: "..tostring(rawData))
else
local respStr = tostring(rawData)
local respObj = json.decode(respStr)
if not respObj or type(respObj.allow) ~= "boolean" then
logError("Checking banlist/whitelist failed with invalid response: "..respStr)
else
if respObj.allow == true then
if not isDone then
d.done()
isDone = true
end
else
if not isDone then
local reason = respObj.reason or "\n[txAdmin] no reason provided"
d.done("\n"..reason)
isDone = true
end
end
end
end
end, 'POST', json.encode(exData), {['Content-Type']='application/json'})
Expand Down

0 comments on commit 0d9e6c9

Please sign in to comment.