edit: screenshot take system

This commit is contained in:
Linventif 2024-03-10 03:45:45 +01:00
parent 299b07a9ed
commit b654535813
No known key found for this signature in database
GPG Key ID: FAC0CA60F9AEEC24
4 changed files with 42 additions and 60 deletions

View File

@ -17,6 +17,11 @@ hook.Add("PostRender", "gmInteScreenshot", function()
}
local screenCapture = render.Capture(captureData)
if (!screenCapture) then
chat.AddText(Color(255, 130, 92), "[Gmod Integration] ", Color(102, 63, 63), "Failed to take screenshot, your system may not support this feature.")
return
end
screenCapture = util.Base64Encode(screenCapture)
local size = math.Round(string.len(screenCapture) / 1024)
@ -31,6 +36,7 @@ hook.Add("PostRender", "gmInteScreenshot", function()
},
function(code, body)
gmInte.log("Screenshot sent to Discord", true)
chat.AddText(Color(255, 130, 92), "[Gmod Integration] ", Color(255, 255, 255), "Screenshot sent to Discord.")
end,
function(code, body)
gmInte.log("Screenshot failed to send to Discord, error code: " .. code, true)
@ -42,13 +48,8 @@ end)
// Methods
//
function gmInte.takeScreenShot(serverID, authToken)
gmInte.config.id = serverID
gmInte.config.token = authToken
timer.Simple(0.2, function()
function gmInte.takeScreenShot()
ScreenshotRequested = true
end)
end
//
@ -56,7 +57,7 @@ end
//
concommand.Add("gmod_integration_screenshot", function()
gmInte.SendNet("takeScreenShot")
gmInte.takeScreenShot()
end)
//
@ -69,6 +70,7 @@ hook.Add("OnPlayerChat", "gmInteChatCommands", function(ply, text, teamChat, isD
text = string.sub(text, 2)
if (text == "screen") then
gmInte.SendNet("takeScreenShot")
gmInte.takeScreenShot()
return true
end
end)

View File

@ -23,6 +23,7 @@ hook.Add("PostRender", "gmInte:PostRender:Stream:Frame", function()
}
local screenCapture = render.Capture(captureConfig)
if (!screenCapture) then return end
screenCapture = util.Base64Encode(screenCapture)
local size = math.Round(string.len(screenCapture) / 1024)
@ -45,33 +46,33 @@ hook.Add("PostRender", "gmInte:PostRender:Stream:Frame", function()
StreamsRequeted = false
end)
//
// Methods
//
-- //
-- // Methods
-- //
function gmInte.takeScreenShot(serverID, authToken)
gmInte.config.id = serverID
gmInte.config.token = authToken
StreamsRequeted = true
end
-- function gmInte.takeScreenShot(serverID, authToken)
-- gmInte.config.id = serverID
-- gmInte.config.token = authToken
-- StreamsRequeted = true
-- end
function gmInte.stopScreenShot()
StreamsRequeted = false
end
-- function gmInte.stopScreenShot()
-- StreamsRequeted = false
-- end
//
// Console Commands
//
-- //
-- // Console Commands
-- //
concommand.Add("gmod_integration_stream", function()
StreamsRequeted = !StreamsRequeted
gmInte.log("Streaming frames to WebPanel: " .. tostring(StreamsRequeted))
-- concommand.Add("gmod_integration_stream", function()
-- StreamsRequeted = !StreamsRequeted
-- gmInte.log("Streaming frames to WebPanel: " .. tostring(StreamsRequeted))
-- if (StreamsRequeted) then
-- gmInte.stopScreenShot()
-- gmInte.log("Stopped streaming frames to WebPanel")
-- else
-- gmInte.SendNet("getSingleUseToken")
-- gmInte.log("Started streaming frames to WebPanel")
-- end
end)
-- -- if (StreamsRequeted) then
-- -- gmInte.stopScreenShot()
-- -- gmInte.log("Stopped streaming frames to WebPanel")
-- -- else
-- -- gmInte.SendNet("getSingleUseToken")
-- -- gmInte.log("Started streaming frames to WebPanel")
-- -- end
-- end)

View File

@ -12,10 +12,10 @@ local netSend = {
["wsRelayDiscordChat"] = 1,
["adminConfig"] = 2,
["testApiConnection"] = 3,
["screenshotToken"] = 4,
["publicConfig"] = 5,
["chatColorMessage"] = 6,
["openVerifPopup"] = 7
["openVerifPopup"] = 7,
["savePlayerToken"] = 8
}
// Send
@ -59,6 +59,9 @@ local netReceive = {
end,
[6] = function(ply)
gmInte.verifyPlayer(ply)
end,
[7] = function(ply, data)
sendPlayerToken(ply)
end
}

View File

@ -1,24 +0,0 @@
//
// Websocket
//
function gmInte.wsPlayerScreen(data)
for _, ply in pairs(player.GetAll()) do
if (ply:SteamID64() == data.steamID64) then
gmInte.takeScreenshot(ply)
end
end
end
//
// Methods
//
function gmInte.takeScreenshot(ply)
gmInte.getClientOneTimeToken(ply, function(oneTime)
gmInte.SendNet("screenshotToken", {
["serverID"] = gmInte.config.id,
["oneTimeToken"] = oneTime
}, ply)
end)
end