add config menu

This commit is contained in:
Linventif 2023-12-16 13:42:40 +01:00
parent b468a72c33
commit aacd24712d
9 changed files with 425 additions and 12 deletions

View File

@ -5,9 +5,12 @@ if game.SinglePlayer() then return end
//
gmInte = {}
gmInte.version = "0.1.3"
gmInte.config = {}
gmInte.version = "0.1.8"
gmInte.config = {
["redownloadMaterials"] = false,
}
gmInte.debug = false
gmInte.materials = {}
//
// Functions

View File

@ -0,0 +1,23 @@
surface.CreateFont("GmodIntegration_Roboto_16", {
font = "Roboto",
size = 16,
weight = 500,
antialias = true,
shadow = false
})
surface.CreateFont("GmodIntegration_Roboto_18", {
font = "Roboto",
size = 18,
weight = 500,
antialias = true,
shadow = false
})
surface.CreateFont("GmodIntegration_Roboto_20", {
font = "Roboto",
size = 20,
weight = 500,
antialias = true,
shadow = false
})

View File

@ -0,0 +1,246 @@
local function saveConfig(setting, value)
gmInte.SendNet("3", {
[setting] = value
})
end
local configCat = {
"Authentication",
"Main",
"Trust & Safety"
}
local possibleConfig = {
["id"] = {
["label"] = "ID",
["description"] = "Your server ID. You can find it on the webpanel.",
["type"] = "textEntry",
["value"] = function(value)
return value
end,
["onEdit"] = function(value)
saveConfig("id", value)
end,
["onEditDelay"] = 0.5,
["category"] = "Authentication"
},
["token"] = {
["label"] = "Token",
["description"] = "Your server Token. You can find it on the webpanel.",
["type"] = "textEntry",
["value"] = function(value)
return value
end,
["onEdit"] = function(value)
saveConfig("token", value)
end,
["onEditDelay"] = 0.5,
["category"] = "Authentication"
},
["logs"] = {
["label"] = "Logs",
["description"] = "Activate or deactivate the logs.",
["type"] = "checkbox",
["value"] = function(value)
return value
end,
["onEdit"] = function(value)
saveConfig("disableLog", value == "Enabled" && true || false)
end,
["category"] = "Main"
},
["filterOnBan"] = {
["label"] = "Block Discord Ban Player",
["description"] = "Block players that are banned on the discord server.",
["type"] = "checkbox",
["value"] = function(value)
return value
end,
["onEdit"] = function(value)
saveConfig("disableLog", value == "Enabled" && true || false)
end,
["category"] = "Trust & Safety"
},
["filterOnTrust"] = {
["label"] = "Block UnTrust Player",
["description"] = "",
["type"] = "checkbox",
["value"] = function(value)
return value
end,
["onEdit"] = function(value)
saveConfig("disableLog", value == "Enabled" && true || false)
end,
["category"] = "Trust & Safety"
},
}
local buttonsInfo = {
{
["label"] = "Open Webpanel",
["func"] = function()
gui.OpenURL("https://gmod-integration.com/config/server")
end,
},
{
["try"] = "Test Connection",
["func"] = function()
gmInte.SendNet("1")
end,
},
{
["try"] = "Tdest Connection",
["func"] = function()
gmInte.SendNet("1")
end,
}
}
function gmInte.openConfigMenu(data)
local frame = vgui.Create("DFrame")
frame:SetSize(400, 400)
frame:Center()
frame:SetTitle("Gmod Integration - Server Config")
frame:SetDraggable(true)
frame:ShowCloseButton(true)
frame:MakePopup()
local scrollPanel = vgui.Create("DScrollPanel", frame)
scrollPanel:Dock(FILL)
// add message explain that this config is superiort then the webpanel config
local messagePanel = vgui.Create("DPanel", scrollPanel)
messagePanel:Dock(TOP)
messagePanel:SetSize(300, 60)
messagePanel:SetBackgroundColor(Color(0, 0, 0, 0))
local messageLabel = vgui.Create("DLabel", messagePanel)
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:SetWrap(true)
for k, catName in pairs(configCat) do
// create DCollapsibleCategory
local collapsibleCategory = vgui.Create("DCollapsibleCategory", scrollPanel)
collapsibleCategory:Dock(TOP)
collapsibleCategory:DockMargin(0, 0, 0, 5)
collapsibleCategory:SetLabel(catName)
collapsibleCategory:SetExpanded(true)
// create DPanelList as content of DCollapsibleCategory
local configList = vgui.Create("DPanelList", collapsibleCategory)
configList:Dock(FILL)
configList:SetSpacing(5)
configList:EnableHorizontal(false)
configList:EnableVerticalScrollbar(false)
collapsibleCategory:SetContents(configList)
for k, v in pairs(possibleConfig) do
if v.category == catName then
local panel = vgui.Create("DPanel", configList)
panel:Dock(TOP)
panel:SetSize(300, 25)
panel:SetBackgroundColor(Color(0, 0, 0, 0))
local label = vgui.Create("DLabel", panel)
label:Dock(LEFT)
label:SetSize(140, 25)
label:SetText(v.label)
-- label:SetContentAlignment(5)
local input
if v.type == "textEntry" then
input = vgui.Create("DTextEntry", panel)
input:SetText(v.value(data[k]))
local isLastID = 0
input.OnChange = function(self)
isLastID = isLastID + 1
local isLocalLastID = isLastID
timer.Simple(v.onEditDelay || 0.5, function()
if isLocalLastID == isLastID then
v.onEdit(self:GetValue())
end
end)
end
elseif v.type == "checkbox" then
input = vgui.Create("DComboBox", panel)
input:AddChoice("Enabled")
input:AddChoice("Disabled")
input:SetText(v.value(data[k]) && "Enabled" || "Disabled")
input.OnSelect = function(self, index, value)
v.onEdit(value)
end
end
input:Dock(FILL)
input:SetSize(150, 25)
if v.description then
panel:SetTooltip(v.description)
end
configList:AddItem(panel)
end
end
end
local buttonsPanel = vgui.Create("DPanel", frame)
buttonsPanel:Dock(BOTTOM)
buttonsPanel:SetSize(300, 50)
buttonsPanel:SetBackgroundColor(Color(0, 0, 0, 0))
local buttonRows = {}
local currentRow = nil
for k, v in pairs(buttonsInfo) do
if k % 2 == 1 then
currentRow = vgui.Create("DPanel", buttonsPanel)
currentRow:Dock(TOP)
currentRow:SetSize(300, 25)
currentRow:SetBackgroundColor(Color(0, 0, 0, 0))
table.insert(buttonRows, currentRow)
end
local button = vgui.Create("DButton", currentRow)
button:Dock(k % 2 == 1 && LEFT || RIGHT)
button:SetText(v.label or v.try)
button:SetWide(button:GetParent():GetWide() / 2)
button.DoClick = function()
v.func()
end
end
end
// Add on Desktop Widgets
-- Vérifie si l'interface utilisateur de widgets existe et la crée si ce n'est pas le cas
if not MyWidget then
MyWidget = {}
end
-- Fonction pour créer le widget
function MyWidget.CreateWidget()
local frame = vgui.Create("DFrame")
frame:SetSize(200, 100)
frame:SetTitle("Mon Widget")
frame:MakePopup()
-- Ajouter d'autres éléments à votre widget ici
return frame
end
list.Set("DesktopWindows", "GmodIntegration:DesktopWindows", {
icon = "icon64/gmodintegration.png",
title = "Gmod Integration",
width = 100,
height = 100,
onewindow = true,
init = function(icon, window)
window:Close()
gmInte.openAdminConfig()
end
}
)

