From 90de28575c106017c2dc7a9340af1c00e9fc0a42 Mon Sep 17 00:00:00 2001 From: Linventif Date: Fri, 5 Jul 2024 21:50:00 +0000 Subject: [PATCH] refactor: now using glualint --- lua/autorun/gmod_integration.lua | 47 +- lua/gmod_integration/client/cl__color.lua | 11 +- .../client/cl_context_menu.lua | 11 +- lua/gmod_integration/client/cl_gui_admin.lua | 452 +++++++----------- lua/gmod_integration/client/cl_gui_link.lua | 14 +- lua/gmod_integration/client/cl_hook.lua | 18 +- lua/gmod_integration/client/cl_main.lua | 9 +- lua/gmod_integration/client/cl_materials.lua | 23 +- lua/gmod_integration/client/cl_net.lua | 42 +- .../client/cl_screenshots.lua | 118 ++--- lua/gmod_integration/client/cl_steaming.lua | 57 --- lua/gmod_integration/client/cl_sync_chat.lua | 5 +- lua/gmod_integration/server/sv__websocket.lua | 21 +- lua/gmod_integration/server/sv_con.lua | 44 +- lua/gmod_integration/server/sv_filtrers.lua | 76 +-- lua/gmod_integration/server/sv_net.lua | 61 +-- lua/gmod_integration/server/sv_players.lua | 193 +++----- .../server/sv_players_verif.lua | 26 +- lua/gmod_integration/server/sv_rcon.lua | 4 - lua/gmod_integration/server/sv_settings.lua | 54 +-- lua/gmod_integration/server/sv_status.lua | 28 +- lua/gmod_integration/server/sv_sync_bans.lua | 20 +- lua/gmod_integration/server/sv_sync_chat.lua | 28 +- lua/gmod_integration/server/sv_sync_kicks.lua | 22 +- lua/gmod_integration/server/sv_sync_names.lua | 33 +- lua/gmod_integration/server/sv_sync_roles.lua | 75 +-- lua/gmod_integration/server/sv_tokens.lua | 31 +- lua/gmod_integration/shared/sh_api_format.lua | 12 +- lua/gmod_integration/shared/sh_errors.lua | 47 +- lua/gmod_integration/shared/sh_http.lua | 27 +- lua/gmod_integration/shared/sh_main.lua | 43 +- .../shared/sh_player_meta.lua | 27 +- lua/gmod_integration/sv_config.lua | 32 +- 33 files changed, 498 insertions(+), 1213 deletions(-) delete mode 100644 lua/gmod_integration/client/cl_steaming.lua diff --git a/lua/autorun/gmod_integration.lua b/lua/autorun/gmod_integration.lua index ff8d2ef..dde10a2 100644 --- a/lua/autorun/gmod_integration.lua +++ b/lua/autorun/gmod_integration.lua @@ -1,30 +1,17 @@ -if (game.SinglePlayer()) then return print("Gmod Integration is not supported in Singleplayer!") end - -// -// Variables -// - +if game.SinglePlayer() then return print("Gmod Integration is not supported in Singleplayer!") end gmInte = gmInte || {} - gmInte.version = "0.3.6" gmInte.config = {} gmInte.materials = {} - -// -// Functions -// - local function loadServerConfig() RunConsoleCommand("sv_hibernate_think", "1") - - if (!file.Exists("gm_integration", "DATA") || !file.Exists("gm_integration/config.json", "DATA")) then + if !file.Exists("gm_integration", "DATA") || !file.Exists("gm_integration/config.json", "DATA") then file.CreateDir("gm_integration") file.Write("gm_integration/config.json", util.TableToJSON(gmInte.config, true)) else - if (gmInte.config.id && gmInte.config.id != "") then return end - + if gmInte.config.id && gmInte.config.id != "" then return end local oldConfig = util.JSONToTable(file.Read("gm_integration/config.json", "DATA")) - if (!oldConfig.version || (oldConfig.version < gmInte.version)) then + if !oldConfig.version || (oldConfig.version < gmInte.version) then print(" | Merging Config | gmod_integration/sv_config.lua") table.Merge(gmInte.config, oldConfig) gmInte.config.version = gmInte.version @@ -37,29 +24,26 @@ end local function loadAllFiles(folder) local files, folders = file.Find(folder .. "/*", "LUA") - for k, fileName in SortedPairs(files) do local path = folder .. "/" .. fileName print(" | Loading File | " .. path) - - if (string.StartWith(fileName, "cl_")) then + if string.StartWith(fileName, "cl_") then if SERVER then AddCSLuaFile(path) else include(path) end - elseif (string.StartWith(fileName, "sv_")) then - if SERVER then - include(path) - end - elseif (string.StartWith(fileName, "sh_")) then - if SERVER then - AddCSLuaFile(path) - end + elseif string.StartWith(fileName, "sv_") then + if SERVER then include(path) end + elseif string.StartWith(fileName, "sh_") then + if SERVER then AddCSLuaFile(path) end include(path) end - if (fileName == "sv_config.lua") then loadServerConfig() continue end + if fileName == "sv_config.lua" then + loadServerConfig() + continue + end end for k, v in SortedPairs(folders, true) do @@ -67,11 +51,6 @@ local function loadAllFiles(folder) end end - -// -// Load Files -// - print(" ") print(" ") print(" - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - ") diff --git a/lua/gmod_integration/client/cl__color.lua b/lua/gmod_integration/client/cl__color.lua index bb25a43..e9c1a92 100644 --- a/lua/gmod_integration/client/cl__color.lua +++ b/lua/gmod_integration/client/cl__color.lua @@ -23,19 +23,14 @@ function gmInte.getColor(name) end function gmInte.applyPaint(element, id) - if (element.DoClick) then + if element.DoClick then element:SetTextColor(gmInte.getColor("font")) - element.Paint = function(self, w, h) local color = gmInte.getColor("primary") - - if (self:IsHovered()) then - color = gmInte.getColor("primary-active") - end - + if self:IsHovered() then color = gmInte.getColor("primary-active") end draw.RoundedBox(0, 0, 0, w, h, color) end - elseif (element.SetTitle) then + elseif element.SetTitle then element.Paint = function(self, w, h) draw.RoundedBox(0, 0, 0, w, h, gmInte.getColor("background")) // first 20px = title bar = primary diff --git a/lua/gmod_integration/client/cl_context_menu.lua b/lua/gmod_integration/client/cl_context_menu.lua index 17c337e..f08fce5 100644 --- a/lua/gmod_integration/client/cl_context_menu.lua +++ b/lua/gmod_integration/client/cl_context_menu.lua @@ -1,12 +1,11 @@ list.Set("DesktopWindows", "GmodIntegration:DesktopWindows", { - icon = "gmod_integration/logo_context.png", + icon = "gmod_integration/logo_context.png", title = "GM Integration", - width = 960, - height = 700, - onewindow = true, + width = 960, + height = 700, + onewindow = true, init = function(icon, window) window:Close() gmInte.openAdminConfig() end - } -) \ No newline at end of file +}) \ No newline at end of file diff --git a/lua/gmod_integration/client/cl_gui_admin.lua b/lua/gmod_integration/client/cl_gui_admin.lua index f42887d..9484a33 100644 --- a/lua/gmod_integration/client/cl_gui_admin.lua +++ b/lua/gmod_integration/client/cl_gui_admin.lua @@ -8,7 +8,7 @@ local configCat = { "Authentication", "Main", "Trust & Safety", - -- "Punishment", + // "Punishment", "Advanced", } @@ -18,242 +18,210 @@ local possibleConfig = { ["label"] = "Server ID", ["description"] = "Server ID found on the webpanel.", ["type"] = "textEntry", - ["value"] = function(setting, value) - return value - end, - ["onEdit"] = function(setting, value) - saveConfig(setting, value) - end, + ["value"] = function(setting, value) return value end, + ["onEdit"] = function(setting, value) saveConfig(setting, value) end, ["onEditDelay"] = 0.5, ["category"] = "Authentication" }, { - ["id"]= "token", + ["id"] = "token", ["label"] = "Server Token", ["description"] = "Server Token found on the webpanel.", ["type"] = "textEntry", ["secret"] = true, - ["value"] = function(setting, value) - return value - end, - ["onEdit"] = function(setting, value) - saveConfig(setting, value) - end, + ["value"] = function(setting, value) return value end, + ["onEdit"] = function(setting, value) saveConfig(setting, value) end, ["onEditDelay"] = 0.5, ["category"] = "Authentication" }, - -- { - -- ["id"]= "sendLog", - -- ["label"] = "Logs", - -- ["description"] = "Activate or deactivate logs.", - -- ["type"] = "checkbox", - -- ["value"] = function(setting, value) - -- return value - -- end, - -- ["onEdit"] = function(setting, value) - -- saveConfig(setting, value == "Enabled" && true || false) - -- end, - -- ["category"] = "Main" - -- }, - -- { - -- ["id"]= "logBotActions", - -- ["label"] = "Log Bot Actions", - -- ["description"] = "Activate or deactivate logs for bot actions.", - -- ["type"] = "checkbox", - -- ["value"] = function(setting, value) - -- return value - -- end, - -- ["onEdit"] = function(setting, value) - -- saveConfig(setting, value == "Enabled" && true || false) - -- end, - -- ["category"] = "Main" - -- }, + // { + // ["id"]= "sendLog", + // ["label"] = "Logs", + // ["description"] = "Activate or deactivate logs.", + // ["type"] = "checkbox", + // ["value"] = function(setting, value) + // return value + // end, + // ["onEdit"] = function(setting, value) + // saveConfig(setting, value == "Enabled" && true || false) + // end, + // ["category"] = "Main" + // }, + // { + // ["id"]= "logBotActions", + // ["label"] = "Log Bot Actions", + // ["description"] = "Activate or deactivate logs for bot actions.", + // ["type"] = "checkbox", + // ["value"] = function(setting, value) + // return value + // end, + // ["onEdit"] = function(setting, value) + // saveConfig(setting, value == "Enabled" && true || false) + // end, + // ["category"] = "Main" + // }, { - ["id"]= "maintenance", + ["id"] = "maintenance", ["label"] = "Maintenance", ["description"] = "Activate or deactivate maintenance mode.", ["type"] = "checkbox", - ["value"] = function(setting, value) - return value - end, - ["onEdit"] = function(setting, value) - saveConfig(setting, value == "Enabled" && true || false) - end, + ["value"] = function(setting, value) return value end, + ["onEdit"] = function(setting, value) saveConfig(setting, value == "Enabled" && true || false) end, ["category"] = "Main" }, { - ["id"]= "filterOnBan", + ["id"] = "filterOnBan", ["label"] = "Block Discord Ban Player", ["description"] = "Block players banned on the discord server.", ["type"] = "checkbox", - ["value"] = function(setting, value) - return value - end, - ["onEdit"] = function(setting, value) - saveConfig(setting, value == "Enabled" && true || false) - end, + ["value"] = function(setting, value) return value end, + ["onEdit"] = function(setting, value) saveConfig(setting, value == "Enabled" && true || false) end, ["category"] = "Trust & Safety" }, - -- { - -- ["id"]= "filterOnTrust", - -- ["label"] = "Block UnTrust Player", - -- ["description"] = "Block players with a trust level lower than the minimal trust level set in the config.", - -- ["type"] = "checkbox", - -- ["value"] = function(setting, value) - -- return value - -- end, - -- ["onEdit"] = function(setting, value) - -- saveConfig(setting, value == "Enabled" && true || false) - -- end, - -- ["category"] = "Trust & Safety" - -- }, - -- { - -- ["id"]= "minimalTrust", - -- ["label"] = "Minimal Trust Level", - -- ["description"] = "The minimal trust level to be able to join the server.", - -- ["type"] = "textEntry", - -- ["value"] = function(setting, value) - -- return value - -- end, - -- ["onEdit"] = function(setting, value) - -- saveConfig(setting, value) - -- end, - -- ["onEditDelay"] = 0.5, - -- ["category"] = "Trust & Safety" - -- }, - -- { - -- ["id"]= "syncChat", - -- ["label"] = "Sync Chat", - -- ["description"] = "Sync chat between the server and the discord server.", - -- ["websocket"] = true, - -- ["restart"] = true, - -- ["type"] = "checkbox", - -- ["value"] = function(setting, value) - -- return value - -- end, - -- ["onEdit"] = function(setting, value) - -- saveConfig(setting, value == "Enabled" && true || false) - -- end, - -- ["category"] = "Main" - -- }, - -- { - -- ["id"]= "syncBan", - -- ["label"] = "Sync Ban", - -- ["description"] = "Sync chat between the server and the discord server.", - -- ["type"] = "checkbox", - -- ["condition"] = function(data) - -- return false // Disabled for now - -- end, - -- ["value"] = function(setting, value) - -- return value - -- end, - -- ["onEdit"] = function(setting, value) - -- saveConfig(setting, value == "Enabled" && true || false) - -- end, - -- ["category"] = "Punishment" - -- }, - -- { - -- ["id"]= "syncTimeout", - -- ["label"] = "Sync Timeout", - -- ["description"] = "Sync chat between the server and the discord server.", - -- ["type"] = "checkbox", - -- ["condition"] = function(data) - -- return false // Disabled for now - -- end, - -- ["value"] = function(setting, value) - -- return value - -- end, - -- ["onEdit"] = function(setting, value) - -- saveConfig(setting, value == "Enabled" && true || false) - -- end, - -- ["category"] = "Punishment" - -- }, - -- { - -- ["id"]= "syncKick", - -- ["label"] = "Sync Kick", - -- ["description"] = "Sync chat between the server and the discord server.", - -- ["type"] = "checkbox", - -- ["condition"] = function(data) - -- return false // Disabled for now - -- end, - -- ["value"] = function(setting, value) - -- return value - -- end, - -- ["onEdit"] = function(setting, value) - -- saveConfig(setting, value == "Enabled" && true || false) - -- end, - -- ["category"] = "Punishment" - -- }, + // { + // ["id"]= "filterOnTrust", + // ["label"] = "Block UnTrust Player", + // ["description"] = "Block players with a trust level lower than the minimal trust level set in the config.", + // ["type"] = "checkbox", + // ["value"] = function(setting, value) + // return value + // end, + // ["onEdit"] = function(setting, value) + // saveConfig(setting, value == "Enabled" && true || false) + // end, + // ["category"] = "Trust & Safety" + // }, + // { + // ["id"]= "minimalTrust", + // ["label"] = "Minimal Trust Level", + // ["description"] = "The minimal trust level to be able to join the server.", + // ["type"] = "textEntry", + // ["value"] = function(setting, value) + // return value + // end, + // ["onEdit"] = function(setting, value) + // saveConfig(setting, value) + // end, + // ["onEditDelay"] = 0.5, + // ["category"] = "Trust & Safety" + // }, + // { + // ["id"]= "syncChat", + // ["label"] = "Sync Chat", + // ["description"] = "Sync chat between the server and the discord server.", + // ["websocket"] = true, + // ["restart"] = true, + // ["type"] = "checkbox", + // ["value"] = function(setting, value) + // return value + // end, + // ["onEdit"] = function(setting, value) + // saveConfig(setting, value == "Enabled" && true || false) + // end, + // ["category"] = "Main" + // }, + // { + // ["id"]= "syncBan", + // ["label"] = "Sync Ban", + // ["description"] = "Sync chat between the server and the discord server.", + // ["type"] = "checkbox", + // ["condition"] = function(data) + // return false // Disabled for now + // end, + // ["value"] = function(setting, value) + // return value + // end, + // ["onEdit"] = function(setting, value) + // saveConfig(setting, value == "Enabled" && true || false) + // end, + // ["category"] = "Punishment" + // }, + // { + // ["id"]= "syncTimeout", + // ["label"] = "Sync Timeout", + // ["description"] = "Sync chat between the server and the discord server.", + // ["type"] = "checkbox", + // ["condition"] = function(data) + // return false // Disabled for now + // end, + // ["value"] = function(setting, value) + // return value + // end, + // ["onEdit"] = function(setting, value) + // saveConfig(setting, value == "Enabled" && true || false) + // end, + // ["category"] = "Punishment" + // }, + // { + // ["id"]= "syncKick", + // ["label"] = "Sync Kick", + // ["description"] = "Sync chat between the server and the discord server.", + // ["type"] = "checkbox", + // ["condition"] = function(data) + // return false // Disabled for now + // end, + // ["value"] = function(setting, value) + // return value + // end, + // ["onEdit"] = function(setting, value) + // saveConfig(setting, value == "Enabled" && true || false) + // end, + // ["category"] = "Punishment" + // }, { - ["id"]= "forcePlayerLink", + ["id"] = "forcePlayerLink", ["label"] = "Force Player Verif", ["description"] = "Sync 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, + ["value"] = function(setting, value) return value end, + ["onEdit"] = function(setting, value) saveConfig(setting, value == "Enabled" && true || false) end, ["category"] = "Main" }, { - ["id"]= "supportLink", + ["id"] = "supportLink", ["label"] = "Support Link", ["description"] = "Server ID found on the webpanel.", ["type"] = "textEntry", - ["value"] = function(setting, value) - return value - end, - ["onEdit"] = function(setting, value) - saveConfig(setting, value) - end, + ["value"] = function(setting, value) return value end, + ["onEdit"] = function(setting, value) saveConfig(setting, value) end, ["onEditDelay"] = 0.5, ["category"] = "Trust & Safety" }, { - ["id"]= "debug", + ["id"] = "debug", ["label"] = "Debug", ["description"] = "Activate or deactivate debug mode.", ["type"] = "checkbox", - ["value"] = function(setting, value) - return value - end, + ["value"] = function(setting, value) return value end, ["position"] = 1, - ["onEdit"] = function(setting, value) - saveConfig(setting, value == "Enabled" && true || false) - end, + ["onEdit"] = function(setting, value) saveConfig(setting, value == "Enabled" && true || false) end, ["category"] = "Advanced" }, { - ["id"]= "websocketFQDN", + ["id"] = "websocketFQDN", ["label"] = "Websocket FQDN", ["description"] = "Websocket FQDN that will be used for the Websocket connection.", ["type"] = "textEntry", - ["value"] = function(setting, value) - return value - end, + ["value"] = function(setting, value) return value end, ["resetIfEmpty"] = true, ["defaultValue"] = "ws.gmod-integration.com", ["onEdit"] = function(setting, value) - if (!value || value == "") then return end + if !value || value == "" then return end saveConfig(setting, value) end, ["onEditDelay"] = 0.5, ["category"] = "Advanced" }, { - ["id"]= "apiFQDN", + ["id"] = "apiFQDN", ["label"] = "API FQDN", ["description"] = "API FQDN that will be used for the API connection.", ["type"] = "textEntry", ["resetIfEmpty"] = true, ["defaultValue"] = "api.gmod-integration.com", - ["value"] = function(setting, value) - return value - end, + ["value"] = function(setting, value) return value end, ["onEdit"] = function(setting, value) - if (!value || value == "") then return end + if !value || value == "" then return end saveConfig(setting, value) end, ["onEditDelay"] = 0.5, @@ -264,42 +232,32 @@ local possibleConfig = { local buttonsInfo = { { ["label"] = "Open Webpanel", - ["func"] = function() - gui.OpenURL("https://gmod-integration.com/config/server") - end, + ["func"] = function() gui.OpenURL("https://gmod-integration.com/config/server") end, }, { ["label"] = "Test Connection", - ["func"] = function() - gmInte.SendNet("testConnection") - end, + ["func"] = function() gmInte.SendNet("testConnection") end, }, { ["label"] = "Buy Premium", - ["func"] = function() - gui.OpenURL("https://gmod-integration.com/premium") - end, + ["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, + ["condition"] = function(data) return !data.websocket end, + ["func"] = function() gui.OpenURL("https://github.com/FredyH/GWSockets/releases") end, }, - -- { - -- ["label"] = "Load Server Config", - -- ["condition"] = function(data) - -- return data.debug - -- end, - -- ["func"] = function(data) - -- gmInte.config = data - -- end, - -- } } +// { +// ["label"] = "Load Server Config", +// ["condition"] = function(data) +// return data.debug +// end, +// ["func"] = function(data) +// gmInte.config = data +// end, +// } local colorTable = { ["text"] = Color(255, 255, 255, 255), ["background"] = Color(0, 0, 0, 200), @@ -318,52 +276,44 @@ function gmInte.needRestart() frame:ShowCloseButton(true) frame:MakePopup() gmInte.applyPaint(frame) - local messagePanel = vgui.Create("DPanel", frame) messagePanel:Dock(TOP) messagePanel:SetSize(300, 40) messagePanel:DockMargin(10, 0, 10, 10) messagePanel:SetBackgroundColor(Color(0, 0, 0, 0)) - local messageLabel = vgui.Create("DLabel", messagePanel) messageLabel:Dock(FILL) messageLabel:SetText("Some changes require a restart to be applied.\nRestart now ?") messageLabel:SetContentAlignment(5) messageLabel:SetWrap(true) - local buttonGrid = vgui.Create("DGrid", frame) buttonGrid:Dock(BOTTOM) buttonGrid:DockMargin(5, 10, 5, 5) buttonGrid:SetCols(2) buttonGrid:SetColWide(frame:GetWide() / 2 - 5) buttonGrid:SetRowHeight(35) - local button = vgui.Create("DButton") button:SetText("Restart") button.DoClick = function() frame:Close() gmInte.SendNet("restartMap") end - button:SetSize(buttonGrid:GetColWide() -10, buttonGrid:GetRowHeight()) + + button:SetSize(buttonGrid:GetColWide() - 10, buttonGrid:GetRowHeight()) gmInte.applyPaint(button) buttonGrid:AddItem(button) - local button = vgui.Create("DButton") button:SetText("Maybe Later") - button.DoClick = function() - frame:Close() - end - button:SetSize(buttonGrid:GetColWide() -10, buttonGrid:GetRowHeight()) + button.DoClick = function() frame:Close() end + button:SetSize(buttonGrid:GetColWide() - 10, buttonGrid:GetRowHeight()) gmInte.applyPaint(button) buttonGrid:AddItem(button) end function gmInte.openConfigMenu(data) local needRestart = false - - if (gmInte.openAdminPanel) then return end + if gmInte.openAdminPanel then return end gmInte.openAdminPanel = true - local frame = vgui.Create("DFrame") frame:SetSize(400, (600 / 1080) * ScrH()) frame:Center() @@ -372,21 +322,17 @@ function gmInte.openConfigMenu(data) frame:ShowCloseButton(true) frame:MakePopup() gmInte.applyPaint(frame) - local scrollPanel = vgui.Create("DScrollPanel", frame) scrollPanel:Dock(FILL) - local messagePanel = vgui.Create("DPanel", scrollPanel) messagePanel:Dock(TOP) messagePanel:SetSize(300, 60) messagePanel:DockMargin(10, 0, 10, 10) messagePanel:SetBackgroundColor(Color(0, 0, 0, 0)) - local messageLabel = vgui.Create("DLabel", messagePanel) messageLabel:Dock(FILL) messageLabel:SetText("Here you can configure your server settings.\nServer ID and Token are available on the webpanel in the server settings.\nThe documentation is available at https://docs.gmod-integration.com/\nIf you need help, please contact us on our discord server.") messageLabel:SetWrap(true) - for k, catName in pairs(configCat) do local collapsibleCategory = vgui.Create("DCollapsibleCategory", scrollPanel) collapsibleCategory:Dock(TOP) @@ -394,98 +340,69 @@ function gmInte.openConfigMenu(data) collapsibleCategory:SetLabel(catName) collapsibleCategory:SetExpanded(true) gmInte.applyPaint(collapsibleCategory) - local configList = vgui.Create("DPanelList", collapsibleCategory) configList:Dock(FILL) configList:SetSpacing(5) configList:EnableHorizontal(false) configList:EnableVerticalScrollbar(false) collapsibleCategory:SetContents(configList) - local categoryConfig = {} for k, v in pairs(possibleConfig) do - if v.category == catName then - table.insert(categoryConfig, v) - end + if v.category == catName then table.insert(categoryConfig, v) end end // Sort by position - table.sort(categoryConfig, function(a, b) - return (a.position || 0) < (b.position || 0) - end) - + table.sort(categoryConfig, function(a, b) return (a.position || 0) < (b.position || 0) end) for k, actualConfig in pairs(categoryConfig) do 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(actualConfig.label) label:SetContentAlignment(4) - local input - if actualConfig.type == "textEntry" then input = vgui.Create("DTextEntry", panel) local value = actualConfig.value(actualConfig.id, data[actualConfig.id] || "") - if (actualConfig.secret) then + if actualConfig.secret then input:SetText("*** Click to show ***") else input:SetText(value) end - input.OnGetFocus = function(self) - if (actualConfig.secret) then - self:SetText(value) - end - end - input.OnLoseFocus = function(self) - if (actualConfig.secret) then - self:SetText("*** Click to show ***") - end - end + + input.OnGetFocus = function(self) if actualConfig.secret then self:SetText(value) end end + input.OnLoseFocus = function(self) if actualConfig.secret then self:SetText("*** Click to show ***") end end local isLastID = 0 input.OnChange = function(self) - if (actualConfig.resetIfEmpty && self:GetValue() == "" && actualConfig.defaultValue) then + if actualConfig.resetIfEmpty && self:GetValue() == "" && actualConfig.defaultValue then self:SetText(actualConfig.defaultValue) return end + isLastID = isLastID + 1 local isLocalLastID = isLastID - timer.Simple(actualConfig.onEditDelay || 0.5, function() - if isLocalLastID == isLastID then - actualConfig.onEdit(actualConfig.id, self:GetValue()) - end - end) + timer.Simple(actualConfig.onEditDelay || 0.5, function() if isLocalLastID == isLastID then actualConfig.onEdit(actualConfig.id, self:GetValue()) end end) end - elseif (actualConfig.type == "checkbox") then + elseif actualConfig.type == "checkbox" then input = vgui.Create("DComboBox", panel) - if (actualConfig.condition && !actualConfig.condition(data)) then - input:SetEnabled(false) - end + if actualConfig.condition && !actualConfig.condition(data) then input:SetEnabled(false) end input:AddChoice("Enabled") input:AddChoice("Disabled") input:SetText(actualConfig.value(actualConfig.id, data[actualConfig.id]) && "Enabled" || "Disabled") input.OnSelect = function(self, index, value) - if (actualConfig.restart) then - needRestart = true - end + if actualConfig.restart then needRestart = true end actualConfig.onEdit(actualConfig.id, value) end end input:Dock(FILL) input:SetSize(150, 25) - - if (actualConfig.description) then - if (actualConfig.websocket && !data.websocket) then - actualConfig.description = actualConfig.description .. "\n\nThis feature require a websocket connection to work properly." - end - if (actualConfig.disable) then - actualConfig.description = actualConfig.description .. "\n\nThis feature will be available soon." - end + if actualConfig.description then + if actualConfig.websocket && !data.websocket then actualConfig.description = actualConfig.description .. "\n\nThis feature require a websocket connection to work properly." end + if actualConfig.disable then actualConfig.description = actualConfig.description .. "\n\nThis feature will be available soon." end input:SetTooltip(actualConfig.description) end @@ -499,35 +416,28 @@ function gmInte.openConfigMenu(data) buttonGrid:SetCols(2) buttonGrid:SetColWide(frame:GetWide() / 2 - 5) buttonGrid:SetRowHeight(45) - local buttonsCount = 0 for k, v in pairs(buttonsInfo) do - if (v.condition && !v.condition(data)) then continue end + if v.condition && !v.condition(data) then continue end local button = vgui.Create("DButton") button:SetText(v.label) - button.DoClick = function() - v.func(data) - end + button.DoClick = function() v.func(data) end gmInte.applyPaint(button) button:SetSize(buttonGrid:GetColWide() - 10, buttonGrid:GetRowHeight() - 10) buttonGrid:AddItem(button) buttonsCount = buttonsCount + 1 end - if (buttonsCount % 2 == 1) then + if buttonsCount % 2 == 1 then local lastButton = buttonGrid:GetItems()[buttonsCount] lastButton:SetWide(frame:GetWide() - 20) end frame.OnClose = function() gmInte.openAdminPanel = false - if (needRestart) then gmInte.needRestart() end + if needRestart then gmInte.needRestart() end end end -// -// Concommands -// - concommand.Add("gmod_integration_admin", function() gmInte.SendNet("getConfig") end) concommand.Add("gmi_admin", function() gmInte.SendNet("getConfig") end) \ No newline at end of file diff --git a/lua/gmod_integration/client/cl_gui_link.lua b/lua/gmod_integration/client/cl_gui_link.lua index 18be09b..b37481d 100644 --- a/lua/gmod_integration/client/cl_gui_link.lua +++ b/lua/gmod_integration/client/cl_gui_link.lua @@ -7,7 +7,6 @@ function gmInte.openVerifPopup() frame:ShowCloseButton(false) frame:MakePopup() gmInte.applyPaint(frame) - local messageLabel = vgui.Create("DLabel", frame) messageLabel:Dock(FILL) messageLabel:DockMargin(10, 0, 10, 0) @@ -15,34 +14,27 @@ function gmInte.openVerifPopup() messageLabel:SetContentAlignment(5) messageLabel:SetFont("GmodIntegration_Roboto_16") messageLabel:SetWrap(true) - local buttonGrid = vgui.Create("DGrid", frame) buttonGrid:Dock(BOTTOM) buttonGrid:DockMargin(10, 0, 10, 10) buttonGrid:SetCols(2) buttonGrid:SetColWide(frame:GetWide() / 2 - 10) buttonGrid:SetRowHeight(35) - local button = vgui.Create("DButton") button:SetText("Open Verification Page") - button.DoClick = function() - gui.OpenURL("https://verif.gmod-integration.com") - end + button.DoClick = function() gui.OpenURL("https://verif.gmod-integration.com") end button:SetSize(buttonGrid:GetColWide() - 10, buttonGrid:GetRowHeight()) gmInte.applyPaint(button) buttonGrid:AddItem(button) - local button = vgui.Create("DButton") button:SetText("Refresh Verification") button.DoClick = function() gmInte.http.get("/users?steamID64" .. LocalPlayer():SteamID64(), function(code, body) gmInte.SendNet("verifyMe") frame:Close() - end, - function(code, body) - LocalPlayer():ChatPrint("Failed to refresh verification: " .. code) - end) + end, function(code, body) LocalPlayer():ChatPrint("Failed to refresh verification: " .. code) end) end + button:SetSize(buttonGrid:GetColWide() - 10, buttonGrid:GetRowHeight()) gmInte.applyPaint(button) buttonGrid:AddItem(button) diff --git a/lua/gmod_integration/client/cl_hook.lua b/lua/gmod_integration/client/cl_hook.lua index abb5fb1..3ffbdef 100644 --- a/lua/gmod_integration/client/cl_hook.lua +++ b/lua/gmod_integration/client/cl_hook.lua @@ -1,19 +1,9 @@ -// -// Hook -// - -// Player Finish Init -hook.Add("InitPostEntity", "gmInte:Ply:Ready", function() - gmInte.SendNet("ready") -end) - +hook.Add("InitPostEntity", "gmInte:Ply:Ready", function() gmInte.SendNet("ready") end) hook.Add("OnPlayerChat", "gmInte:OnPlayerChat:AdminCmd", function(ply, strText, bTeamOnly, bPlayerIsDead) - if (ply != LocalPlayer()) then return end - + if ply != LocalPlayer() then return end strText = string.lower(strText) - - if (strText == "/gmi") then - gmInte.openAdminConfig() + if strText == "/gmi" then + gmInte.openAdminConfig() return true end end) \ No newline at end of file diff --git a/lua/gmod_integration/client/cl_main.lua b/lua/gmod_integration/client/cl_main.lua index 4214890..923800a 100644 --- a/lua/gmod_integration/client/cl_main.lua +++ b/lua/gmod_integration/client/cl_main.lua @@ -1,18 +1,15 @@ -// -// Main -// - function gmInte.chatAddText(data) local args = {} for _, v in ipairs(data) do table.insert(args, v.color) table.insert(args, v.text) end + chat.AddText(unpack(args)) end function gmInte.showTestConnection(data) - if (data && data.id) then + 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") @@ -20,7 +17,7 @@ function gmInte.showTestConnection(data) end function gmInte.openAdminConfig() - if (!LocalPlayer():IsSuperAdmin()) then + if !LocalPlayer():IsSuperAdmin() then chat.AddText(Color(255, 130, 92), "[Gmod Integration] ", Color(102, 63, 63), "You are not superadmin") return end diff --git a/lua/gmod_integration/client/cl_materials.lua b/lua/gmod_integration/client/cl_materials.lua index 958400b..87a1193 100644 --- a/lua/gmod_integration/client/cl_materials.lua +++ b/lua/gmod_integration/client/cl_materials.lua @@ -1,21 +1,8 @@ -// -// Variables -// - local ImageCache = {} - -// -// Functions -// - function gmInte.createImgurMaterials(materials, addon_var, folder, name) - if !file.Exists(folder, "DATA") then - file.CreateDir(folder) - end - + 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") @@ -30,6 +17,7 @@ function gmInte.createImgurMaterials(materials, addon_var, folder, name) ["addon_var"] = addon_var, ["id"] = id } + gmInte.log("materials", name .. " - Image Downloaded - " .. id .. ".png") end) end @@ -46,12 +34,9 @@ function gmInte.redowloadMaterials() end end -concommand.Add("gmod_integration_reload_materials", function() - gmInte.redowloadMaterials() -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") +gmInte.createImgurMaterials(materialsList, gmInte.materials, "gmod_integration/material", "Gmod Integration") \ No newline at end of file diff --git a/lua/gmod_integration/client/cl_net.lua b/lua/gmod_integration/client/cl_net.lua index 8f85484..a300e82 100644 --- a/lua/gmod_integration/client/cl_net.lua +++ b/lua/gmod_integration/client/cl_net.lua @@ -1,7 +1,3 @@ -// -// Send Net -// - local netSend = { ["ready"] = 0, ["testConnection"] = 1, @@ -14,44 +10,28 @@ local netSend = { function gmInte.SendNet(id, args, func) net.Start("gmIntegration") - net.WriteUInt(netSend[id], 8) - net.WriteString(util.TableToJSON(args || {})) - if (func) then func() end + net.WriteUInt(netSend[id], 8) + net.WriteString(util.TableToJSON(args || {})) + if func then func() end net.SendToServer() end -// -// Receive Net -// - local netReceive = { - [1] = function(data) - gmInte.discordSyncChatPly(data) - end, - [2] = function(data) - gmInte.openConfigMenu(data) - end, - [3] = function(data) - gmInte.showTestConnection(data) - end, + [1] = function(data) gmInte.discordSyncChatPly(data) end, + [2] = function(data) gmInte.openConfigMenu(data) end, + [3] = function(data) gmInte.showTestConnection(data) end, [5] = function(data) gmInte.config = table.Merge(gmInte.config, data.config) gmInte.version = data.other.version - if (!data.other.aprovedCredentials) then RunConsoleCommand("gmod_integration_admin") end + if !data.other.aprovedCredentials then RunConsoleCommand("gmod_integration_admin") end end, - [6] = function(data) - gmInte.chatAddText(data) - end, - [7] = function() - gmInte.openVerifPopup() - end, - [8] = function(data) - gmInte.config.token = data.token - end + [6] = function(data) gmInte.chatAddText(data) end, + [7] = function() gmInte.openVerifPopup() end, + [8] = function(data) gmInte.config.token = data.token end } net.Receive("gmIntegration", function() local id = net.ReadUInt(8) local args = util.JSONToTable(net.ReadString()) - if (netReceive[id]) then netReceive[id](args) end + if netReceive[id] then netReceive[id](args) end end) \ No newline at end of file diff --git a/lua/gmod_integration/client/cl_screenshots.lua b/lua/gmod_integration/client/cl_screenshots.lua index 4b486e6..660b24b 100644 --- a/lua/gmod_integration/client/cl_screenshots.lua +++ b/lua/gmod_integration/client/cl_screenshots.lua @@ -1,88 +1,58 @@ -// -// Hooks -// - local ScreenshotRequested = false local FailAttempts = 0 hook.Add("PostRender", "gmInteScreenshot", function() - if (!ScreenshotRequested) then return end - ScreenshotRequested = false + if !ScreenshotRequested then return end + ScreenshotRequested = false + local captureData = { + format = "jpeg", + x = 0, + y = 0, + w = ScrW(), + h = ScrH(), + quality = 95, + } - local captureData = { - format = "jpeg", - x = 0, - y = 0, - w = ScrW(), - h = ScrH(), - quality = 95, - } - - local screenCapture = render.Capture(captureData) - if (!screenCapture) then - if (FailAttempts < 3) then - timer.Simple(0.5, function() - ScreenshotRequested = true - FailAttempts = FailAttempts + 1 - gmInte.log("Failed to take screenshot, retrying... (" .. FailAttempts .. "/3)", true) - end) - return - else - FailAttempts = 0 - chat.AddText(Color(255, 130, 92), "[Gmod Integration] ", Color(102, 63, 63), "Failed to take screenshot, your system may not support this feature.") - return - end + local screenCapture = render.Capture(captureData) + if !screenCapture then + if FailAttempts < 3 then + timer.Simple(0.5, function() + ScreenshotRequested = true + FailAttempts = FailAttempts + 1 + gmInte.log("Failed to take screenshot, retrying... (" .. FailAttempts .. "/3)", true) + end) + return + else + FailAttempts = 0 + chat.AddText(Color(255, 130, 92), "[Gmod Integration] ", Color(102, 63, 63), "Failed to take screenshot, your system may not support this feature.") + return end + end - local base64Capture = util.Base64Encode(screenCapture) - - local size = math.Round(string.len(base64Capture) / 1024) - gmInte.log("Screenshot Taken - " .. size .. "KB", true) - - gmInte.http.post("/clients/:steamID64/servers/:serverID/screenshots", - { - ["player"] = gmInte.getPlayerFormat(LocalPlayer()), - ["screenshot"] = base64Capture, - ["captureData"] = captureData, - ["size"] = size .. "KB" - }, - function(code, body) - gmInte.log("Screenshot sent to Discord", true) - chat.AddText(Color(255, 130, 92), "[Gmod Integration] ", Color(255, 255, 255), "Screenshot sent to Discord.") - end, - function(code, body) - gmInte.log("Screenshot failed to send to Discord, error code: " .. code, true) - end - ) + local base64Capture = util.Base64Encode(screenCapture) + local size = math.Round(string.len(base64Capture) / 1024) + gmInte.log("Screenshot Taken - " .. size .. "KB", true) + gmInte.http.post("/clients/:steamID64/servers/:serverID/screenshots", { + ["player"] = gmInte.getPlayerFormat(LocalPlayer()), + ["screenshot"] = base64Capture, + ["captureData"] = captureData, + ["size"] = size .. "KB" + }, function(code, body) + gmInte.log("Screenshot sent to Discord", true) + chat.AddText(Color(255, 130, 92), "[Gmod Integration] ", Color(255, 255, 255), "Screenshot sent to Discord.") + end, function(code, body) gmInte.log("Screenshot failed to send to Discord, error code: " .. code, true) end) end) -// -// Methods -// - function gmInte.takeScreenShot() - timer.Simple(0.5, function() - ScreenshotRequested = true - end) + timer.Simple(0.5, function() ScreenshotRequested = true end) end -// -// Console Commands -// - -concommand.Add("gmod_integration_screenshot", gmInte.takeScreenShot) concommand.Add("gmi_screen", gmInte.takeScreenShot) - -// -// Chat Commands -// - hook.Add("OnPlayerChat", "gmInteChatCommands", function(ply, text, teamChat, isDead) - if (ply != LocalPlayer()) then return end - text = string.lower(text) - text = string.sub(text, 2) - - if (text == "screen") then - gmInte.takeScreenShot() - return true - end + if ply != LocalPlayer() then return end + text = string.lower(text) + text = string.sub(text, 2) + if text == "screen" then + gmInte.takeScreenShot() + return true + end end) \ No newline at end of file diff --git a/lua/gmod_integration/client/cl_steaming.lua b/lua/gmod_integration/client/cl_steaming.lua deleted file mode 100644 index 816cd6d..0000000 --- a/lua/gmod_integration/client/cl_steaming.lua +++ /dev/null @@ -1,57 +0,0 @@ -// -// Hooks -// - -local StreamsRequeted = false -hook.Add("PostRender", "gmInte:PostRender:Stream:Frame", function() - if (!StreamsRequeted) then return end - StreamsRequeted = false - - // Capture frame - local captureConfig = { - format = "jpeg", - x = 0, - y = 0, - w = ScrW(), - h = ScrH(), - quality = 30, - } - - local screenCapture = render.Capture(captureConfig) - if (!screenCapture) then return end - screenCapture = util.Base64Encode(screenCapture) - - local size = math.Round(string.len(screenCapture) / 1024) - gmInte.log("Frame captured, size: " .. size .. "KB", true) - - gmInte.http.post("/clients/:steamID64/servers/:serverID/streams/frames", - { - ["player"] = gmInte.getPlayerFormat(LocalPlayer()), - ["base64Capture"] = screenCapture, - ["captureConfig"] = captureConfig, - ["size"] = size .. "KB" - }, - function(code, body) - gmInte.log("Frame sent to WebPanel, size: " .. size .. "KB", true) - end, - function(code, body) - gmInte.log("Failed to send frame to WebPanel", true) - end - ) -end) - -local Steam = false -timer.Create("gmInte:Stream:Frame", 0.5, 0, function() - if (Steam) then - StreamsRequeted = true - end -end) - -// -// Console Commands -// - -concommand.Add("gmod_integration_stream", function() - Steam = !Steam - gmInte.log("Streaming frames to WebPanel: " .. tostring(Steam)) -end) \ No newline at end of file diff --git a/lua/gmod_integration/client/cl_sync_chat.lua b/lua/gmod_integration/client/cl_sync_chat.lua index 3a3f891..6a641f8 100644 --- a/lua/gmod_integration/client/cl_sync_chat.lua +++ b/lua/gmod_integration/client/cl_sync_chat.lua @@ -1,10 +1,7 @@ local function formatName(name) - // all un down case name = string.lower(name) - // first leter in upper case name = string.upper(string.sub(name, 1, 1)) .. string.sub(name, 2) - // every letter after a space in upper case - name = string.gsub(name, "(%a)([%w_']*)", function(a,b) return string.upper(a) .. string.lower(b) end) + name = string.gsub(name, "(%a)([%w_']*)", function(a, b) return string.upper(a) .. string.lower(b) end) return name end diff --git a/lua/gmod_integration/server/sv__websocket.lua b/lua/gmod_integration/server/sv__websocket.lua index 540f76d..1325450 100644 --- a/lua/gmod_integration/server/sv__websocket.lua +++ b/lua/gmod_integration/server/sv__websocket.lua @@ -1,15 +1,8 @@ -// -// WebSocket -// - local function websocketDLLExist() local files, _ = file.Find("lua/bin/*", "GAME") for k, v in pairs(files) do - if (v:find("gwsockets")) then - return true - end + if v:find("gwsockets") then return true end end - return false end @@ -22,18 +15,14 @@ if !websocketDLLExist() then end require("gwsockets") - local function getWebSocketURL() local method = gmInte.isPrivateIP(gmInte.config.websocketFQDN) && "ws" || "wss" return method .. "://" .. gmInte.config.websocketFQDN end local socket = GWSockets.createWebSocket(getWebSocketURL()) - -// Authentication socket:setHeader("id", gmInte.config.id) socket:setHeader("token", gmInte.config.token) - function gmInte.resetWebSocket() socket:closeNow() socket = GWSockets.createWebSocket(getWebSocketURL()) @@ -47,12 +36,10 @@ function socket:onConnected() gmInte.log("WebSocket Connected", true) end -// log on message function socket:onMessage(txt) gmInte.log("WebSocket Message: " .. txt, true) - local data = util.JSONToTable(txt) - if (gmInte[data.method]) then + if gmInte[data.method] then gmInte[data.method](data) else gmInte.logError("WebSocket Message: " .. txt .. " is not a valid method !", true) @@ -60,7 +47,7 @@ function socket:onMessage(txt) end function socket:onDisconnected() - if (hasConnected) then + if hasConnected then hasConnected = false gmInte.log("WebSocket Disconnected", true) else @@ -73,7 +60,7 @@ function socket:onError(txt) end timer.Create("gmInte:WebSocket:CheckConnection", 4, 0, function() - if (!socket:isConnected()) then + if !socket:isConnected() then gmInte.resetWebSocket() socket:open() end diff --git a/lua/gmod_integration/server/sv_con.lua b/lua/gmod_integration/server/sv_con.lua index 4bae5d6..8c6f842 100644 --- a/lua/gmod_integration/server/sv_con.lua +++ b/lua/gmod_integration/server/sv_con.lua @@ -1,50 +1,22 @@ local conFuncs = { - ["version"] = function() - gmInte.log("Version: " .. gmInte.version) - end, - ["setting"] = function(args) - gmInte.saveSetting(args[2], args[3]) - end, - ["try"] = function() - gmInte.tryConfig() - end, - ["refresh"] = function() - gmInte.refreshSettings() - end, - ["get-server-id"] = function() - print(gmInte.config.id || "none") - end, + ["version"] = function() gmInte.log("Version: " .. gmInte.version) end, + ["setting"] = function(args) gmInte.saveSetting(args[2], args[3]) end, + ["try"] = function() gmInte.tryConfig() end, + ["refresh"] = function() gmInte.refreshSettings() end, + ["get-server-id"] = function() print(gmInte.config.id || "none") end, ["screenshot"] = function(args) - if (!args[2]) then return gmInte.log("No SteamID64 provided") end + if !args[2] then return gmInte.log("No SteamID64 provided") end for _, ply in pairs(player.GetAll()) do - if (ply:SteamID64() == args[2]) then return gmInte.takeScreenshot(ply) end + if ply:SteamID64() == args[2] then return gmInte.takeScreenshot(ply) end end end, } -concommand.Add("gmod-integration", function(ply, cmd, args) - // only usable by server console and superadmins +concommand.Add("gmi", function(ply, cmd, args) if ply:IsPlayer() && !ply:IsSuperAdmin() then return end - - // check if argument is valid if conFuncs[args[1]] then conFuncs[args[1]](args) else gmInte.log("Unknown Command Argument") end -end) - -concommand.Add("gm_integration", function(ply, cmd, args) - // run the old command - RunConsoleCommand("gmod-integration", unpack(args)) -end) - -concommand.Add("gmod_integration", function(ply, cmd, args) - // run the old command - RunConsoleCommand("gmod-integration", unpack(args)) -end) - -concommand.Add("gm-integration", function(ply, cmd, args) - // run the old command - RunConsoleCommand("gmod-integration", unpack(args)) end) \ No newline at end of file diff --git a/lua/gmod_integration/server/sv_filtrers.lua b/lua/gmod_integration/server/sv_filtrers.lua index 066c426..3693042 100644 --- a/lua/gmod_integration/server/sv_filtrers.lua +++ b/lua/gmod_integration/server/sv_filtrers.lua @@ -1,86 +1,38 @@ -// -// Methods -// - local function filterMessage(reason) - local Message = { - "\n----------------------------------------\n", - "You cannot join this server", - "", - "Reason: " .. (reason && reason || "none"), - "Help URL: " .. (gmInte.config.supportLink && gmInte.config.supportLink || "none"), - "", - "Have a nice day", - "\n----------------------------------------\n", - "Service provided by Gmod Integration", - } - + local Message = {"\n----------------------------------------\n", "You cannot join this server", "", "Reason: " .. (reason && reason || "none"), "Help URL: " .. (gmInte.config.supportLink && gmInte.config.supportLink || "none"), "", "Have a nice day", "\n----------------------------------------\n", "Service provided by Gmod Integration",} for k, v in pairs(Message) do Message[k] = "\n" .. v end - return table.concat(Message) end local function checkTrustFactor(trustLevel) - if (gmInte.config.filterOnTrust && (trustLevel < gmInte.config.minimalTrust)) then - return false - end - + if gmInte.config.filterOnTrust && (trustLevel < gmInte.config.minimalTrust) then return false end return true end local function checkBanStatus(banStatus) - if (gmInte.config.filterOnBan && banStatus) then - return false - end - + if gmInte.config.filterOnBan && banStatus then return false end return true end local function checkDiscordBanStatus(banStatus) - if (gmInte.config.syncBan && banStatus) then - return false - end - + if gmInte.config.syncBan && banStatus then return false end return true end local function playerFilter(data) - if (data.bot == 1) then return end + if data.bot == 1 then return end data.steamID64 = util.SteamIDTo64(data.networkid) - - gmInte.http.get("/servers/:serverID/players/" .. data.steamID64, - function(code, body) - if (gmInte.config.maintenance && !body.bypassMaintenance && !body.discordAdmin) then - game.KickID(data.networkid, filterMessage("The server is currently under maintenance and you are not whitelisted.")) - end - - if (!checkBanStatus(body.ban)) then - game.KickID(data.networkid, filterMessage("You are banned from this server.")) - end - - if (!checkDiscordBanStatus(body.discord_ban)) then - game.KickID(data.networkid, filterMessage("You are banned from our discord server.")) - end - - -- if (!checkTrustFactor(body.trust)) then - -- game.KickID(data.networkid, filterMessage("Your trust factor is too low.")) - -- end - end, - function (code, body) - if (gmInte.config.maintenance) then - game.KickID(data.networkid, filterMessage("The server is currently under maintenance and we cannot verify your account.\nVerification URL: https://verif.gmod-integration.com")) - end - end - ) + gmInte.http.get("/servers/:serverID/players/" .. data.steamID64, function(code, body) + if gmInte.config.maintenance && !body.bypassMaintenance && !body.discordAdmin then game.KickID(data.networkid, filterMessage("The server is currently under maintenance and you are not whitelisted.")) end + if !checkBanStatus(body.ban) then game.KickID(data.networkid, filterMessage("You are banned from this server.")) end + if !checkDiscordBanStatus(body.discord_ban) then game.KickID(data.networkid, filterMessage("You are banned from our discord server.")) end + // if (!checkTrustFactor(body.trust)) then + // game.KickID(data.networkid, filterMessage("Your trust factor is too low.")) + // end + end, function(code, body) if gmInte.config.maintenance then game.KickID(data.networkid, filterMessage("The server is currently under maintenance and we cannot verify your account.\nVerification URL: https://verif.gmod-integration.com")) end end) end -// -// Hooks -// - gameevent.Listen("player_connect") -hook.Add("player_connect", "gmInte:Player:Connect:Filter", function(data) - playerFilter(data) -end) \ No newline at end of file +hook.Add("player_connect", "gmInte:Player:Connect:Filter", function(data) playerFilter(data) end) \ No newline at end of file diff --git a/lua/gmod_integration/server/sv_net.lua b/lua/gmod_integration/server/sv_net.lua index aa32f56..5c99dcf 100644 --- a/lua/gmod_integration/server/sv_net.lua +++ b/lua/gmod_integration/server/sv_net.lua @@ -1,13 +1,4 @@ -// -// Networking -// - util.AddNetworkString("gmIntegration") - -// -// Send Net -// - local netSend = { ["wsRelayDiscordChat"] = 1, ["adminConfig"] = 2, @@ -20,58 +11,36 @@ local netSend = { // Send function gmInte.SendNet(id, data, ply, func) - if (!netSend[id]) then return end - + if !netSend[id] then return end net.Start("gmIntegration") - net.WriteUInt(netSend[id], 8) - net.WriteString(util.TableToJSON(data || {})) - if (func) then func() end - if (ply == nil) then + net.WriteUInt(netSend[id], 8) + net.WriteString(util.TableToJSON(data || {})) + if func then func() end + if ply == nil then net.Broadcast() else net.Send(ply) end end -// -// Receive net -// - local netReceive = { - [0] = function(ply) - hook.Run("gmInte:PlayerReady", ply) - 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, - [4] = function(ply) - gmInte.takeScreenshot(ply) - end, + [0] = function(ply) hook.Run("gmInte:PlayerReady", ply) 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, + [4] = function(ply) gmInte.takeScreenshot(ply) end, [5] = function(ply) - if (!ply:IsSuperAdmin()) then return end + if !ply:IsSuperAdmin() then return end RunConsoleCommand("changelevel", game.GetMap()) end, - [6] = function(ply) - gmInte.verifyPlayer(ply) - end, - [7] = function(ply, data) - sendPlayerToken(ply) - end + [6] = function(ply) gmInte.verifyPlayer(ply) end, + [7] = function(ply, data) sendPlayerToken(ply) end } net.Receive("gmIntegration", function(len, ply) - if (!ply || ply && !ply:IsValid()) then return end - + if !ply || ply && !ply:IsValid() then return end local id = net.ReadUInt(8) local data = util.JSONToTable(net.ReadString() || "{}") - - if (!netReceive[id]) then return end - + if !netReceive[id] then return end netReceive[id](ply, data) end) \ No newline at end of file diff --git a/lua/gmod_integration/server/sv_players.lua b/lua/gmod_integration/server/sv_players.lua index b401b18..91dddcd 100644 --- a/lua/gmod_integration/server/sv_players.lua +++ b/lua/gmod_integration/server/sv_players.lua @@ -1,16 +1,9 @@ -// -// Methods -// - function gmInte.playerReady(ply) - if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end - + if !ply:IsValid() || !ply:IsPlayer(ply) then return end // Initialize Time ply.gmIntTimeConnect = math.Round(RealTime()) - // Send Public Config gmInte.publicGetConfig(ply) - gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/ready", { ["player"] = gmInte.getPlayerFormat(ply) }) @@ -22,109 +15,80 @@ function gmInte.playerConnect(data) end function gmInte.playerDisconnected(ply) - if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end - - gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/disconnect", - { - ["player"] = gmInte.getPlayerFormat(ply), - } - ) + if !ply:IsValid() || !ply:IsPlayer(ply) then return end + gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/disconnect", { + ["player"] = gmInte.getPlayerFormat(ply), + }) end function gmInte.playerSpawn(ply) - if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end - - gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/spawn", - { - ["player"] = gmInte.getPlayerFormat(ply) - } - ) + if !ply:IsValid() || !ply:IsPlayer(ply) then return end + gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/spawn", { + ["player"] = gmInte.getPlayerFormat(ply) + }) end function gmInte.playerDeath(ply, inflictor, attacker) - if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end - if (!attacker:IsValid() || !attacker:IsPlayer(attacker)) then return end - if (!inflictor:IsValid()) then return end - - gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/death", - { - ["player"] = gmInte.getPlayerFormat(ply), - ["inflictor"] = gmInte.getEntityFormat(inflictor), - ["attacker"] = gmInte.getPlayerFormat(attacker) - } - ) + if !ply:IsValid() || !ply:IsPlayer(ply) then return end + if !attacker:IsValid() || !attacker:IsPlayer(attacker) then return end + if !inflictor:IsValid() then return end + gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/death", { + ["player"] = gmInte.getPlayerFormat(ply), + ["inflictor"] = gmInte.getEntityFormat(inflictor), + ["attacker"] = gmInte.getPlayerFormat(attacker) + }) end function gmInte.playerInitialSpawn(ply) - if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end - - gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/initial-spawn", - { - ["player"] = gmInte.getPlayerFormat(ply) - } - ) + if !ply:IsValid() || !ply:IsPlayer(ply) then return end + gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/initial-spawn", { + ["player"] = gmInte.getPlayerFormat(ply) + }) end function gmInte.postLogPlayerHurt(ply, attacker, healthRemaining, damageTaken) - if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end - if (!attacker:IsValid() || !attacker:IsPlayer(attacker)) then return end - + if !ply:IsValid() || !ply:IsPlayer(ply) then return end + if !attacker:IsValid() || !attacker:IsPlayer(attacker) then return end // Wait a second to see if the player is going to be hurt again ply.gmodInteLastHurt = ply.gmodInteLastHurt || {} local locCurTime = CurTime() ply.gmodInteLastHurt[attacker:SteamID64()] = locCurTime - timer.Simple(1, function() - if (ply.gmodInteLastHurt[attacker:SteamID64()] != locCurTime) then + if ply.gmodInteLastHurt[attacker:SteamID64()] != locCurTime then ply.gmodInteTotalDamage = ply.gmodInteTotalDamage || 0 ply.gmodInteTotalDamage = ply.gmodInteTotalDamage + damageTaken return end - gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/hurt", - { - ["victim"] = gmInte.getPlayerFormat(ply), - ["attacker"] = gmInte.getPlayerFormat(attacker), - ["healthRemaining"] = math.Round(healthRemaining), - ["damageTaken"] = math.Round(damageTaken) - } - ) + gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/hurt", { + ["victim"] = gmInte.getPlayerFormat(ply), + ["attacker"] = gmInte.getPlayerFormat(attacker), + ["healthRemaining"] = math.Round(healthRemaining), + ["damageTaken"] = math.Round(damageTaken) + }) end) end function gmInte.postLogPlayerSpawnedSomething(object, ply, ent, model) - if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end - if (!ent:IsValid()) then return end - - gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/spawn/" .. object, - { - ["player"] = gmInte.getPlayerFormat(ply), - ["entity"] = gmInte.getEntityFormat(ent), - ["model"] = model || "" - } - ) + if !ply:IsValid() || !ply:IsPlayer(ply) then return end + if !ent:IsValid() then return end + gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/spawn/" .. object, { + ["player"] = gmInte.getPlayerFormat(ply), + ["entity"] = gmInte.getEntityFormat(ent), + ["model"] = model || "" + }) end function gmInte.postLogPlayerGive(ply, class, swep) - if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end - - gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/give", - { - ["player"] = gmInte.getPlayerFormat(ply), - ["class"] = class, - ["swep"] = swep - } - ) + if !ply:IsValid() || !ply:IsPlayer(ply) then return end + gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/give", { + ["player"] = gmInte.getPlayerFormat(ply), + ["class"] = class, + ["swep"] = swep + }) end -// -// Hooks -// - -hook.Add("gmInte:PlayerReady", "gmInte:Player:Ready", function(ply) - gmInte.playerReady(ply) -end) - +hook.Add("gmInte:PlayerReady", "gmInte:Player:Ready", function(ply) gmInte.playerReady(ply) end) hook.Add("ShutDown", "gmInte:Server:Shutdown:SavePlayers", function() for ply, ply in pairs(player.GetAll()) do gmInte.playerDisconnected(ply) @@ -132,58 +96,17 @@ hook.Add("ShutDown", "gmInte:Server:Shutdown:SavePlayers", function() end) gameevent.Listen("player_connect") -hook.Add("player_connect", "gmInte:Player:Connect", function(data) - gmInte.playerConnect(data) -end) - -hook.Add("PlayerDisconnected", "gmInte:Player:Disconnect", function(ply) - gmInte.playerDisconnected(ply) -end) - -hook.Add("PlayerSpawn", "gmInte:Player:Spawn", function(ply) - gmInte.playerSpawn(ply) -end) - -hook.Add("PlayerInitialSpawn", "gmInte:Player:InitialSpawn", function(ply) - gmInte.playerInitialSpawn(ply) -end) - -hook.Add("PlayerGiveSWEP", "gmInte:Player:SWEPs", function( ply, class, swep ) - gmInte.postLogPlayerGive(ply, class, swep) -end) - -hook.Add("PlayerDeath", "gmInte:Player:Death", function(ply, inflictor, attacker) - gmInte.playerDeath(ply, inflictor, attacker) -end) - -hook.Add("PlayerHurt", "gmInte:Player:Hurt", function(ply, attacker, healthRemaining, damageTaken) - gmInte.postLogPlayerHurt(ply, attacker, healthRemaining, damageTaken) -end) - -hook.Add("PlayerSpawnedProp", "gmInte:Player:SpawnedProp", function(ply, model, ent) - gmInte.postLogPlayerSpawnedSomething("prop", ply, ent, model) -end) - -hook.Add("PlayerSpawnedSENT", "gmInte:Player:SpawnedSENT", function(ply, ent) - gmInte.postLogPlayerSpawnedSomething("sent", ply, ent) -end) - -hook.Add("PlayerSpawnedNPC", "gmInte:Player:SpawnedNPC", function(ply, ent) - gmInte.postLogPlayerSpawnedSomething("npc", ply, ent) -end) - -hook.Add("PlayerSpawnedVehicle", "gmInte:Player:SpawnedVehicle", function(ply, ent) - gmInte.postLogPlayerSpawnedSomething("vehicle", ply, ent) -end) - -hook.Add("PlayerSpawnedEffect", "gmInte:Player:SpawnedEffect", function(ply, model, ent) - gmInte.postLogPlayerSpawnedSomething("effect", ply, ent, model) -end) - -hook.Add("PlayerSpawnedRagdoll", "gmInte:Player:SpawnedRagdoll", function(ply, model, ent) - gmInte.postLogPlayerSpawnedSomething("ragdoll", ply, ent, model) -end) - -hook.Add("PlayerSpawnedSWEP", "gmInte:Player:SpawnedSWEP", function(ply, ent) - gmInte.postLogPlayerSpawnedSomething("swep", ply, ent) -end) \ No newline at end of file +hook.Add("player_connect", "gmInte:Player:Connect", function(data) gmInte.playerConnect(data) end) +hook.Add("PlayerDisconnected", "gmInte:Player:Disconnect", function(ply) gmInte.playerDisconnected(ply) end) +hook.Add("PlayerSpawn", "gmInte:Player:Spawn", function(ply) gmInte.playerSpawn(ply) end) +hook.Add("PlayerInitialSpawn", "gmInte:Player:InitialSpawn", function(ply) gmInte.playerInitialSpawn(ply) end) +hook.Add("PlayerGiveSWEP", "gmInte:Player:SWEPs", function(ply, class, swep) gmInte.postLogPlayerGive(ply, class, swep) end) +hook.Add("PlayerDeath", "gmInte:Player:Death", function(ply, inflictor, attacker) gmInte.playerDeath(ply, inflictor, attacker) end) +hook.Add("PlayerHurt", "gmInte:Player:Hurt", function(ply, attacker, healthRemaining, damageTaken) gmInte.postLogPlayerHurt(ply, attacker, healthRemaining, damageTaken) end) +hook.Add("PlayerSpawnedProp", "gmInte:Player:SpawnedProp", function(ply, model, ent) gmInte.postLogPlayerSpawnedSomething("prop", ply, ent, model) end) +hook.Add("PlayerSpawnedSENT", "gmInte:Player:SpawnedSENT", function(ply, ent) gmInte.postLogPlayerSpawnedSomething("sent", ply, ent) end) +hook.Add("PlayerSpawnedNPC", "gmInte:Player:SpawnedNPC", function(ply, ent) gmInte.postLogPlayerSpawnedSomething("npc", ply, ent) end) +hook.Add("PlayerSpawnedVehicle", "gmInte:Player:SpawnedVehicle", function(ply, ent) gmInte.postLogPlayerSpawnedSomething("vehicle", ply, ent) end) +hook.Add("PlayerSpawnedEffect", "gmInte:Player:SpawnedEffect", function(ply, model, ent) gmInte.postLogPlayerSpawnedSomething("effect", ply, ent, model) end) +hook.Add("PlayerSpawnedRagdoll", "gmInte:Player:SpawnedRagdoll", function(ply, model, ent) gmInte.postLogPlayerSpawnedSomething("ragdoll", ply, ent, model) end) +hook.Add("PlayerSpawnedSWEP", "gmInte:Player:SpawnedSWEP", function(ply, ent) gmInte.postLogPlayerSpawnedSomething("swep", ply, ent) end) \ No newline at end of file diff --git a/lua/gmod_integration/server/sv_players_verif.lua b/lua/gmod_integration/server/sv_players_verif.lua index 619bf9e..23497a8 100644 --- a/lua/gmod_integration/server/sv_players_verif.lua +++ b/lua/gmod_integration/server/sv_players_verif.lua @@ -1,24 +1,16 @@ -// -// Methods -// - function gmInte.verifyPlayer(ply) - if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end - + if !ply:IsValid() || !ply:IsPlayer(ply) then return end gmInte.http.get("/user?steamID64=" .. ply:SteamID64(), function(code, data) - if (data && data.discordID) then - ply.gmIntVerified = true - end - - if (!gmInte.config.forcePlayerLink || !ply.gmIntIsReady) then return end - - if (ply:gmIntIsVerified()) then + if data && data.discordID then ply.gmIntVerified = true end + if !gmInte.config.forcePlayerLink || !ply.gmIntIsReady then return end + if ply:gmIntIsVerified() then gmInte.SendNet("chatColorMessage", { [1] = { ["text"] = "You have been verified", ["color"] = Color(255, 255, 255) } }, ply) + ply:Freeze(false) else gmInte.SendNet("chatColorMessage", { @@ -27,19 +19,15 @@ function gmInte.verifyPlayer(ply) ["color"] = Color(255, 0, 0) } }, ply) + ply:Freeze(true) gmInte.SendNet("openVerifPopup", nil, ply) end end) end -// -// Hooks -// - hook.Add("gmInte:PlayerReady", "gmInte:Verif:PlayerReady", function(ply) ply.gmIntIsReady = true - - if (!gmInte.config.forcePlayerLink) then return end + if !gmInte.config.forcePlayerLink then return end gmInte.verifyPlayer(ply) end) \ No newline at end of file diff --git a/lua/gmod_integration/server/sv_rcon.lua b/lua/gmod_integration/server/sv_rcon.lua index 8cb8259..f49a76f 100644 --- a/lua/gmod_integration/server/sv_rcon.lua +++ b/lua/gmod_integration/server/sv_rcon.lua @@ -1,7 +1,3 @@ -// -// Websocket -// - function gmInte.wsRcon(data) gmInte.log("Rcon Command from Discord '" .. data.command .. "' by " .. data.steamID) game.ConsoleCommand(data.command .. "\n") diff --git a/lua/gmod_integration/server/sv_settings.lua b/lua/gmod_integration/server/sv_settings.lua index 0469def..41f5df5 100644 --- a/lua/gmod_integration/server/sv_settings.lua +++ b/lua/gmod_integration/server/sv_settings.lua @@ -5,23 +5,17 @@ function gmInte.saveSetting(setting, value) end // Boolean - if (value == "true") then value = true end - if (value == "false") then value = false end - + if value == "true" then value = true end + if value == "false" then value = false end // Number - if (tonumber(value) != nil) then value = tonumber(value) end - + if tonumber(value) != nil then value = tonumber(value) end gmInte.config[setting] = value file.Write("gm_integration/config.json", util.TableToJSON(gmInte.config, true)) gmInte.log("Setting Saved") - - if (value == "websocketFQDN" || value == "id" || value == "token") then - gmInte.resetWebSocket() - end - + if value == "websocketFQDN" || value == "id" || value == "token" then gmInte.resetWebSocket() end // send to all players the new public config for _, ply in pairs(player.GetAll()) do - if (ply:IsValid() && ply:IsPlayer(ply)) then + if ply:IsValid() && ply:IsPlayer(ply) then gmInte.log("Sending new Public Config to " .. ply:Nick(), true) gmInte.publicGetConfig(ply) end @@ -29,26 +23,17 @@ function gmInte.saveSetting(setting, value) end function gmInte.tryConfig() - gmInte.http.get("/servers/:serverID", - function(code, body) - print(" ") - gmInte.log("Congratulations your server is now connected to Gmod Integration") - gmInte.log("Server Name: " .. body.name) - gmInte.log("Server ID: " .. body.id) - print(" ") - end - ) + gmInte.http.get("/servers/:serverID", function(code, body) + print(" ") + gmInte.log("Congratulations your server is now connected to Gmod Integration") + gmInte.log("Server Name: " .. body.name) + gmInte.log("Server ID: " .. body.id) + print(" ") + end) end function gmInte.testConnection(ply) - gmInte.http.get("/servers/:serverID", - function(code, body) - if (ply) then gmInte.SendNet("testApiConnection", body, ply) end - end, - function(code, body) - if (ply) then gmInte.SendNet("testApiConnection", body, ply) end - end - ) + gmInte.http.get("/servers/:serverID", function(code, body) if ply then gmInte.SendNet("testApiConnection", body, ply) end end, function(code, body) if ply then gmInte.SendNet("testApiConnection", body, ply) end end) end function gmInte.refreshSettings() @@ -58,15 +43,13 @@ function gmInte.refreshSettings() end function gmInte.superadminGetConfig(ply) - if (!ply:IsValid() || !ply:IsPlayer(ply) || !ply:IsSuperAdmin()) then return end - + if !ply:IsValid() || !ply:IsPlayer(ply) || !ply:IsSuperAdmin() then return end gmInte.config.websocket = GWSockets && true || false gmInte.SendNet("adminConfig", gmInte.config, ply) end function gmInte.publicGetConfig(ply) - if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end - + if !ply:IsValid() || !ply:IsPlayer(ply) then return end gmInte.SendNet("publicConfig", { ["config"] = { ["id"] = gmInte.config.id, @@ -82,13 +65,10 @@ function gmInte.publicGetConfig(ply) end function gmInte.superadminSetConfig(ply, data) - if (!ply:IsValid() || !ply:IsPlayer(ply) || !ply:IsSuperAdmin()) then return end - + if !ply:IsValid() || !ply:IsPlayer(ply) || !ply:IsSuperAdmin() then return end for k, v in pairs(data) do gmInte.saveSetting(k, v) end - if data.token || data.id then - gmInte.testConnection(ply) - end + if data.token || data.id then gmInte.testConnection(ply) end end \ No newline at end of file diff --git a/lua/gmod_integration/server/sv_status.lua b/lua/gmod_integration/server/sv_status.lua index f103e44..5cb4e98 100644 --- a/lua/gmod_integration/server/sv_status.lua +++ b/lua/gmod_integration/server/sv_status.lua @@ -1,7 +1,3 @@ -// -// Methods -// - function gmInte.sendStatus() gmInte.http.post("/servers/:serverID/status", gmInte.getServerFormat()) end @@ -14,24 +10,6 @@ function gmInte.serverShutDown() gmInte.http.post("/servers/:serverID/stop") end -// -// Timers -// - -timer.Create("gmInte.sendStatus", 300, 0, function() - gmInte.sendStatus() -end) - -// -// Hooks -// - -hook.Add("Initialize", "gmInte:Server:Initialize:SendStatus", function() - timer.Simple(1, function() - gmInte.serverStart() - end) -end) - -hook.Add("ShutDown", "gmInte:Server:ShutDown:SendStatus", function() - gmInte.serverShutDown() -end) \ No newline at end of file +timer.Create("gmInte.sendStatus", 300, 0, function() gmInte.sendStatus() end) +hook.Add("Initialize", "gmInte:Server:Initialize:SendStatus", function() timer.Simple(1, function() gmInte.serverStart() end) end) +hook.Add("ShutDown", "gmInte:Server:ShutDown:SendStatus", function() gmInte.serverShutDown() end) \ No newline at end of file diff --git a/lua/gmod_integration/server/sv_sync_bans.lua b/lua/gmod_integration/server/sv_sync_bans.lua index 8ec19d0..9836f9f 100644 --- a/lua/gmod_integration/server/sv_sync_bans.lua +++ b/lua/gmod_integration/server/sv_sync_bans.lua @@ -1,29 +1,13 @@ -// -// Websocket -// - function gmInte.wsSyncBan(data) for _, ply in ipairs(player.GetAll()) do - if (ply:SteamID64() == data.steam) then - ply:Kick(data.reason || "You have been banned from the server.") - end + if ply:SteamID64() == data.steam then ply:Kick(data.reason || "You have been banned from the server.") end end end -// -// Methods -// - function gmInte.playerBan(data) data.steamID64 = util.SteamIDTo64(data.networkid) gmInte.http.post("/servers/:serverID/players/" .. util.SteamIDTo64(data.networkid) .. "/ban", data) end -// -// Hooks -// - gameevent.Listen("server_addban") -hook.Add("server_addban", "gmInte:Player:Ban", function(data) - gmInte.playerBan(data) -end) \ No newline at end of file +hook.Add("server_addban", "gmInte:Player:Ban", function(data) gmInte.playerBan(data) end) \ No newline at end of file diff --git a/lua/gmod_integration/server/sv_sync_chat.lua b/lua/gmod_integration/server/sv_sync_chat.lua index 4a49982..a29852b 100644 --- a/lua/gmod_integration/server/sv_sync_chat.lua +++ b/lua/gmod_integration/server/sv_sync_chat.lua @@ -1,29 +1,13 @@ -// -// Websocket -// - function gmInte.wsPlayerSay(data) gmInte.SendNet("wsRelayDiscordChat", data, nil) end -// -// Methods -// - function gmInte.playerSay(ply, text, teamOnly) - gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/say", - { - ["player"] = gmInte.getPlayerFormat(ply), - ["text"] = text, - ["teamOnly"] = teamOnly, - } - ) + gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/say", { + ["player"] = gmInte.getPlayerFormat(ply), + ["text"] = text, + ["teamOnly"] = teamOnly, + }) end -// -// Hooks -// - -hook.Add("PlayerSay", "gmInte:SyncChat:PlayerSay", function(ply, text, team) - gmInte.playerSay(ply, text, team) -end) \ No newline at end of file +hook.Add("PlayerSay", "gmInte:SyncChat:PlayerSay", function(ply, text, team) gmInte.playerSay(ply, text, team) end) \ No newline at end of file diff --git a/lua/gmod_integration/server/sv_sync_kicks.lua b/lua/gmod_integration/server/sv_sync_kicks.lua index a71b906..3b06202 100644 --- a/lua/gmod_integration/server/sv_sync_kicks.lua +++ b/lua/gmod_integration/server/sv_sync_kicks.lua @@ -1,30 +1,12 @@ -// -// Websocket -// - function gmInte.wsSyncKick(data) for _, ply in ipairs(player.GetAll()) do - if (ply:SteamID64() == data.steam) then - ply:Kick(data.reason || "You have been banned from the server.") - end + if ply:SteamID64() == data.steam then ply:Kick(data.reason || "You have been banned from the server.") end end end -// -// Methods -// - function gmInte.playerKick(data) gmInte.http.post("/servers/:serverID/players/" .. util.SteamIDTo64(data.networkid) .. "/kick", data) end -// -// Hooks -// - gameevent.Listen("player_disconnect") -hook.Add("player_disconnect", "gmInte:SyncKick:Disconnect", function(data) - if (string.StartWith(data.reason, "Kicked by ") || data.reason == "No reason provided.") then - gmInte.playerKick(data) - end -end) \ No newline at end of file +hook.Add("player_disconnect", "gmInte:SyncKick:Disconnect", function(data) if string.StartWith(data.reason, "Kicked by ") || data.reason == "No reason provided." then gmInte.playerKick(data) end end) \ No newline at end of file diff --git a/lua/gmod_integration/server/sv_sync_names.lua b/lua/gmod_integration/server/sv_sync_names.lua index fc2fc07..b16a9bf 100644 --- a/lua/gmod_integration/server/sv_sync_names.lua +++ b/lua/gmod_integration/server/sv_sync_names.lua @@ -1,33 +1,16 @@ -// -// Websocket -// - function gmInte.wsSyncName(data) local ply = player.GetBySteamID(data.player.steamID64) - if not IsValid(ply) then return end + if !IsValid(ply) then return end ply:SetName(data.newName) end -// -// Methods -// - function gmInte.playerChangeName(ply, oldName, newName) - if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end - - gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/name", - { - ["player"] = gmInte.getPlayerFormat(ply), - ["oldName"] = oldName, - ["newName"] = newName, - } - ) + if !ply:IsValid() || !ply:IsPlayer(ply) then return end + gmInte.http.post("/servers/:serverID/players/" .. ply:SteamID64() .. "/name", { + ["player"] = gmInte.getPlayerFormat(ply), + ["oldName"] = oldName, + ["newName"] = newName, + }) end -// -// Hooks -// - -hook.Add("onPlayerChangedName", "gmInte:PlayerChangeName", function(ply, old, new) - gmInte.playerChangeName(ply, old, new) -end) \ No newline at end of file +hook.Add("onPlayerChangedName", "gmInte:PlayerChangeName", function(ply, old, new) gmInte.playerChangeName(ply, old, new) end) \ No newline at end of file diff --git a/lua/gmod_integration/server/sv_sync_roles.lua b/lua/gmod_integration/server/sv_sync_roles.lua index 07339f2..393be49 100644 --- a/lua/gmod_integration/server/sv_sync_roles.lua +++ b/lua/gmod_integration/server/sv_sync_roles.lua @@ -1,31 +1,17 @@ -// -// Websocket -// - local cachedPlayers = {} - function gmInte.wsPlayerUpdateGroup(data) - if (cachedPlayers[steamID64] == data.group) then return end - + if cachedPlayers[steamID64] == data.group then return end data.steamID = util.SteamIDFrom64(data.steamID64) data.group = data.add && data.group || "user" - cachedPlayers[data.steamID64] = data.group - local ply = player.GetBySteamID(data.steamID) - if (ply && ply:IsValid()) then - ply:SetUserGroup(data.group) - end - + if ply && ply:IsValid() then ply:SetUserGroup(data.group) end // ULX - if (ULib) then - ULib.ucl.addUser(data.steamID, nil, nil, data.group) - end - + if ULib then ULib.ucl.addUser(data.steamID, nil, nil, data.group) end // ServerGuard - if (serverguard) then + if serverguard then local ply = player.GetBySteamID(data.steamID) - if (ply) then + if ply then local rankData = serverguard.ranks:GetRank(data.group) serverguard.player:SetRank(ply, data.group) serverguard.player:SetImmunity(ply, rankData.immunity) @@ -37,52 +23,27 @@ function gmInte.wsPlayerUpdateGroup(data) end // Evolve - if (evolve) then - evolve:RankPlayer(data.steamID64, data.group) - end - + if evolve then evolve:RankPlayer(data.steamID64, data.group) end // SAM - if (SAM) then - SAM:PlayerSetRank(data.steamID64, data.group) - end - + if SAM then SAM:PlayerSetRank(data.steamID64, data.group) end // sam (wtf another one?) - if (sam) then - sam.player.setRank(data.steamID64, data.group) - end - + if sam then sam.player.setRank(data.steamID64, data.group) end // xAdmin - if (xAdmin) then - xAdmin.SetRank(data.steamID64, data.group) - end - + if xAdmin then xAdmin.SetRank(data.steamID64, data.group) end // maestro - if (maestro) then - maestro.userrank(data.steamID64, data.group) - end - + if maestro then maestro.userrank(data.steamID64, data.group) end // D3A - if (D3A) then - D3A.Ranks.SetSteamIDRank(data.steamID, data.group) - end - + if D3A then D3A.Ranks.SetSteamIDRank(data.steamID, data.group) end // Mercury - if (Mercury) then - RunConsoleCommand("hg", "setrank", data.steamID, data.group) - end - + if Mercury then RunConsoleCommand("hg", "setrank", data.steamID, data.group) end // FAdmin - if (FAdmin) then - RunConsoleCommand("fadmin", "setaccess", data.steamID, data.group) - end - + if FAdmin then RunConsoleCommand("fadmin", "setaccess", data.steamID, data.group) end gmInte.log("[Sync Role] Player " .. data.steamID .. " has been updated to group " .. data.group) end function gmInte.playerChangeGroup(steamID64, oldGroup, newGroup) - if (cachedPlayers[steamID64] == newGroup) then return end + if cachedPlayers[steamID64] == newGroup then return end cachedPlayers[steamID64] = newGroup - gmInte.http.post("/servers/:serverID/players/" .. steamID64 .. "/group", { ["player"] = gmInte.getPlayerFormat(ply), ["oldGroup"] = oldGroup || "user", @@ -90,12 +51,12 @@ function gmInte.playerChangeGroup(steamID64, oldGroup, newGroup) }) end -hook.Add('CAMI.PlayerUsergroupChanged', 'gmInte:SyncChat:CAMI:PlayerUsergroupChanged', function(ply, old, new) - if (ply:IsBot() || !ply:IsValid()) then return end +hook.Add("CAMI.PlayerUsergroupChanged", "gmInte:SyncChat:CAMI:PlayerUsergroupChanged", function(ply, old, new) + if ply:IsBot() || !ply:IsValid() then return end gmInte.playerChangeGroup(ply:SteamID64(), old, new) end) -hook.Add('CAMI.SteamIDUsergroupChanged', 'gmInte:SyncChat:CAMI:SteamIDUsergroupChanged', function(SteamID64, old, new) - if (string.StartWith(SteamID64, "STEAM_")) then SteamID64 = util.SteamIDTo64(SteamID64) end +hook.Add("CAMI.SteamIDUsergroupChanged", "gmInte:SyncChat:CAMI:SteamIDUsergroupChanged", function(SteamID64, old, new) + if string.StartWith(SteamID64, "STEAM_") then SteamID64 = util.SteamIDTo64(SteamID64) end gmInte.playerChangeGroup(SteamID64, old, new) end) \ No newline at end of file diff --git a/lua/gmod_integration/server/sv_tokens.lua b/lua/gmod_integration/server/sv_tokens.lua index 2c9250c..29a5ee0 100644 --- a/lua/gmod_integration/server/sv_tokens.lua +++ b/lua/gmod_integration/server/sv_tokens.lua @@ -1,11 +1,7 @@ -// -// Methods -// - gmInte.serverPublicToken = gmInte.serverPublicToken || nil function gmInte.getPublicServerToken(callback) - if (gmInte.serverPublicToken) then - if (callback) then callback(gmInte.serverPublicToken) end + if gmInte.serverPublicToken then + if callback then callback(gmInte.serverPublicToken) end return end @@ -15,24 +11,20 @@ function gmInte.getPublicServerToken(callback) end) end -hook.Add("Initialize", "gmInte:Server:Initialize:GetPublicToken", function() - timer.Simple(1, function() - gmInte.getPublicServerToken(function(publicToken) - gmInte.log("Server Public Token Received: " .. publicToken) - end) - end) -end) - gmInte.serverPlayerTempTokens = gmInte.serverPlayerTempTokens || {} function gmInte.getPlayerTempToken(ply, callback) - if (gmInte.serverPlayerTempTokens[ply:SteamID64()] && gmInte.serverPlayerTempTokens[ply:SteamID64()].userID == ply:UserID()) then - if (callback) then callback(gmInte.serverPlayerTempTokens[ply:SteamID64()].token) end + if gmInte.serverPlayerTempTokens[ply:SteamID64()] && gmInte.serverPlayerTempTokens[ply:SteamID64()].userID == ply:UserID() then + if callback then callback(gmInte.serverPlayerTempTokens[ply:SteamID64()].token) end return end gmInte.getPublicServerToken(function(publicToken) local token = util.SHA256(ply:SteamID64() .. "-" .. publicToken .. "-" .. gmInte.config.token .. "-" .. ply:UserID()) .. " " .. ply:UserID() - gmInte.serverPlayerTempTokens[ply:SteamID64()] = { token = token, userID = ply:UserID() } + gmInte.serverPlayerTempTokens[ply:SteamID64()] = { + token = token, + userID = ply:UserID() + } + callback(token) end) end @@ -45,6 +37,5 @@ function sendPlayerToken(ply) end) end -hook.Add("gmInte:PlayerReady", "gmInte:Verif:PlayerReady", function(ply) - sendPlayerToken(ply) -end) \ No newline at end of file +hook.Add("gmInte:PlayerReady", "gmInte:Verif:PlayerReady", function(ply) sendPlayerToken(ply) end) +hook.Add("Initialize", "gmInte:Server:Initialize:GetPublicToken", function() timer.Simple(1, function() gmInte.getPublicServerToken(function(publicToken) gmInte.log("Server Public Token Received: " .. publicToken) end) end) end) \ No newline at end of file diff --git a/lua/gmod_integration/shared/sh_api_format.lua b/lua/gmod_integration/shared/sh_api_format.lua index 54081c9..da378b1 100644 --- a/lua/gmod_integration/shared/sh_api_format.lua +++ b/lua/gmod_integration/shared/sh_api_format.lua @@ -1,5 +1,5 @@ function gmInte.getPlayerFormat(ply) - if (!IsValid(ply) || !ply:IsPlayer()) then return end + if !IsValid(ply) || !ply:IsPlayer() then return end return { ["steamID"] = ply:SteamID(), ["steamID64"] = ply:SteamID64(), @@ -40,7 +40,7 @@ function gmInte.getServerFormat() end function gmInte.getWeaponFormat(weapon) - if (!IsValid(weapon) || !weapon:IsWeapon()) then return end + if !IsValid(weapon) || !weapon:IsWeapon() then return end return { ["class"] = weapon:GetClass(), ["printName"] = weapon:GetPrintName() @@ -48,7 +48,7 @@ function gmInte.getWeaponFormat(weapon) end function gmInte.getEntityFormat(ent) - if (!IsValid(ent)) then return end + if !IsValid(ent) then return end return { ["class"] = ent:GetClass(), ["model"] = ent:GetModel(), @@ -58,7 +58,7 @@ function gmInte.getEntityFormat(ent) end function gmInte.getVectorFormat(vec) - if (!isvector(vec)) then return end + if !isvector(vec) then return end return { ["x"] = math.Round(vec.x), ["y"] = math.Round(vec.y), @@ -67,7 +67,7 @@ function gmInte.getVectorFormat(vec) end function gmInte.getAngleFormat(ang) - if (!isangle(ang)) then return end + if !isangle(ang) then return end return { ["p"] = math.Round(ang.p), ["y"] = math.Round(ang.y), @@ -76,7 +76,7 @@ function gmInte.getAngleFormat(ang) end function gmInte.getTeamFormat(teamID) - if (!isnumber(teamID)) then return end + if !isnumber(teamID) then return end return { ["id"] = teamID, ["name"] = team.GetName(teamID) diff --git a/lua/gmod_integration/shared/sh_errors.lua b/lua/gmod_integration/shared/sh_errors.lua index 5ba99cf..8ba7992 100644 --- a/lua/gmod_integration/shared/sh_errors.lua +++ b/lua/gmod_integration/shared/sh_errors.lua @@ -1,49 +1,32 @@ -// -// Methods -// - local cacheErrors = {} - function gmInte.sendLuaErrorReport(err, realm, stack, name, id) cacheErrors[err] = { ["time"] = CurTime(), ["count"] = cacheErrors[err] && cacheErrors[err].count + 1 || 1, } - if (!gmInte.config.id || !gmInte.config.token) then return end - if (CLIENT && !IsValid(LocalPlayer())) then return end - + if !gmInte.config.id || !gmInte.config.token then return end + if CLIENT && !IsValid(LocalPlayer()) then return end local count = cacheErrors[err].count timer.Simple(0.5, function() - if (cacheErrors[err].count != count) then - if (cacheErrors[err].count == 100) then - else - return - end + if cacheErrors[err].count != count then + if cacheErrors[err].count != 100 then return end else cacheErrors[err] = nil end local endpoint = SERVER && "/servers/:serverID/errors" || "/clients/:steamID64/servers/:serverID/errors" - gmInte.http.post(endpoint, - { - ["error"] = err, - ["realm"] = realm, - ["stack"] = stack, - ["name"] = name, - ["id"] = id, - ["count"] = count, - ["uptime"] = math.Round(RealTime()), - ["identifier"] = SERVER && gmInte.config.id || CLIENT && LocalPlayer():SteamID64() - } - ) + gmInte.http.post(endpoint, { + ["error"] = err, + ["realm"] = realm, + ["stack"] = stack, + ["name"] = name, + ["id"] = id, + ["count"] = count, + ["uptime"] = math.Round(RealTime()), + ["identifier"] = SERVER && gmInte.config.id || CLIENT && LocalPlayer():SteamID64() + }) end) end -// -// Hooks -// - -hook.Add("OnLuaError", "gmInte:OnLuaError:SendReport", function(err, realm, stack, name, id) - gmInte.sendLuaErrorReport(err, realm, stack, name, id) -end) \ No newline at end of file +hook.Add("OnLuaError", "gmInte:OnLuaError:SendReport", function(err, realm, stack, name, id) gmInte.sendLuaErrorReport(err, realm, stack, name, id) end) \ No newline at end of file diff --git a/lua/gmod_integration/shared/sh_http.lua b/lua/gmod_integration/shared/sh_http.lua index b4a1ba8..b44ca3d 100644 --- a/lua/gmod_integration/shared/sh_http.lua +++ b/lua/gmod_integration/shared/sh_http.lua @@ -1,23 +1,14 @@ local apiVersion = "v3" gmInte.http = gmInte.http || {} - local function getAPIURL(endpoint) local method = gmInte.isPrivateIP(gmInte.config.apiFQDN) && "http" || "https" - endpoint = string.gsub(endpoint, ":serverID", gmInte.config.id) - - if (CLIENT) then - endpoint = string.gsub(endpoint, ":steamID64", LocalPlayer():SteamID64()) - end - + if CLIENT then endpoint = string.gsub(endpoint, ":steamID64", LocalPlayer():SteamID64()) end return method .. "://" .. gmInte.config.apiFQDN .. "/" .. apiVersion .. endpoint end local function showableBody(endpoint) - if (string.sub(endpoint, 1, 8) == "/streams" || string.sub(endpoint, 1, 12) == "/screenshots") then - return false - end - + if string.sub(endpoint, 1, 8) == "/streams" || string.sub(endpoint, 1, 12) == "/screenshots" then return false end return true end @@ -32,8 +23,7 @@ function gmInte.http.requestAPI(params) local version = gmInte.version || "Unknown" local showableBody = showableBody(params.endpoint) local localRequestID = util.CRC(tostring(SysTime())) - - if (token == "") then + if token == "" then return failed(401, { ["error"] = "No token provided" }) @@ -51,7 +41,6 @@ function gmInte.http.requestAPI(params) gmInte.log("HTTP Request ID: " .. localRequestID, true) gmInte.log("HTTP Request: " .. method .. " " .. url, true) gmInte.log("HTTP Body: " .. (showableBody && body || "HIDDEN"), true) - HTTP({ ["url"] = url, ["method"] = method, @@ -62,15 +51,13 @@ function gmInte.http.requestAPI(params) gmInte.log("HTTP Request ID: " .. localRequestID, true) gmInte.log("HTTP Response: " .. code, true) gmInte.log("HTTP Body: " .. body, true) - - if (string.sub(headers["Content-Type"], 1, 16) != "application/json") then + if string.sub(headers["Content-Type"], 1, 16) != "application/json" then gmInte.log("HTTP Failed: Invalid Content-Type", true) return failed(code, body) end body = util.JSONToTable(body || "{}") - - if (code < 200 || code >= 300) then + if code < 200 || code >= 300 then gmInte.log("HTTP Failed: Invalid Status Code", true) return failed(code, body) end @@ -85,10 +72,6 @@ function gmInte.http.requestAPI(params) }) end -// -// HTTP Methods -// - function gmInte.http.get(endpoint, onSuccess, onFailed) gmInte.http.requestAPI({ ["endpoint"] = endpoint, diff --git a/lua/gmod_integration/shared/sh_main.lua b/lua/gmod_integration/shared/sh_main.lua index b81f1bc..a81719a 100644 --- a/lua/gmod_integration/shared/sh_main.lua +++ b/lua/gmod_integration/shared/sh_main.lua @@ -1,59 +1,50 @@ -// -// Functions -// - -// Log function gmInte.log(msg, debug) - if (debug && !gmInte.config.debug) then return end - print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] " .. msg) + if debug && !gmInte.config.debug then return end + print("[" .. os.date("%Y-%m-%d %H:%M:%S") .. "] [Gmod Integration] " .. msg) end // Log Error function gmInte.logError(msg, debug) - if (debug && !gmInte.config.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) end // Log Warning function gmInte.logWarning(msg, debug) - if (debug && !gmInte.config.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) end // Log Hint function gmInte.logHint(msg, debug) - if (debug && !gmInte.config.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) end // Is Private IP function gmInte.isPrivateIP(ip) // detect localhost - if (ip == "localhost") then return true end + if ip == "localhost" then return true end // detect private IP addresses (RFC 1918) local parts = string.Explode(".", ip) - if (parts[1] == "192" && parts[2] == "168") then return true end - if (parts[1] == "10") then return true end - if (parts[1] == "172" && tonumber(parts[2]) >= 16 && tonumber(parts[2]) <= 31) then return true end - if (parts[1] == "127") then return true end + if parts[1] == "192" && parts[2] == "168" then return true end + if parts[1] == "10" then return true end + if parts[1] == "172" && tonumber(parts[2]) >= 16 && tonumber(parts[2]) <= 31 then return true end + if parts[1] == "127" then return true end return false end -concommand.Add("gmi_test_error", function( ply, cmd, args ) +concommand.Add("gmi_test_error", function(ply, cmd, args) print(ply, cmd) PrintTable(args) - if (#args == 0) then + if #args == 0 then error("This is a test error") else - if (args[1] == "loop") then - hook.Add("Think", "gmInte:TestError:Loop", function() - error("This is a test error") - end) - timer.Simple(5, function() - hook.Remove("Think", "gmInte:TestError:Loop") - end) - elseif (args[1] == "crash") then - while (true) do + if args[1] == "loop" then + hook.Add("Think", "gmInte:TestError:Loop", function() error("This is a test error") end) + timer.Simple(5, function() hook.Remove("Think", "gmInte:TestError:Loop") end) + elseif args[1] == "crash" then + while true do error("This is a crash error") end else diff --git a/lua/gmod_integration/shared/sh_player_meta.lua b/lua/gmod_integration/shared/sh_player_meta.lua index 3ac4545..77f6b79 100644 --- a/lua/gmod_integration/shared/sh_player_meta.lua +++ b/lua/gmod_integration/shared/sh_player_meta.lua @@ -1,9 +1,4 @@ -// -// Meta -// - local ply = FindMetaTable("Player") - function ply:gmIntGetConnectTime() return self.gmIntTimeConnect || 0 end @@ -22,52 +17,38 @@ function ply:gmIntGetCustomValue(key) end function ply:gmIntRemoveCustomValue(key) - if (self.gmIntCustomValues) then - self.gmIntCustomValues[key] = nil - end + if self.gmIntCustomValues then self.gmIntCustomValues[key] = nil end end -// -// Compatibility -// - local function getCustomCompatability(ply) local values = {} - // DarkRP - if (DarkRP) then + if DarkRP then values.money = ply:getDarkRPVar("money") values.job = ply:getDarkRPVar("job") end // GUI Level System - if (GUILevelSystem) then + if GUILevelSystem then values.level = ply:GetLevel() values.xp = ply:GetXP() end - return values end -// -// Methods -// - local function getCustomValues(ply) local values = {} - // Get compatability values for key, value in pairs(getCustomCompatability(ply)) do values[key] = value end // Get custom values or overwrite compatability values - if (ply.gmIntCustomValues) then + if ply.gmIntCustomValues then for key, value in pairs(ply.gmIntCustomValues) do values[key] = value end end - return values end diff --git a/lua/gmod_integration/sv_config.lua b/lua/gmod_integration/sv_config.lua index 6a7290e..7f12415 100644 --- a/lua/gmod_integration/sv_config.lua +++ b/lua/gmod_integration/sv_config.lua @@ -5,10 +5,11 @@ Add Server: 0. Add the bot to your guild if it's not already done: https://gmod-integration.com/invite - 1. Go to our dashboard and Login with Discord: https://gmod-integration.com/login - 2. Go to the "Servers" page: https://gmod-integration.com/config/servers and click on "Create Server" - 3. Copy the ID and Token of your server and paste them in this file - 4. Everything is ready, you can now restart your server + 1. Go to our dashboard and Login with Discord: https://gmod-integration.com/login you should be redirected to the dashboard + 2. Add the bot to your guild and click on "Add to Guild" or select your guild if it's already added + 3. Go to the "Servers" page and click on "Create Server" + 4. Copy the ID and Token of your server and paste them in this file + 5 Everything is ready, you can now restart your server To go further, you can check the documentation: https://docs.gmod-integration.com @@ -17,43 +18,22 @@ IF ANY PROBLEM OCCURS, GO TO OUR WEBSITE AND FOLLOW THE INSTRUCTIONS: https://gmod-integration.com/emergency */ - -// -// General -// - // API Connection gmInte.config.id = "" // Server ID gmInte.config.token = "" // Server Token gmInte.config.websocketFQDN = "ws.gmod-integration.com" // The FQDN of the websocket server gmInte.config.apiFQDN = "api.gmod-integration.com" // The FQDN of the API server - // 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.supportLink = "" // The link of your support (shown when a player do not have the requiments to join the server) gmInte.config.maintenance = false // If true, the addon will only allow the players with the "gmod-integration.maintenance" permission to join the server - -// -// Syncronization -// - // Punishment gmInte.config.syncBan = true // If true, the addon will sync gmod bans with discord bans (and vice versa) gmInte.config.syncTimeout = false // If true, the addon will sync gmod timeouts with discord timeouts (and vice versa) gmInte.config.syncKick = false // If true, the addon will sync gmod kicks with discord kicks (and vice versa) - // Ban gmInte.config.filterOnBan = true // If true, the addon will filter the players according to their ban status - -// // Materials -// - gmInte.config.redownloadMaterials = false // If true, the addon will redownload the materials of the addon (useful if you have a problem with the materials) - -// // Debug & Development -// - -gmInte.config.debug = false // If true, the addon will show debug informations in the console -gmInte.config.devInstance = false // If true, the addon will use the development instance of API and Websocket \ No newline at end of file +gmInte.config.debug = false // If true, the addon will show debug informations in the console \ No newline at end of file