This commit is contained in:
Linventif 2023-09-25 11:38:49 +02:00
parent 328f446c6d
commit 3230849679
5 changed files with 14 additions and 6 deletions

View File

@ -14,7 +14,7 @@ function gmInte.SendNet(id, args, func)
net.Start("gmIntegration")
net.WriteUInt(id, 8)
net.WriteString(util.TableToJSON(args || {}))
func && func()
if (func) then func() end
net.SendToServer()
end
@ -28,5 +28,5 @@ local netFunc = {
net.Receive("gmIntegration", function()
local id = net.ReadUInt(8)
local args = util.JSONToTable(net.ReadString())
netFunc[id] && netFunc[id](args)
if (netFunc[id]) then netFunc[id](args) end
end)

View File

@ -16,7 +16,7 @@ function gmInte.SendNet(id, data, ply, func)
net.Start("gmIntegration")
net.WriteUInt(id, 8)
net.WriteString(util.TableToJSON(data))
func && func()
if (func) then func() end
net.Send(ply)
end
@ -31,5 +31,5 @@ net.Receive("gmIntegration", function(len, ply)
if !ply:IsPlayer() then return end
local id = net.ReadUInt(8)
local data = util.JSONToTable(net.ReadString() || "{}")
netFuncs[id] && netFuncs[id](ply, data)
if (netFuncs[id]) then netFuncs[id](ply, data) end
end)

View File

@ -1,3 +1,9 @@
//
// WebSocket
//
if (!GWSockets) then return gmInte.logError("GWSockets not found!") end
require("gwsockets")
local socket = GWSockets.createWebSocket("wss://ws.gmod-integration.com")

View File

@ -21,7 +21,9 @@ local function sendHTTP(params)
gmInte.log("HTTP Response: " .. code, true)
gmInte.log("HTTP Body: " .. body, true)
if (string.sub(code, 1, 1) == "2") then
params.success && params.success(body, code, headers)
if (params.success) then
params.success(body, code, headers)
end
else
gmInte.logError("HTTP Request failed with code " .. code .. " and body " .. body)
end

View File

@ -12,5 +12,5 @@ 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)
debug && print(debug.traceback())
if (debug) then print(debug.traceback()) end
end