mirror of
https://github.com/gmod-integration/lua.git
synced 2025-03-15 22:27:34 +00:00
Fix: add antispamer for websocket connection
This commit is contained in:
parent
82e01ef55e
commit
ebfef087ac
|
@ -20,6 +20,7 @@ local function getWebSocketURL()
|
||||||
return method .. "://" .. gmInte.config.websocketFQDN
|
return method .. "://" .. gmInte.config.websocketFQDN
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local nbOfTry = 0
|
||||||
function gmInte.setupWebSocket()
|
function gmInte.setupWebSocket()
|
||||||
local socket = GWSockets.createWebSocket(getWebSocketURL())
|
local socket = GWSockets.createWebSocket(getWebSocketURL())
|
||||||
socket:setHeader("id", gmInte.config.id)
|
socket:setHeader("id", gmInte.config.id)
|
||||||
|
@ -47,12 +48,23 @@ function gmInte.setupWebSocket()
|
||||||
gmInte.logError("WebSocket Error: " .. txt, true)
|
gmInte.logError("WebSocket Error: " .. txt, true)
|
||||||
end
|
end
|
||||||
|
|
||||||
timer.Create("gmInte:WebSocket:CheckConnection", 4, 0, function()
|
function reconnect()
|
||||||
if !socket:isConnected() then
|
|
||||||
gmInte.log("WebSocket is not connected, trying to reconnect", true)
|
gmInte.log("WebSocket is not connected, trying to reconnect", true)
|
||||||
timer.Remove("gmInte:WebSocket:CheckConnection")
|
timer.Remove("gmInte:WebSocket:CheckConnection")
|
||||||
gmInte.setupWebSocket()
|
gmInte.setupWebSocket()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
timer.Create("gmInte:WebSocket:CheckConnection", 4, 0, function()
|
||||||
|
if !socket:isConnected() then
|
||||||
|
nbOfTry = nbOfTry + 1
|
||||||
|
if nbOfTry > 10 && nbOfTry % 40 != 0 then return end
|
||||||
|
reconnect()
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
|
hook.Add("GmodIntegration:Websocket:Restart", "gmInte:WebSocket:Restart", function()
|
||||||
|
socket:close()
|
||||||
|
reconnect()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user