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
|
// Send Net
|
||||||
//
|
//
|
||||||
|
|
||||||
local netList = {
|
local netSend = {
|
||||||
["ready"] = 0,
|
["ready"] = 0,
|
||||||
["testConnection"] = 1,
|
["testConnection"] = 1,
|
||||||
["getConfig"] = 2,
|
["getConfig"] = 2,
|
||||||
|
@ -16,7 +16,7 @@ local netList = {
|
||||||
|
|
||||||
function gmInte.SendNet(id, args, func)
|
function gmInte.SendNet(id, args, func)
|
||||||
net.Start("gmIntegration")
|
net.Start("gmIntegration")
|
||||||
net.WriteUInt(netList[id], 8)
|
net.WriteUInt(netSend[id], 8)
|
||||||
net.WriteString(util.TableToJSON(args || {}))
|
net.WriteString(util.TableToJSON(args || {}))
|
||||||
if (func) then func() end
|
if (func) then func() end
|
||||||
net.SendToServer()
|
net.SendToServer()
|
||||||
|
@ -26,7 +26,7 @@ end
|
||||||
// Receive Net
|
// Receive Net
|
||||||
//
|
//
|
||||||
|
|
||||||
local netFunc = {
|
local netReceive = {
|
||||||
[1] = function(data)
|
[1] = function(data)
|
||||||
gmInte.discordSyncChatPly(data)
|
gmInte.discordSyncChatPly(data)
|
||||||
end,
|
end,
|
||||||
|
@ -59,5 +59,5 @@ local netFunc = {
|
||||||
net.Receive("gmIntegration", function()
|
net.Receive("gmIntegration", function()
|
||||||
local id = net.ReadUInt(8)
|
local id = net.ReadUInt(8)
|
||||||
local args = util.JSONToTable(net.ReadString())
|
local args = util.JSONToTable(net.ReadString())
|
||||||
if (netFunc[id]) then netFunc[id](args) end
|
if (netReceive[id]) then netReceive[id](args) end
|
||||||
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")
|
util.AddNetworkString("gmIntegration")
|
||||||
|
|
||||||
|
//
|
||||||
|
// Send Net
|
||||||
|
//
|
||||||
|
|
||||||
|
local netSend = {
|
||||||
|
["wsRelayDiscordChat"] = 1,
|
||||||
|
["adminConfig"] = 2,
|
||||||
|
["testApiConnection"] = 3,
|
||||||
|
["screenshotToken"] = 4,
|
||||||
|
["publicConfig"] = 5,
|
||||||
|
["chatColorMessage"] = 6,
|
||||||
|
["openVerifPopup"] = 7
|
||||||
|
}
|
||||||
|
|
||||||
// Send
|
// Send
|
||||||
function gmInte.SendNet(id, data, ply, func)
|
function gmInte.SendNet(id, data, ply, func)
|
||||||
|
if (!netSend[id]) then return end
|
||||||
|
|
||||||
net.Start("gmIntegration")
|
net.Start("gmIntegration")
|
||||||
net.WriteUInt(id, 8)
|
net.WriteUInt(netSend[id], 8)
|
||||||
net.WriteString(util.TableToJSON(data || {}))
|
net.WriteString(util.TableToJSON(data || {}))
|
||||||
if (func) then func() end
|
if (func) then func() end
|
||||||
if (ply == nil) then
|
if (ply == nil) then
|
||||||
|
@ -35,8 +33,11 @@ function gmInte.SendNet(id, data, ply, func)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
// Receive
|
//
|
||||||
local netFuncs = {
|
// Receive net
|
||||||
|
//
|
||||||
|
|
||||||
|
local netReceive = {
|
||||||
[0] = function(ply)
|
[0] = function(ply)
|
||||||
gmInte.userFinishConnect(ply)
|
gmInte.userFinishConnect(ply)
|
||||||
end,
|
end,
|
||||||
|
@ -62,8 +63,12 @@ local netFuncs = {
|
||||||
}
|
}
|
||||||
|
|
||||||
net.Receive("gmIntegration", function(len, ply)
|
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 id = net.ReadUInt(8)
|
||||||
local data = util.JSONToTable(net.ReadString() || "{}")
|
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)
|
end)
|
|
@ -9,7 +9,7 @@ function gmInte.verifyPlayer(ply)
|
||||||
|
|
||||||
if (data && data.steamID64) then
|
if (data && data.steamID64) then
|
||||||
if (ply.gmIntVerified) then return end
|
if (ply.gmIntVerified) then return end
|
||||||
gmInte.SendNet(6, {
|
gmInte.SendNet("chatColorMessage", {
|
||||||
[1] = {
|
[1] = {
|
||||||
["text"] = "You have been verified",
|
["text"] = "You have been verified",
|
||||||
["color"] = Color(255, 255, 255)
|
["color"] = Color(255, 255, 255)
|
||||||
|
@ -18,14 +18,14 @@ function gmInte.verifyPlayer(ply)
|
||||||
ply:Freeze(false)
|
ply:Freeze(false)
|
||||||
ply.gmIntVerified = true
|
ply.gmIntVerified = true
|
||||||
else
|
else
|
||||||
gmInte.SendNet(6, {
|
gmInte.SendNet("chatColorMessage", {
|
||||||
[1] = {
|
[1] = {
|
||||||
["text"] = "You are not verified",
|
["text"] = "You are not verified",
|
||||||
["color"] = Color(255, 0, 0)
|
["color"] = Color(255, 0, 0)
|
||||||
}
|
}
|
||||||
}, ply)
|
}, ply)
|
||||||
ply:Freeze(true)
|
ply:Freeze(true)
|
||||||
gmInte.SendNet(7, nil, ply)
|
gmInte.SendNet("openVerifPopup", nil, ply)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
|
@ -16,7 +16,7 @@ end
|
||||||
|
|
||||||
function gmInte.takeScreenshot(ply)
|
function gmInte.takeScreenshot(ply)
|
||||||
gmInte.getClientOneTimeToken(ply, function(oneTime)
|
gmInte.getClientOneTimeToken(ply, function(oneTime)
|
||||||
gmInte.SendNet(4, {
|
gmInte.SendNet("screenshotToken", {
|
||||||
["serverID"] = gmInte.config.id,
|
["serverID"] = gmInte.config.id,
|
||||||
["oneTimeToken"] = oneTime
|
["oneTimeToken"] = oneTime
|
||||||
}, ply)
|
}, ply)
|
||||||
|
|
|
@ -31,10 +31,10 @@ end
|
||||||
function gmInte.testConnection(ply)
|
function gmInte.testConnection(ply)
|
||||||
gmInte.http.get("",
|
gmInte.http.get("",
|
||||||
function(code, body)
|
function(code, body)
|
||||||
if (ply) then gmInte.SendNet(3, body, ply) end
|
if (ply) then gmInte.SendNet("testApiConnection", body, ply) end
|
||||||
end,
|
end,
|
||||||
function(code, body)
|
function(code, body)
|
||||||
if (ply) then gmInte.SendNet(3, body, ply) end
|
if (ply) then gmInte.SendNet("testApiConnection", body, ply) end
|
||||||
end
|
end
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
@ -49,13 +49,13 @@ function gmInte.superadminGetConfig(ply)
|
||||||
if (!gmInte.plyValid(ply) || !ply:IsSuperAdmin()) then return end
|
if (!gmInte.plyValid(ply) || !ply:IsSuperAdmin()) then return end
|
||||||
|
|
||||||
gmInte.config.websocket = GWSockets && true || false
|
gmInte.config.websocket = GWSockets && true || false
|
||||||
gmInte.SendNet(2, gmInte.config, ply)
|
gmInte.SendNet("adminConfig", gmInte.config, ply)
|
||||||
end
|
end
|
||||||
|
|
||||||
function gmInte.publicGetConfig(ply)
|
function gmInte.publicGetConfig(ply)
|
||||||
if (!gmInte.plyValid(ply)) then return end
|
if (!gmInte.plyValid(ply)) then return end
|
||||||
|
|
||||||
gmInte.SendNet(5, {
|
gmInte.SendNet("publicConfig", {
|
||||||
["debug"] = gmInte.config.debug,
|
["debug"] = gmInte.config.debug,
|
||||||
["devInstance"] = gmInte.config.devInstance
|
["devInstance"] = gmInte.config.devInstance
|
||||||
}, ply)
|
}, ply)
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
//
|
//
|
||||||
|
|
||||||
function gmInte.wsPlayerSay(data)
|
function gmInte.wsPlayerSay(data)
|
||||||
gmInte.SendNet(1, data, nil)
|
gmInte.SendNet("wsRelayDiscordChat", data, nil)
|
||||||
end
|
end
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
Loading…
Reference in New Issue
Block a user