edit: change net name system

This commit is contained in:
Linventif 2024-02-16 14:44:34 +01:00
parent 4219ebcf12
commit 40f7bb8079
No known key found for this signature in database
GPG Key ID: FAC0CA60F9AEEC24
6 changed files with 42 additions and 37 deletions

View File

@ -2,7 +2,7 @@
// Send Net
//
local netList = {
local netSend = {
["ready"] = 0,
["testConnection"] = 1,
["getConfig"] = 2,
@ -16,7 +16,7 @@ local netList = {
function gmInte.SendNet(id, args, func)
net.Start("gmIntegration")
net.WriteUInt(netList[id], 8)
net.WriteUInt(netSend[id], 8)
net.WriteString(util.TableToJSON(args || {}))
if (func) then func() end
net.SendToServer()
@ -26,7 +26,7 @@ end
// Receive Net
//
local netFunc = {
local netReceive = {
[1] = function(data)
gmInte.discordSyncChatPly(data)
end,
@ -59,5 +59,5 @@ local netFunc = {
net.Receive("gmIntegration", function()
local id = net.ReadUInt(8)
local args = util.JSONToTable(net.ReadString())
if (netFunc[id]) then netFunc[id](args) end
if (netReceive[id]) then netReceive[id](args) end
end)

View File

@ -1,31 +1,29 @@
//
// Network
// Networking
//
/*
Upload
1 - Add Chat Message
2 - Get Config
3 - Test Connection
4 - Take Screenshot
5 - Send Public Config
6 - Send Message
7 - Open Verif Popup
Receive
0 - Player is Ready
1 - Test Connection
2 - Get Config
3 - Set Config
4 - Take Screenshot
5 - Restart Map
*/
util.AddNetworkString("gmIntegration")
//
// Send Net
//
local netSend = {
["wsRelayDiscordChat"] = 1,
["adminConfig"] = 2,
["testApiConnection"] = 3,
["screenshotToken"] = 4,
["publicConfig"] = 5,
["chatColorMessage"] = 6,
["openVerifPopup"] = 7
}
// Send
function gmInte.SendNet(id, data, ply, func)
if (!netSend[id]) then return end
net.Start("gmIntegration")
net.WriteUInt(id, 8)
net.WriteUInt(netSend[id], 8)
net.WriteString(util.TableToJSON(data || {}))
if (func) then func() end
if (ply == nil) then
@ -35,8 +33,11 @@ function gmInte.SendNet(id, data, ply, func)
end
end
// Receive
local netFuncs = {
//
// Receive net
//
local netReceive = {
[0] = function(ply)
gmInte.userFinishConnect(ply)
end,
@ -62,8 +63,12 @@ local netFuncs = {
}
net.Receive("gmIntegration", function(len, ply)
if !ply:IsPlayer() then return end
if (!ply || ply && !ply:IsValid()) then return end
local id = net.ReadUInt(8)
local data = util.JSONToTable(net.ReadString() || "{}")
if (netFuncs[id]) then netFuncs[id](ply, data) end
if (!netReceive[id]) then return end
netReceive[id](ply, data)
end)

View File

@ -9,7 +9,7 @@ function gmInte.verifyPlayer(ply)
if (data && data.steamID64) then
if (ply.gmIntVerified) then return end
gmInte.SendNet(6, {
gmInte.SendNet("chatColorMessage", {
[1] = {
["text"] = "You have been verified",
["color"] = Color(255, 255, 255)
@ -18,14 +18,14 @@ function gmInte.verifyPlayer(ply)
ply:Freeze(false)
ply.gmIntVerified = true
else
gmInte.SendNet(6, {
gmInte.SendNet("chatColorMessage", {
[1] = {
["text"] = "You are not verified",
["color"] = Color(255, 0, 0)
}
}, ply)
ply:Freeze(true)
gmInte.SendNet(7, nil, ply)
gmInte.SendNet("openVerifPopup", nil, ply)
end
end)
end

View File

@ -16,7 +16,7 @@ end
function gmInte.takeScreenshot(ply)
gmInte.getClientOneTimeToken(ply, function(oneTime)
gmInte.SendNet(4, {
gmInte.SendNet("screenshotToken", {
["serverID"] = gmInte.config.id,
["oneTimeToken"] = oneTime
}, ply)

View File

@ -31,10 +31,10 @@ end
function gmInte.testConnection(ply)
gmInte.http.get("",
function(code, body)
if (ply) then gmInte.SendNet(3, body, ply) end
if (ply) then gmInte.SendNet("testApiConnection", body, ply) end
end,
function(code, body)
if (ply) then gmInte.SendNet(3, body, ply) end
if (ply) then gmInte.SendNet("testApiConnection", body, ply) end
end
)
end
@ -49,13 +49,13 @@ function gmInte.superadminGetConfig(ply)
if (!gmInte.plyValid(ply) || !ply:IsSuperAdmin()) then return end
gmInte.config.websocket = GWSockets && true || false
gmInte.SendNet(2, gmInte.config, ply)
gmInte.SendNet("adminConfig", gmInte.config, ply)
end
function gmInte.publicGetConfig(ply)
if (!gmInte.plyValid(ply)) then return end
gmInte.SendNet(5, {
gmInte.SendNet("publicConfig", {
["debug"] = gmInte.config.debug,
["devInstance"] = gmInte.config.devInstance
}, ply)

View File

@ -3,7 +3,7 @@
//
function gmInte.wsPlayerSay(data)
gmInte.SendNet(1, data, nil)
gmInte.SendNet("wsRelayDiscordChat", data, nil)
end
//