View File

@ -5,4 +5,15 @@
// Player Finish Init
hook.Add("InitPostEntity", "gmInte:Ply:Ready", function()
gmInte.SendNet(0)
end)
hook.Add("OnPlayerChat", "gmInte:OnPlayerChat:AdminCmd", function(ply, strText, bTeamOnly, bPlayerIsDead)
if (ply != LocalPlayer()) then return end
strText = string.lower(strText)
if (strText == "/gminte") then
gmInte.openAdminConfig()
return true
end
end)

View File

@ -14,4 +14,21 @@ end
function gmInte.discordSyncChatPly(data)
chat.AddText(Color(92, 105, 255), "(DISCORD) ", Color(12, 151, 12), formatName(data.name) .. ": ", Color(255, 255, 255), data.content)
end
end
function gmInte.showTestConnection(data)
if (data && data.id) then
chat.AddText(Color(255, 130, 92), "[Gmod Integration] ", Color(63, 102, 63), "Connection Successfull", Color(255, 255, 255), ", server logged as '" .. data.name .. "'")
else
chat.AddText(Color(255, 130, 92), "[Gmod Integration] ", Color(102, 63, 63), "Connection Failed", Color(255, 255, 255), ", please check your ID and Token")
end
end
function gmInte.openAdminConfig()
if (!LocalPlayer():IsSuperAdmin()) then return end
gmInte.SendNet("2")
end
// add concommand
concommand.Add("gmod_integration_admin", gmInte.openAdminConfig)

