mirror of
https://github.com/gmod-integration/lua.git
synced 2025-03-15 22:07:34 +00:00
add: new player temp token
This commit is contained in:
parent
58d6477d4b
commit
299b07a9ed
|
@ -10,8 +10,6 @@ local netSend = {
|
||||||
["takeScreenShot"] = 4,
|
["takeScreenShot"] = 4,
|
||||||
["restartMap"] = 5,
|
["restartMap"] = 5,
|
||||||
["verifyMe"] = 6,
|
["verifyMe"] = 6,
|
||||||
["getSingleUseToken"] = 7,
|
|
||||||
["getMultiUseToken"] = 8
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function gmInte.SendNet(id, args, func)
|
function gmInte.SendNet(id, args, func)
|
||||||
|
@ -36,9 +34,6 @@ local netReceive = {
|
||||||
[3] = function(data)
|
[3] = function(data)
|
||||||
gmInte.showTestConnection(data)
|
gmInte.showTestConnection(data)
|
||||||
end,
|
end,
|
||||||
[4] = function(data)
|
|
||||||
gmInte.takeScreenShot(data.serverID, data.authToken)
|
|
||||||
end,
|
|
||||||
[5] = function(data)
|
[5] = function(data)
|
||||||
gmInte.config = data
|
gmInte.config = data
|
||||||
end,
|
end,
|
||||||
|
@ -49,10 +44,7 @@ local netReceive = {
|
||||||
gmInte.openVerifPopup()
|
gmInte.openVerifPopup()
|
||||||
end,
|
end,
|
||||||
[8] = function(data)
|
[8] = function(data)
|
||||||
gmInte.singleUseToken(data)
|
gmInte.config.token = data.token
|
||||||
end,
|
|
||||||
[9] = function(data)
|
|
||||||
gmInte.multiUseToken(data)
|
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,27 +0,0 @@
|
||||||
//
|
|
||||||
// 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
|
|
|
@ -56,6 +56,7 @@ function gmInte.publicGetConfig(ply)
|
||||||
if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end
|
if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end
|
||||||
|
|
||||||
gmInte.SendNet("publicConfig", {
|
gmInte.SendNet("publicConfig", {
|
||||||
|
["id"] = gmInte.config.id,
|
||||||
["debug"] = gmInte.config.debug,
|
["debug"] = gmInte.config.debug,
|
||||||
["apiFQDN"] = gmInte.config.apiFQDN,
|
["apiFQDN"] = gmInte.config.apiFQDN,
|
||||||
["websocketFQDN"] = gmInte.config.websocketFQDN,
|
["websocketFQDN"] = gmInte.config.websocketFQDN,
|
||||||
|
|
50
lua/gmod_integration/server/sv_tokens.lua
Normal file
50
lua/gmod_integration/server/sv_tokens.lua
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
//
|
||||||
|
// Methods
|
||||||
|
//
|
||||||
|
|
||||||
|
gmInte.serverPublicToken = gmInte.serverPublicToken || nil
|
||||||
|
function gmInte.getPublicServerToken(callback)
|
||||||
|
if (gmInte.serverPublicToken) then
|
||||||
|
if (callback) then callback(gmInte.serverPublicToken) end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
gmInte.http.get("/public-token", function(code, data)
|
||||||
|
gmInte.serverPublicToken = data.publicTempToken
|
||||||
|
callback(data.publicTempToken)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
hook.Add("Initialize", "gmInte:Server:Initialize:GetPublicToken", function()
|
||||||
|
timer.Simple(1, function()
|
||||||
|
gmInte.getPublicServerToken(function(publicToken)
|
||||||
|
gmInte.log("Server Public Token Received: " .. publicToken)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
end)
|
||||||
|
|
||||||
|
gmInte.serverPlayerTempTokens = gmInte.serverPlayerTempTokens || {}
|
||||||
|
function gmInte.getPlayerTempToken(ply, callback)
|
||||||
|
if (gmInte.serverPlayerTempTokens[ply:SteamID64()] && gmInte.serverPlayerTempTokens[ply:SteamID64()].userID == ply:UserID()) then
|
||||||
|
if (callback) then callback(gmInte.serverPlayerTempTokens[ply:SteamID64()].token) end
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
|
gmInte.getPublicServerToken(function(publicToken)
|
||||||
|
local token = util.SHA256(ply:SteamID64() .. "-" .. publicToken .. "-" .. gmInte.config.token .. "-" .. ply:UserID()) .. " " .. ply:UserID()
|
||||||
|
gmInte.serverPlayerTempTokens[ply:SteamID64()] = { token = token, userID = ply:UserID() }
|
||||||
|
callback(token)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
function sendPlayerToken(ply)
|
||||||
|
gmInte.getPlayerTempToken(ply, function(token)
|
||||||
|
gmInte.SendNet("savePlayerToken", {
|
||||||
|
token = token,
|
||||||
|
}, ply)
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
hook.Add("gmInte:PlayerReady", "gmInte:Verif:PlayerReady", function(ply)
|
||||||
|
sendPlayerToken(ply)
|
||||||
|
end)
|
|
@ -15,7 +15,7 @@ local function getAPIURL(endpoint)
|
||||||
return url .. endpoint
|
return url .. endpoint
|
||||||
end
|
end
|
||||||
|
|
||||||
url = url .. "/clients/" .. LocalPlayer():SteamID64()
|
url = url .. "/clients/" .. LocalPlayer():SteamID64() .. "/servers/" .. gmInte.config.id
|
||||||
end
|
end
|
||||||
|
|
||||||
return url .. endpoint
|
return url .. endpoint
|
||||||
|
|
Loading…
Reference in New Issue
Block a user