mirror of
https://github.com/gmod-integration/lua.git
synced 2025-03-16 15:57:34 +00:00
refactor: player token gen & verif
This commit is contained in:
parent
fe44cb1180
commit
a24f1a846d
lua/gmod_integration/server
27
lua/gmod_integration/server/sv_players_tokens.lua
Normal file
27
lua/gmod_integration/server/sv_players_tokens.lua
Normal 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
|
42
lua/gmod_integration/server/sv_players_verif.lua
Normal file
42
lua/gmod_integration/server/sv_players_verif.lua
Normal 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)
|
Loading…
Reference in New Issue
Block a user