View File

@ -0,0 +1,57 @@
//
// Variables
//
local ImageCache = {}
//
// Functions
//
function gmInte.createImgurMaterials(materials, addon_var, folder, name)
if !file.Exists(folder, "DATA") then
file.CreateDir(folder)
end
local function getMatFromUrl(url, id)
materials[id] = Material("nil")
if file.Exists(folder .. "/" .. id .. ".png", "DATA") && !gmInte.config.redownloadMaterials then
addon_var[id] = Material("../data/" .. folder .. "/" .. id .. ".png", "noclamp smooth")
gmInte.log("materials", name .. " - Image Loaded - " .. id .. ".png")
return
end
http.Fetch(url, function(body)
file.Write(folder .. "/" .. id .. ".png", body)
addon_var[id] = Material("../data/" .. folder .. "/" .. id .. ".png", "noclamp smooth")
ImageCache[table.Count(ImageCache) + 1] = {
["folder"] = folder,
["addon_var"] = addon_var,
["id"] = id
}
gmInte.log("materials", name .. " - Image Downloaded - " .. id .. ".png")
end)
end
for k, v in pairs(materials) do
getMatFromUrl("https://i.imgur.com/" .. v .. ".png", k)
end
end
function gmInte.redowloadMaterials()
for k, v in pairs(ImageCache) do
v.addon_var[v.id] = Material("../data/" .. v.folder .. "/" .. v.id .. ".png", "noclamp smooth")
gmInte.log("materials", v.name .. " - Image Redownloaded - " .. v.id .. ".png")
end
end
concommand.Add("gmod_integration_reload_materials", function()
gmInte.redowloadMaterials()
end)
local materialsList = {
["logo"] = "y3Mypbn"
}
gmInte.createImgurMaterials(materialsList, gmInte.materials, "gmod_integration/material", "Gmod Integration")

View File

@ -5,8 +5,12 @@
/*
Upload
0 - Say I'm ready
1 - Test Connection
2 - Get Config
Receive
1 - Sync Chat
2 - Get Config (Response)
3 - Test Connection (Response)
*/
// Send
@ -22,6 +26,12 @@ end
local netFunc = {
[1] = function(data)
gmInte.discordSyncChatPly(data)
end,
[2] = function(data)
gmInte.openConfigMenu(data)
end,
[3] = function(data)
gmInte.showTestConnection(data)
end
}

View File

