refactor: player token gen & verif

This commit is contained in:
Linventif 2024-02-27 02:31:14 +01:00
parent fe44cb1180
commit a24f1a846d
No known key found for this signature in database
GPG Key ID: FAC0CA60F9AEEC24
2 changed files with 69 additions and 0 deletions

View File

@ -0,0 +1,27 @@
//
// Methods
//
function gmInte.getClientOneTimeToken(ply, callback)
if (!ply:IsValid() || !ply:IsPlayer()) then return end
gmInte.http.get("/players/" .. ply:SteamID64() .. "/single-token", function(code, data)
if (callback) then callback(data) end
end)
end
function gmInte.createClientToken(ply, callback)
if (!ply:IsValid() || !ply:IsPlayer()) then return end
gmInte.http.get("/players/" .. ply:SteamID64() .. "/tokens", function(code, data)
if (callback) then callback(data) end
end)
end
function gmInte.revokeClientToken(ply, callback)
if (!ply:IsValid() || !ply:IsPlayer()) then return end
gmInte.http.delete("/players/" .. ply:SteamID64() .. "/tokens", function(code, data)
if (callback) then callback(data) end
end)
end

View File

@ -0,0 +1,42 @@
//
// Methods
//
function gmInte.verifyPlayer(ply)
if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end
gmInte.http.get("/players/" .. ply:SteamID64(), function(code, data)
if (!gmInte.config.forcePlayerLink) then return end
if (data && data.steamID64) then
if (ply.gmIntVerified) then return end
gmInte.SendNet("chatColorMessage", {
[1] = {
["text"] = "You have been verified",
["color"] = Color(255, 255, 255)
}
}, ply)
ply:Freeze(false)
ply.gmIntVerified = true
else
gmInte.SendNet("chatColorMessage", {
[1] = {
["text"] = "You are not verified",
["color"] = Color(255, 0, 0)
}
}, ply)
ply:Freeze(true)
gmInte.SendNet("openVerifPopup", nil, ply)
end
end)
end
//
// Hooks
//
hook.Add("gmInte:PlayerReady", "gmInte:Verif:PlayerReady", function(ply)
if (!gmInte.config.forcePlayerLink) then return end
gmInte.verifyPlayer(ply)
end)