Remove debug flag and add config option for debug

This commit is contained in:
Linventif 2023-12-16 15:02:03 +01:00
parent aacd24712d
commit b66e088811
8 changed files with 158 additions and 90 deletions

View File

@ -9,7 +9,6 @@ gmInte.version = "0.1.8"
gmInte.config = { gmInte.config = {
["redownloadMaterials"] = false, ["redownloadMaterials"] = false,
} }
gmInte.debug = false
gmInte.materials = {} gmInte.materials = {}
// //

View File

@ -7,7 +7,9 @@ end
local configCat = { local configCat = {
"Authentication", "Authentication",
"Main", "Main",
"Trust & Safety" "Trust & Safety",
"Punishment",
"Other"
} }
local possibleConfig = { local possibleConfig = {
@ -15,11 +17,11 @@ local possibleConfig = {
["label"] = "ID", ["label"] = "ID",
["description"] = "Your server ID. You can find it on the webpanel.", ["description"] = "Your server ID. You can find it on the webpanel.",
["type"] = "textEntry", ["type"] = "textEntry",
["value"] = function(value) ["value"] = function(setting, value)
return value return value
end, end,
["onEdit"] = function(value) ["onEdit"] = function(setting, value)
saveConfig("id", value) saveConfig(setting, value)
end, end,
["onEditDelay"] = 0.5, ["onEditDelay"] = 0.5,
["category"] = "Authentication" ["category"] = "Authentication"
@ -28,11 +30,11 @@ local possibleConfig = {
["label"] = "Token", ["label"] = "Token",
["description"] = "Your server Token. You can find it on the webpanel.", ["description"] = "Your server Token. You can find it on the webpanel.",
["type"] = "textEntry", ["type"] = "textEntry",
["value"] = function(value) ["value"] = function(setting, value)
return value return value
end, end,
["onEdit"] = function(value) ["onEdit"] = function(setting, value)
saveConfig("token", value) saveConfig(setting, value)
end, end,
["onEditDelay"] = 0.5, ["onEditDelay"] = 0.5,
["category"] = "Authentication" ["category"] = "Authentication"
@ -41,11 +43,11 @@ local possibleConfig = {
["label"] = "Logs", ["label"] = "Logs",
["description"] = "Activate or deactivate the logs.", ["description"] = "Activate or deactivate the logs.",
["type"] = "checkbox", ["type"] = "checkbox",
["value"] = function(value) ["value"] = function(setting, value)
return value return value
end, end,
["onEdit"] = function(value) ["onEdit"] = function(setting, value)
saveConfig("disableLog", value == "Enabled" && true || false) saveConfig(setting, value == "Enabled" && true || false)
end, end,
["category"] = "Main" ["category"] = "Main"
}, },
@ -53,11 +55,11 @@ local possibleConfig = {
["label"] = "Block Discord Ban Player", ["label"] = "Block Discord Ban Player",
["description"] = "Block players that are banned on the discord server.", ["description"] = "Block players that are banned on the discord server.",
["type"] = "checkbox", ["type"] = "checkbox",
["value"] = function(value) ["value"] = function(setting, value)
return value return value
end, end,
["onEdit"] = function(value) ["onEdit"] = function(setting, value)
saveConfig("disableLog", value == "Enabled" && true || false) saveConfig(setting, value == "Enabled" && true || false)
end, end,
["category"] = "Trust & Safety" ["category"] = "Trust & Safety"
}, },
@ -65,14 +67,112 @@ local possibleConfig = {
["label"] = "Block UnTrust Player", ["label"] = "Block UnTrust Player",
["description"] = "", ["description"] = "",
["type"] = "checkbox", ["type"] = "checkbox",
["value"] = function(value) ["value"] = function(setting, value)
return value return value
end, end,
["onEdit"] = function(value) ["onEdit"] = function(setting, value)
saveConfig("disableLog", value == "Enabled" && true || false) saveConfig(setting, value == "Enabled" && true || false)
end, end,
["category"] = "Trust & Safety" ["category"] = "Trust & Safety"
}, },
["minimalTrust"] = {
["label"] = "Minimal Trust Level",
["description"] = "Your server ID. You can find it on the webpanel.",
["type"] = "textEntry",
["value"] = function(setting, value)
return value
end,
["onEdit"] = function(setting, value)
saveConfig(setting, value)
end,
["onEditDelay"] = 0.5,
["category"] = "Trust & Safety"
},
["syncChat"] = {
["label"] = "Sync Chat",
["description"] = "Sync the chat between the server and the discord server.",
["type"] = "checkbox",
["value"] = function(setting, value)
return value
end,
["onEdit"] = function(setting, value)
saveConfig(setting, value == "Enabled" && true || false)
end,
["category"] = "Main"
},
["syncBan"] = {
["label"] = "Sync Ban",
["description"] = "Sync the chat between the server and the discord server.",
["type"] = "checkbox",
["value"] = function(setting, value)
return value
end,
["onEdit"] = function(setting, value)
saveConfig(setting, value == "Enabled" && true || false)
end,
["category"] = "Punishment"
},
["syncTimeout"] = {
["label"] = "Sync Timeout",
["description"] = "Sync the chat between the server and the discord server.",
["type"] = "checkbox",
["value"] = function(setting, value)
return value
end,
["onEdit"] = function(setting, value)
saveConfig(setting, value == "Enabled" && true || false)
end,
["category"] = "Punishment"
},
["syncKick"] = {
["label"] = "Sync Kick",
["description"] = "Sync the chat between the server and the discord server.",
["type"] = "checkbox",
["value"] = function(setting, value)
return value
end,
["onEdit"] = function(setting, value)
saveConfig(setting, value == "Enabled" && true || false)
end,
["category"] = "Punishment"
},
["forcePlayerLink"] = {
["label"] = "Force Player Verif",
["description"] = "Sync the chat between the server and the discord server.",
["type"] = "checkbox",
["value"] = function(setting, value)
return value
end,
["onEdit"] = function(setting, value)
saveConfig(setting, value == "Enabled" && true || false)
end,
["category"] = "Main"
},
["supportLink"] = {
["label"] = "Support Link",
["description"] = "Your server ID. You can find it on the webpanel.",
["type"] = "textEntry",
["value"] = function(setting, value)
return value
end,
["onEdit"] = function(setting, value)
saveConfig(setting, value)
end,
["onEditDelay"] = 0.5,
["category"] = "Trust & Safety"
},
["debug"] = {
["label"] = "Debug",
["description"] = "Activate or deactivate the debug mode.",
["type"] = "checkbox",
["value"] = function(setting, value)
return value
end,
["onEdit"] = function(setting, value)
saveConfig(setting, value == "Enabled" && true || false)
end,
["category"] = "Other"
},
} }
local buttonsInfo = { local buttonsInfo = {
@ -83,17 +183,11 @@ local buttonsInfo = {
end, end,
}, },
{ {
["try"] = "Test Connection", ["label"] = "Test Connection",
["func"] = function() ["func"] = function()
gmInte.SendNet("1") gmInte.SendNet("1")
end, end,
}, },
{
["try"] = "Tdest Connection",
["func"] = function()
gmInte.SendNet("1")
end,
}
} }
function gmInte.openConfigMenu(data) function gmInte.openConfigMenu(data)
@ -112,6 +206,7 @@ function gmInte.openConfigMenu(data)
local messagePanel = vgui.Create("DPanel", scrollPanel) local messagePanel = vgui.Create("DPanel", scrollPanel)
messagePanel:Dock(TOP) messagePanel:Dock(TOP)
messagePanel:SetSize(300, 60) messagePanel:SetSize(300, 60)
messagePanel:DockMargin(10, 0, 10, 10)
messagePanel:SetBackgroundColor(Color(0, 0, 0, 0)) messagePanel:SetBackgroundColor(Color(0, 0, 0, 0))
local messageLabel = vgui.Create("DLabel", messagePanel) local messageLabel = vgui.Create("DLabel", messagePanel)
@ -124,7 +219,7 @@ function gmInte.openConfigMenu(data)
// create DCollapsibleCategory // create DCollapsibleCategory
local collapsibleCategory = vgui.Create("DCollapsibleCategory", scrollPanel) local collapsibleCategory = vgui.Create("DCollapsibleCategory", scrollPanel)
collapsibleCategory:Dock(TOP) collapsibleCategory:Dock(TOP)
collapsibleCategory:DockMargin(0, 0, 0, 5) collapsibleCategory:DockMargin(10, 0, 10, 10)
collapsibleCategory:SetLabel(catName) collapsibleCategory:SetLabel(catName)
collapsibleCategory:SetExpanded(true) collapsibleCategory:SetExpanded(true)
@ -153,14 +248,14 @@ function gmInte.openConfigMenu(data)
if v.type == "textEntry" then if v.type == "textEntry" then
input = vgui.Create("DTextEntry", panel) input = vgui.Create("DTextEntry", panel)
input:SetText(v.value(data[k])) input:SetText(v.value(k, data[k]))
local isLastID = 0 local isLastID = 0
input.OnChange = function(self) input.OnChange = function(self)
isLastID = isLastID + 1 isLastID = isLastID + 1
local isLocalLastID = isLastID local isLocalLastID = isLastID
timer.Simple(v.onEditDelay || 0.5, function() timer.Simple(v.onEditDelay || 0.5, function()
if isLocalLastID == isLastID then if isLocalLastID == isLastID then
v.onEdit(self:GetValue()) v.onEdit(k, self:GetValue())
end end
end) end)
end end
@ -168,9 +263,9 @@ function gmInte.openConfigMenu(data)
input = vgui.Create("DComboBox", panel) input = vgui.Create("DComboBox", panel)
input:AddChoice("Enabled") input:AddChoice("Enabled")
input:AddChoice("Disabled") input:AddChoice("Disabled")
input:SetText(v.value(data[k]) && "Enabled" || "Disabled") input:SetText(v.value(k, data[k]) && "Enabled" || "Disabled")
input.OnSelect = function(self, index, value) input.OnSelect = function(self, index, value)
v.onEdit(value) v.onEdit(k, value)
end end
end end
@ -178,7 +273,7 @@ function gmInte.openConfigMenu(data)
input:SetSize(150, 25) input:SetSize(150, 25)
if v.description then if v.description then
panel:SetTooltip(v.description) input:SetTooltip(v.description)
end end
configList:AddItem(panel) configList:AddItem(panel)
@ -186,57 +281,31 @@ function gmInte.openConfigMenu(data)
end end
end end
local buttonsPanel = vgui.Create("DPanel", frame) // grid of buttons (2 buttons per row take 50% of the width)
buttonsPanel:Dock(BOTTOM) local buttonGrid = vgui.Create("DGrid", frame)
buttonsPanel:SetSize(300, 50) buttonGrid:Dock(BOTTOM)
buttonsPanel:SetBackgroundColor(Color(0, 0, 0, 0)) buttonGrid:DockMargin(5, 10, 5, 5)
buttonGrid:SetCols(2)
local buttonRows = {} buttonGrid:SetColWide(frame:GetWide() / 2 - 10)
local currentRow = nil buttonGrid:SetRowHeight(35)
for k, v in pairs(buttonsInfo) do for k, v in pairs(buttonsInfo) do
if k % 2 == 1 then local button = vgui.Create("DButton")
currentRow = vgui.Create("DPanel", buttonsPanel) button:SetText(v.label)
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() button.DoClick = function()
v.func() v.func()
end end
button:SetSize(buttonGrid:GetColWide(), buttonGrid:GetRowHeight())
buttonGrid:AddItem(button)
end 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", { list.Set("DesktopWindows", "GmodIntegration:DesktopWindows", {
icon = "icon64/gmodintegration.png", // use icon 'gear'
icon = "icon16/wrench.png",
title = "Gmod Integration", title = "Gmod Integration",
width = 100, width = 32,
height = 100, height = 32,
onewindow = true, onewindow = true,
init = function(icon, window) init = function(icon, window)
window:Close() window:Close()

