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