lua/lua/gmod_integration/client/cl_net.lua
2024-11-21 17:07:28 +00:00

40 lines
1.3 KiB
Lua

local netSend = {
["ready"] = 0,
["testConnection"] = 1,
["getConfig"] = 2,
["saveConfig"] = 3,
["takeScreenShot"] = 4,
["restartMap"] = 5,
["verifyMe"] = 6,
["sendFPS"] = 7
}
function gmInte.SendNet(id, args, func)
net.Start("gmIntegration")
net.WriteUInt(netSend[id], 8)
net.WriteString(util.TableToJSON(args || {}))
if func then func() end
net.SendToServer()
end
local netReceive = {
[1] = function(data) gmInte.discordSyncChatPly(data) end,
[2] = function(data) gmInte.openConfigMenu(data) end,
[3] = function(data) gmInte.showTestConnection(data) end,
[5] = function(data)
gmInte.config = table.Merge(gmInte.config, data.config)
gmInte.version = data.other.version
gmInte.loadTranslations()
if gmInte.config.clientBranch != "any" && gmInte.config.clientBranch != BRANCH then gmInte.openWrongBranchPopup() end
if !data.other.aprovedCredentials then RunConsoleCommand("gmod_integration_admin") end
end,
[6] = function(data) gmInte.chatAddTextFromTable(data) end,
[7] = function() gmInte.openVerifPopup() end,
[8] = function(data) gmInte.config.token = data.token end
}
net.Receive("gmIntegration", function()
local id = net.ReadUInt(8)
local args = util.JSONToTable(net.ReadString())
if netReceive[id] then netReceive[id](args) end
end)