Trying to return a true or false to CheckPassword hook from http request.
4 replies, posted
So i'm working on a whitelist addon that makes an http request to check against a database to see if a player is allowed to join or not. I am having issues with returning true or false with a kick message. When I join I don't get any errors but it just lets me in the server when i'm and when i'm not in the database. Can someone explain to me what i'm doing wrong. Any and all help is appreciated.
local function passwordCheck(sid64, ip, svpas, clpass, name)
local function CheckSuccess(response, len, headers, code)
if code == 200 then
local result = util.JSONToTable(response)
if result.api.allow == "true" then
return true
else
return false, "You are not whitelisted to join the server"
end
end
end
local function CheckFailed(err)
print(err)
return false
end
local url = Settings["Webpage"] .."/api/check?server_id=".. Settings["ServerID"] .."&steam_id=".. sid64
http.Fetch(url, CheckSuccess, CheckFailed)
end
hook.Add("CheckPassword", "whitelist", passwordCheck)
It's because http.Fetch is delayed, you can't return value instanlty. I suggest you to use game.KickID on not whitelisted players.
Thank you for the help! Now I have no clue how to set this to solved, I haven't used the new forum system yet.
Danke schön!
Alternatively you can download the entire whitelist of players when the server starts (and update regularly). Then you have a local copy which you can check against instantly, and still use the CheckPassword hook.
Sorry, you need to Log In to post a reply to this thread.