@ -20,6 +20,7 @@ function gmInte.saveSetting(setting, value)
// Boolean
if (value == "true") then value = true end
if (value == "false") then value = false end
// Number
if (tonumber(value) != nil) then value = tonumber(value) end
@ -161,15 +162,24 @@ end
function gmInte.tryConfig()
gmInte.get("/server",
function(code, body)
local receiveData = util.JSONToTable(body)
print(" ")
gmInte.log("Congratulations your server is now connected to Gmod Integration")
gmInte.log("Server Name: " .. receiveData.name)
gmInte.log("Server ID: " .. receiveData.id)
gmInte.log("Server Name: " .. body.name)
gmInte.log("Server ID: " .. body.id)
print(" ")
end)
end
function gmInte.testConnection(ply)
gmInte.get("/server",
function(code, body)
gmInte.SendNet(3, body, ply)
end,
function(code, body, headers)
gmInte.SendNet(3, body, ply)
end)
end
function gmInte.serverShutDown()
for ply, ply in pairs(player.GetAll()) do
gmInte.playerDisconnected(ply)
@ -214,25 +224,47 @@ function gmInte.playerFilter(data)
// get data
gmInte.get("/server/user" .. "?steamID64=" .. data.steamID64,
function(code, body)
if (!body || !receiveData.trust) then return end
if (!body || !body.trust) then return end
// Gmod Integration Trust
if (gmInte.config.filterOnTrust && (receiveData.trust < gmInte.config.minimalTrust)) then
if (gmInte.config.filterOnTrust && (body.trust < gmInte.config.minimalTrust)) then
// kick player
game.KickID(data.networkid, filterMessage("Insufficient Trust Level\nYour Trust Level: " .. receiveData.trust .. "\nMinimal Trust Level: " .. gmInte.config.minimalTrust))
game.KickID(data.networkid, filterMessage("Insufficient Trust Level\nYour Trust Level: " .. body.trust .. "\nMinimal Trust Level: " .. gmInte.config.minimalTrust))
end
// Gmod Integration Ban
if (gmInte.config.filterOnBan && receiveData.ban) then
if (gmInte.config.filterOnBan && body.ban) then
// kick player
game.KickID(data.networkid, filterMessage("You are banned from Gmod Integration"))
end
// Server Discord Ban
if (gmInte.config.syncBan && receiveData.discord_ban) then
if (gmInte.config.syncBan && body.discord_ban) then
// kick player
game.KickID(data.networkid, filterMessage("You are banned from the discord server\nReason: " .. (receiveData.discord_ban_reason && receiveData.discord_ban_reason || "No Reason")))
game.KickID(data.networkid, filterMessage("You are banned from the discord server\nReason: " .. (body.discord_ban_reason && body.discord_ban_reason || "No Reason")))
end
end
)
end
function gmInte.superadminGetConfig(ply)
if (!gmInte.plyValid(ply) || !ply:IsSuperAdmin()) then return end
gmInte.SendNet(2, gmInte.config, ply)
end
function gmInte.superadminSetConfig(ply, data)
if (!gmInte.plyValid(ply) || !ply:IsSuperAdmin()) then return end
if data.id then
gmInte.saveSetting("id", data.id)
end
if data.token then
gmInte.saveSetting("token", data.token)
end
if data.token || data.id then
gmInte.testConnection(ply)
end
end

View File

@ -5,8 +5,13 @@
/*
Upload
1 - Add Chat Message
2 - Get Config
3 - Test Connection (Response)
Receive
0 - Player is Ready
1 - Test Connection
2 - Get Config
3 - Set Config
*/
util.AddNetworkString("gmIntegration")
@ -31,6 +36,15 @@ local netFuncs = {
// set gmInteTime to acual time
ply.gmIntTimeConnect = os.time()
end,
[1] = function(ply, data)
gmInte.testConnection(ply, data)
end,
[2] = function(ply)
gmInte.superadminGetConfig(ply)
end,
[3] = function(ply, data)
gmInte.superadminSetConfig(ply, data)
end
}
net.Receive("gmIntegration", function(len, ply)