View File

@ -25,7 +25,10 @@ function gmInte.showTestConnection(data)
end end
function gmInte.openAdminConfig() function gmInte.openAdminConfig()
if (!LocalPlayer():IsSuperAdmin()) then return end if (!LocalPlayer():IsSuperAdmin()) then
chat.AddText(Color(255, 130, 92), "[Gmod Integration] ", Color(102, 63, 63), "You are not superadmin")
return
end
gmInte.SendNet("2") gmInte.SendNet("2")
end end

View File

@ -22,7 +22,7 @@ end
function socket:onMessage(txt) function socket:onMessage(txt)
gmInte.log("WebSocket Message: " .. txt, true) gmInte.log("WebSocket Message: " .. txt, true)
local data = util.JSONToTable(txt) local data = util.JSONToTable(txt)
if (gmInte.debug) then if (gmInte.config.debug) then
gmInte.log("WebSocket Message: " .. txt, true) gmInte.log("WebSocket Message: " .. txt, true)
end end
if (gmInte[data.method]) then if (gmInte[data.method]) then

View File

@ -256,12 +256,8 @@ end
function gmInte.superadminSetConfig(ply, data) function gmInte.superadminSetConfig(ply, data)
if (!gmInte.plyValid(ply) || !ply:IsSuperAdmin()) then return end if (!gmInte.plyValid(ply) || !ply:IsSuperAdmin()) then return end
if data.id then for k, v in pairs(data) do
gmInte.saveSetting("id", data.id) gmInte.saveSetting(k, v)
end
if data.token then
gmInte.saveSetting("token", data.token)
end end
if data.token || data.id then if data.token || data.id then

