mirror of
https://github.com/gmod-integration/lua.git
synced 2025-03-16 06:37:34 +00:00
Add websocket support and related functionality
This commit is contained in:
parent
fc5117b63e
commit
e6f7d5bead
|
@ -103,6 +103,7 @@ local possibleConfig = {
|
||||||
["syncChat"] = {
|
["syncChat"] = {
|
||||||
["label"] = "Sync Chat",
|
["label"] = "Sync Chat",
|
||||||
["description"] = "Sync chat between the server and the discord server.",
|
["description"] = "Sync chat between the server and the discord server.",
|
||||||
|
["websocket"] = true,
|
||||||
["type"] = "checkbox",
|
["type"] = "checkbox",
|
||||||
["value"] = function(setting, value)
|
["value"] = function(setting, value)
|
||||||
return value
|
return value
|
||||||
|
@ -187,6 +188,22 @@ local possibleConfig = {
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
|
||||||
|
|
||||||
|
// if data.websocket is false add button to download websocket
|
||||||
|
if !data.websocket then
|
||||||
|
local button = vgui.Create("DButton")
|
||||||
|
button:SetText("Download Websocket")
|
||||||
|
button.DoClick = function()
|
||||||
|
gui.OpenURL("https://github.com/FredyH/GWSockets/releases")
|
||||||
|
end
|
||||||
|
button:SetSize(buttonGrid:GetColWide(), buttonGrid:GetRowHeight())
|
||||||
|
buttonGrid:AddItem(button)
|
||||||
|
end
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
local buttonsInfo = {
|
local buttonsInfo = {
|
||||||
{
|
{
|
||||||
["label"] = "Open Webpanel",
|
["label"] = "Open Webpanel",
|
||||||
|
@ -200,6 +217,21 @@ local buttonsInfo = {
|
||||||
gmInte.SendNet("1")
|
gmInte.SendNet("1")
|
||||||
end,
|
end,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
["label"] = "Buy Premium",
|
||||||
|
["func"] = function()
|
||||||
|
gui.OpenURL("https://gmod-integration.com/premium")
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
["label"] = "Install Websocket",
|
||||||
|
["condition"] = function(data)
|
||||||
|
return !data.websocket
|
||||||
|
end,
|
||||||
|
["func"] = function()
|
||||||
|
gui.OpenURL("https://github.com/FredyH/GWSockets/releases")
|
||||||
|
end,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function gmInte.openConfigMenu(data)
|
function gmInte.openConfigMenu(data)
|
||||||
|
@ -223,7 +255,7 @@ function gmInte.openConfigMenu(data)
|
||||||
|
|
||||||
local messageLabel = vgui.Create("DLabel", messagePanel)
|
local messageLabel = vgui.Create("DLabel", messagePanel)
|
||||||
messageLabel:Dock(FILL)
|
messageLabel:Dock(FILL)
|
||||||
messageLabel:SetText("This config is superior to the webpanel config. If you change something here you can override the webpanel config. For example if you disable the logs here, the logs will not be available on the webpanel.")
|
messageLabel:SetText("This config is superior to the webpanel config.\nIf you change something here you can override the webpanel config.\nSome features require a websocket connection to work properly.")
|
||||||
messageLabel:SetWrap(true)
|
messageLabel:SetWrap(true)
|
||||||
|
|
||||||
|
|
||||||
|
@ -273,6 +305,10 @@ function gmInte.openConfigMenu(data)
|
||||||
end
|
end
|
||||||
elseif v.type == "checkbox" then
|
elseif v.type == "checkbox" then
|
||||||
input = vgui.Create("DComboBox", panel)
|
input = vgui.Create("DComboBox", panel)
|
||||||
|
// if websocket is required and websocket is not enabled (!GWSockets) then disable the checkbox
|
||||||
|
if v.websocket && !data.websocket then
|
||||||
|
input:SetEnabled(false)
|
||||||
|
end
|
||||||
input:AddChoice("Enabled")
|
input:AddChoice("Enabled")
|
||||||
input:AddChoice("Disabled")
|
input:AddChoice("Disabled")
|
||||||
input:SetText(v.value(k, data[k]) && "Enabled" || "Disabled")
|
input:SetText(v.value(k, data[k]) && "Enabled" || "Disabled")
|
||||||
|
@ -285,6 +321,9 @@ function gmInte.openConfigMenu(data)
|
||||||
input:SetSize(150, 25)
|
input:SetSize(150, 25)
|
||||||
|
|
||||||
if v.description then
|
if v.description then
|
||||||
|
if (v.websocket && !data.websocket) then
|
||||||
|
v.description = v.description .. "\n\nThis feature require a websocket connection to work properly."
|
||||||
|
end
|
||||||
input:SetTooltip(v.description)
|
input:SetTooltip(v.description)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -301,7 +340,9 @@ function gmInte.openConfigMenu(data)
|
||||||
buttonGrid:SetColWide(frame:GetWide() / 2 - 10)
|
buttonGrid:SetColWide(frame:GetWide() / 2 - 10)
|
||||||
buttonGrid:SetRowHeight(35)
|
buttonGrid:SetRowHeight(35)
|
||||||
|
|
||||||
|
local buttonsCount = 0
|
||||||
for k, v in pairs(buttonsInfo) do
|
for k, v in pairs(buttonsInfo) do
|
||||||
|
if v.condition && !v.condition(data) then continue end
|
||||||
local button = vgui.Create("DButton")
|
local button = vgui.Create("DButton")
|
||||||
button:SetText(v.label)
|
button:SetText(v.label)
|
||||||
button.DoClick = function()
|
button.DoClick = function()
|
||||||
|
@ -309,6 +350,12 @@ function gmInte.openConfigMenu(data)
|
||||||
end
|
end
|
||||||
button:SetSize(buttonGrid:GetColWide(), buttonGrid:GetRowHeight())
|
button:SetSize(buttonGrid:GetColWide(), buttonGrid:GetRowHeight())
|
||||||
buttonGrid:AddItem(button)
|
buttonGrid:AddItem(button)
|
||||||
|
buttonsCount = buttonsCount + 1
|
||||||
|
end
|
||||||
|
|
||||||
|
if buttonsCount % 2 == 1 then
|
||||||
|
local lastButton = buttonGrid:GetItems()[buttonsCount]
|
||||||
|
lastButton:SetWide(frame:GetWide() - 20)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,15 +2,34 @@
|
||||||
// WebSocket
|
// WebSocket
|
||||||
//
|
//
|
||||||
|
|
||||||
// TODO made a proper system to detect if the server need to be connected to the websocket
|
local useWebsocket = false
|
||||||
if (!gmInte.config.syncChat && !gmInte.config.websocket) then
|
local websocketFeature = {
|
||||||
gmInte.log("WebSocket is disabled", true)
|
'syncChat',
|
||||||
|
'websocket',
|
||||||
|
}
|
||||||
|
|
||||||
|
for k, v in pairs(websocketFeature) do
|
||||||
|
if (gmInte.config[v]) then
|
||||||
|
useWebsocket = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if (!useWebsocket) then
|
||||||
|
return gmInte.log("WebSocket is not used")
|
||||||
|
end
|
||||||
|
|
||||||
|
require("gwsockets")
|
||||||
|
|
||||||
|
if (!GWSockets) then
|
||||||
|
timer.Simple(1, function()
|
||||||
|
if (!GWSockets) then
|
||||||
|
gmInte.logError("GWSockets is not installed! Please install it from https://github.com/FredyH/GWSockets/releases")
|
||||||
|
end
|
||||||
|
end)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
if (!GWSockets) then return gmInte.logError("GWSockets is not installed! Please install it from https://github.com/FredyH/GWSockets") end
|
gmInte.config.websocket = true
|
||||||
|
|
||||||
require("gwsockets")
|
|
||||||
|
|
||||||
local socket = GWSockets.createWebSocket("wss://ws.gmod-integration.com")
|
local socket = GWSockets.createWebSocket("wss://ws.gmod-integration.com")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user