mirror of
https://github.com/gmod-integration/lua.git
synced 2025-03-15 22:07:34 +00:00
commit
b51d317d8d
|
@ -40,7 +40,7 @@ socket:setHeader("id", gmInte.config.id)
|
||||||
socket:setHeader("token", gmInte.config.token)
|
socket:setHeader("token", gmInte.config.token)
|
||||||
|
|
||||||
function socket:onConnected()
|
function socket:onConnected()
|
||||||
gmInte.log("WebSocket Connected", true)
|
gmInte.log("WebSocket Connected")
|
||||||
end
|
end
|
||||||
|
|
||||||
// log on message
|
// log on message
|
||||||
|
@ -56,11 +56,19 @@ function socket:onMessage(txt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function socket:onDisconnected()
|
function socket:onDisconnected()
|
||||||
gmInte.log("WebSocket Disconnected", true)
|
gmInte.log("WebSocket Disconnected")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local lastConnectError = 0
|
||||||
function socket:onError(txt)
|
function socket:onError(txt)
|
||||||
gmInte.logError("WebSocket Error: " .. txt)
|
if (string.StartWith(txt, "Connection failed:")) then
|
||||||
|
if (CurTime() - lastConnectError < 5) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
gmInte.logError("WebSocket Error: " .. txt, true)
|
||||||
|
return
|
||||||
|
end
|
||||||
|
gmInte.logError("WebSocket Error: " .. txt, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
function gmInte.websocketWrite(data)
|
function gmInte.websocketWrite(data)
|
||||||
|
|
|
@ -11,8 +11,6 @@ end
|
||||||
//
|
//
|
||||||
|
|
||||||
function gmInte.playerSay(ply, text, teamOnly)
|
function gmInte.playerSay(ply, text, teamOnly)
|
||||||
if (!gmInte.config.syncChat) then return end
|
|
||||||
|
|
||||||
gmInte.http.post("/players/" .. ply:SteamID64() .. "/say",
|
gmInte.http.post("/players/" .. ply:SteamID64() .. "/say",
|
||||||
{
|
{
|
||||||
["player"] = gmInte.getPlayerFormat(ply),
|
["player"] = gmInte.getPlayerFormat(ply),
|
||||||
|
|
|
@ -1,10 +1,6 @@
|
||||||
local apiVersion = "v3"
|
local apiVersion = "v3"
|
||||||
gmInte.http = gmInte.http || {}
|
gmInte.http = gmInte.http || {}
|
||||||
|
|
||||||
//
|
|
||||||
// HTTP
|
|
||||||
//
|
|
||||||
|
|
||||||
local function getAPIURL(endpoint)
|
local function getAPIURL(endpoint)
|
||||||
local url = "https://" .. gmInte.config.apiFQDN .. "/" .. apiVersion
|
local url = "https://" .. gmInte.config.apiFQDN .. "/" .. apiVersion
|
||||||
|
|
||||||
|
@ -22,7 +18,6 @@ local function getAPIURL(endpoint)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function showableBody(endpoint)
|
local function showableBody(endpoint)
|
||||||
// if start with /streams or /screenshots return false
|
|
||||||
if (string.sub(endpoint, 1, 8) == "/streams" || string.sub(endpoint, 1, 12) == "/screenshots") then
|
if (string.sub(endpoint, 1, 8) == "/streams" || string.sub(endpoint, 1, 12) == "/screenshots") then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
@ -34,6 +29,12 @@ local function genRequestID()
|
||||||
return "gmInte-" .. util.CRC(tostring(SysTime()))
|
return "gmInte-" .. util.CRC(tostring(SysTime()))
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local lastErrorMessages = 0
|
||||||
|
local function noTokenError()
|
||||||
|
if (curTime() - lastErrorMessages < 10) then return end
|
||||||
|
gmInte.log("HTTP Failed: No token provided")
|
||||||
|
end
|
||||||
|
|
||||||
function gmInte.http.requestAPI(params)
|
function gmInte.http.requestAPI(params)
|
||||||
local body = params.body && util.TableToJSON(params.body || {}) || ""
|
local body = params.body && util.TableToJSON(params.body || {}) || ""
|
||||||
local bodyLength = string.len(body)
|
local bodyLength = string.len(body)
|
||||||
|
@ -46,6 +47,10 @@ function gmInte.http.requestAPI(params)
|
||||||
local showableBody = showableBody(params.endpoint)
|
local showableBody = showableBody(params.endpoint)
|
||||||
local requestID = genRequestID()
|
local requestID = genRequestID()
|
||||||
|
|
||||||
|
if (token == "") then
|
||||||
|
return noTokenError()
|
||||||
|
end
|
||||||
|
|
||||||
local headers = {
|
local headers = {
|
||||||
["Content-Type"] = "application/json",
|
["Content-Type"] = "application/json",
|
||||||
["Content-Length"] = bodyLength,
|
["Content-Length"] = bodyLength,
|
||||||
|
|
|
@ -12,19 +12,16 @@ end
|
||||||
function gmInte.logError(msg, debug)
|
function gmInte.logError(msg, debug)
|
||||||
if (debug && !gmInte.config.debug) then return end
|
if (debug && !gmInte.config.debug) then return end
|
||||||
print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] [ERROR] " .. msg)
|
print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] [ERROR] " .. msg)
|
||||||
if (debug) then print(debug.traceback()) end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
// Log Warning
|
// Log Warning
|
||||||
function gmInte.logWarning(msg, debug)
|
function gmInte.logWarning(msg, debug)
|
||||||
if (debug && !gmInte.config.debug) then return end
|
if (debug && !gmInte.config.debug) then return end
|
||||||
print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] [WARNING] " .. msg)
|
print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] [WARNING] " .. msg)
|
||||||
if (debug) then print(debug.traceback()) end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
// Log Hint
|
// Log Hint
|
||||||
function gmInte.logHint(msg, debug)
|
function gmInte.logHint(msg, debug)
|
||||||
if (debug && !gmInte.config.debug) then return end
|
if (debug && !gmInte.config.debug) then return end
|
||||||
print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] [HINT] " .. msg)
|
print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] [HINT] " .. msg)
|
||||||
if (debug) then print(debug.traceback()) end
|
|
||||||
end
|
end
|
Loading…
Reference in New Issue
Block a user