mirror of
https://github.com/gmod-integration/lua.git
synced 2025-03-15 22:07:34 +00:00
edit: change net name system
This commit is contained in:
parent
4219ebcf12
commit
40f7bb8079
|
@ -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)
|
|
@ -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)
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
//
|
||||
|
||||
function gmInte.wsPlayerSay(data)
|
||||
gmInte.SendNet(1, data, nil)
|
||||
gmInte.SendNet("wsRelayDiscordChat", data, nil)
|
||||
end
|
||||
|
||||
//
|
||||
|
|
Loading…
Reference in New Issue
Block a user