View File

@ -46,7 +46,7 @@ local function sendHTTP(params)
success = function(code, body, headers) success = function(code, body, headers)
// Log the HTTP response // Log the HTTP response
gmInte.log("HTTP Response: " .. code, true) gmInte.log("HTTP Response: " .. code, true)
if (gmInte.debug) then gmInte.log("HTTP Body: " .. body, true) end if (gmInte.config.debug) then gmInte.log("HTTP Body: " .. body, true) end
// if body and is json extract it // if body and is json extract it
if (body && string.sub(headers["Content-Type"], 1, 16) == "application/json") then if (body && string.sub(headers["Content-Type"], 1, 16) == "application/json") then

View File

@ -4,27 +4,27 @@
// Log // Log
function gmInte.log(msg, debug) function gmInte.log(msg, debug)
if (debug && !gmInte.debug) then return end if (debug && !gmInte.config.debug) then return end
print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] " .. msg) print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] " .. msg)
end end
// Log Error // Log Error
function gmInte.logError(msg, debug) function gmInte.logError(msg, debug)
if (debug && !gmInte.debug) then return end if (debug && !gmInte.config.debug) then return end
print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] [ERROR] " .. msg) print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] [ERROR] " .. msg)
if (debug) then print(debug.traceback()) end if (debug) then print(debug.traceback()) end
end end
// Log Warning // Log Warning
function gmInte.logWarning(msg, debug) function gmInte.logWarning(msg, debug)
if (debug && !gmInte.debug) then return end if (debug && !gmInte.config.debug) then return end
print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] [WARNING] " .. msg) print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] [WARNING] " .. msg)
if (debug) then print(debug.traceback()) end if (debug) then print(debug.traceback()) end
end end
// Log Hint // Log Hint
function gmInte.logHint(msg, debug) function gmInte.logHint(msg, debug)
if (debug && !gmInte.debug) then return end if (debug && !gmInte.config.debug) then return end
print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] [HINT] " .. msg) print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] [HINT] " .. msg)
if (debug) then print(debug.traceback()) end if (debug) then print(debug.traceback()) end
end end

View File

@ -64,6 +64,7 @@ gmInte.config.chatTrigger = {
// Other // Other
gmInte.config.forcePlayerLink = false // If true, the addon will force the players to link their discord account to their steam account before playing gmInte.config.forcePlayerLink = false // If true, the addon will force the players to link their discord account to their steam account before playing
gmInte.config.supportLink = "" // The link of your support (shown when a player do not have the requiments to join the server) gmInte.config.supportLink = "" // The link of your support (shown when a player do not have the requiments to join the server)
gmInte.config.debug = false // If true, the addon will show debug informations in the console
// //
// Syncronization // Syncronization