diff --git a/lua/gmod_integration/server/sv__websocket.lua b/lua/gmod_integration/server/sv__websocket.lua index a460907..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,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) 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), 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, 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