From 8b5280e736c296349c1c35c920c399ce65e2db88 Mon Sep 17 00:00:00 2001 From: Linventif Date: Mon, 25 Mar 2024 15:47:46 +0100 Subject: [PATCH 1/5] fix: error on debug only --- lua/gmod_integration/server/sv__websocket.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/gmod_integration/server/sv__websocket.lua b/lua/gmod_integration/server/sv__websocket.lua index a460907..79f4346 100644 --- a/lua/gmod_integration/server/sv__websocket.lua +++ b/lua/gmod_integration/server/sv__websocket.lua @@ -60,7 +60,7 @@ function socket:onDisconnected() end function socket:onError(txt) - gmInte.logError("WebSocket Error: " .. txt) + gmInte.logError("WebSocket Error: " .. txt, true) end function gmInte.websocketWrite(data) From 797aabd3cf6199b9234123325ad87ff3ed537ec7 Mon Sep 17 00:00:00 2001 From: Linventif Date: Fri, 29 Mar 2024 14:22:51 +0100 Subject: [PATCH 2/5] fix: chat relay --- lua/gmod_integration/server/sv_sync_chat.lua | 2 -- 1 file changed, 2 deletions(-) diff --git a/lua/gmod_integration/server/sv_sync_chat.lua b/lua/gmod_integration/server/sv_sync_chat.lua index 3507080..e3b357a 100644 --- a/lua/gmod_integration/server/sv_sync_chat.lua +++ b/lua/gmod_integration/server/sv_sync_chat.lua @@ -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), From 3210d70554ab0054e23cdf2ef939b8f143b87cdb Mon Sep 17 00:00:00 2001 From: Linventif Date: Fri, 29 Mar 2024 14:23:10 +0100 Subject: [PATCH 3/5] fix: failed connection spam --- lua/gmod_integration/server/sv__websocket.lua | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lua/gmod_integration/server/sv__websocket.lua b/lua/gmod_integration/server/sv__websocket.lua index 79f4346..f150aa1 100644 --- a/lua/gmod_integration/server/sv__websocket.lua +++ b/lua/gmod_integration/server/sv__websocket.lua @@ -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,10 +56,18 @@ 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) + 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 From 343f00798cec9cf74d3282f4fe75073215c10556 Mon Sep 17 00:00:00 2001 From: Linventif Date: Fri, 29 Mar 2024 14:23:29 +0100 Subject: [PATCH 4/5] fix: failded connection spam --- lua/gmod_integration/shared/sh_http.lua | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lua/gmod_integration/shared/sh_http.lua b/lua/gmod_integration/shared/sh_http.lua index fd848b5..df2041a 100644 --- a/lua/gmod_integration/shared/sh_http.lua +++ b/lua/gmod_integration/shared/sh_http.lua @@ -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, From 336ae27b17f99842e70a77f01b02795e6ab1d2e6 Mon Sep 17 00:00:00 2001 From: Linventif Date: Fri, 29 Mar 2024 14:23:47 +0100 Subject: [PATCH 5/5] fix: don't try to log the print debug --- lua/gmod_integration/shared/sh_main.lua | 3 --- 1 file changed, 3 deletions(-) diff --git a/lua/gmod_integration/shared/sh_main.lua b/lua/gmod_integration/shared/sh_main.lua index e5e2a44..280f944 100644 --- a/lua/gmod_integration/shared/sh_main.lua +++ b/lua/gmod_integration/shared/sh_main.lua @@ -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 \ No newline at end of file