From e694dcddcd8ad2bee1c4efcf43bb9656980168bb Mon Sep 17 00:00:00 2001 From: Linventif Date: Fri, 9 Feb 2024 20:56:17 +0100 Subject: [PATCH 01/66] big rewrite of everything --- lua/autorun/gmod_integration.lua | 2 +- .../client/cl_context_menu.lua | 12 + .../client/{cl_gui.lua => cl_gui_admin.lua} | 52 +-- lua/gmod_integration/client/cl_gui_link.lua | 52 +++ lua/gmod_integration/client/cl_hook.lua | 2 +- lua/gmod_integration/client/cl_main.lua | 61 +--- lua/gmod_integration/client/cl_net.lua | 1 + .../client/cl_screenshots.lua | 71 +++++ .../server/sv__api_format.lua | 14 + lua/gmod_integration/server/sv__websocket.lua | 14 +- lua/gmod_integration/server/sv_con.lua | 4 - lua/gmod_integration/server/sv_filtrers.lua | 85 +++++ lua/gmod_integration/server/sv_hook.lua | 40 --- .../server/{sv_log.lua => sv_logs.lua} | 62 ++-- lua/gmod_integration/server/sv_main.lua | 300 ------------------ lua/gmod_integration/server/sv_meta.lua | 12 - lua/gmod_integration/server/sv_net.lua | 6 +- lua/gmod_integration/server/sv_players.lua | 145 +++++++++ lua/gmod_integration/server/sv_rcon.lua | 8 + .../server/sv_screenshots.lua | 24 ++ lua/gmod_integration/server/sv_settings.lua | 65 ++++ lua/gmod_integration/server/sv_status.lua | 51 +++ lua/gmod_integration/server/sv_sync_bans.lua | 28 ++ lua/gmod_integration/server/sv_sync_chat.lua | 31 ++ lua/gmod_integration/server/sv_sync_names.lua | 33 ++ lua/gmod_integration/server/sv_sync_roles.lua | 35 ++ lua/gmod_integration/server/sv_sync_warns.lua | 15 + lua/gmod_integration/shared/sh_http.lua | 168 +++++----- 28 files changed, 815 insertions(+), 578 deletions(-) create mode 100644 lua/gmod_integration/client/cl_context_menu.lua rename lua/gmod_integration/client/{cl_gui.lua => cl_gui_admin.lua} (93%) create mode 100644 lua/gmod_integration/client/cl_gui_link.lua create mode 100644 lua/gmod_integration/client/cl_screenshots.lua create mode 100644 lua/gmod_integration/server/sv__api_format.lua create mode 100644 lua/gmod_integration/server/sv_filtrers.lua delete mode 100644 lua/gmod_integration/server/sv_hook.lua rename lua/gmod_integration/server/{sv_log.lua => sv_logs.lua} (82%) delete mode 100644 lua/gmod_integration/server/sv_main.lua delete mode 100644 lua/gmod_integration/server/sv_meta.lua create mode 100644 lua/gmod_integration/server/sv_players.lua create mode 100644 lua/gmod_integration/server/sv_rcon.lua create mode 100644 lua/gmod_integration/server/sv_screenshots.lua create mode 100644 lua/gmod_integration/server/sv_settings.lua create mode 100644 lua/gmod_integration/server/sv_status.lua create mode 100644 lua/gmod_integration/server/sv_sync_bans.lua create mode 100644 lua/gmod_integration/server/sv_sync_chat.lua create mode 100644 lua/gmod_integration/server/sv_sync_names.lua create mode 100644 lua/gmod_integration/server/sv_sync_roles.lua create mode 100644 lua/gmod_integration/server/sv_sync_warns.lua diff --git a/lua/autorun/gmod_integration.lua b/lua/autorun/gmod_integration.lua index 558500a..6125023 100644 --- a/lua/autorun/gmod_integration.lua +++ b/lua/autorun/gmod_integration.lua @@ -5,7 +5,7 @@ if game.SinglePlayer() then return end // gmInte = gmInte or {} -gmInte.version = "0.2.3" +gmInte.version = "0.3.0" gmInte.config = { ["redownloadMaterials"] = false, } diff --git a/lua/gmod_integration/client/cl_context_menu.lua b/lua/gmod_integration/client/cl_context_menu.lua new file mode 100644 index 0000000..17c337e --- /dev/null +++ b/lua/gmod_integration/client/cl_context_menu.lua @@ -0,0 +1,12 @@ +list.Set("DesktopWindows", "GmodIntegration:DesktopWindows", { + icon = "gmod_integration/logo_context.png", + title = "GM Integration", + width = 960, + height = 700, + onewindow = true, + init = function(icon, window) + window:Close() + gmInte.openAdminConfig() + end + } +) \ No newline at end of file diff --git a/lua/gmod_integration/client/cl_gui.lua b/lua/gmod_integration/client/cl_gui_admin.lua similarity index 93% rename from lua/gmod_integration/client/cl_gui.lua rename to lua/gmod_integration/client/cl_gui_admin.lua index 638e24d..fbb035b 100644 --- a/lua/gmod_integration/client/cl_gui.lua +++ b/lua/gmod_integration/client/cl_gui_admin.lua @@ -9,7 +9,7 @@ local configCat = { "Main", "Trust & Safety", "Punishment", - "Other" + "Advanced", } local possibleConfig = { @@ -118,7 +118,9 @@ local possibleConfig = { ["label"] = "Sync Ban", ["description"] = "Sync chat between the server and the discord server.", ["type"] = "checkbox", - ["disable"] = true, + ["condition"] = function(data) + return false // Disabled for now + end, ["value"] = function(setting, value) return value end, @@ -131,7 +133,9 @@ local possibleConfig = { ["label"] = "Sync Timeout", ["description"] = "Sync chat between the server and the discord server.", ["type"] = "checkbox", - ["disable"] = true, + ["condition"] = function(data) + return false // Disabled for now + end, ["value"] = function(setting, value) return value end, @@ -144,7 +148,9 @@ local possibleConfig = { ["label"] = "Sync Kick", ["description"] = "Sync chat between the server and the discord server.", ["type"] = "checkbox", - ["disable"] = true, + ["condition"] = function(data) + return false // Disabled for now + end, ["value"] = function(setting, value) return value end, @@ -157,7 +163,9 @@ local possibleConfig = { ["label"] = "Force Player Verif", ["description"] = "Sync chat between the server and the discord server.", ["type"] = "checkbox", - ["disable"] = true, + ["condition"] = function(data) + return false // Disabled for now + end, ["value"] = function(setting, value) return value end, @@ -170,7 +178,6 @@ local possibleConfig = { ["label"] = "Support Link", ["description"] = "Server ID found on the webpanel.", ["type"] = "textEntry", - ["disable"] = true, ["value"] = function(setting, value) return value end, @@ -190,7 +197,7 @@ local possibleConfig = { ["onEdit"] = function(setting, value) saveConfig(setting, value == "Enabled" && true || false) end, - ["category"] = "Other" + ["category"] = "Advanced" }, ['devInstance'] = { ["label"] = "Dev Instance", @@ -199,10 +206,13 @@ local possibleConfig = { ["value"] = function(setting, value) return value end, + ["condition"] = function(data) + return data.debug + end, ["onEdit"] = function(setting, value) saveConfig(setting, value == "Enabled" && true || false) end, - ["category"] = "Other" + ["category"] = "Advanced" } } @@ -245,6 +255,15 @@ local buttonsInfo = { } } +local colorTable = { + ["text"] = Color(255, 255, 255, 255), + ["background"] = Color(0, 0, 0, 200), + ["button"] = Color(0, 0, 0, 200), + ["buttonHover"] = Color(0, 0, 0, 255), + ["buttonText"] = Color(255, 255, 255, 255), + ["buttonTextHover"] = Color(255, 255, 255, 255), +} + function gmInte.needRestart() local frame = vgui.Create("DFrame") frame:SetSize(400, 120) @@ -360,7 +379,7 @@ function gmInte.openConfigMenu(data) end elseif (v.type == "checkbox") then input = vgui.Create("DComboBox", panel) - if (v.disable) then + if (v.condition && !v.condition(data)) then input:SetEnabled(false) end input:AddChoice("Enabled") @@ -420,17 +439,4 @@ function gmInte.openConfigMenu(data) frame.OnClose = function() if (needRestart) then gmInte.needRestart() end end -end - -list.Set("DesktopWindows", "GmodIntegration:DesktopWindows", { - icon = "gmod_integration/logo_context.png", - title = "GM Integration", - width = 960, - height = 700, - onewindow = true, - init = function(icon, window) - window:Close() - gmInte.openAdminConfig() - end - } -) \ No newline at end of file +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 new file mode 100644 index 0000000..5e4b520 --- /dev/null +++ b/lua/gmod_integration/client/cl_gui_link.lua @@ -0,0 +1,52 @@ +function gmInte.openVerifPopup() + local frame = vgui.Create("DFrame") + frame:SetSize(400, 140) + frame:Center() + frame:SetTitle("Gmod Integration - Verification Required") + frame:SetDraggable(false) + frame:ShowCloseButton(false) + frame:MakePopup() + + 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("Hey! It looks like you haven't linked your Steam account to Discord yet. This is required to play on this server. Please click the button below to link your account. After you've done that, click the refresh button.") + 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 - 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:SetSize(buttonGrid:GetColWide(), buttonGrid:GetRowHeight()) + buttonGrid:AddItem(button) + + local button = vgui.Create("DButton") + button:SetText("Refresh Verification") + button.DoClick = function() + gmInte.get("/players/" .. LocalPlayer():SteamID64(), function(code, body) + gmInte.SendNet(6) + frame:Close() + end, + function(err) + LocalPlayer():ChatPrint("Failed to refresh verification: " .. err) + end) + end + button:SetSize(buttonGrid:GetColWide(), buttonGrid:GetRowHeight()) + buttonGrid:AddItem(button) +end + +gmInte.openVerifPopup() \ No newline at end of file diff --git a/lua/gmod_integration/client/cl_hook.lua b/lua/gmod_integration/client/cl_hook.lua index 86d960b..2a698c7 100644 --- a/lua/gmod_integration/client/cl_hook.lua +++ b/lua/gmod_integration/client/cl_hook.lua @@ -12,7 +12,7 @@ hook.Add("OnPlayerChat", "gmInte:OnPlayerChat:AdminCmd", function(ply, strText, strText = string.lower(strText) - if (strText == "/gminte") then + if (strText == "/gmi") then gmInte.openAdminConfig() return true end diff --git a/lua/gmod_integration/client/cl_main.lua b/lua/gmod_integration/client/cl_main.lua index aea0a93..2525b58 100644 --- a/lua/gmod_integration/client/cl_main.lua +++ b/lua/gmod_integration/client/cl_main.lua @@ -33,67 +33,8 @@ function gmInte.openAdminConfig() gmInte.SendNet(2) end -local ScreenshotRequested = false -hook.Add("PostRender", "gmInteScreenshot", function() - if (!ScreenshotRequested) then return end - ScreenshotRequested = false - - local captureData = { - format = "png", - x = 0, - y = 0, - w = ScrW(), - h = ScrH() - } - - local screenCapture = render.Capture(captureData) - screenCapture = util.Base64Encode(screenCapture) - gmInte.log("Screenshot Taken - " .. string.len(#screenCapture / 1024) .. "KB", true) - - gmInte.post("/player/screenshots", - { - ["steamID64"] = LocalPlayer():SteamID64(), - ["screenshot"] = screenCapture, - ["options"] = captureData, - ["name"] = LocalPlayer():Nick() - }, - function(code, body) - gmInte.log("Screenshot sent to Discord", true) - end, - function(code, body) - gmInte.log("Screenshot failed to send to Discord, error code: " .. code, true) - end - ) -end) - -function gmInte.takeScreenShot(serverID, authToken) - gmInte.config.id = serverID - gmInte.config.token = authToken - - timer.Simple(0.2, function() - ScreenshotRequested = true - end) -end - // // Concommands // -concommand.Add("gmod_integration_admin", gmInte.openAdminConfig) -concommand.Add("gmod_integration_screenshot", function() - gmInte.SendNet(4) -end) - -// -// 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.SendNet(4) - end -end) \ No newline at end of file +concommand.Add("gmod_integration_admin", gmInte.openAdminConfig) \ 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 5938cfb..5e8608a 100644 --- a/lua/gmod_integration/client/cl_net.lua +++ b/lua/gmod_integration/client/cl_net.lua @@ -10,6 +10,7 @@ Upload 3 - Save Config 4 - Take ScreenShot 5 - Restart Map + 6 - Verify Me Receive 1 - Sync Chat 2 - Get Config diff --git a/lua/gmod_integration/client/cl_screenshots.lua b/lua/gmod_integration/client/cl_screenshots.lua new file mode 100644 index 0000000..36ce215 --- /dev/null +++ b/lua/gmod_integration/client/cl_screenshots.lua @@ -0,0 +1,71 @@ +// +// Hooks +// + +local ScreenshotRequested = false +hook.Add("PostRender", "gmInteScreenshot", function() + if (!ScreenshotRequested) then return end + ScreenshotRequested = false + + local captureData = { + format = "png", + x = 0, + y = 0, + w = ScrW(), + h = ScrH() + } + + local screenCapture = render.Capture(captureData) + screenCapture = util.Base64Encode(screenCapture) + gmInte.log("Screenshot Taken - " .. string.len(#screenCapture / 1024) .. "KB", true) + + gmInte.post("/screenshots", + { + ["steamID64"] = LocalPlayer():SteamID64(), + ["screenshot"] = screenCapture, + ["options"] = captureData, + ["name"] = LocalPlayer():Nick() + }, + function(code, body) + gmInte.log("Screenshot sent to Discord", true) + end, + function(code, body) + gmInte.log("Screenshot failed to send to Discord, error code: " .. code, true) + end + ) +end) + +// +// Methods +// + +function gmInte.takeScreenShot(serverID, authToken) + gmInte.config.id = serverID + gmInte.config.token = authToken + + timer.Simple(0.2, function() + ScreenshotRequested = true + end) +end + +// +// Console Commands +// + +concommand.Add("gmod_integration_screenshot", function() + gmInte.SendNet(4) +end) + +// +// 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.SendNet(4) + end +end) \ No newline at end of file diff --git a/lua/gmod_integration/server/sv__api_format.lua b/lua/gmod_integration/server/sv__api_format.lua new file mode 100644 index 0000000..11582f7 --- /dev/null +++ b/lua/gmod_integration/server/sv__api_format.lua @@ -0,0 +1,14 @@ +function gmInte.playerFormat(ply) + return { + steamID = ply:SteamID(), + steamID64 = ply:SteamID64(), + userGroup = ply:GetUserGroup(), + team = ply:Team(), + teamName = team.GetName(ply:Team()), + name = ply:Nick(), + kills = ply:Frags(), + deaths = ply:Deaths(), + customValues = ply:gmIntGetCustomValues(), + connectTime = math.Round(RealTime() - ply:gmIntGetConnectTime()), + } +end \ No newline at end of file diff --git a/lua/gmod_integration/server/sv__websocket.lua b/lua/gmod_integration/server/sv__websocket.lua index c6faa6f..4e80cb8 100644 --- a/lua/gmod_integration/server/sv__websocket.lua +++ b/lua/gmod_integration/server/sv__websocket.lua @@ -1,3 +1,6 @@ +local websocketFQDN = "ws.gmod-integration.com" +local websocketDevFQDN = "dev-ws.gmod-integration.com" + // // WebSocket // @@ -30,16 +33,7 @@ if (!GWSockets) then end local function getWebSocketURL() - local url = "wss://ws.gmod-integration.com" - local devURL = "wss://dev-ws.gmod-integration.com" - - if (!gmInte.config.debug) then return url end - if (gmInte.config.devInstance) then - gmInte.log("Using dev Instance", true) - return devURL - end - - return url + return "wss://" .. (gmInte.config.dev and websocketDevFQDN or websocketFQDN) end local socket = GWSockets.createWebSocket(getWebSocketURL()) diff --git a/lua/gmod_integration/server/sv_con.lua b/lua/gmod_integration/server/sv_con.lua index b9648b7..4bae5d6 100644 --- a/lua/gmod_integration/server/sv_con.lua +++ b/lua/gmod_integration/server/sv_con.lua @@ -1,7 +1,3 @@ -// -// Console Commands -// - local conFuncs = { ["version"] = function() gmInte.log("Version: " .. gmInte.version) diff --git a/lua/gmod_integration/server/sv_filtrers.lua b/lua/gmod_integration/server/sv_filtrers.lua new file mode 100644 index 0000000..44571d7 --- /dev/null +++ b/lua/gmod_integration/server/sv_filtrers.lua @@ -0,0 +1,85 @@ +// +// Methods +// + +local function filterMessage(reason) + local Message = { + "", + "This server has player filtering enabled", + "You are not allowed to join this server", + "", + "Reason: " .. reason, + "", + "For more information, please contact the server owner", + "Help URL: " .. (gmInte.config.supportLink && gmInte.config.supportLink || "No Support Link"), + "", + "You can also contact us on our discord server", + "https://gmod-integration.com/discord", + "", + "Have a nice day", + "", + "Service provided by Gmod Integration", + } + + for k, v in pairs(Message) do + Message[k] = v .. "\n" + end + + return table.concat(Message) +end + +local function checkTrustFactor(trustLevel) + 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 + + return true +end + +local function checkDiscordBanStatus(banStatus) + if (gmInte.config.syncBan && banStatus) then + return false + end + + return true +end + +local function playerFilter(data) + if (data.bot == 1) then return end + data.steamID64 = util.SteamIDTo64(data.networkid) + + gmInte.get("/players/" .. data.steamID64, + function(code, body) + if (!body.trust) then return 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 + ) +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 diff --git a/lua/gmod_integration/server/sv_hook.lua b/lua/gmod_integration/server/sv_hook.lua deleted file mode 100644 index d28a4ba..0000000 --- a/lua/gmod_integration/server/sv_hook.lua +++ /dev/null @@ -1,40 +0,0 @@ -// -// Server Hooks -// - -hook.Add("ShutDown", "gmInte:Server:ShutDown", function() - gmInte.serverShutDown() -end) - -hook.Add("Initialize", "gmInte.sendStatus", function() - timer.Simple(1, function() - gmInte.serverStart() - end) -end) - -// -// Player Hooks -// - -gameevent.Listen("player_connect") -hook.Add("player_connect", "gmInte:Player:Connect", function(data) - gmInte.playerConnect(data) - gmInte.playerFilter(data) -end) - -gameevent.Listen("server_addban") -hook.Add("server_addban", "gmInte:Player:Ban", function(data) - gmInte.playerBan(data) -end) - -hook.Add("PlayerDisconnected", "gmInte:Player:Disconnect", function(ply) - gmInte.playerDisconnected(ply) -end) - -hook.Add("onPlayerChangedName", "gmInte:PlayerChangeName", function(ply, old, new) - gmInte.playerChangeName(ply, old, new) -end) - -hook.Add("PlayerSay", "gmInte: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_log.lua b/lua/gmod_integration/server/sv_logs.lua similarity index 82% rename from lua/gmod_integration/server/sv_log.lua rename to lua/gmod_integration/server/sv_logs.lua index 038c2ff..310baff 100644 --- a/lua/gmod_integration/server/sv_log.lua +++ b/lua/gmod_integration/server/sv_logs.lua @@ -41,16 +41,6 @@ local function logFormatTeam(teamID, data) return data end -local function logFormatPlayer(ply, data) - data = data or {} - data.steamID64 = ply:SteamID64() - data.steamID = ply:SteamID() - data.nick = ply:Nick() - data.userGroup = ply:GetUserGroup() - data.team = logFormatTeam(ply:Team()) - return data -end - local function logDisable() return !gmInte.config.sendLog end @@ -73,9 +63,9 @@ end function gmInte.postLogPlayerSay(ply, text, teamChat) if (!validLogAndPlayers({ply})) then return end - gmInte.post("/server/log/playerSay", + gmInte.post("/logs/playerSay", { - ["ply"] = logFormatPlayer(ply), + ["ply"] = gmInte.playerFormat(ply), ["text"] = text, ["teamChat"] = teamChat } @@ -85,11 +75,11 @@ end function gmInte.postLogPlayerDeath(ply, inflictor, attacker) if (!validLogAndPlayers({ply, attacker})) then return end - gmInte.post("/server/log/playerDeath", + gmInte.post("/logs/playerDeath", { - ["ply"] = logFormatPlayer(ply), + ["ply"] = gmInte.playerFormat(ply), ["inflictor"] = logFormatEntity(inflictor), - ["attacker"] = logFormatPlayer(attacker) + ["attacker"] = gmInte.playerFormat(attacker) } ) end @@ -97,9 +87,9 @@ end function gmInte.postLogPlayerInitialSpawn(ply) if (!validLogAndPlayers({ply})) then return end - gmInte.post("/server/log/playerInitialSpawn", + gmInte.post("/logs/playerInitialSpawn", { - ["ply"] = logFormatPlayer(ply) + ["ply"] = gmInte.playerFormat(ply) } ) end @@ -119,10 +109,10 @@ function gmInte.postLogPlayerHurt(ply, attacker, healthRemaining, damageTaken) return end - gmInte.post("/server/log/playerHurt", + gmInte.post("/logs/playerHurt", { - ["ply"] = logFormatPlayer(ply), - ["attacker"] = logFormatPlayer(attacker), + ["ply"] = gmInte.playerFormat(ply), + ["attacker"] = gmInte.playerFormat(attacker), ["healthRemaining"] = healthRemaining, ["damageTaken"] = ply.gmodInteTotalDamage } @@ -133,10 +123,10 @@ end function gmInte.postLogPlayerSpawnedSomething(object, ply, ent, model) if (!validLogAndPlayers({ply})) then return end - gmInte.post("/server/log/playerSpawnedSomething", + gmInte.post("/logs/playerSpawnedSomething", { ["object"] = object, - ["ply"] = logFormatPlayer(ply), + ["ply"] = gmInte.playerFormat(ply), ["ent"] = logFormatEntity(ent), ["model"] = model || "" } @@ -146,9 +136,9 @@ end function gmInte.postLogPlayerSpawn(ply) if (!validLogAndPlayers({ply})) then return end - gmInte.post("/server/log/playerSpawn", + gmInte.post("/logs/playerSpawn", { - ["ply"] = logFormatPlayer(ply) + ["ply"] = gmInte.playerFormat(ply) } ) end @@ -156,9 +146,9 @@ end function gmInte.postLogPlayerDisconnect(ply) if (!validLogAndPlayers({ply})) then return end - gmInte.post("/server/log/playerDisconnect", + gmInte.post("/logs/playerDisconnect", { - ["ply"] = logFormatPlayer(ply) + ["ply"] = gmInte.playerFormat(ply) } ) end @@ -166,7 +156,7 @@ end function gmInte.postLogPlayerConnect(data) if (logDisable() || data.bot) then return end - gmInte.post("/server/log/playerConnect", + gmInte.post("/logs/playerConnect", { ["steamID64"] = util.SteamIDTo64(data.networkid), ["steamID"] = data.networkid, @@ -179,9 +169,9 @@ end function gmInte.postLogPlayerGivet(ply, class, swep) if (!validLogAndPlayers({ply})) then return end - gmInte.post("/server/log/playerGive", + gmInte.post("/logs/playerGive", { - ["ply"] = logFormatPlayer(ply), + ["ply"] = gmInte.playerFormat(ply), ["class"] = class, ["swep"] = swep } @@ -194,13 +184,16 @@ end gameevent.Listen("player_connect") -// Sandbox - Player +// Base - Player hook.Add("PlayerSay", "gmInte:Log:PlayerSay", function(ply, text, teamChat) gmInte.postLogPlayerSay(ply, text, teamChat) end) hook.Add("PlayerSpawn", "gmInte:Log:PlayerSpawn", function(ply) gmInte.postLogPlayerSpawn(ply) end) +hook.Add("player_connect", "gmInte:Log:PlayerConnect", function(data) + gmInte.postLogPlayerConnect(data) +end) hook.Add("PlayerInitialSpawn", "gmInte:Log:PlayerInitialSpawn", function(ply) gmInte.postLogPlayerInitialSpawn(ply) end) @@ -211,12 +204,7 @@ hook.Add("PlayerGiveSWEP", "gmInte:Log:PlayerSWEPs", function( ply, class, swep gmInte.postLogPlayerGivet(ply, class, swep) end) -// Sandbox - Server Events -hook.Add("player_connect", "gmInte:Log:PlayerConnect", function(data) - gmInte.postLogPlayerConnect(data) -end) - -// Sandbox - Player Combat +// Base - Player Combat hook.Add("PlayerDeath", "gmInte:Log:PlayerDeath", function(ply, inflictor, attacker) gmInte.postLogPlayerDeath(ply, inflictor, attacker) end) @@ -224,7 +212,7 @@ hook.Add("PlayerHurt", "gmInte:Log:PlayerHurt", function(ply, attacker, healthRe gmInte.postLogPlayerHurt(ply, attacker, healthRemaining, damageTaken) end) -// Sandbox - Spawnables +// Base - Spawnables hook.Add("PlayerSpawnedProp", "gmInte:Log:PlayerSpawnedProp", function(ply, model, ent) gmInte.postLogPlayerSpawnedSomething("SENT", ply, ent, model) end) diff --git a/lua/gmod_integration/server/sv_main.lua b/lua/gmod_integration/server/sv_main.lua deleted file mode 100644 index b56919a..0000000 --- a/lua/gmod_integration/server/sv_main.lua +++ /dev/null @@ -1,300 +0,0 @@ -// -// Functions -// - -function gmInte.removePort(ip) - return string.Explode(":", ip)[1] -end - -function gmInte.plyValid(ply) - return ply:IsValid() && ply:IsPlayer() && !ply:IsBot() -end - -function gmInte.saveSetting(setting, value) - // save this in data/gmod_integration/setting.json but first check if variable is valid - if gmInte.config[setting] == nil then - gmInte.log("Unknown Setting") - return - end - - // Boolean - if (value == "true") then value = true end - if (value == "false") then value = false end - - // Number - if (tonumber(value) != nil) then value = tonumber(value) end - - gmInte.config[setting] = value - file.Write("gm_integration/config.json", util.TableToJSON(gmInte.config, true)) - gmInte.log("Setting Saved") -end - -function gmInte.playerConnect(data) - if (data.bot == 1) then return end - - data.steam = util.SteamIDTo64(data.networkid) - - gmInte.post("/server/user/connect", data) -end - -local function getCustomValues(ply) - local customValues = {} - - customValues.money = ply:gmInteGetTotalMoney() || 0 - - return customValues -end - -local function getTriggerInfo(text) - for k, v in pairs(gmInte.config.chatTrigger) do - if (string.StartWith(text, k)) then - local defaultConfig = { - ["trigger"] = k, - ["prefix"] = "", - ["show_rank"] = false, - ["anonymous"] = false, - ["channel"] = "admin_sync_chat" - } - for k2, v2 in pairs(v) do - defaultConfig[k2] = v2 - end - return defaultConfig - end - end - - return false -end - -function gmInte.playerSay(ply, text, team) - if (!gmInte.config.syncChat) then return end - - gmInte.post("/server/user/say", - { - ["steamID64"] = ply:SteamID64(), - ["message"] = text, - ["name"] = ply:Nick(), - ["usergroup"] = ply:GetUserGroup(), - ["message_info"] = triggerInfo - } - ) -end - -function gmInte.wsPlayerSay(data) - gmInte.SendNet(1, data, nil) -end - -function gmInte.generatePlayerToken(steamID64) - return util.SHA256(steamID64 .. '-' .. gmInte.config.token .. '-' .. gmInte.publicTempToken) -end - -function gmInte.takeScreenshot(ply) - gmInte.SendNet(4, { - ["serverID"] = gmInte.config.id, - ["authToken"] = gmInte.generatePlayerToken(ply:SteamID64()) - }, ply) -end - -function gmInte.wsPlayerScreen(data) - for _, ply in pairs(player.GetAll()) do - if (ply:SteamID64() == data.steamID64) then - gmInte.takeScreenshot(ply) - end - end -end - -function gmInte.wsRcon(data) - gmInte.log("Rcon Command from Discord '" .. data.command .. "' by " .. data.steamID) - game.ConsoleCommand(data.command .. "\n") -end - -function gmInte.playerBan(data) - data.steam = util.SteamIDTo64(data.networkid) - gmInte.post("/server/user/ban", data) -end - -function gmInte.userFinishConnect(ply) - if (!gmInte.plyValid(ply)) then return end - - gmInte.post("/server/user/finishConnect", - { - ["steam"] = ply:SteamID64(), - ["name"] = ply:Nick(), - } - ) -end - -function gmInte.serverShutDown() - gmInte.post("/server/shutdown") -end - -function gmInte.sendStatus(start) - if (gmInte.config.id == "" || gmInte.config.token == "") then - gmInte.logError("ID or Token is empty: (id: " .. (gmInte.config.id == "" && "empty" || gmInte.config.id) .. ", token: " .. (gmInte.config.token == "" && "empty" || "not empty but hide") .. ")") - gmInte.logHint("Use 'gmod-integration setting id YOUR_SERVER_ID' and 'gmod-integration setting token YOUR_SERVER_TOKEN' to set your credentials, you can find them on https://gmod-integration.com/config/servers") - return - end - gmInte.post("/server/status", - { - ["start"] = start || false, - ["hostname"] = GetHostName(), - ["ip"] = game.GetIPAddress(), - ["port"] = GetConVar("hostport"):GetInt(), - ["map"] = game.GetMap(), - ["players"] = #player.GetAll(), - ["maxplayers"] = game.MaxPlayers(), - ["gamemode"] = engine.ActiveGamemode() - }, - function(code, body) - if (body.publicTempToken) then - gmInte.publicTempToken = body.publicTempToken - end - end, - function(code, body, headers) - gmInte.logError("Your Credentials are Invalid: (id: " .. (gmInte.config.id == "" && "empty" || gmInte.config.id) .. ", token: " .. (gmInte.config.token == "" && "empty" || "not empty but hide") .. ")") - gmInte.logHint("Use 'gmod-integration setting id YOUR_SERVER_ID' and 'gmod-integration setting token YOUR_SERVER_TOKEN' to set your credentials, you can find them on https://gmod-integration.com/config/servers") - end - ) -end - -function gmInte.serverStart() - gmInte.sendStatus(true) -end - -// every 5 minutes -timer.Create("gmInte.sendStatus", 300, 0, function() - gmInte.sendStatus() -end) - -function gmInte.playerChangeName(ply, old, new) - if (!gmInte.plyValid(ply)) then return end - - gmInte.post("/server/user/changeName", - { - ["steamID64"] = ply:SteamID64(), - ["oldName"] = old, - ["newName"] = new, - } - ) -end - -function gmInte.playerDisconnected(ply) - if (!gmInte.plyValid(ply)) then return end - - gmInte.post("/server/user/disconnect", - { - ["steam"] = ply:SteamID64(), - ["kills"] = ply:Frags() || 0, - ["deaths"] = ply:Deaths() || 0, - ["customValues"] = getCustomValues(ply), - ["rank"] = ply:GetUserGroup() || "user", - ["time"] = math.Round(RealTime() - ply.gmIntTimeConnect) || 0, - } - ) -end - -function gmInte.tryConfig() - gmInte.get("/server", - 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.get("/server", - function(code, body) - gmInte.SendNet(3, body, ply) - end, - function(code, body, headers) - gmInte.SendNet(3, body, ply) - end) -end - -function gmInte.serverShutDown() - for ply, ply in pairs(player.GetAll()) do - gmInte.playerDisconnected(ply) - end -end - -function gmInte.refreshSettings() - gmInte.config = util.JSONToTable(file.Read("gm_integration/config.json", "DATA")) - gmInte.log("Settings Refreshed") - gmInte.tryConfig() -end - -local function filterMessage(reason) - local Message = { - [1] = "\n", - [2] = "This server has player filtering enabled", - [3] = "You are not allowed to join this server", - [4] = "", - [5] = "Reason: " .. reason, - [6] = "", - [7] = "For more information, please contact the server owner", - [8] = "Help URL: " .. (gmInte.config.supportLink && gmInte.config.supportLink || "No Support Link"), - [9] = "", - [10] = "You can also contact us on our discord server", - [11] = "https://gmod-integration.com/discord", - [12] = "", - [13] = "Have a nice day", - [14] = "", - [15] = "Service provided by Gmod Integration", - } - for k, v in pairs(Message) do - Message[k] = v .. "\n" - end - return table.concat(Message) -end - -function gmInte.playerFilter(data) - if (data.bot == 1) then return end - - data.steamID64 = util.SteamIDTo64(data.networkid) - - // get data - gmInte.get("/server/user" .. "?steamID64=" .. data.steamID64, - function(code, body) - if (!body || !body.trust) then return end - - // Gmod Integration Trust - if (gmInte.config.filterOnTrust && (body.trust < gmInte.config.minimalTrust)) then - // kick player - game.KickID(data.networkid, filterMessage("Insufficient Trust Level\nYour Trust Level: " .. body.trust .. "\nMinimal Trust Level: " .. gmInte.config.minimalTrust)) - end - - // Gmod Integration Ban - if (gmInte.config.filterOnBan && body.ban) then - // kick player - game.KickID(data.networkid, filterMessage("You are banned from Gmod Integration")) - end - - // Server Discord Ban - if (gmInte.config.syncBan && body.discord_ban) then - // kick player - game.KickID(data.networkid, filterMessage("You are banned from the discord server\nReason: " .. (body.discord_ban_reason && body.discord_ban_reason || "No Reason"))) - end - end - ) -end - -function gmInte.superadminGetConfig(ply) - if (!gmInte.plyValid(ply) || !ply:IsSuperAdmin()) then return end - - gmInte.config.websocket = GWSockets && true || false - gmInte.SendNet(2, gmInte.config, ply) -end - -function gmInte.superadminSetConfig(ply, data) - if (!gmInte.plyValid(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 -end \ No newline at end of file diff --git a/lua/gmod_integration/server/sv_meta.lua b/lua/gmod_integration/server/sv_meta.lua deleted file mode 100644 index ec90cd1..0000000 --- a/lua/gmod_integration/server/sv_meta.lua +++ /dev/null @@ -1,12 +0,0 @@ -// Meta -local ply = FindMetaTable("Player") - -function ply:gmInteGetTotalMoney() - // if darkrp - if DarkRP then - return self:getDarkRPVar("money") - end - - // else - return 0 -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 11452ee..431ad1c 100644 --- a/lua/gmod_integration/server/sv_net.lua +++ b/lua/gmod_integration/server/sv_net.lua @@ -23,7 +23,7 @@ util.AddNetworkString("gmIntegration") function gmInte.SendNet(id, data, ply, func) net.Start("gmIntegration") net.WriteUInt(id, 8) - net.WriteString(util.TableToJSON(data)) + net.WriteString(util.TableToJSON(data || {})) if (func) then func() end if (ply == nil) then net.Broadcast() @@ -36,7 +36,6 @@ end local netFuncs = { [0] = function(ply) gmInte.userFinishConnect(ply) - ply.gmIntTimeConnect = math.Round(RealTime()) end, [1] = function(ply, data) gmInte.testConnection(ply, data) @@ -54,6 +53,9 @@ local netFuncs = { if (!ply:IsSuperAdmin()) then return end RunConsoleCommand("changelevel", game.GetMap()) end, + [6] = function(ply) + gmInte.verifyPlayer(ply) + end } net.Receive("gmIntegration", function(len, ply) diff --git a/lua/gmod_integration/server/sv_players.lua b/lua/gmod_integration/server/sv_players.lua new file mode 100644 index 0000000..8d1ee1f --- /dev/null +++ b/lua/gmod_integration/server/sv_players.lua @@ -0,0 +1,145 @@ +// +// Meta +// + +local ply = FindMetaTable("Player") + +function ply:gmIntGetConnectTime() + return self.gmIntTimeConnect || 0 +end + +function ply:gmIntSetCustomValue(key, value) + self.gmIntCustomValues = self.gmIntCustomValues || {} + self.gmIntCustomValues[key] = value +end + +function ply:gmIntGetCustomValue(key) + return self.gmIntCustomValues && self.gmIntCustomValues[key] +end + +function ply:gmIntRemoveCustomValue(key) + if (self.gmIntCustomValues) then + self.gmIntCustomValues[key] = nil + end +end + +// +// Compatibility +// + +local function getCustomCompatability(ply) + local values = {} + + // DarkRP + if (DarkRP) then + values.money = ply:getDarkRPVar("money") + values.job = ply:getDarkRPVar("job") + end + + // GUI Level System + 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 + for key, value in pairs(ply.gmIntCustomValues) do + values[key] = value + end + end + + return values +end + +function ply:gmIntGetCustomValues() + return getCustomValues(self) +end + +function gmInte.plyValid(ply) + return ply:IsValid() && ply:IsPlayer() && !ply:IsBot() +end + +function gmInte.verifyPlayer(ply) + if (!gmInte.plyValid(ply)) then return end + gmInte.get("/players/" .. ply:SteamID64(), function(data) + if (data.discordID && ply.gmIntUnVerified) then + ply:Freeze(false) + ply.gmIntUnVerified = false + end + end) +end + +// Generate a unique token that allow player to update data link to this server (ex: screnshot, report bug, etc.) +function gmInte.getClientOneTimeToken(ply, callback) + gmInte.get("/players/" .. ply:SteamID64() .. "/get-one-time-token", function(data) + callback(data.token) + end) +end + +function gmInte.playerConnect(data) + gmInte.post("/players/" .. util.SteamIDTo64(data.networkid) .. "/connect", data) +end + +function gmInte.userFinishConnect(ply) + if (!gmInte.plyValid(ply)) then return end + ply.gmIntTimeConnect = math.Round(RealTime()) + + gmInte.post("/players/" .. ply:SteamID64() .. "/finish-connect", + { + ["player"] = gmInte.playerFormat(ply), + } + ) + + if (!gmInte.config.forcePlayerLink) then return end + gmInte.get("/players/" .. ply:SteamID64(), function(data) + if (!data.discordID) then + ply:Freeze(true) + ply.gmIntUnVerified = true + end + end) +end + +function gmInte.playerDisconnected(ply) + if (!gmInte.plyValid(ply)) then return end + + gmInte.post("/players/" .. ply:SteamID64() .. "/disconnect", + { + ["player"] = gmInte.playerFormat(ply), + } + ) +end + +// +// Hooks +// + +hook.Add("ShutDown", "gmInte:Server:Shutdown:SavePlayers", function() + for ply, ply in pairs(player.GetAll()) do + gmInte.playerDisconnected(ply) + end +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) \ No newline at end of file diff --git a/lua/gmod_integration/server/sv_rcon.lua b/lua/gmod_integration/server/sv_rcon.lua new file mode 100644 index 0000000..8cb8259 --- /dev/null +++ b/lua/gmod_integration/server/sv_rcon.lua @@ -0,0 +1,8 @@ +// +// Websocket +// + +function gmInte.wsRcon(data) + gmInte.log("Rcon Command from Discord '" .. data.command .. "' by " .. data.steamID) + game.ConsoleCommand(data.command .. "\n") +end \ No newline at end of file diff --git a/lua/gmod_integration/server/sv_screenshots.lua b/lua/gmod_integration/server/sv_screenshots.lua new file mode 100644 index 0000000..97a0536 --- /dev/null +++ b/lua/gmod_integration/server/sv_screenshots.lua @@ -0,0 +1,24 @@ +// +// Websocket +// + +function gmInte.wsPlayerScreen(data) + for _, ply in pairs(player.GetAll()) do + if (ply:SteamID64() == data.steamID64) then + gmInte.takeScreenshot(ply) + end + end +end + +// +// Methods +// + +function gmInte.takeScreenshot(ply) + gmInte.getClientOneTimeToken(ply, function(oneTime) + gmInte.SendNet(4, { + ["serverID"] = gmInte.config.id, + ["oneTimeToken"] = oneTime + }, ply) + end) +end \ No newline at end of file diff --git a/lua/gmod_integration/server/sv_settings.lua b/lua/gmod_integration/server/sv_settings.lua new file mode 100644 index 0000000..a0c1eaf --- /dev/null +++ b/lua/gmod_integration/server/sv_settings.lua @@ -0,0 +1,65 @@ +function gmInte.saveSetting(setting, value) + if gmInte.config[setting] == nil then + gmInte.log("Unknown Setting") + return + end + + // Boolean + if (value == "true") then value = true end + if (value == "false") then value = false end + + // Number + if (tonumber(value) != nil) then value = tonumber(value) end + + gmInte.config[setting] = value + file.Write("gm_integration/config.json", util.TableToJSON(gmInte.config, true)) + gmInte.log("Setting Saved") +end + +function gmInte.tryConfig() + gmInte.get("", + 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.get("", + function(code, body) + if (ply) then gmInte.SendNet(3, body, ply) end + end, + function(code, body) + if (ply) then gmInte.SendNet(3, body, ply) end + end + ) +end + +function gmInte.refreshSettings() + gmInte.config = util.JSONToTable(file.Read("gm_integration/config.json", "DATA")) + gmInte.log("Settings Refreshed") + gmInte.tryConfig() +end + +function gmInte.superadminGetConfig(ply) + if (!gmInte.plyValid(ply) || !ply:IsSuperAdmin()) then return end + + gmInte.config.websocket = GWSockets && true || false + gmInte.SendNet(2, gmInte.config, ply) +end + +function gmInte.superadminSetConfig(ply, data) + if (!gmInte.plyValid(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 +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 new file mode 100644 index 0000000..aafffc2 --- /dev/null +++ b/lua/gmod_integration/server/sv_status.lua @@ -0,0 +1,51 @@ +// +// Methods +// + +local function getServerFormat() + return { + ["hostname"] = GetHostName(), + ["ip"] = game.GetIPAddress(), + ["port"] = GetConVar("hostport"):GetInt(), + ["map"] = game.GetMap(), + ["players"] = #player.GetAll(), + ["maxplayers"] = game.MaxPlayers(), + ["gamemode"] = engine.ActiveGamemode(), + ["uptime"] = math.Round(RealTime() / 60) + } +end + +function gmInte.sendStatus() + gmInte.post("/status", getServerFormat()) +end + +-- function gmInte.serverStart() +-- gmInte.post("/start", getServerFormat()) +-- end + +function gmInte.serverShutDown() + gmInte.post("/shutdown") +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() + gmInte.sendStatus() + 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 new file mode 100644 index 0000000..121b160 --- /dev/null +++ b/lua/gmod_integration/server/sv_sync_bans.lua @@ -0,0 +1,28 @@ +// +// 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 + end +end + +// +// Methods +// + +function gmInte.playerBan(data) + gmInte.post("/players/" .. util.SteamIDTo64(data.networkid) .. "/bans", 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 diff --git a/lua/gmod_integration/server/sv_sync_chat.lua b/lua/gmod_integration/server/sv_sync_chat.lua new file mode 100644 index 0000000..b567815 --- /dev/null +++ b/lua/gmod_integration/server/sv_sync_chat.lua @@ -0,0 +1,31 @@ +// +// Websocket +// + +function gmInte.wsPlayerSay(data) + gmInte.SendNet(1, data, nil) +end + +// +// Methods +// + +function gmInte.playerSay(ply, text, team) + if (!gmInte.config.syncChat) then return end + + gmInte.post("/players/" .. ply:SteamID64() .. "/say", + { + ["player"] = gmInte.playerFormat(ply), + ["text"] = text, + ["team"] = team, + } + ) +end + +// +// Hooks +// + +hook.Add("PlayerSay", "gmInte:PlayerSay:SyncChat", 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_names.lua b/lua/gmod_integration/server/sv_sync_names.lua new file mode 100644 index 0000000..601bb48 --- /dev/null +++ b/lua/gmod_integration/server/sv_sync_names.lua @@ -0,0 +1,33 @@ +// +// Websocket +// + +function gmInte.wsSyncName(data) + local ply = player.GetBySteamID(data.player.steamID64) + if not IsValid(ply) then return end + ply:SetName(data.newName) +end + +// +// Methods +// + +function gmInte.playerChangeName(ply, oldName, newName) + if (!gmInte.plyValid(ply)) then return end + + gmInte.post("/players/" .. ply:SteamID64() .. "/name", + { + ["player"] = gmInte.playerFormat(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 diff --git a/lua/gmod_integration/server/sv_sync_roles.lua b/lua/gmod_integration/server/sv_sync_roles.lua new file mode 100644 index 0000000..6baff9e --- /dev/null +++ b/lua/gmod_integration/server/sv_sync_roles.lua @@ -0,0 +1,35 @@ +// +// Websocket +// + +function gmInte.wsSyncRoles(data) + local ply = player.GetBySteamID(data.steamID) + if (ply:IsValid()) then + ply:SetUserGroup(data.role) + end + + // ULX + if (ULib) then + ULib.ucl.addUser(data.steamID, nil, nil, data.role) + end + + // FAdmin + if (CAMI) then + CAMI.PlayerRank(data.steamID64, data.role, "user") + end + + // ServerGuard + if (serverguard) then + serverguard.player:SetRank(data.steamID64, data.role) + end + + // Evolve + if (evolve) then + evolve:RankPlayer(data.steamID64, data.role) + end + + // SAM + if (SAM) then + SAM:PlayerSetRank(data.steamID64, data.role) + end +end \ No newline at end of file diff --git a/lua/gmod_integration/server/sv_sync_warns.lua b/lua/gmod_integration/server/sv_sync_warns.lua new file mode 100644 index 0000000..3167988 --- /dev/null +++ b/lua/gmod_integration/server/sv_sync_warns.lua @@ -0,0 +1,15 @@ +// +// Websocket +// + +function gmInte.wsSyncWarns(data) + // +end + +// +// Methods +// + +function gmInte.playerWarn(data) + // +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 b592152..0b16146 100644 --- a/lua/gmod_integration/shared/sh_http.lua +++ b/lua/gmod_integration/shared/sh_http.lua @@ -1,126 +1,118 @@ +local apiVersion = "v3" +local apiFQDN = "api.gmod-integration.com" +local apiDevFQDN = "dev-api.gmod-integration.com" + // // HTTP // -local failMessage = { - ["401"] = "Bad Credentials", - ["403"] = "Forbidden", - ["404"] = "Not Found", - ["500"] = "Internal Server Error", - ["503"] = "Service Unavailable", - ["504"] = "Gateway Timeout", -} +local function getAPIURL(endpoint) + local url = "https://" .. (gmInte.config.devInstance && apiDevFQDN || apiFQDN) .. "/" .. apiVersion -local function errorMessage(body, code) - if (body && body.error) then - if (failMessage[code]) then - return failMessage[code] - else - return body.error - end - elseif (failMessage[code]) then - return failMessage[code] - else - return code - end -end - -local function getAPIURL() - local url = "https://api.gmod-integration.com" - local devURL = "https://dev-api.gmod-integration.com" - - if (!gmInte.config.debug) then return url end - if (gmInte.config.devInstance) then - gmInte.log("Using dev Instance", true) - return devURL + if (SERVER) then + url = url .. "/servers/" .. gmInte.config.id + elseif (endpoint == "/players") then + url = url .. "/clients/" .. LocalPlayer():SteamID64() end - return url + return url .. endpoint end -local function sendHTTP(params) - // Log the HTTP request - gmInte.log("HTTP Request: " .. params.method .. " " .. params.endpoint, true) - gmInte.log("HTTP Body: " .. (params.body || "No body"), true) +function gmInte.requestAPI(params) + local body = params.body || "" + local bodyLength = string.len(body) + local token = params.token || gmInte.config.token || "" + local url = getAPIURL(params.endpoint) + local method = params.method + local success = params.success || function() end + local failed = params.failed || function(error) gmInte.logError(error.error || error) end + local version = gmInte.config.version - // Send the HTTP request + local headers = { + ["Content-Type"] = "application/json", + ["Content-Length"] = bodyLength, + ["Authorization"] = "Bearer " .. token, + ["Version"] = version + } + local type = "application/json" + + // Log + if (gmInte.config.devInstance) then gmInte.log("HTTP Using dev Instance", true) end + gmInte.log("HTTP Request: " .. method .. " " .. url, true) + gmInte.log("HTTP Body: " .. body, true) + + // Send HTTP({ - url = getAPIURL() .. params.endpoint, - method = params.method, - headers = { - ["Content-Type"] = "application/json", - ["Content-Length"] = params.body && string.len(params.body) || 0, - ["id"] = gmInte.config.id, - ["token"] = gmInte.config.token, - ["version"] = gmInte.version - }, - body = params.body && params.body || "", - type = "application/json", - success = function(code, body, headers) - // Log the HTTP response + ["url"] = url, + ["method"] = method, + ["headers"] = headers, + ["body"] = body, + ["type"] = type, + ["success"] = function(code, body, headers) + // Log gmInte.log("HTTP Response: " .. code, true) if (gmInte.config.debug) then gmInte.log("HTTP Body: " .. body, true) end - // if body and is json extract it - if (body && string.sub(headers["Content-Type"], 1, 16) == "application/json") then - body = util.JSONToTable(body) + // if not 2xx return failed + if (code < 200 || code >= 300) then + return failed(body, code, headers) end - // Check if the request was successful - if (string.sub(code, 1, 1) == "2") then - if (params.success) then - params.success(code, body, headers) - else - gmInte.log("HTTP Request Successful", true) - end - else - if (params.failed) then - params.failed(code, body, headers) - else - gmInte.logError(errorMessage(body, code)) - end + // if not application/json return failed + if (string.sub(headers["Content-Type"], 1, 16) != "application/json") then + return failed({ ["error"] = "Invalid Content-Type" }, code, headers) end + + // Tableify the body if it's JSON + body = util.JSONToTable(body || "{}") + + // Return success + return success(code, body, headers) end, - failed = function(error) + ["failed"] = function(error) gmInte.logError(error) end }) end +// +// HTTP Methods +// + function gmInte.get(endpoint, onSuccess, onFailed) - sendHTTP({ - endpoint = endpoint, - method = "GET", - success = onSuccess, - failed = onFailed + gmInte.requestAPI({ + ["endpoint"] = endpoint, + ["method"] = "GET", + ["success"] = onSuccess, + ["failed"] = onFailed }) end function gmInte.post(endpoint, data, onSuccess, onFailed) - sendHTTP({ - endpoint = endpoint, - method = "POST", - body = util.TableToJSON(data), - success = onSuccess, - failed = onFailed + gmInte.requestAPI({ + ["endpoint"] = endpoint, + ["method"] = "POST", + ["body"] = util.TableToJSON(data), + ["success"] = onSuccess, + ["failed"] = onFailed }) end function gmInte.put(endpoint, data, onSuccess, onFailed) - sendHTTP({ - endpoint = endpoint, - method = "PUT", - body = util.TableToJSON(data), - success = onSuccess, - failed = onFailed + gmInte.requestAPI({ + ["endpoint"] = endpoint, + ["method"] = "PUT", + ["body"] = util.TableToJSON(data), + ["success"] = onSuccess, + ["failed"] = onFailed }) end function gmInte.delete(endpoint, onSuccess, onFailed) - sendHTTP({ - endpoint = endpoint, - method = "DELETE", - success = onSuccess, - failed = onFailed + gmInte.requestAPI({ + ["endpoint"] = endpoint, + ["method"] = "DELETE", + ["success"] = onSuccess, + ["failed"] = onFailed }) end \ No newline at end of file From d2312f55a992e3464f35d7691ba19a62e58ccfbf Mon Sep 17 00:00:00 2001 From: Linventif Date: Fri, 9 Feb 2024 22:48:07 +0100 Subject: [PATCH 02/66] add error reporter --- lua/gmod_integration/shared/sh_errors.lua | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 lua/gmod_integration/shared/sh_errors.lua diff --git a/lua/gmod_integration/shared/sh_errors.lua b/lua/gmod_integration/shared/sh_errors.lua new file mode 100644 index 0000000..ebe31e6 --- /dev/null +++ b/lua/gmod_integration/shared/sh_errors.lua @@ -0,0 +1,25 @@ +// +// Methods +// + +function gmInte.sendLuaErrorReport(err, realm, stack, name, id) + if (name !== "gmod_integration") then return end + gmInte.http.post("/errors", + { + ["error"] = err, + ["realm"] = realm, + ["stack"] = stack, + ["name"] = name, + ["id"] = id, + ["identifier"] = SERVER && gmInte.config.id || LocalPlayer():SteamID64() + } + ) +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 From 909b429111759bc7f546e4518d8264224c14530f Mon Sep 17 00:00:00 2001 From: Linventif Date: Fri, 9 Feb 2024 22:48:31 +0100 Subject: [PATCH 03/66] Update gmInte.config initialization --- lua/autorun/gmod_integration.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lua/autorun/gmod_integration.lua b/lua/autorun/gmod_integration.lua index 6125023..4be2ce5 100644 --- a/lua/autorun/gmod_integration.lua +++ b/lua/autorun/gmod_integration.lua @@ -4,9 +4,9 @@ if game.SinglePlayer() then return end // Variables // -gmInte = gmInte or {} +gmInte = gmInte || {} gmInte.version = "0.3.0" -gmInte.config = { +gmInte.config = gmInte.config || { ["redownloadMaterials"] = false, } gmInte.materials = {} @@ -17,7 +17,6 @@ gmInte.materials = {} local function loadConfig() if (SERVER) then - print(" | Loading File | gmod_integration/sv_config.lua") RunConsoleCommand("sv_hibernate_think", "1") if (!file.Exists("gm_integration", "DATA") || !file.Exists("gm_integration/config.json", "DATA")) then file.CreateDir("gm_integration") From 28c064241acb5c5951843ce2d50ebd6c10acdfc8 Mon Sep 17 00:00:00 2001 From: Linventif Date: Fri, 9 Feb 2024 22:49:34 +0100 Subject: [PATCH 04/66] add gmInte.http.METHOD insted of gmInte.METHOD --- lua/gmod_integration/client/cl_gui_admin.lua | 3 -- lua/gmod_integration/client/cl_gui_link.lua | 2 +- lua/gmod_integration/client/cl_main.lua | 9 +++++ lua/gmod_integration/client/cl_net.lua | 12 ++++++ .../client/cl_screenshots.lua | 2 +- lua/gmod_integration/server/sv_filtrers.lua | 4 +- lua/gmod_integration/server/sv_logs.lua | 18 ++++----- lua/gmod_integration/server/sv_net.lua | 3 ++ lua/gmod_integration/server/sv_players.lua | 40 +++++++++++++------ lua/gmod_integration/server/sv_settings.lua | 13 +++++- lua/gmod_integration/server/sv_status.lua | 6 +-- lua/gmod_integration/server/sv_sync_bans.lua | 2 +- lua/gmod_integration/server/sv_sync_chat.lua | 2 +- lua/gmod_integration/server/sv_sync_names.lua | 2 +- lua/gmod_integration/shared/sh_http.lua | 28 ++++++++----- 15 files changed, 99 insertions(+), 47 deletions(-) diff --git a/lua/gmod_integration/client/cl_gui_admin.lua b/lua/gmod_integration/client/cl_gui_admin.lua index fbb035b..112c59a 100644 --- a/lua/gmod_integration/client/cl_gui_admin.lua +++ b/lua/gmod_integration/client/cl_gui_admin.lua @@ -163,9 +163,6 @@ local possibleConfig = { ["label"] = "Force Player Verif", ["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, diff --git a/lua/gmod_integration/client/cl_gui_link.lua b/lua/gmod_integration/client/cl_gui_link.lua index 5e4b520..3056a18 100644 --- a/lua/gmod_integration/client/cl_gui_link.lua +++ b/lua/gmod_integration/client/cl_gui_link.lua @@ -37,7 +37,7 @@ function gmInte.openVerifPopup() local button = vgui.Create("DButton") button:SetText("Refresh Verification") button.DoClick = function() - gmInte.get("/players/" .. LocalPlayer():SteamID64(), function(code, body) + gmInte.http.get("/players/" .. LocalPlayer():SteamID64(), function(code, body) gmInte.SendNet(6) frame:Close() end, diff --git a/lua/gmod_integration/client/cl_main.lua b/lua/gmod_integration/client/cl_main.lua index 2525b58..1153572 100644 --- a/lua/gmod_integration/client/cl_main.lua +++ b/lua/gmod_integration/client/cl_main.lua @@ -12,6 +12,15 @@ local function formatName(name) return name end +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.discordSyncChatPly(data) chat.AddText(Color(92, 105, 255), "(DISCORD) ", Color(12, 151, 12), formatName(data.name) .. ": ", Color(255, 255, 255), data.content) end diff --git a/lua/gmod_integration/client/cl_net.lua b/lua/gmod_integration/client/cl_net.lua index 5e8608a..9c917f0 100644 --- a/lua/gmod_integration/client/cl_net.lua +++ b/lua/gmod_integration/client/cl_net.lua @@ -16,6 +16,9 @@ Receive 2 - Get Config 3 - Test Connection 4 - Take ScreenShot + 5 - Set Public Config + 6 - Add Chat + 7 - Open Verif Popup */ // Send @@ -40,6 +43,15 @@ local netFunc = { end, [4] = function(data) gmInte.takeScreenShot(data.serverID, data.authToken) + end, + [5] = function(data) + gmInte.config = data + end, + [6] = function(data) + gmInte.chatAddText(data) + end, + [7] = function() + gmInte.openVerifPopup() end } diff --git a/lua/gmod_integration/client/cl_screenshots.lua b/lua/gmod_integration/client/cl_screenshots.lua index 36ce215..4cb215f 100644 --- a/lua/gmod_integration/client/cl_screenshots.lua +++ b/lua/gmod_integration/client/cl_screenshots.lua @@ -19,7 +19,7 @@ hook.Add("PostRender", "gmInteScreenshot", function() screenCapture = util.Base64Encode(screenCapture) gmInte.log("Screenshot Taken - " .. string.len(#screenCapture / 1024) .. "KB", true) - gmInte.post("/screenshots", + gmInte.http.post("/screenshots", { ["steamID64"] = LocalPlayer():SteamID64(), ["screenshot"] = screenCapture, diff --git a/lua/gmod_integration/server/sv_filtrers.lua b/lua/gmod_integration/server/sv_filtrers.lua index 44571d7..c5a2565 100644 --- a/lua/gmod_integration/server/sv_filtrers.lua +++ b/lua/gmod_integration/server/sv_filtrers.lua @@ -56,9 +56,9 @@ local function playerFilter(data) if (data.bot == 1) then return end data.steamID64 = util.SteamIDTo64(data.networkid) - gmInte.get("/players/" .. data.steamID64, + gmInte.http.get("/players/" .. data.steamID64, function(code, body) - if (!body.trust) then return end + if (!body || !body.trust) then return end if (!checkBanStatus(body.ban)) then game.KickID(data.networkid, filterMessage("You are banned from this server")) diff --git a/lua/gmod_integration/server/sv_logs.lua b/lua/gmod_integration/server/sv_logs.lua index 310baff..ef4d091 100644 --- a/lua/gmod_integration/server/sv_logs.lua +++ b/lua/gmod_integration/server/sv_logs.lua @@ -63,7 +63,7 @@ end function gmInte.postLogPlayerSay(ply, text, teamChat) if (!validLogAndPlayers({ply})) then return end - gmInte.post("/logs/playerSay", + gmInte.http.post("/logs/playerSay", { ["ply"] = gmInte.playerFormat(ply), ["text"] = text, @@ -75,7 +75,7 @@ end function gmInte.postLogPlayerDeath(ply, inflictor, attacker) if (!validLogAndPlayers({ply, attacker})) then return end - gmInte.post("/logs/playerDeath", + gmInte.http.post("/logs/playerDeath", { ["ply"] = gmInte.playerFormat(ply), ["inflictor"] = logFormatEntity(inflictor), @@ -87,7 +87,7 @@ end function gmInte.postLogPlayerInitialSpawn(ply) if (!validLogAndPlayers({ply})) then return end - gmInte.post("/logs/playerInitialSpawn", + gmInte.http.post("/logs/playerInitialSpawn", { ["ply"] = gmInte.playerFormat(ply) } @@ -109,7 +109,7 @@ function gmInte.postLogPlayerHurt(ply, attacker, healthRemaining, damageTaken) return end - gmInte.post("/logs/playerHurt", + gmInte.http.post("/logs/playerHurt", { ["ply"] = gmInte.playerFormat(ply), ["attacker"] = gmInte.playerFormat(attacker), @@ -123,7 +123,7 @@ end function gmInte.postLogPlayerSpawnedSomething(object, ply, ent, model) if (!validLogAndPlayers({ply})) then return end - gmInte.post("/logs/playerSpawnedSomething", + gmInte.http.post("/logs/playerSpawnedSomething", { ["object"] = object, ["ply"] = gmInte.playerFormat(ply), @@ -136,7 +136,7 @@ end function gmInte.postLogPlayerSpawn(ply) if (!validLogAndPlayers({ply})) then return end - gmInte.post("/logs/playerSpawn", + gmInte.http.post("/logs/playerSpawn", { ["ply"] = gmInte.playerFormat(ply) } @@ -146,7 +146,7 @@ end function gmInte.postLogPlayerDisconnect(ply) if (!validLogAndPlayers({ply})) then return end - gmInte.post("/logs/playerDisconnect", + gmInte.http.post("/logs/playerDisconnect", { ["ply"] = gmInte.playerFormat(ply) } @@ -156,7 +156,7 @@ end function gmInte.postLogPlayerConnect(data) if (logDisable() || data.bot) then return end - gmInte.post("/logs/playerConnect", + gmInte.http.post("/logs/playerConnect", { ["steamID64"] = util.SteamIDTo64(data.networkid), ["steamID"] = data.networkid, @@ -169,7 +169,7 @@ end function gmInte.postLogPlayerGivet(ply, class, swep) if (!validLogAndPlayers({ply})) then return end - gmInte.post("/logs/playerGive", + gmInte.http.post("/logs/playerGive", { ["ply"] = gmInte.playerFormat(ply), ["class"] = class, diff --git a/lua/gmod_integration/server/sv_net.lua b/lua/gmod_integration/server/sv_net.lua index 431ad1c..354b478 100644 --- a/lua/gmod_integration/server/sv_net.lua +++ b/lua/gmod_integration/server/sv_net.lua @@ -8,6 +8,9 @@ Upload 2 - Get Config 3 - Test Connection 4 - Take Screenshot + 5 - Send Public Config + 6 - Send Message + 7 - Open Verif Popup Receive 0 - Player is Ready 1 - Test Connection diff --git a/lua/gmod_integration/server/sv_players.lua b/lua/gmod_integration/server/sv_players.lua index 8d1ee1f..4769cff 100644 --- a/lua/gmod_integration/server/sv_players.lua +++ b/lua/gmod_integration/server/sv_players.lua @@ -77,48 +77,64 @@ end function gmInte.verifyPlayer(ply) if (!gmInte.plyValid(ply)) then return end - gmInte.get("/players/" .. ply:SteamID64(), function(data) - if (data.discordID && ply.gmIntUnVerified) then + gmInte.http.get("/players/" .. ply:SteamID64(), function(code, data) + if ((data && data.steam_id && ply.gmIntUnVerified) || !gmInte.config.forcePlayerLink) then + gmInte.SendNet(6, { + [1] = { + ["text"] = "You have been verified", + ["color"] = Color(255, 255, 255) + } + }, ply) ply:Freeze(false) ply.gmIntUnVerified = false + else + gmInte.SendNet(6, { + [1] = { + ["text"] = "You are not verified", + ["color"] = Color(255, 0, 0) + } + }, ply) + ply:Freeze(true) + ply.gmIntUnVerified = true + gmInte.SendNet(7, nil, ply) end end) end // Generate a unique token that allow player to update data link to this server (ex: screnshot, report bug, etc.) function gmInte.getClientOneTimeToken(ply, callback) - gmInte.get("/players/" .. ply:SteamID64() .. "/get-one-time-token", function(data) + gmInte.http.get("/players/" .. ply:SteamID64() .. "/get-one-time-token", function(code, data) callback(data.token) end) end function gmInte.playerConnect(data) - gmInte.post("/players/" .. util.SteamIDTo64(data.networkid) .. "/connect", data) + gmInte.http.post("/players/" .. util.SteamIDTo64(data.networkid) .. "/connect", data) end function gmInte.userFinishConnect(ply) if (!gmInte.plyValid(ply)) then return end + + // Initialize Time ply.gmIntTimeConnect = math.Round(RealTime()) - gmInte.post("/players/" .. ply:SteamID64() .. "/finish-connect", + // Send Public Config + gmInte.publicGetConfig(ply) + + gmInte.http.post("/players/" .. ply:SteamID64() .. "/finish-connect", { ["player"] = gmInte.playerFormat(ply), } ) if (!gmInte.config.forcePlayerLink) then return end - gmInte.get("/players/" .. ply:SteamID64(), function(data) - if (!data.discordID) then - ply:Freeze(true) - ply.gmIntUnVerified = true - end - end) + gmInte.verifyPlayer(ply) end function gmInte.playerDisconnected(ply) if (!gmInte.plyValid(ply)) then return end - gmInte.post("/players/" .. ply:SteamID64() .. "/disconnect", + gmInte.http.post("/players/" .. ply:SteamID64() .. "/disconnect", { ["player"] = gmInte.playerFormat(ply), } diff --git a/lua/gmod_integration/server/sv_settings.lua b/lua/gmod_integration/server/sv_settings.lua index a0c1eaf..7cf2796 100644 --- a/lua/gmod_integration/server/sv_settings.lua +++ b/lua/gmod_integration/server/sv_settings.lua @@ -17,7 +17,7 @@ function gmInte.saveSetting(setting, value) end function gmInte.tryConfig() - gmInte.get("", + gmInte.http.get("", function(code, body) print(" ") gmInte.log("Congratulations your server is now connected to Gmod Integration") @@ -29,7 +29,7 @@ function gmInte.tryConfig() end function gmInte.testConnection(ply) - gmInte.get("", + gmInte.http.get("", function(code, body) if (ply) then gmInte.SendNet(3, body, ply) end end, @@ -52,6 +52,15 @@ function gmInte.superadminGetConfig(ply) gmInte.SendNet(2, gmInte.config, ply) end +function gmInte.publicGetConfig(ply) + if (!gmInte.plyValid(ply)) then return end + + gmInte.SendNet(5, { + ["debug"] = gmInte.config.debug, + ["devInstance"] = gmInte.config.devInstance + }, ply) +end + function gmInte.superadminSetConfig(ply, data) if (!gmInte.plyValid(ply) || !ply:IsSuperAdmin()) then return end diff --git a/lua/gmod_integration/server/sv_status.lua b/lua/gmod_integration/server/sv_status.lua index aafffc2..6397f71 100644 --- a/lua/gmod_integration/server/sv_status.lua +++ b/lua/gmod_integration/server/sv_status.lua @@ -16,15 +16,15 @@ local function getServerFormat() end function gmInte.sendStatus() - gmInte.post("/status", getServerFormat()) + gmInte.http.post("/status", getServerFormat()) end -- function gmInte.serverStart() --- gmInte.post("/start", getServerFormat()) +-- gmInte.http.post("/start", getServerFormat()) -- end function gmInte.serverShutDown() - gmInte.post("/shutdown") + gmInte.http.post("/shutdown") end // diff --git a/lua/gmod_integration/server/sv_sync_bans.lua b/lua/gmod_integration/server/sv_sync_bans.lua index 121b160..246e69d 100644 --- a/lua/gmod_integration/server/sv_sync_bans.lua +++ b/lua/gmod_integration/server/sv_sync_bans.lua @@ -15,7 +15,7 @@ end // function gmInte.playerBan(data) - gmInte.post("/players/" .. util.SteamIDTo64(data.networkid) .. "/bans", data) + gmInte.http.post("/players/" .. util.SteamIDTo64(data.networkid) .. "/bans", data) end // diff --git a/lua/gmod_integration/server/sv_sync_chat.lua b/lua/gmod_integration/server/sv_sync_chat.lua index b567815..bc324ef 100644 --- a/lua/gmod_integration/server/sv_sync_chat.lua +++ b/lua/gmod_integration/server/sv_sync_chat.lua @@ -13,7 +13,7 @@ end function gmInte.playerSay(ply, text, team) if (!gmInte.config.syncChat) then return end - gmInte.post("/players/" .. ply:SteamID64() .. "/say", + gmInte.http.post("/players/" .. ply:SteamID64() .. "/say", { ["player"] = gmInte.playerFormat(ply), ["text"] = text, diff --git a/lua/gmod_integration/server/sv_sync_names.lua b/lua/gmod_integration/server/sv_sync_names.lua index 601bb48..5bc0224 100644 --- a/lua/gmod_integration/server/sv_sync_names.lua +++ b/lua/gmod_integration/server/sv_sync_names.lua @@ -15,7 +15,7 @@ end function gmInte.playerChangeName(ply, oldName, newName) if (!gmInte.plyValid(ply)) then return end - gmInte.post("/players/" .. ply:SteamID64() .. "/name", + gmInte.http.post("/players/" .. ply:SteamID64() .. "/name", { ["player"] = gmInte.playerFormat(ply), ["oldName"] = oldName, diff --git a/lua/gmod_integration/shared/sh_http.lua b/lua/gmod_integration/shared/sh_http.lua index 0b16146..c8454fc 100644 --- a/lua/gmod_integration/shared/sh_http.lua +++ b/lua/gmod_integration/shared/sh_http.lua @@ -2,6 +2,8 @@ local apiVersion = "v3" local apiFQDN = "api.gmod-integration.com" local apiDevFQDN = "dev-api.gmod-integration.com" +gmInte.http = gmInte.http || {} + // // HTTP // @@ -11,14 +13,18 @@ local function getAPIURL(endpoint) if (SERVER) then url = url .. "/servers/" .. gmInte.config.id - elseif (endpoint == "/players") then + else + if (string.sub(endpoint, 1, 8) == "/players" || string.sub(endpoint, 1, 7) == "/errors") then + return url .. endpoint + end + url = url .. "/clients/" .. LocalPlayer():SteamID64() end return url .. endpoint end -function gmInte.requestAPI(params) +function gmInte.http.requestAPI(params) local body = params.body || "" local bodyLength = string.len(body) local token = params.token || gmInte.config.token || "" @@ -67,7 +73,7 @@ function gmInte.requestAPI(params) body = util.JSONToTable(body || "{}") // Return success - return success(code, body, headers) + return success(body) end, ["failed"] = function(error) gmInte.logError(error) @@ -79,8 +85,8 @@ end // HTTP Methods // -function gmInte.get(endpoint, onSuccess, onFailed) - gmInte.requestAPI({ +function gmInte.http.get(endpoint, onSuccess, onFailed) + gmInte.http.requestAPI({ ["endpoint"] = endpoint, ["method"] = "GET", ["success"] = onSuccess, @@ -88,8 +94,8 @@ function gmInte.get(endpoint, onSuccess, onFailed) }) end -function gmInte.post(endpoint, data, onSuccess, onFailed) - gmInte.requestAPI({ +function gmInte.http.post(endpoint, data, onSuccess, onFailed) + gmInte.http.requestAPI({ ["endpoint"] = endpoint, ["method"] = "POST", ["body"] = util.TableToJSON(data), @@ -98,8 +104,8 @@ function gmInte.post(endpoint, data, onSuccess, onFailed) }) end -function gmInte.put(endpoint, data, onSuccess, onFailed) - gmInte.requestAPI({ +function gmInte.http.put(endpoint, data, onSuccess, onFailed) + gmInte.http.requestAPI({ ["endpoint"] = endpoint, ["method"] = "PUT", ["body"] = util.TableToJSON(data), @@ -108,8 +114,8 @@ function gmInte.put(endpoint, data, onSuccess, onFailed) }) end -function gmInte.delete(endpoint, onSuccess, onFailed) - gmInte.requestAPI({ +function gmInte.http.delete(endpoint, onSuccess, onFailed) + gmInte.http.requestAPI({ ["endpoint"] = endpoint, ["method"] = "DELETE", ["success"] = onSuccess, From b77633275ced8ca0392c3d2c2cdd6e1db388e0b7 Mon Sep 17 00:00:00 2001 From: Linventif Date: Fri, 9 Feb 2024 22:52:15 +0100 Subject: [PATCH 05/66] format tbl key format --- .../server/sv__api_format.lua | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lua/gmod_integration/server/sv__api_format.lua b/lua/gmod_integration/server/sv__api_format.lua index 11582f7..f8641b8 100644 --- a/lua/gmod_integration/server/sv__api_format.lua +++ b/lua/gmod_integration/server/sv__api_format.lua @@ -1,14 +1,14 @@ function gmInte.playerFormat(ply) return { - steamID = ply:SteamID(), - steamID64 = ply:SteamID64(), - userGroup = ply:GetUserGroup(), - team = ply:Team(), - teamName = team.GetName(ply:Team()), - name = ply:Nick(), - kills = ply:Frags(), - deaths = ply:Deaths(), - customValues = ply:gmIntGetCustomValues(), - connectTime = math.Round(RealTime() - ply:gmIntGetConnectTime()), + ["steamID"] = ply:SteamID(), + ["steamID64"] = ply:SteamID64(), + ["userGroup"] = ply:GetUserGroup(), + ["team"] = ply:Team(), + ["teamName"] = team.GetName(ply:Team()), + ["name"] = ply:Nick(), + ["kills"] = ply:Frags(), + ["deaths"] = ply:Deaths(), + ["customValues"] = ply:gmIntGetCustomValues(), + ["connectTime"] = math.Round(RealTime() - ply:gmIntGetConnectTime()), } end \ No newline at end of file From d525675e4f3c0d32f85933f158614f34866c7443 Mon Sep 17 00:00:00 2001 From: Linventif Date: Fri, 9 Feb 2024 22:54:08 +0100 Subject: [PATCH 06/66] !== do not exist in glua --- lua/gmod_integration/shared/sh_errors.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/gmod_integration/shared/sh_errors.lua b/lua/gmod_integration/shared/sh_errors.lua index ebe31e6..155bdb8 100644 --- a/lua/gmod_integration/shared/sh_errors.lua +++ b/lua/gmod_integration/shared/sh_errors.lua @@ -3,7 +3,7 @@ // function gmInte.sendLuaErrorReport(err, realm, stack, name, id) - if (name !== "gmod_integration") then return end + if (name != "gmod_integration") then return end gmInte.http.post("/errors", { ["error"] = err, From 92635144b559ea52446e21711089e71c53782837 Mon Sep 17 00:00:00 2001 From: Linventif Date: Fri, 9 Feb 2024 23:00:07 +0100 Subject: [PATCH 07/66] Fix openVerifPopup function --- lua/gmod_integration/client/cl_gui_link.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lua/gmod_integration/client/cl_gui_link.lua b/lua/gmod_integration/client/cl_gui_link.lua index 3056a18..c7e0a10 100644 --- a/lua/gmod_integration/client/cl_gui_link.lua +++ b/lua/gmod_integration/client/cl_gui_link.lua @@ -47,6 +47,4 @@ function gmInte.openVerifPopup() end button:SetSize(buttonGrid:GetColWide(), buttonGrid:GetRowHeight()) buttonGrid:AddItem(button) -end - -gmInte.openVerifPopup() \ No newline at end of file +end \ No newline at end of file From d55e160320057e5bbfd97337da488d333c714abb Mon Sep 17 00:00:00 2001 From: Linventif Date: Fri, 9 Feb 2024 23:36:11 +0100 Subject: [PATCH 08/66] fix: force player link --- lua/gmod_integration/server/sv_players.lua | 8 +++++--- lua/gmod_integration/shared/sh_http.lua | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lua/gmod_integration/server/sv_players.lua b/lua/gmod_integration/server/sv_players.lua index 4769cff..58b48f1 100644 --- a/lua/gmod_integration/server/sv_players.lua +++ b/lua/gmod_integration/server/sv_players.lua @@ -78,7 +78,10 @@ end function gmInte.verifyPlayer(ply) if (!gmInte.plyValid(ply)) then return end gmInte.http.get("/players/" .. ply:SteamID64(), function(code, data) - if ((data && data.steam_id && ply.gmIntUnVerified) || !gmInte.config.forcePlayerLink) then + if (!gmInte.config.forcePlayerLink) then return end + + if (data && data.steamID64) then + if (ply.gmIntVerified) then return end gmInte.SendNet(6, { [1] = { ["text"] = "You have been verified", @@ -86,7 +89,7 @@ function gmInte.verifyPlayer(ply) } }, ply) ply:Freeze(false) - ply.gmIntUnVerified = false + ply.gmIntVerified = true else gmInte.SendNet(6, { [1] = { @@ -95,7 +98,6 @@ function gmInte.verifyPlayer(ply) } }, ply) ply:Freeze(true) - ply.gmIntUnVerified = true gmInte.SendNet(7, nil, ply) end end) diff --git a/lua/gmod_integration/shared/sh_http.lua b/lua/gmod_integration/shared/sh_http.lua index c8454fc..982b316 100644 --- a/lua/gmod_integration/shared/sh_http.lua +++ b/lua/gmod_integration/shared/sh_http.lua @@ -69,11 +69,11 @@ function gmInte.http.requestAPI(params) return failed({ ["error"] = "Invalid Content-Type" }, code, headers) end - // Tableify the body if it's JSON + // Parse body body = util.JSONToTable(body || "{}") // Return success - return success(body) + return success(code, body) end, ["failed"] = function(error) gmInte.logError(error) From ee5c17056062925524a7527210ea8a17fb825113 Mon Sep 17 00:00:00 2001 From: Linventif Date: Sat, 10 Feb 2024 00:59:17 +0100 Subject: [PATCH 09/66] Update font weight and popup size --- lua/gmod_integration/client/cl__color.lua | 23 +++++++++++ lua/gmod_integration/client/cl_font.lua | 2 +- lua/gmod_integration/client/cl_gui_link.lua | 43 ++++++++++++++------- 3 files changed, 54 insertions(+), 14 deletions(-) create mode 100644 lua/gmod_integration/client/cl__color.lua diff --git a/lua/gmod_integration/client/cl__color.lua b/lua/gmod_integration/client/cl__color.lua new file mode 100644 index 0000000..7115573 --- /dev/null +++ b/lua/gmod_integration/client/cl__color.lua @@ -0,0 +1,23 @@ +local colorTbl = { + ["background"] = Color(41, 44, 54), + ["primary"] = Color(58, 62, 73), + ["primary-active"] = Color(58, 62, 73, 163), -- Adjusted alpha for opacity + ["secondary"] = Color(44, 47, 59), + ["secondary-active"] = Color(31, 33, 40), + ["green"] = Color(78, 151, 53), + ["green-active"] = Color(58, 122, 38), + ["orange"] = Color(204, 145, 62), + ["orange-active"] = Color(168, 122, 43), + ["red"] = Color(201, 59, 59), + ["red-active"] = Color(168, 43, 43), + ["blue"] = Color(67, 197, 214), + ["blue-active"] = Color(41, 152, 167), + ["purple"] = Color(73, 90, 252), + ["purple-active"] = Color(47, 63, 159), + ["font"] = Color(255, 255, 255), + ["font-secondary"] = Color(179, 179, 179) +} + +function gmInte.getColor(name) + return colorTbl[name] +end \ No newline at end of file diff --git a/lua/gmod_integration/client/cl_font.lua b/lua/gmod_integration/client/cl_font.lua index 7655a1c..eba3bea 100644 --- a/lua/gmod_integration/client/cl_font.lua +++ b/lua/gmod_integration/client/cl_font.lua @@ -1,7 +1,7 @@ surface.CreateFont("GmodIntegration_Roboto_16", { font = "Roboto", size = 16, - weight = 500, + weight = 100, antialias = true, shadow = false }) diff --git a/lua/gmod_integration/client/cl_gui_link.lua b/lua/gmod_integration/client/cl_gui_link.lua index c7e0a10..b648066 100644 --- a/lua/gmod_integration/client/cl_gui_link.lua +++ b/lua/gmod_integration/client/cl_gui_link.lua @@ -1,27 +1,26 @@ function gmInte.openVerifPopup() local frame = vgui.Create("DFrame") - frame:SetSize(400, 140) + frame:SetSize(400, 200) frame:Center() frame:SetTitle("Gmod Integration - Verification Required") frame:SetDraggable(false) frame:ShowCloseButton(false) frame:MakePopup() + frame.Paint = function(self, w, h) + draw.RoundedBox(8, 0, 0, w, h, gmInte.getColor("background")) + end - 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) + local messageLabel = vgui.Create("DLabel", frame) messageLabel:Dock(FILL) - messageLabel:SetText("Hey! It looks like you haven't linked your Steam account to Discord yet. This is required to play on this server. Please click the button below to link your account. After you've done that, click the refresh button.") + messageLabel:DockMargin(10, 0, 10, 0) + messageLabel:SetText("Hey,\nIt looks like you haven't linked your Steam account to Discord yet. This is required to play on this server. Please click the button below to link your account.\n\nAfter you've done that, click the refresh button.") messageLabel:SetContentAlignment(5) + messageLabel:SetFont("GmodIntegration_Roboto_16") messageLabel:SetWrap(true) local buttonGrid = vgui.Create("DGrid", frame) buttonGrid:Dock(BOTTOM) - buttonGrid:DockMargin(5, 10, 5, 5) + buttonGrid:DockMargin(10, 0, 10, 10) buttonGrid:SetCols(2) buttonGrid:SetColWide(frame:GetWide() / 2 - 10) buttonGrid:SetRowHeight(35) @@ -31,8 +30,16 @@ function gmInte.openVerifPopup() button.DoClick = function() gui.OpenURL("https://verif.gmod-integration.com") end - button:SetSize(buttonGrid:GetColWide(), buttonGrid:GetRowHeight()) + button:SetSize(buttonGrid:GetColWide() - 10, buttonGrid:GetRowHeight()) buttonGrid:AddItem(button) + button:SetTextColor(Color(255, 255, 255)) + button.Paint = function(self, w, h) + local color = gmInte.getColor("primary") + if self:IsHovered() then + color = gmInte.getColor("primary-active") + end + draw.RoundedBox(8, 0, 0, w, h, color) + end local button = vgui.Create("DButton") button:SetText("Refresh Verification") @@ -45,6 +52,16 @@ function gmInte.openVerifPopup() LocalPlayer():ChatPrint("Failed to refresh verification: " .. err) end) end - button:SetSize(buttonGrid:GetColWide(), buttonGrid:GetRowHeight()) + button:SetSize(buttonGrid:GetColWide() - 10, buttonGrid:GetRowHeight()) buttonGrid:AddItem(button) -end \ No newline at end of file + button:SetTextColor(Color(255, 255, 255)) + button.Paint = function(self, w, h) + local color = gmInte.getColor("primary") + if self:IsHovered() then + color = gmInte.getColor("primary-active") + end + draw.RoundedBox(8, 0, 0, w, h, color) + end +end + +gmInte.openVerifPopup() \ No newline at end of file From 74dbccbc0be8e0828fb22e70a04f5541e74d566b Mon Sep 17 00:00:00 2001 From: Linventif Date: Sat, 10 Feb 2024 00:59:35 +0100 Subject: [PATCH 10/66] remove comment --- lua/gmod_integration/client/cl__color.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/gmod_integration/client/cl__color.lua b/lua/gmod_integration/client/cl__color.lua index 7115573..d29eaf2 100644 --- a/lua/gmod_integration/client/cl__color.lua +++ b/lua/gmod_integration/client/cl__color.lua @@ -1,7 +1,7 @@ local colorTbl = { ["background"] = Color(41, 44, 54), ["primary"] = Color(58, 62, 73), - ["primary-active"] = Color(58, 62, 73, 163), -- Adjusted alpha for opacity + ["primary-active"] = Color(58, 62, 73, 163), ["secondary"] = Color(44, 47, 59), ["secondary-active"] = Color(31, 33, 40), ["green"] = Color(78, 151, 53), From b20e453e7e8a67e4b943bc15c8e31c662475df13 Mon Sep 17 00:00:00 2001 From: Linventif Date: Sat, 10 Feb 2024 01:01:25 +0100 Subject: [PATCH 11/66] Fix openVerifPopup function in cl_gui_link.lua --- lua/gmod_integration/client/cl_gui_link.lua | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lua/gmod_integration/client/cl_gui_link.lua b/lua/gmod_integration/client/cl_gui_link.lua index b648066..604218c 100644 --- a/lua/gmod_integration/client/cl_gui_link.lua +++ b/lua/gmod_integration/client/cl_gui_link.lua @@ -62,6 +62,4 @@ function gmInte.openVerifPopup() end draw.RoundedBox(8, 0, 0, w, h, color) end -end - -gmInte.openVerifPopup() \ No newline at end of file +end \ No newline at end of file From e72fbef924556df94cc3d45cd9097aff2fd97d04 Mon Sep 17 00:00:00 2001 From: Linventif Date: Sun, 11 Feb 2024 23:23:05 +0100 Subject: [PATCH 12/66] edit format --- .../client/cl__api_format.lua | 1 + .../server/sv__api_format.lua | 54 +++++++++++++++- lua/gmod_integration/server/sv_logs.lua | 63 ++++--------------- lua/gmod_integration/server/sv_players.lua | 8 +-- lua/gmod_integration/server/sv_status.lua | 17 +---- lua/gmod_integration/server/sv_sync_chat.lua | 2 +- lua/gmod_integration/server/sv_sync_names.lua | 2 +- 7 files changed, 72 insertions(+), 75 deletions(-) create mode 100644 lua/gmod_integration/client/cl__api_format.lua diff --git a/lua/gmod_integration/client/cl__api_format.lua b/lua/gmod_integration/client/cl__api_format.lua new file mode 100644 index 0000000..ab0c014 --- /dev/null +++ b/lua/gmod_integration/client/cl__api_format.lua @@ -0,0 +1 @@ +// \ No newline at end of file diff --git a/lua/gmod_integration/server/sv__api_format.lua b/lua/gmod_integration/server/sv__api_format.lua index f8641b8..d15fb96 100644 --- a/lua/gmod_integration/server/sv__api_format.lua +++ b/lua/gmod_integration/server/sv__api_format.lua @@ -1,4 +1,4 @@ -function gmInte.playerFormat(ply) +function gmInte.getPlayerFormat(ply) return { ["steamID"] = ply:SteamID(), ["steamID64"] = ply:SteamID64(), @@ -11,4 +11,56 @@ function gmInte.playerFormat(ply) ["customValues"] = ply:gmIntGetCustomValues(), ["connectTime"] = math.Round(RealTime() - ply:gmIntGetConnectTime()), } +end + +function gmInte.getServerFormat() + return { + ["hostname"] = GetHostName(), + ["ip"] = game.GetIPAddress(), + ["port"] = GetConVar("hostport"):GetInt(), + ["map"] = game.GetMap(), + ["players"] = #player.GetAll(), + ["maxPlayers"] = game.MaxPlayers(), + ["gameMode"] = engine.ActiveGamemode(), + ["uptime"] = math.Round(RealTime() / 60) + } +end + +function gmInte.getWeaponFormat(weapon) + return { + ["class"] = weapon:GetClass(), + ["printName"] = weapon:GetPrintName() + } +end + +function gmInte.getEntityFormat(ent) + return { + ["class"] = ent:GetClass(), + ["model"] = ent:GetModel(), + ["pos"] = gmInte.getVectorFormat(ent:GetPos()), + ["ang"] = gmInte.getAngleFormat(ent:GetAngles()) + } +end + +function gmInte.getVectorFormat(vec) + return { + ["x"] = vec.x, + ["y"] = vec.y, + ["z"] = vec.z + } +end + +function gmInte.getAngleFormat(ang) + return { + ["p"] = ang.p, + ["y"] = ang.y, + ["r"] = ang.r + } +end + +local function gmInte.getTeamFormat(teamID) + return { + ["id"] = teamID, + ["name"] = team.GetName(teamID) + } end \ No newline at end of file diff --git a/lua/gmod_integration/server/sv_logs.lua b/lua/gmod_integration/server/sv_logs.lua index ef4d091..4c18820 100644 --- a/lua/gmod_integration/server/sv_logs.lua +++ b/lua/gmod_integration/server/sv_logs.lua @@ -2,45 +2,6 @@ // Functions // -local function logFormatWeapon(weapon, data) - data = data or {} - data.class = weapon:GetClass() - data.printName = weapon:GetPrintName() - return data -end - -local function logFormatEntity(ent, data) - data = data or {} - data.class = ent:GetClass() - data.model = ent:GetModel() - data.pos = ent:GetPos() - data.ang = ent:GetAngles() - return data -end - -local function logFormatVector(vec, data) - data = data or {} - data.x = vec.x - data.y = vec.y - data.z = vec.z - return data -end - -local function logFormatAngle(ang, data) - data = data or {} - data.p = ang.p - data.y = ang.y - data.r = ang.r - return data -end - -local function logFormatTeam(teamID, data) - data = data or {} - data.id = teamID - data.name = team.GetName(teamID) - return data -end - local function logDisable() return !gmInte.config.sendLog end @@ -65,7 +26,7 @@ function gmInte.postLogPlayerSay(ply, text, teamChat) gmInte.http.post("/logs/playerSay", { - ["ply"] = gmInte.playerFormat(ply), + ["ply"] = gmInte.getPlayerFormat(ply), ["text"] = text, ["teamChat"] = teamChat } @@ -77,9 +38,9 @@ function gmInte.postLogPlayerDeath(ply, inflictor, attacker) gmInte.http.post("/logs/playerDeath", { - ["ply"] = gmInte.playerFormat(ply), - ["inflictor"] = logFormatEntity(inflictor), - ["attacker"] = gmInte.playerFormat(attacker) + ["ply"] = gmInte.getPlayerFormat(ply), + ["inflictor"] = gmInte.getEntityFormat(inflictor), + ["attacker"] = gmInte.getPlayerFormat(attacker) } ) end @@ -89,7 +50,7 @@ function gmInte.postLogPlayerInitialSpawn(ply) gmInte.http.post("/logs/playerInitialSpawn", { - ["ply"] = gmInte.playerFormat(ply) + ["ply"] = gmInte.getPlayerFormat(ply) } ) end @@ -111,8 +72,8 @@ function gmInte.postLogPlayerHurt(ply, attacker, healthRemaining, damageTaken) gmInte.http.post("/logs/playerHurt", { - ["ply"] = gmInte.playerFormat(ply), - ["attacker"] = gmInte.playerFormat(attacker), + ["ply"] = gmInte.getPlayerFormat(ply), + ["attacker"] = gmInte.getPlayerFormat(attacker), ["healthRemaining"] = healthRemaining, ["damageTaken"] = ply.gmodInteTotalDamage } @@ -126,8 +87,8 @@ function gmInte.postLogPlayerSpawnedSomething(object, ply, ent, model) gmInte.http.post("/logs/playerSpawnedSomething", { ["object"] = object, - ["ply"] = gmInte.playerFormat(ply), - ["ent"] = logFormatEntity(ent), + ["ply"] = gmInte.getPlayerFormat(ply), + ["ent"] = gmInte.getEntityFormat(ent), ["model"] = model || "" } ) @@ -138,7 +99,7 @@ function gmInte.postLogPlayerSpawn(ply) gmInte.http.post("/logs/playerSpawn", { - ["ply"] = gmInte.playerFormat(ply) + ["ply"] = gmInte.getPlayerFormat(ply) } ) end @@ -148,7 +109,7 @@ function gmInte.postLogPlayerDisconnect(ply) gmInte.http.post("/logs/playerDisconnect", { - ["ply"] = gmInte.playerFormat(ply) + ["ply"] = gmInte.getPlayerFormat(ply) } ) end @@ -171,7 +132,7 @@ function gmInte.postLogPlayerGivet(ply, class, swep) gmInte.http.post("/logs/playerGive", { - ["ply"] = gmInte.playerFormat(ply), + ["ply"] = gmInte.getPlayerFormat(ply), ["class"] = class, ["swep"] = swep } diff --git a/lua/gmod_integration/server/sv_players.lua b/lua/gmod_integration/server/sv_players.lua index 58b48f1..852134e 100644 --- a/lua/gmod_integration/server/sv_players.lua +++ b/lua/gmod_integration/server/sv_players.lua @@ -123,11 +123,7 @@ function gmInte.userFinishConnect(ply) // Send Public Config gmInte.publicGetConfig(ply) - gmInte.http.post("/players/" .. ply:SteamID64() .. "/finish-connect", - { - ["player"] = gmInte.playerFormat(ply), - } - ) + gmInte.http.post("/players/" .. ply:SteamID64() .. "/finish-connect", gmInte.getPlayerFormat(ply)) if (!gmInte.config.forcePlayerLink) then return end gmInte.verifyPlayer(ply) @@ -138,7 +134,7 @@ function gmInte.playerDisconnected(ply) gmInte.http.post("/players/" .. ply:SteamID64() .. "/disconnect", { - ["player"] = gmInte.playerFormat(ply), + ["player"] = gmInte.getPlayerFormat(ply), } ) end diff --git a/lua/gmod_integration/server/sv_status.lua b/lua/gmod_integration/server/sv_status.lua index 6397f71..f78809b 100644 --- a/lua/gmod_integration/server/sv_status.lua +++ b/lua/gmod_integration/server/sv_status.lua @@ -2,25 +2,12 @@ // Methods // -local function getServerFormat() - return { - ["hostname"] = GetHostName(), - ["ip"] = game.GetIPAddress(), - ["port"] = GetConVar("hostport"):GetInt(), - ["map"] = game.GetMap(), - ["players"] = #player.GetAll(), - ["maxplayers"] = game.MaxPlayers(), - ["gamemode"] = engine.ActiveGamemode(), - ["uptime"] = math.Round(RealTime() / 60) - } -end - function gmInte.sendStatus() - gmInte.http.post("/status", getServerFormat()) + gmInte.http.post("/status", gmInte.getServerFormat()) end -- function gmInte.serverStart() --- gmInte.http.post("/start", getServerFormat()) +-- gmInte.http.post("/start", gmInte.getServerFormat()) -- end function gmInte.serverShutDown() diff --git a/lua/gmod_integration/server/sv_sync_chat.lua b/lua/gmod_integration/server/sv_sync_chat.lua index bc324ef..8bd1042 100644 --- a/lua/gmod_integration/server/sv_sync_chat.lua +++ b/lua/gmod_integration/server/sv_sync_chat.lua @@ -15,7 +15,7 @@ function gmInte.playerSay(ply, text, team) gmInte.http.post("/players/" .. ply:SteamID64() .. "/say", { - ["player"] = gmInte.playerFormat(ply), + ["player"] = gmInte.getPlayerFormat(ply), ["text"] = text, ["team"] = team, } diff --git a/lua/gmod_integration/server/sv_sync_names.lua b/lua/gmod_integration/server/sv_sync_names.lua index 5bc0224..836ce7b 100644 --- a/lua/gmod_integration/server/sv_sync_names.lua +++ b/lua/gmod_integration/server/sv_sync_names.lua @@ -17,7 +17,7 @@ function gmInte.playerChangeName(ply, oldName, newName) gmInte.http.post("/players/" .. ply:SteamID64() .. "/name", { - ["player"] = gmInte.playerFormat(ply), + ["player"] = gmInte.getPlayerFormat(ply), ["oldName"] = oldName, ["newName"] = newName, } From 2b7b01b132e204a4a5b6bd27e7961f3c8ae9e5a7 Mon Sep 17 00:00:00 2001 From: Linventif Date: Sun, 11 Feb 2024 23:28:29 +0100 Subject: [PATCH 13/66] change team format --- lua/gmod_integration/server/sv__api_format.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lua/gmod_integration/server/sv__api_format.lua b/lua/gmod_integration/server/sv__api_format.lua index d15fb96..5896ec8 100644 --- a/lua/gmod_integration/server/sv__api_format.lua +++ b/lua/gmod_integration/server/sv__api_format.lua @@ -3,8 +3,7 @@ function gmInte.getPlayerFormat(ply) ["steamID"] = ply:SteamID(), ["steamID64"] = ply:SteamID64(), ["userGroup"] = ply:GetUserGroup(), - ["team"] = ply:Team(), - ["teamName"] = team.GetName(ply:Team()), + ["team"] = gmInte.getTeamFormat(ply:Team()), ["name"] = ply:Nick(), ["kills"] = ply:Frags(), ["deaths"] = ply:Deaths(), From 11be2c9d068b4bb2f1a1b322f1a0a83ea7d04069 Mon Sep 17 00:00:00 2001 From: Linventif Date: Fri, 16 Feb 2024 13:52:35 +0100 Subject: [PATCH 14/66] edit: player format --- lua/gmod_integration/client/cl__api_format.lua | 1 - .../sv__api_format.lua => shared/sh_api_format.lua} | 7 +++++-- 2 files changed, 5 insertions(+), 3 deletions(-) delete mode 100644 lua/gmod_integration/client/cl__api_format.lua rename lua/gmod_integration/{server/sv__api_format.lua => shared/sh_api_format.lua} (87%) diff --git a/lua/gmod_integration/client/cl__api_format.lua b/lua/gmod_integration/client/cl__api_format.lua deleted file mode 100644 index ab0c014..0000000 --- a/lua/gmod_integration/client/cl__api_format.lua +++ /dev/null @@ -1 +0,0 @@ -// \ No newline at end of file diff --git a/lua/gmod_integration/server/sv__api_format.lua b/lua/gmod_integration/shared/sh_api_format.lua similarity index 87% rename from lua/gmod_integration/server/sv__api_format.lua rename to lua/gmod_integration/shared/sh_api_format.lua index 5896ec8..4753773 100644 --- a/lua/gmod_integration/server/sv__api_format.lua +++ b/lua/gmod_integration/shared/sh_api_format.lua @@ -9,6 +9,9 @@ function gmInte.getPlayerFormat(ply) ["deaths"] = ply:Deaths(), ["customValues"] = ply:gmIntGetCustomValues(), ["connectTime"] = math.Round(RealTime() - ply:gmIntGetConnectTime()), + ["ping"] = ply:Ping(), + ["pos"] = gmInte.getVectorFormat(ply:GetPos()), + ["ang"] = gmInte.getAngleFormat(ply:EyeAngles()) } end @@ -21,7 +24,7 @@ function gmInte.getServerFormat() ["players"] = #player.GetAll(), ["maxPlayers"] = game.MaxPlayers(), ["gameMode"] = engine.ActiveGamemode(), - ["uptime"] = math.Round(RealTime() / 60) + ["uptime"] = math.Round(RealTime()) } end @@ -57,7 +60,7 @@ function gmInte.getAngleFormat(ang) } end -local function gmInte.getTeamFormat(teamID) +function gmInte.getTeamFormat(teamID) return { ["id"] = teamID, ["name"] = team.GetName(teamID) From 9a6e29382e2f8150fe1683a5dbe8ad8590aa6f3d Mon Sep 17 00:00:00 2001 From: Linventif Date: Fri, 16 Feb 2024 13:54:00 +0100 Subject: [PATCH 15/66] edit: post header & screen quality --- lua/gmod_integration/client/cl_screenshots.lua | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/lua/gmod_integration/client/cl_screenshots.lua b/lua/gmod_integration/client/cl_screenshots.lua index 4cb215f..3de87fe 100644 --- a/lua/gmod_integration/client/cl_screenshots.lua +++ b/lua/gmod_integration/client/cl_screenshots.lua @@ -8,23 +8,26 @@ hook.Add("PostRender", "gmInteScreenshot", function() ScreenshotRequested = false local captureData = { - format = "png", + format = "jpeg", x = 0, y = 0, w = ScrW(), - h = ScrH() + h = ScrH(), + quality = 95, } local screenCapture = render.Capture(captureData) screenCapture = util.Base64Encode(screenCapture) - gmInte.log("Screenshot Taken - " .. string.len(#screenCapture / 1024) .. "KB", true) + + local size = math.Round(string.len(screenCapture) / 1024) + gmInte.log("Screenshot Taken - " .. size .. "KB", true) gmInte.http.post("/screenshots", { - ["steamID64"] = LocalPlayer():SteamID64(), + ["player"] = gmInte.getPlayerFormat(LocalPlayer()), ["screenshot"] = screenCapture, - ["options"] = captureData, - ["name"] = LocalPlayer():Nick() + ["captureData"] = captureData, + ["size"] = size .. "KB" }, function(code, body) gmInte.log("Screenshot sent to Discord", true) From 51c24d13f5e8e116361f3f320d6400caa1cd539b Mon Sep 17 00:00:00 2001 From: Linventif Date: Fri, 16 Feb 2024 13:54:28 +0100 Subject: [PATCH 16/66] move: server meta player to shared --- lua/gmod_integration/server/sv_players.lua | 73 ------------------ .../shared/sh_player_meta.lua | 76 +++++++++++++++++++ 2 files changed, 76 insertions(+), 73 deletions(-) create mode 100644 lua/gmod_integration/shared/sh_player_meta.lua diff --git a/lua/gmod_integration/server/sv_players.lua b/lua/gmod_integration/server/sv_players.lua index 852134e..dcd9356 100644 --- a/lua/gmod_integration/server/sv_players.lua +++ b/lua/gmod_integration/server/sv_players.lua @@ -1,80 +1,7 @@ -// -// Meta -// - -local ply = FindMetaTable("Player") - -function ply:gmIntGetConnectTime() - return self.gmIntTimeConnect || 0 -end - -function ply:gmIntSetCustomValue(key, value) - self.gmIntCustomValues = self.gmIntCustomValues || {} - self.gmIntCustomValues[key] = value -end - -function ply:gmIntGetCustomValue(key) - return self.gmIntCustomValues && self.gmIntCustomValues[key] -end - -function ply:gmIntRemoveCustomValue(key) - if (self.gmIntCustomValues) then - self.gmIntCustomValues[key] = nil - end -end - -// -// Compatibility -// - -local function getCustomCompatability(ply) - local values = {} - - // DarkRP - if (DarkRP) then - values.money = ply:getDarkRPVar("money") - values.job = ply:getDarkRPVar("job") - end - - // GUI Level System - 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 - for key, value in pairs(ply.gmIntCustomValues) do - values[key] = value - end - end - - return values -end - -function ply:gmIntGetCustomValues() - return getCustomValues(self) -end - -function gmInte.plyValid(ply) - return ply:IsValid() && ply:IsPlayer() && !ply:IsBot() -end - function gmInte.verifyPlayer(ply) if (!gmInte.plyValid(ply)) then return end gmInte.http.get("/players/" .. ply:SteamID64(), function(code, data) diff --git a/lua/gmod_integration/shared/sh_player_meta.lua b/lua/gmod_integration/shared/sh_player_meta.lua new file mode 100644 index 0000000..eaf507b --- /dev/null +++ b/lua/gmod_integration/shared/sh_player_meta.lua @@ -0,0 +1,76 @@ +// +// Meta +// + +local ply = FindMetaTable("Player") + +function ply:gmIntGetConnectTime() + return self.gmIntTimeConnect || 0 +end + +function ply:gmIntSetCustomValue(key, value) + self.gmIntCustomValues = self.gmIntCustomValues || {} + self.gmIntCustomValues[key] = value +end + +function ply:gmIntGetCustomValue(key) + return self.gmIntCustomValues && self.gmIntCustomValues[key] +end + +function ply:gmIntRemoveCustomValue(key) + if (self.gmIntCustomValues) then + self.gmIntCustomValues[key] = nil + end +end + +// +// Compatibility +// + +local function getCustomCompatability(ply) + local values = {} + + // DarkRP + if (DarkRP) then + values.money = ply:getDarkRPVar("money") + values.job = ply:getDarkRPVar("job") + end + + // GUI Level System + 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 + for key, value in pairs(ply.gmIntCustomValues) do + values[key] = value + end + end + + return values +end + +function ply:gmIntGetCustomValues() + return getCustomValues(self) +end + +function gmInte.plyValid(ply) + return ply:IsValid() && ply:IsPlayer() && !ply:IsBot() +end \ No newline at end of file From 805b7d3fefa9398982503e0dd8ea919a05411747 Mon Sep 17 00:00:00 2001 From: Linventif Date: Fri, 16 Feb 2024 13:54:58 +0100 Subject: [PATCH 17/66] fix: don't send report if serv not start --- lua/gmod_integration/shared/sh_errors.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/gmod_integration/shared/sh_errors.lua b/lua/gmod_integration/shared/sh_errors.lua index 155bdb8..bc3a989 100644 --- a/lua/gmod_integration/shared/sh_errors.lua +++ b/lua/gmod_integration/shared/sh_errors.lua @@ -4,6 +4,8 @@ function gmInte.sendLuaErrorReport(err, realm, stack, name, id) if (name != "gmod_integration") then return end + if (SERVER && math.Round(RealTime()) == 0) then return end + gmInte.http.post("/errors", { ["error"] = err, From 8e9c4717b6ec5bcd5d4bae9cfa114a95b9e7e9ac Mon Sep 17 00:00:00 2001 From: Linventif Date: Fri, 16 Feb 2024 14:15:46 +0100 Subject: [PATCH 18/66] add: revoke token & sigle token --- lua/gmod_integration/server/sv_players.lua | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lua/gmod_integration/server/sv_players.lua b/lua/gmod_integration/server/sv_players.lua index dcd9356..1cce015 100644 --- a/lua/gmod_integration/server/sv_players.lua +++ b/lua/gmod_integration/server/sv_players.lua @@ -32,11 +32,23 @@ end // Generate a unique token that allow player to update data link to this server (ex: screnshot, report bug, etc.) function gmInte.getClientOneTimeToken(ply, callback) - gmInte.http.get("/players/" .. ply:SteamID64() .. "/get-one-time-token", function(code, data) + gmInte.http.get("/players/" .. ply:SteamID64() .. "/single-token", function(code, data) callback(data.token) end) end +function gmInte.createClientToken(ply, callback) + gmInte.http.get("/players/" .. ply:SteamID64() .. "/tokens", function(code, data) + callback(data) + end) +end + +function gmInte.revokeClientToken(ply, callback) + gmInte.http.delete("/players/" .. ply:SteamID64() .. "/tokens", function(code, data) + callback(data) + end) +end + function gmInte.playerConnect(data) gmInte.http.post("/players/" .. util.SteamIDTo64(data.networkid) .. "/connect", data) end From c38c4737621d99156f7262436c7b16ba4edd69b4 Mon Sep 17 00:00:00 2001 From: Linventif Date: Fri, 16 Feb 2024 14:26:13 +0100 Subject: [PATCH 19/66] add: test steaming --- lua/gmod_integration/client/cl_steaming.lua | 76 +++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 lua/gmod_integration/client/cl_steaming.lua diff --git a/lua/gmod_integration/client/cl_steaming.lua b/lua/gmod_integration/client/cl_steaming.lua new file mode 100644 index 0000000..5902d8b --- /dev/null +++ b/lua/gmod_integration/client/cl_steaming.lua @@ -0,0 +1,76 @@ +// +// Hooks +// + +local StreamsRequeted = false +local LastFrame = 0 + +hook.Add("PostRender", "gmInte:PostRender:Stream:Frame", function() + if (!StreamsRequeted) then return end + + // Limit frame rate + if (LastFrame > CurTime()) then return end + LastFrame = CurTime() + 0.25 + + // Capture frame + local captureData = { + format = "jpeg", + x = 0, + y = 0, + w = ScrW(), + h = ScrH(), + quality = 50, + } + + local screenCapture = render.Capture(captureData) + screenCapture = util.Base64Encode(screenCapture) + + local size = math.Round(string.len(screenCapture) / 1024) + gmInte.log("Frame captured, size: " .. size .. "KB", true) + + gmInte.http.post("/streams/frames", + { + ["player"] = gmInte.getPlayerFormat(LocalPlayer()), + ["screenshot"] = screenCapture, + ["captureData"] = captureData, + ["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) + +// +// Methods +// + +function gmInte.takeScreenShot(serverID, authToken) + gmInte.config.id = serverID + gmInte.config.token = authToken + + timer.Simple(0.2, function() + StreamsRequeted = true + end) +end + +function gmInte.stopScreenShot() + StreamsRequeted = false +end + +// +// Console Commands +// + +concommand.Add("gmod_integration_stream", function() + if (StreamsRequeted) then + gmInte.stopScreenShot() + gmInte.log("Stopped streaming frames to WebPanel") + else + gmInte.SendNet("getSingleUseToken") + gmInte.log("Started streaming frames to WebPanel") + end +end) \ No newline at end of file From 4219ebcf12027aaf9c522ebf12fbc61cdbffe5da Mon Sep 17 00:00:00 2001 From: Linventif Date: Fri, 16 Feb 2024 14:26:27 +0100 Subject: [PATCH 20/66] edit: net Names --- lua/gmod_integration/client/cl_gui_admin.lua | 6 +-- lua/gmod_integration/client/cl_gui_link.lua | 2 +- lua/gmod_integration/client/cl_hook.lua | 2 +- lua/gmod_integration/client/cl_main.lua | 2 +- lua/gmod_integration/client/cl_net.lua | 45 ++++++++++--------- .../client/cl_screenshots.lua | 4 +- 6 files changed, 31 insertions(+), 30 deletions(-) diff --git a/lua/gmod_integration/client/cl_gui_admin.lua b/lua/gmod_integration/client/cl_gui_admin.lua index 112c59a..d5840f1 100644 --- a/lua/gmod_integration/client/cl_gui_admin.lua +++ b/lua/gmod_integration/client/cl_gui_admin.lua @@ -1,5 +1,5 @@ local function saveConfig(setting, value) - gmInte.SendNet(3, { + gmInte.SendNet("saveConfig", { [setting] = value }) end @@ -223,7 +223,7 @@ local buttonsInfo = { { ["label"] = "Test Connection", ["func"] = function() - gmInte.SendNet(1) + gmInte.SendNet("testConnection") end, }, { @@ -293,7 +293,7 @@ function gmInte.needRestart() button:SetText("Restart") button.DoClick = function() frame:Close() - gmInte.SendNet(5) + gmInte.SendNet("restartMap") end button:SetSize(buttonGrid:GetColWide(), buttonGrid:GetRowHeight()) buttonGrid:AddItem(button) diff --git a/lua/gmod_integration/client/cl_gui_link.lua b/lua/gmod_integration/client/cl_gui_link.lua index 604218c..be9d8e9 100644 --- a/lua/gmod_integration/client/cl_gui_link.lua +++ b/lua/gmod_integration/client/cl_gui_link.lua @@ -45,7 +45,7 @@ function gmInte.openVerifPopup() button:SetText("Refresh Verification") button.DoClick = function() gmInte.http.get("/players/" .. LocalPlayer():SteamID64(), function(code, body) - gmInte.SendNet(6) + gmInte.SendNet("verifyMe") frame:Close() end, function(err) diff --git a/lua/gmod_integration/client/cl_hook.lua b/lua/gmod_integration/client/cl_hook.lua index 2a698c7..abb5fb1 100644 --- a/lua/gmod_integration/client/cl_hook.lua +++ b/lua/gmod_integration/client/cl_hook.lua @@ -4,7 +4,7 @@ // Player Finish Init hook.Add("InitPostEntity", "gmInte:Ply:Ready", function() - gmInte.SendNet(0) + gmInte.SendNet("ready") end) hook.Add("OnPlayerChat", "gmInte:OnPlayerChat:AdminCmd", function(ply, strText, bTeamOnly, bPlayerIsDead) diff --git a/lua/gmod_integration/client/cl_main.lua b/lua/gmod_integration/client/cl_main.lua index 1153572..74ba997 100644 --- a/lua/gmod_integration/client/cl_main.lua +++ b/lua/gmod_integration/client/cl_main.lua @@ -39,7 +39,7 @@ function gmInte.openAdminConfig() return end - gmInte.SendNet(2) + gmInte.SendNet("getConfig") end // diff --git a/lua/gmod_integration/client/cl_net.lua b/lua/gmod_integration/client/cl_net.lua index 9c917f0..a21dfbb 100644 --- a/lua/gmod_integration/client/cl_net.lua +++ b/lua/gmod_integration/client/cl_net.lua @@ -1,36 +1,31 @@ // -// Network +// Send Net // -/* -Upload - 0 - Say I'm ready - 1 - Test Connection - 2 - Get Config - 3 - Save Config - 4 - Take ScreenShot - 5 - Restart Map - 6 - Verify Me -Receive - 1 - Sync Chat - 2 - Get Config - 3 - Test Connection - 4 - Take ScreenShot - 5 - Set Public Config - 6 - Add Chat - 7 - Open Verif Popup -*/ +local netList = { + ["ready"] = 0, + ["testConnection"] = 1, + ["getConfig"] = 2, + ["saveConfig"] = 3, + ["takeScreenShot"] = 4, + ["restartMap"] = 5, + ["verifyMe"] = 6, + ["getSingleUseToken"] = 7, + ["getMultiUseToken"] = 8 +} -// Send function gmInte.SendNet(id, args, func) net.Start("gmIntegration") - net.WriteUInt(id, 8) + net.WriteUInt(netList[id], 8) net.WriteString(util.TableToJSON(args || {})) if (func) then func() end net.SendToServer() end -// Receive +// +// Receive Net +// + local netFunc = { [1] = function(data) gmInte.discordSyncChatPly(data) @@ -52,6 +47,12 @@ local netFunc = { end, [7] = function() gmInte.openVerifPopup() + end, + [8] = function(data) + gmInte.singleUseToken(data) + end, + [9] = function(data) + gmInte.multiUseToken(data) end } diff --git a/lua/gmod_integration/client/cl_screenshots.lua b/lua/gmod_integration/client/cl_screenshots.lua index 3de87fe..2bdbd5b 100644 --- a/lua/gmod_integration/client/cl_screenshots.lua +++ b/lua/gmod_integration/client/cl_screenshots.lua @@ -56,7 +56,7 @@ end // concommand.Add("gmod_integration_screenshot", function() - gmInte.SendNet(4) + gmInte.SendNet("takeScreenShot") end) // @@ -69,6 +69,6 @@ hook.Add("OnPlayerChat", "gmInteChatCommands", function(ply, text, teamChat, isD text = string.sub(text, 2) if (text == "screen") then - gmInte.SendNet(4) + gmInte.SendNet("takeScreenShot") end end) \ No newline at end of file From 40f7bb80791c44fd1b06b149fc748b8c57baa691 Mon Sep 17 00:00:00 2001 From: Linventif Date: Fri, 16 Feb 2024 14:44:34 +0100 Subject: [PATCH 21/66] edit: change net name system --- lua/gmod_integration/client/cl_net.lua | 8 +-- lua/gmod_integration/server/sv_net.lua | 53 ++++++++++--------- lua/gmod_integration/server/sv_players.lua | 6 +-- .../server/sv_screenshots.lua | 2 +- lua/gmod_integration/server/sv_settings.lua | 8 +-- lua/gmod_integration/server/sv_sync_chat.lua | 2 +- 6 files changed, 42 insertions(+), 37 deletions(-) diff --git a/lua/gmod_integration/client/cl_net.lua b/lua/gmod_integration/client/cl_net.lua index a21dfbb..28d2c52 100644 --- a/lua/gmod_integration/client/cl_net.lua +++ b/lua/gmod_integration/client/cl_net.lua @@ -2,7 +2,7 @@ // Send Net // -local netList = { +local netSend = { ["ready"] = 0, ["testConnection"] = 1, ["getConfig"] = 2, @@ -16,7 +16,7 @@ local netList = { function gmInte.SendNet(id, args, func) net.Start("gmIntegration") - net.WriteUInt(netList[id], 8) + net.WriteUInt(netSend[id], 8) net.WriteString(util.TableToJSON(args || {})) if (func) then func() end net.SendToServer() @@ -26,7 +26,7 @@ end // Receive Net // -local netFunc = { +local netReceive = { [1] = function(data) gmInte.discordSyncChatPly(data) end, @@ -59,5 +59,5 @@ local netFunc = { net.Receive("gmIntegration", function() local id = net.ReadUInt(8) local args = util.JSONToTable(net.ReadString()) - if (netFunc[id]) then netFunc[id](args) end + if (netReceive[id]) then netReceive[id](args) end 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 354b478..15c86dc 100644 --- a/lua/gmod_integration/server/sv_net.lua +++ b/lua/gmod_integration/server/sv_net.lua @@ -1,31 +1,29 @@ // -// Network +// Networking // -/* -Upload - 1 - Add Chat Message - 2 - Get Config - 3 - Test Connection - 4 - Take Screenshot - 5 - Send Public Config - 6 - Send Message - 7 - Open Verif Popup -Receive - 0 - Player is Ready - 1 - Test Connection - 2 - Get Config - 3 - Set Config - 4 - Take Screenshot - 5 - Restart Map -*/ - util.AddNetworkString("gmIntegration") +// +// Send Net +// + +local netSend = { + ["wsRelayDiscordChat"] = 1, + ["adminConfig"] = 2, + ["testApiConnection"] = 3, + ["screenshotToken"] = 4, + ["publicConfig"] = 5, + ["chatColorMessage"] = 6, + ["openVerifPopup"] = 7 +} + // Send function gmInte.SendNet(id, data, ply, func) + if (!netSend[id]) then return end + net.Start("gmIntegration") - net.WriteUInt(id, 8) + net.WriteUInt(netSend[id], 8) net.WriteString(util.TableToJSON(data || {})) if (func) then func() end if (ply == nil) then @@ -35,8 +33,11 @@ function gmInte.SendNet(id, data, ply, func) end end -// Receive -local netFuncs = { +// +// Receive net +// + +local netReceive = { [0] = function(ply) gmInte.userFinishConnect(ply) end, @@ -62,8 +63,12 @@ local netFuncs = { } net.Receive("gmIntegration", function(len, ply) - if !ply:IsPlayer() then return end + if (!ply || ply && !ply:IsValid()) then return end + local id = net.ReadUInt(8) local data = util.JSONToTable(net.ReadString() || "{}") - if (netFuncs[id]) then netFuncs[id](ply, data) end + + if (!netReceive[id]) then return end + + netReceive[id](ply, data) end) \ 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 1cce015..bf8debc 100644 --- a/lua/gmod_integration/server/sv_players.lua +++ b/lua/gmod_integration/server/sv_players.lua @@ -9,7 +9,7 @@ function gmInte.verifyPlayer(ply) if (data && data.steamID64) then if (ply.gmIntVerified) then return end - gmInte.SendNet(6, { + gmInte.SendNet("chatColorMessage", { [1] = { ["text"] = "You have been verified", ["color"] = Color(255, 255, 255) @@ -18,14 +18,14 @@ function gmInte.verifyPlayer(ply) ply:Freeze(false) ply.gmIntVerified = true else - gmInte.SendNet(6, { + gmInte.SendNet("chatColorMessage", { [1] = { ["text"] = "You are not verified", ["color"] = Color(255, 0, 0) } }, ply) ply:Freeze(true) - gmInte.SendNet(7, nil, ply) + gmInte.SendNet("openVerifPopup", nil, ply) end end) end diff --git a/lua/gmod_integration/server/sv_screenshots.lua b/lua/gmod_integration/server/sv_screenshots.lua index 97a0536..9d160bf 100644 --- a/lua/gmod_integration/server/sv_screenshots.lua +++ b/lua/gmod_integration/server/sv_screenshots.lua @@ -16,7 +16,7 @@ end function gmInte.takeScreenshot(ply) gmInte.getClientOneTimeToken(ply, function(oneTime) - gmInte.SendNet(4, { + gmInte.SendNet("screenshotToken", { ["serverID"] = gmInte.config.id, ["oneTimeToken"] = oneTime }, ply) diff --git a/lua/gmod_integration/server/sv_settings.lua b/lua/gmod_integration/server/sv_settings.lua index 7cf2796..dfaaa61 100644 --- a/lua/gmod_integration/server/sv_settings.lua +++ b/lua/gmod_integration/server/sv_settings.lua @@ -31,10 +31,10 @@ end function gmInte.testConnection(ply) gmInte.http.get("", function(code, body) - if (ply) then gmInte.SendNet(3, body, ply) end + if (ply) then gmInte.SendNet("testApiConnection", body, ply) end end, function(code, body) - if (ply) then gmInte.SendNet(3, body, ply) end + if (ply) then gmInte.SendNet("testApiConnection", body, ply) end end ) end @@ -49,13 +49,13 @@ function gmInte.superadminGetConfig(ply) if (!gmInte.plyValid(ply) || !ply:IsSuperAdmin()) then return end gmInte.config.websocket = GWSockets && true || false - gmInte.SendNet(2, gmInte.config, ply) + gmInte.SendNet("adminConfig", gmInte.config, ply) end function gmInte.publicGetConfig(ply) if (!gmInte.plyValid(ply)) then return end - gmInte.SendNet(5, { + gmInte.SendNet("publicConfig", { ["debug"] = gmInte.config.debug, ["devInstance"] = gmInte.config.devInstance }, ply) diff --git a/lua/gmod_integration/server/sv_sync_chat.lua b/lua/gmod_integration/server/sv_sync_chat.lua index 8bd1042..502cb70 100644 --- a/lua/gmod_integration/server/sv_sync_chat.lua +++ b/lua/gmod_integration/server/sv_sync_chat.lua @@ -3,7 +3,7 @@ // function gmInte.wsPlayerSay(data) - gmInte.SendNet(1, data, nil) + gmInte.SendNet("wsRelayDiscordChat", data, nil) end // From 00880889bf777c1e9b74948fbc6e2afe42801707 Mon Sep 17 00:00:00 2001 From: Linventif Date: Fri, 16 Feb 2024 15:22:50 +0100 Subject: [PATCH 22/66] refactor: load file & moving 1 conf val --- lua/autorun/gmod_integration.lua | 54 ++++++++++++++++-------------- lua/gmod_integration/sv_config.lua | 6 ++++ 2 files changed, 34 insertions(+), 26 deletions(-) diff --git a/lua/autorun/gmod_integration.lua b/lua/autorun/gmod_integration.lua index 4be2ce5..e5ea6ee 100644 --- a/lua/autorun/gmod_integration.lua +++ b/lua/autorun/gmod_integration.lua @@ -1,65 +1,67 @@ -if game.SinglePlayer() then return end +if (game.SinglePlayer()) then return print("Gmod Integration is not supported in Singleplayer!") end // // Variables // gmInte = gmInte || {} + gmInte.version = "0.3.0" -gmInte.config = gmInte.config || { - ["redownloadMaterials"] = false, -} +gmInte.config = {} gmInte.materials = {} // // Functions // -local function loadConfig() - if (SERVER) then - RunConsoleCommand("sv_hibernate_think", "1") - if (!file.Exists("gm_integration", "DATA") || !file.Exists("gm_integration/config.json", "DATA")) then - file.CreateDir("gm_integration") +local function loadServerConfig() + RunConsoleCommand("sv_hibernate_think", "1") + + 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 + + local oldConfig = util.JSONToTable(file.Read("gm_integration/config.json", "DATA")) + 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 file.Write("gm_integration/config.json", util.TableToJSON(gmInte.config, true)) else - 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 - print(" | Merging Config | gmod_integration/sv_config.lua") - table.Merge(gmInte.config, oldConfig) - gmInte.config.version = gmInte.version - file.Write("gm_integration/config.json", util.TableToJSON(gmInte.config, true)) - else - gmInte.config = oldConfig - end + gmInte.config = oldConfig end end end local function loadAllFiles(folder) local files, folders = file.Find(folder .. "/*", "LUA") - for k, v in SortedPairs(files) do - local path = folder .. "/" .. v + + for k, fileName in SortedPairs(files) do + local path = folder .. "/" .. fileName print(" | Loading File | " .. path) - if string.StartWith(v, "cl_") then + + if (string.StartWith(fileName, "cl_")) then if SERVER then AddCSLuaFile(path) else include(path) end - elseif string.StartWith(v, "sv_") then + elseif (string.StartWith(fileName, "sv_")) then if SERVER then include(path) end - elseif string.StartWith(v, "sh_") then + elseif (string.StartWith(fileName, "sh_")) then if SERVER then AddCSLuaFile(path) end include(path) end - if (path == "gmod_integration/sv_config.lua") then loadConfig() continue end + + if (fileName == "sv_config.lua") then loadServerConfig() continue end end + for k, v in SortedPairs(folders, true) do loadAllFiles(folder .. "/" .. v, name) end diff --git a/lua/gmod_integration/sv_config.lua b/lua/gmod_integration/sv_config.lua index b365912..a578054 100644 --- a/lua/gmod_integration/sv_config.lua +++ b/lua/gmod_integration/sv_config.lua @@ -70,6 +70,12 @@ gmInte.config.filterOnBan = true // If true, the addon will filter the players a // Will disable the features of the addon gmInte.config.sendLog = false // Disable the logs +// +// 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 // From 0cb1caa02054ce18f21237324211e11cf1b81b6d Mon Sep 17 00:00:00 2001 From: Linventif Date: Thu, 22 Feb 2024 17:48:51 +0100 Subject: [PATCH 23/66] edit: hide body if not showable --- lua/gmod_integration/shared/sh_http.lua | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lua/gmod_integration/shared/sh_http.lua b/lua/gmod_integration/shared/sh_http.lua index 982b316..2541579 100644 --- a/lua/gmod_integration/shared/sh_http.lua +++ b/lua/gmod_integration/shared/sh_http.lua @@ -24,6 +24,15 @@ local function getAPIURL(endpoint) return url .. endpoint end +local function showableBody(endpoint) + // if start with /streams or /screenshots return false + if (string.sub(endpoint, 1, 8) == "/streams" || string.sub(endpoint, 1, 12) == "/screenshots") then + return false + end + + return true +end + function gmInte.http.requestAPI(params) local body = params.body || "" local bodyLength = string.len(body) @@ -33,6 +42,7 @@ function gmInte.http.requestAPI(params) local success = params.success || function() end local failed = params.failed || function(error) gmInte.logError(error.error || error) end local version = gmInte.config.version + local showableBody = showableBody(params.endpoint) local headers = { ["Content-Type"] = "application/json", @@ -45,7 +55,7 @@ function gmInte.http.requestAPI(params) // Log if (gmInte.config.devInstance) then gmInte.log("HTTP Using dev Instance", true) end gmInte.log("HTTP Request: " .. method .. " " .. url, true) - gmInte.log("HTTP Body: " .. body, true) + gmInte.log("HTTP Body: " .. (showableBody && body || "HIDDEN"), true) // Send HTTP({ From 209edbf8a642609f88ad63837363c2f0924c59df Mon Sep 17 00:00:00 2001 From: Linventif Date: Thu, 22 Feb 2024 17:49:23 +0100 Subject: [PATCH 24/66] reformat: signature function --- lua/gmod_integration/server/sv_sync_chat.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/gmod_integration/server/sv_sync_chat.lua b/lua/gmod_integration/server/sv_sync_chat.lua index 502cb70..e57d7a5 100644 --- a/lua/gmod_integration/server/sv_sync_chat.lua +++ b/lua/gmod_integration/server/sv_sync_chat.lua @@ -10,14 +10,14 @@ end // Methods // -function gmInte.playerSay(ply, text, team) +function gmInte.playerSay(ply, text, teamOnly) if (!gmInte.config.syncChat) then return end gmInte.http.post("/players/" .. ply:SteamID64() .. "/say", { ["player"] = gmInte.getPlayerFormat(ply), ["text"] = text, - ["team"] = team, + ["teamOnly"] = teamOnly, } ) end From 061af311b107e81e549b15b1acf8babd205bc2ec Mon Sep 17 00:00:00 2001 From: Linventif Date: Thu, 22 Feb 2024 17:49:55 +0100 Subject: [PATCH 25/66] edit: change name for better comprehansion --- lua/gmod_integration/client/cl_steaming.lua | 31 +++++++++++---------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/lua/gmod_integration/client/cl_steaming.lua b/lua/gmod_integration/client/cl_steaming.lua index 5902d8b..51b377c 100644 --- a/lua/gmod_integration/client/cl_steaming.lua +++ b/lua/gmod_integration/client/cl_steaming.lua @@ -13,7 +13,7 @@ hook.Add("PostRender", "gmInte:PostRender:Stream:Frame", function() LastFrame = CurTime() + 0.25 // Capture frame - local captureData = { + local captureConfig = { format = "jpeg", x = 0, y = 0, @@ -22,7 +22,7 @@ hook.Add("PostRender", "gmInte:PostRender:Stream:Frame", function() quality = 50, } - local screenCapture = render.Capture(captureData) + local screenCapture = render.Capture(captureConfig) screenCapture = util.Base64Encode(screenCapture) local size = math.Round(string.len(screenCapture) / 1024) @@ -31,8 +31,8 @@ hook.Add("PostRender", "gmInte:PostRender:Stream:Frame", function() gmInte.http.post("/streams/frames", { ["player"] = gmInte.getPlayerFormat(LocalPlayer()), - ["screenshot"] = screenCapture, - ["captureData"] = captureData, + ["base64Capture"] = screenCapture, + ["captureConfig"] = captureConfig, ["size"] = size .. "KB" }, function(code, body) @@ -42,6 +42,7 @@ hook.Add("PostRender", "gmInte:PostRender:Stream:Frame", function() gmInte.log("Failed to send frame to WebPanel", true) end ) + StreamsRequeted = false end) // @@ -51,10 +52,7 @@ end) function gmInte.takeScreenShot(serverID, authToken) gmInte.config.id = serverID gmInte.config.token = authToken - - timer.Simple(0.2, function() - StreamsRequeted = true - end) + StreamsRequeted = true end function gmInte.stopScreenShot() @@ -66,11 +64,14 @@ end // concommand.Add("gmod_integration_stream", function() - if (StreamsRequeted) then - gmInte.stopScreenShot() - gmInte.log("Stopped streaming frames to WebPanel") - else - gmInte.SendNet("getSingleUseToken") - gmInte.log("Started streaming frames to WebPanel") - end + StreamsRequeted = !StreamsRequeted + gmInte.log("Streaming frames to WebPanel: " .. tostring(StreamsRequeted)) + + -- if (StreamsRequeted) then + -- gmInte.stopScreenShot() + -- gmInte.log("Stopped streaming frames to WebPanel") + -- else + -- gmInte.SendNet("getSingleUseToken") + -- gmInte.log("Started streaming frames to WebPanel") + -- end end) \ No newline at end of file From 0143b77db8f13a1cc8ff2f8748ef4bfd677cda89 Mon Sep 17 00:00:00 2001 From: Linventif Date: Tue, 27 Feb 2024 02:16:46 +0100 Subject: [PATCH 26/66] format: pos & ang -> position & angle. --- lua/gmod_integration/shared/sh_api_format.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lua/gmod_integration/shared/sh_api_format.lua b/lua/gmod_integration/shared/sh_api_format.lua index 4753773..1a4b603 100644 --- a/lua/gmod_integration/shared/sh_api_format.lua +++ b/lua/gmod_integration/shared/sh_api_format.lua @@ -10,8 +10,8 @@ function gmInte.getPlayerFormat(ply) ["customValues"] = ply:gmIntGetCustomValues(), ["connectTime"] = math.Round(RealTime() - ply:gmIntGetConnectTime()), ["ping"] = ply:Ping(), - ["pos"] = gmInte.getVectorFormat(ply:GetPos()), - ["ang"] = gmInte.getAngleFormat(ply:EyeAngles()) + ["position"] = gmInte.getVectorFormat(ply:GetPos()), + ["angle"] = gmInte.getAngleFormat(ply:EyeAngles()) } end @@ -39,8 +39,8 @@ function gmInte.getEntityFormat(ent) return { ["class"] = ent:GetClass(), ["model"] = ent:GetModel(), - ["pos"] = gmInte.getVectorFormat(ent:GetPos()), - ["ang"] = gmInte.getAngleFormat(ent:GetAngles()) + ["position"] = gmInte.getVectorFormat(ent:GetPos()), + ["angle"] = gmInte.getAngleFormat(ent:GetAngles()) } end From a9f33efd4cd5b394cb89874825a86bcc7cf9aa24 Mon Sep 17 00:00:00 2001 From: Linventif Date: Tue, 27 Feb 2024 02:25:53 +0100 Subject: [PATCH 27/66] move: sync chat to a custom file --- lua/gmod_integration/client/cl_main.lua | 4 ---- lua/gmod_integration/client/cl_sync_chat.lua | 3 +++ 2 files changed, 3 insertions(+), 4 deletions(-) create mode 100644 lua/gmod_integration/client/cl_sync_chat.lua diff --git a/lua/gmod_integration/client/cl_main.lua b/lua/gmod_integration/client/cl_main.lua index 74ba997..77d95b1 100644 --- a/lua/gmod_integration/client/cl_main.lua +++ b/lua/gmod_integration/client/cl_main.lua @@ -21,10 +21,6 @@ function gmInte.chatAddText(data) chat.AddText(unpack(args)) end -function gmInte.discordSyncChatPly(data) - chat.AddText(Color(92, 105, 255), "(DISCORD) ", Color(12, 151, 12), formatName(data.name) .. ": ", Color(255, 255, 255), data.content) -end - function gmInte.showTestConnection(data) if (data && data.id) then chat.AddText(Color(255, 130, 92), "[Gmod Integration] ", Color(63, 102, 63), "Connection Successfull", Color(255, 255, 255), ", server logged as '" .. data.name .. "'") diff --git a/lua/gmod_integration/client/cl_sync_chat.lua b/lua/gmod_integration/client/cl_sync_chat.lua new file mode 100644 index 0000000..cde7b82 --- /dev/null +++ b/lua/gmod_integration/client/cl_sync_chat.lua @@ -0,0 +1,3 @@ +function gmInte.discordSyncChatPly(data) + chat.AddText(Color(92, 105, 255), "(DISCORD) ", Color(12, 151, 12), formatName(data.name) .. ": ", Color(255, 255, 255), data.content) +end \ No newline at end of file From 44480a7499dabba45a8aec9b97aaf945606fc96f Mon Sep 17 00:00:00 2001 From: Linventif Date: Tue, 27 Feb 2024 02:28:22 +0100 Subject: [PATCH 28/66] remove: verif if ply is valid --- lua/gmod_integration/shared/sh_player_meta.lua | 4 ---- 1 file changed, 4 deletions(-) diff --git a/lua/gmod_integration/shared/sh_player_meta.lua b/lua/gmod_integration/shared/sh_player_meta.lua index eaf507b..c4fcae1 100644 --- a/lua/gmod_integration/shared/sh_player_meta.lua +++ b/lua/gmod_integration/shared/sh_player_meta.lua @@ -69,8 +69,4 @@ end function ply:gmIntGetCustomValues() return getCustomValues(self) -end - -function gmInte.plyValid(ply) - return ply:IsValid() && ply:IsPlayer() && !ply:IsBot() end \ No newline at end of file From 89d6d502bb7925bf688f5ef3ce0b85571bb50f8d Mon Sep 17 00:00:00 2001 From: Linventif Date: Tue, 27 Feb 2024 02:29:34 +0100 Subject: [PATCH 29/66] move: local config to cloud config --- lua/gmod_integration/client/cl_gui_admin.lua | 218 +++++++++---------- lua/gmod_integration/sv_config.lua | 30 +-- 2 files changed, 110 insertions(+), 138 deletions(-) diff --git a/lua/gmod_integration/client/cl_gui_admin.lua b/lua/gmod_integration/client/cl_gui_admin.lua index d5840f1..f0b0f59 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", } @@ -39,30 +39,30 @@ local possibleConfig = { ["onEditDelay"] = 0.5, ["category"] = "Authentication" }, - ["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" - }, - ["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" - }, + -- ["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" + -- }, + -- ["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" + -- }, ["filterOnBan"] = { ["label"] = "Block Discord Ban Player", ["description"] = "Block players banned on the discord server.", @@ -75,90 +75,90 @@ local possibleConfig = { end, ["category"] = "Trust & Safety" }, - ["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" - }, - ["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" - }, - ["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" - }, - ["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" - }, - ["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" - }, - ["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" - }, + -- ["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" + -- }, + -- ["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" + -- }, + -- ["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" + -- }, + -- ["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" + -- }, + -- ["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" + -- }, + -- ["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" + -- }, ["forcePlayerLink"] = { ["label"] = "Force Player Verif", ["description"] = "Sync chat between the server and the discord server.", diff --git a/lua/gmod_integration/sv_config.lua b/lua/gmod_integration/sv_config.lua index a578054..d905e78 100644 --- a/lua/gmod_integration/sv_config.lua +++ b/lua/gmod_integration/sv_config.lua @@ -1,6 +1,6 @@ /* Informations: - This file is prioritized over the configuration file in data/gmod-integration/config.json until the id are set. + This file is prioritized over the configuration file in data/gmod-integration/config.json if id and token are set in this file. We don't recommend to use a static version of our addon, you should use the workshop version instead. Add Server: @@ -26,50 +26,22 @@ gmInte.config.id = "" // Server ID gmInte.config.token = "" // Server Token -// Websocket -/* - This is a premium feature, you can buy premium on our website: https://gmod-integration.com/premium - Websocket allow you to made a real-time connection between your server and our servers. - And so use the real-time features of our addon (like the chat syncronization, role syncronization, ...) -*/ -gmInte.config.websocket = false // If true, the addon will use the websocket instead of the http requests - // 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.logBotActions = false // If true, the addon will log the messages of the bot in the console // // Syncronization // -// General -gmInte.config.syncChat = false // If true, the addon will sync the chat gmod with a selected channel on discord (need to be enabled on the dashboard) -gmInte.config.syncPlayerStat = true // If true, the addon will sync the player stats (kills, deaths, playtime, ...) - // 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) -// -// Player Filter -// - -// Trust Factor -gmInte.config.minimalTrust = 30 // The minimal trust factor of an user to be able to join the server (0 to 100) -gmInte.config.filterOnTrust = true // If true, the addon will filter the players according to their trust factor - // Ban gmInte.config.filterOnBan = true // If true, the addon will filter the players according to their ban status -// -// Features Kill Switch -// - -// Will disable the features of the addon -gmInte.config.sendLog = false // Disable the logs - // // Materials // From bd38456959f39297e737ad8fe05b802412fa9958 Mon Sep 17 00:00:00 2001 From: Linventif Date: Tue, 27 Feb 2024 02:30:12 +0100 Subject: [PATCH 30/66] fix: spam log --- lua/gmod_integration/shared/sh_http.lua | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lua/gmod_integration/shared/sh_http.lua b/lua/gmod_integration/shared/sh_http.lua index 2541579..96a7ab7 100644 --- a/lua/gmod_integration/shared/sh_http.lua +++ b/lua/gmod_integration/shared/sh_http.lua @@ -34,13 +34,13 @@ local function showableBody(endpoint) end function gmInte.http.requestAPI(params) - local body = params.body || "" + local body = params.body && util.TableToJSON(params.body || {}) || "" local bodyLength = string.len(body) local token = params.token || gmInte.config.token || "" local url = getAPIURL(params.endpoint) local method = params.method local success = params.success || function() end - local failed = params.failed || function(error) gmInte.logError(error.error || error) end + local failed = params.failed || function() if (!gmInte.config.debug) then gmInte.log("HTTP Failed, if this error persists please contact support") end end local version = gmInte.config.version local showableBody = showableBody(params.endpoint) @@ -76,6 +76,7 @@ function gmInte.http.requestAPI(params) // if not application/json return failed if (string.sub(headers["Content-Type"], 1, 16) != "application/json") then + gmInte.log("HTTP Failed: Invalid Content-Type", true) return failed({ ["error"] = "Invalid Content-Type" }, code, headers) end @@ -86,7 +87,11 @@ function gmInte.http.requestAPI(params) return success(code, body) end, ["failed"] = function(error) - gmInte.logError(error) + // Log + gmInte.log("HTTP Failed: " .. error, true) + + // Return failed + return failed({ ["error"] = error }) end }) end @@ -108,7 +113,7 @@ function gmInte.http.post(endpoint, data, onSuccess, onFailed) gmInte.http.requestAPI({ ["endpoint"] = endpoint, ["method"] = "POST", - ["body"] = util.TableToJSON(data), + ["body"] = data, ["success"] = onSuccess, ["failed"] = onFailed }) @@ -118,7 +123,7 @@ function gmInte.http.put(endpoint, data, onSuccess, onFailed) gmInte.http.requestAPI({ ["endpoint"] = endpoint, ["method"] = "PUT", - ["body"] = util.TableToJSON(data), + ["body"] = data, ["success"] = onSuccess, ["failed"] = onFailed }) From fe44cb11801f5b2e4480cc913cae8453f78392f2 Mon Sep 17 00:00:00 2001 From: Linventif Date: Tue, 27 Feb 2024 02:30:55 +0100 Subject: [PATCH 31/66] refactor: log to players --- lua/gmod_integration/server/sv_logs.lua | 197 ------------------- lua/gmod_integration/server/sv_players.lua | 208 +++++++++++++++------ 2 files changed, 151 insertions(+), 254 deletions(-) delete mode 100644 lua/gmod_integration/server/sv_logs.lua diff --git a/lua/gmod_integration/server/sv_logs.lua b/lua/gmod_integration/server/sv_logs.lua deleted file mode 100644 index 4c18820..0000000 --- a/lua/gmod_integration/server/sv_logs.lua +++ /dev/null @@ -1,197 +0,0 @@ -// -// Functions -// - -local function logDisable() - return !gmInte.config.sendLog -end - -local function validLogAndPlayers(players) - if (logDisable()) then return false end - for _, ply in pairs(players) do - // return if not valid, player or bot and bots logs are disabled - if (!IsValid(ply)) then return false end - if (!ply:IsPlayer()) then return false end - if (!ply:IsBot() && !gmInte.config.logBotActions) then return false end - end - return true -end - -// -// Posts -// - -function gmInte.postLogPlayerSay(ply, text, teamChat) - if (!validLogAndPlayers({ply})) then return end - - gmInte.http.post("/logs/playerSay", - { - ["ply"] = gmInte.getPlayerFormat(ply), - ["text"] = text, - ["teamChat"] = teamChat - } - ) -end - -function gmInte.postLogPlayerDeath(ply, inflictor, attacker) - if (!validLogAndPlayers({ply, attacker})) then return end - - gmInte.http.post("/logs/playerDeath", - { - ["ply"] = gmInte.getPlayerFormat(ply), - ["inflictor"] = gmInte.getEntityFormat(inflictor), - ["attacker"] = gmInte.getPlayerFormat(attacker) - } - ) -end - -function gmInte.postLogPlayerInitialSpawn(ply) - if (!validLogAndPlayers({ply})) then return end - - gmInte.http.post("/logs/playerInitialSpawn", - { - ["ply"] = gmInte.getPlayerFormat(ply) - } - ) -end - -function gmInte.postLogPlayerHurt(ply, attacker, healthRemaining, damageTaken) - if (!validLogAndPlayers({ply, 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 - ply.gmodInteTotalDamage = ply.gmodInteTotalDamage || 0 - ply.gmodInteTotalDamage = ply.gmodInteTotalDamage + damageTaken - return - end - - gmInte.http.post("/logs/playerHurt", - { - ["ply"] = gmInte.getPlayerFormat(ply), - ["attacker"] = gmInte.getPlayerFormat(attacker), - ["healthRemaining"] = healthRemaining, - ["damageTaken"] = ply.gmodInteTotalDamage - } - ) - end) -end - -function gmInte.postLogPlayerSpawnedSomething(object, ply, ent, model) - if (!validLogAndPlayers({ply})) then return end - - gmInte.http.post("/logs/playerSpawnedSomething", - { - ["object"] = object, - ["ply"] = gmInte.getPlayerFormat(ply), - ["ent"] = gmInte.getEntityFormat(ent), - ["model"] = model || "" - } - ) -end - -function gmInte.postLogPlayerSpawn(ply) - if (!validLogAndPlayers({ply})) then return end - - gmInte.http.post("/logs/playerSpawn", - { - ["ply"] = gmInte.getPlayerFormat(ply) - } - ) -end - -function gmInte.postLogPlayerDisconnect(ply) - if (!validLogAndPlayers({ply})) then return end - - gmInte.http.post("/logs/playerDisconnect", - { - ["ply"] = gmInte.getPlayerFormat(ply) - } - ) -end - -function gmInte.postLogPlayerConnect(data) - if (logDisable() || data.bot) then return end - - gmInte.http.post("/logs/playerConnect", - { - ["steamID64"] = util.SteamIDTo64(data.networkid), - ["steamID"] = data.networkid, - ["name"] = data.name, - ["ip"] = data.address - } - ) -end - -function gmInte.postLogPlayerGivet(ply, class, swep) - if (!validLogAndPlayers({ply})) then return end - - gmInte.http.post("/logs/playerGive", - { - ["ply"] = gmInte.getPlayerFormat(ply), - ["class"] = class, - ["swep"] = swep - } - ) -end - -// -// Hooks -// - -gameevent.Listen("player_connect") - -// Base - Player -hook.Add("PlayerSay", "gmInte:Log:PlayerSay", function(ply, text, teamChat) - gmInte.postLogPlayerSay(ply, text, teamChat) -end) -hook.Add("PlayerSpawn", "gmInte:Log:PlayerSpawn", function(ply) - gmInte.postLogPlayerSpawn(ply) -end) -hook.Add("player_connect", "gmInte:Log:PlayerConnect", function(data) - gmInte.postLogPlayerConnect(data) -end) -hook.Add("PlayerInitialSpawn", "gmInte:Log:PlayerInitialSpawn", function(ply) - gmInte.postLogPlayerInitialSpawn(ply) -end) -hook.Add("PlayerDisconnected", "gmInte:Log:PlayerDisconnected", function(ply) - gmInte.postLogPlayerDisconnect(ply) -end) -hook.Add("PlayerGiveSWEP", "gmInte:Log:PlayerSWEPs", function( ply, class, swep ) - gmInte.postLogPlayerGivet(ply, class, swep) -end) - -// Base - Player Combat -hook.Add("PlayerDeath", "gmInte:Log:PlayerDeath", function(ply, inflictor, attacker) - gmInte.postLogPlayerDeath(ply, inflictor, attacker) -end) -hook.Add("PlayerHurt", "gmInte:Log:PlayerHurt", function(ply, attacker, healthRemaining, damageTaken) - gmInte.postLogPlayerHurt(ply, attacker, healthRemaining, damageTaken) -end) - -// Base - Spawnables -hook.Add("PlayerSpawnedProp", "gmInte:Log:PlayerSpawnedProp", function(ply, model, ent) - gmInte.postLogPlayerSpawnedSomething("SENT", ply, ent, model) -end) -hook.Add("PlayerSpawnedSENT", "gmInte:Log:PlayerSpawnedSENT", function(ply, ent) - gmInte.postLogPlayerSpawnedSomething("SENT", ply, ent) -end) -hook.Add("PlayerSpawnedNPC", "gmInte:Log:PlayerSpawnedNPC", function(ply, ent) - gmInte.postLogPlayerSpawnedSomething("NPC", ply, ent) -end) -hook.Add("PlayerSpawnedVehicle", "gmInte:Log:PlayerSpawnedVehicle", function(ply, ent) - gmInte.postLogPlayerSpawnedSomething("Vehicle", ply, ent) -end) -hook.Add("PlayerSpawnedEffect", "gmInte:Log:PlayerSpawnedEffect", function(ply, model, ent) - gmInte.postLogPlayerSpawnedSomething("Effect", ply, ent, model) -end) -hook.Add("PlayerSpawnedRagdoll", "gmInte:Log:PlayerSpawnedRagdoll", function(ply, model, ent) - gmInte.postLogPlayerSpawnedSomething("Ragdoll", ply, ent, model) -end) -hook.Add("PlayerSpawnedSWEP", "gmInte:Log:PlayerSpawnedSWEP", function(ply, ent) - gmInte.postLogPlayerSpawnedSomething("SWEP", ply, ent) -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 bf8debc..e5d5358 100644 --- a/lua/gmod_integration/server/sv_players.lua +++ b/lua/gmod_integration/server/sv_players.lua @@ -2,59 +2,8 @@ // Methods // -function gmInte.verifyPlayer(ply) - if (!gmInte.plyValid(ply)) then return end - gmInte.http.get("/players/" .. ply:SteamID64(), function(code, data) - if (!gmInte.config.forcePlayerLink) then return end - - if (data && data.steamID64) then - if (ply.gmIntVerified) then return end - gmInte.SendNet("chatColorMessage", { - [1] = { - ["text"] = "You have been verified", - ["color"] = Color(255, 255, 255) - } - }, ply) - ply:Freeze(false) - ply.gmIntVerified = true - else - gmInte.SendNet("chatColorMessage", { - [1] = { - ["text"] = "You are not verified", - ["color"] = Color(255, 0, 0) - } - }, ply) - ply:Freeze(true) - gmInte.SendNet("openVerifPopup", nil, ply) - end - end) -end - -// Generate a unique token that allow player to update data link to this server (ex: screnshot, report bug, etc.) -function gmInte.getClientOneTimeToken(ply, callback) - gmInte.http.get("/players/" .. ply:SteamID64() .. "/single-token", function(code, data) - callback(data.token) - end) -end - -function gmInte.createClientToken(ply, callback) - gmInte.http.get("/players/" .. ply:SteamID64() .. "/tokens", function(code, data) - callback(data) - end) -end - -function gmInte.revokeClientToken(ply, callback) - gmInte.http.delete("/players/" .. ply:SteamID64() .. "/tokens", function(code, data) - callback(data) - end) -end - -function gmInte.playerConnect(data) - gmInte.http.post("/players/" .. util.SteamIDTo64(data.networkid) .. "/connect", data) -end - -function gmInte.userFinishConnect(ply) - if (!gmInte.plyValid(ply)) then return end +hook.Add("gmInte:PlayerReady", "gmInte:Player:Ready", function(ply) + if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end // Initialize Time ply.gmIntTimeConnect = math.Round(RealTime()) @@ -62,14 +11,23 @@ function gmInte.userFinishConnect(ply) // Send Public Config gmInte.publicGetConfig(ply) - gmInte.http.post("/players/" .. ply:SteamID64() .. "/finish-connect", gmInte.getPlayerFormat(ply)) + // Send Player Ready + gmInte.playerReady(ply) +end) - if (!gmInte.config.forcePlayerLink) then return end - gmInte.verifyPlayer(ply) +function gmInte.playerReady(ply) + if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end + + gmInte.http.post("/players/" .. ply:SteamID64() .. "/ready", gmInte.getPlayerFormat(ply)) +end + +function gmInte.playerConnect(data) + data.steamID64 = util.SteamIDTo64(data.networkid) + gmInte.http.post("/players/" .. util.SteamIDTo64(data.networkid) .. "/connect", data) end function gmInte.playerDisconnected(ply) - if (!gmInte.plyValid(ply)) then return end + if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end gmInte.http.post("/players/" .. ply:SteamID64() .. "/disconnect", { @@ -78,6 +36,94 @@ function gmInte.playerDisconnected(ply) ) end +function gmInte.playerSpawn(ply) + if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end + + gmInte.http.post("/players/" .. ply:SteamID64() .. "/spawn", + { + ["player"] = gmInte.getPlayerFormat(ply) + } + ) +end + +function gmInte.postLogPlayerDeath(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("/logs/playerDeath", + { + ["player"] = gmInte.getPlayerFormat(ply), + ["inflictor"] = gmInte.getEntityFormat(inflictor), + ["attacker"] = gmInte.getPlayerFormat(attacker) + } + ) +end + +function gmInte.postLogPlayerInitialSpawn(ply) + if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end + + gmInte.http.post("/logs/playerInitialSpawn", + { + ["ply"] = 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 + + // 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 + ply.gmodInteTotalDamage = ply.gmodInteTotalDamage || 0 + ply.gmodInteTotalDamage = ply.gmodInteTotalDamage + damageTaken + return + end + + gmInte.http.post("/logs/playerHurt", + { + ["victim"] = gmInte.getPlayerFormat(ply), + ["attacker"] = gmInte.getPlayerFormat(attacker), + ["healthRemaining"] = healthRemaining, + ["damageTaken"] = ply.gmodInteTotalDamage + } + ) + 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("/logs/playerSpawnedSomething", + { + ["object"] = object, + ["player"] = gmInte.getPlayerFormat(ply), + ["entity"] = gmInte.getEntityFormat(ent), + ["model"] = model || "" + } + ) +end + +function gmInte.postLogPlayerGivet(ply, class, swep) + if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end + + gmInte.http.post("/logs/playerGive", + { + ["player"] = gmInte.getPlayerFormat(ply), + ["class"] = class, + ["swep"] = swep + } + ) +end + + // // Hooks // @@ -95,4 +141,52 @@ 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.postLogPlayerInitialSpawn(ply) +end) + +hook.Add("PlayerGiveSWEP", "gmInte:Player:SWEPs", function( ply, class, swep ) + gmInte.postLogPlayerGivet(ply, class, swep) +end) + +hook.Add("PlayerDeath", "gmInte:Player:Death", function(ply, inflictor, attacker) + gmInte.postLogPlayerDeath(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("SENT", 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 From a24f1a846d9a03af135b9885248f322b52002df7 Mon Sep 17 00:00:00 2001 From: Linventif Date: Tue, 27 Feb 2024 02:31:14 +0100 Subject: [PATCH 32/66] refactor: player token gen & verif --- .../server/sv_players_tokens.lua | 27 ++++++++++++ .../server/sv_players_verif.lua | 42 +++++++++++++++++++ 2 files changed, 69 insertions(+) create mode 100644 lua/gmod_integration/server/sv_players_tokens.lua create mode 100644 lua/gmod_integration/server/sv_players_verif.lua diff --git a/lua/gmod_integration/server/sv_players_tokens.lua b/lua/gmod_integration/server/sv_players_tokens.lua new file mode 100644 index 0000000..9397a3d --- /dev/null +++ b/lua/gmod_integration/server/sv_players_tokens.lua @@ -0,0 +1,27 @@ +// +// Methods +// + +function gmInte.getClientOneTimeToken(ply, callback) + if (!ply:IsValid() || !ply:IsPlayer()) then return end + + gmInte.http.get("/players/" .. ply:SteamID64() .. "/single-token", function(code, data) + if (callback) then callback(data) end + end) +end + +function gmInte.createClientToken(ply, callback) + if (!ply:IsValid() || !ply:IsPlayer()) then return end + + gmInte.http.get("/players/" .. ply:SteamID64() .. "/tokens", function(code, data) + if (callback) then callback(data) end + end) +end + +function gmInte.revokeClientToken(ply, callback) + if (!ply:IsValid() || !ply:IsPlayer()) then return end + + gmInte.http.delete("/players/" .. ply:SteamID64() .. "/tokens", function(code, data) + if (callback) then callback(data) end + end) +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 new file mode 100644 index 0000000..e0005a9 --- /dev/null +++ b/lua/gmod_integration/server/sv_players_verif.lua @@ -0,0 +1,42 @@ +// +// Methods +// + +function gmInte.verifyPlayer(ply) + if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end + + gmInte.http.get("/players/" .. ply:SteamID64(), function(code, data) + if (!gmInte.config.forcePlayerLink) then return end + + if (data && data.steamID64) then + if (ply.gmIntVerified) then return end + gmInte.SendNet("chatColorMessage", { + [1] = { + ["text"] = "You have been verified", + ["color"] = Color(255, 255, 255) + } + }, ply) + ply:Freeze(false) + ply.gmIntVerified = true + else + gmInte.SendNet("chatColorMessage", { + [1] = { + ["text"] = "You are not verified", + ["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) + if (!gmInte.config.forcePlayerLink) then return end + + gmInte.verifyPlayer(ply) +end) \ No newline at end of file From c202329f110f9f197c6519947ef5168804d8facf Mon Sep 17 00:00:00 2001 From: Linventif Date: Tue, 27 Feb 2024 02:31:56 +0100 Subject: [PATCH 33/66] edit: run hook insted of func --- lua/gmod_integration/server/sv_net.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/gmod_integration/server/sv_net.lua b/lua/gmod_integration/server/sv_net.lua index 15c86dc..bd9b3d6 100644 --- a/lua/gmod_integration/server/sv_net.lua +++ b/lua/gmod_integration/server/sv_net.lua @@ -39,7 +39,7 @@ end local netReceive = { [0] = function(ply) - gmInte.userFinishConnect(ply) + hook.Run("gmInte:PlayerReady", ply) end, [1] = function(ply, data) gmInte.testConnection(ply, data) From 7f8e81c909caf495b18101e10e06ee4fd9e0e778 Mon Sep 17 00:00:00 2001 From: Linventif Date: Tue, 27 Feb 2024 02:32:10 +0100 Subject: [PATCH 34/66] add: sync kick --- lua/gmod_integration/server/sv_sync_kicks.lua | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 lua/gmod_integration/server/sv_sync_kicks.lua diff --git a/lua/gmod_integration/server/sv_sync_kicks.lua b/lua/gmod_integration/server/sv_sync_kicks.lua new file mode 100644 index 0000000..72aaf59 --- /dev/null +++ b/lua/gmod_integration/server/sv_sync_kicks.lua @@ -0,0 +1,32 @@ +// +// 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 + end +end + +// +// Methods +// + +function gmInte.playerKick(data) + if (data.reason != "Kicked by console" || data.reason != "No reason given") then + return + end + + gmInte.http.post("/players/" .. util.SteamIDTo64(data.networkid) .. "/kick", data) +end + +// +// Hooks +// + +gameevent.Listen("player_disconnect") +hook.Add("player_disconnect", "gmInte:SyncKick:Disconnect", function(data) + gmInte.playerKick(data) +end) From 513920baa0a9b9d7491daded2259ecbbf0679e5c Mon Sep 17 00:00:00 2001 From: Linventif Date: Tue, 27 Feb 2024 02:32:27 +0100 Subject: [PATCH 35/66] refactor: hooks name id --- lua/gmod_integration/server/sv_sync_chat.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/gmod_integration/server/sv_sync_chat.lua b/lua/gmod_integration/server/sv_sync_chat.lua index e57d7a5..3507080 100644 --- a/lua/gmod_integration/server/sv_sync_chat.lua +++ b/lua/gmod_integration/server/sv_sync_chat.lua @@ -26,6 +26,6 @@ end // Hooks // -hook.Add("PlayerSay", "gmInte:PlayerSay:SyncChat", function(ply, text, team) +hook.Add("PlayerSay", "gmInte:SyncChat:PlayerSay", function(ply, text, team) gmInte.playerSay(ply, text, team) end) \ No newline at end of file From e7210a54245d153ce7c66f85060cb17abccaca77 Mon Sep 17 00:00:00 2001 From: Linventif Date: Tue, 27 Feb 2024 02:32:37 +0100 Subject: [PATCH 36/66] fix: ply verif --- lua/gmod_integration/server/sv_sync_names.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/gmod_integration/server/sv_sync_names.lua b/lua/gmod_integration/server/sv_sync_names.lua index 836ce7b..a1b367c 100644 --- a/lua/gmod_integration/server/sv_sync_names.lua +++ b/lua/gmod_integration/server/sv_sync_names.lua @@ -13,7 +13,7 @@ end // function gmInte.playerChangeName(ply, oldName, newName) - if (!gmInte.plyValid(ply)) then return end + if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end gmInte.http.post("/players/" .. ply:SteamID64() .. "/name", { From 7a739564f128570cb9cd76422f4a9decdfb530f7 Mon Sep 17 00:00:00 2001 From: Linventif Date: Tue, 27 Feb 2024 02:32:47 +0100 Subject: [PATCH 37/66] fix: endpoints --- lua/gmod_integration/server/sv_sync_bans.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/gmod_integration/server/sv_sync_bans.lua b/lua/gmod_integration/server/sv_sync_bans.lua index 246e69d..b74837e 100644 --- a/lua/gmod_integration/server/sv_sync_bans.lua +++ b/lua/gmod_integration/server/sv_sync_bans.lua @@ -15,7 +15,7 @@ end // function gmInte.playerBan(data) - gmInte.http.post("/players/" .. util.SteamIDTo64(data.networkid) .. "/bans", data) + gmInte.http.post("/players/" .. util.SteamIDTo64(data.networkid) .. "/ban", data) end // From 36e2de188340aed7b3cc8e3860ebf896254de3dd Mon Sep 17 00:00:00 2001 From: Linventif Date: Tue, 27 Feb 2024 02:33:38 +0100 Subject: [PATCH 38/66] fix: player is valid --- lua/gmod_integration/server/sv_settings.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/gmod_integration/server/sv_settings.lua b/lua/gmod_integration/server/sv_settings.lua index dfaaa61..6f7f9aa 100644 --- a/lua/gmod_integration/server/sv_settings.lua +++ b/lua/gmod_integration/server/sv_settings.lua @@ -46,14 +46,14 @@ function gmInte.refreshSettings() end function gmInte.superadminGetConfig(ply) - if (!gmInte.plyValid(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 (!gmInte.plyValid(ply)) then return end + if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end gmInte.SendNet("publicConfig", { ["debug"] = gmInte.config.debug, @@ -62,7 +62,7 @@ function gmInte.publicGetConfig(ply) end function gmInte.superadminSetConfig(ply, data) - if (!gmInte.plyValid(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) From 88b55055504839cf59864d146bc41db2133082b4 Mon Sep 17 00:00:00 2001 From: Linventif Date: Tue, 27 Feb 2024 02:47:54 +0100 Subject: [PATCH 39/66] add: uptime in report error --- lua/gmod_integration/shared/sh_errors.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lua/gmod_integration/shared/sh_errors.lua b/lua/gmod_integration/shared/sh_errors.lua index bc3a989..ad97d81 100644 --- a/lua/gmod_integration/shared/sh_errors.lua +++ b/lua/gmod_integration/shared/sh_errors.lua @@ -2,9 +2,9 @@ // Methods // -function gmInte.sendLuaErrorReport(err, realm, stack, name, id) +function gmInte.sendLuaErrorReport(err, realm, stack, name, id, uptime) if (name != "gmod_integration") then return end - if (SERVER && math.Round(RealTime()) == 0) then return end + if (SERVER && math.Round(RealTime()) == 0) then return timer.Simple(1, function() gmInte.sendLuaErrorReport(err, realm, stack, name, id, math.Round(RealTime())) end) end gmInte.http.post("/errors", { @@ -13,6 +13,7 @@ function gmInte.sendLuaErrorReport(err, realm, stack, name, id) ["stack"] = stack, ["name"] = name, ["id"] = id, + ["uptime"] = uptime || math.Round(RealTime()), ["identifier"] = SERVER && gmInte.config.id || LocalPlayer():SteamID64() } ) From 8f4249a68d3b67ff9b76bb7d1d794d5c5fcd257d Mon Sep 17 00:00:00 2001 From: Linventif Date: Tue, 27 Feb 2024 03:52:51 +0100 Subject: [PATCH 40/66] refactor: change endpoint url to get user public info --- lua/gmod_integration/client/cl_gui_link.lua | 2 +- lua/gmod_integration/shared/sh_http.lua | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/gmod_integration/client/cl_gui_link.lua b/lua/gmod_integration/client/cl_gui_link.lua index be9d8e9..968e140 100644 --- a/lua/gmod_integration/client/cl_gui_link.lua +++ b/lua/gmod_integration/client/cl_gui_link.lua @@ -44,7 +44,7 @@ function gmInte.openVerifPopup() local button = vgui.Create("DButton") button:SetText("Refresh Verification") button.DoClick = function() - gmInte.http.get("/players/" .. LocalPlayer():SteamID64(), function(code, body) + gmInte.http.get("/users/" .. LocalPlayer():SteamID64(), function(code, body) gmInte.SendNet("verifyMe") frame:Close() end, diff --git a/lua/gmod_integration/shared/sh_http.lua b/lua/gmod_integration/shared/sh_http.lua index 96a7ab7..5f7aaf8 100644 --- a/lua/gmod_integration/shared/sh_http.lua +++ b/lua/gmod_integration/shared/sh_http.lua @@ -14,7 +14,7 @@ local function getAPIURL(endpoint) if (SERVER) then url = url .. "/servers/" .. gmInte.config.id else - if (string.sub(endpoint, 1, 8) == "/players" || string.sub(endpoint, 1, 7) == "/errors") then + if (string.sub(endpoint, 1, 8) == "/users") then return url .. endpoint end From 09be85b49d18bf78d53e14f02973fc247c850272 Mon Sep 17 00:00:00 2001 From: Linventif Date: Tue, 27 Feb 2024 08:30:08 +0100 Subject: [PATCH 41/66] fix: use wss dev when devInstanceis on --- lua/gmod_integration/server/sv__websocket.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/gmod_integration/server/sv__websocket.lua b/lua/gmod_integration/server/sv__websocket.lua index 4e80cb8..5a5ddb9 100644 --- a/lua/gmod_integration/server/sv__websocket.lua +++ b/lua/gmod_integration/server/sv__websocket.lua @@ -33,7 +33,7 @@ if (!GWSockets) then end local function getWebSocketURL() - return "wss://" .. (gmInte.config.dev and websocketDevFQDN or websocketFQDN) + return "wss://" .. (gmInte.config.devInstance and websocketDevFQDN or websocketFQDN) end local socket = GWSockets.createWebSocket(getWebSocketURL()) From a634821f25bb35febb83c1caca9eb1f23e10b741 Mon Sep 17 00:00:00 2001 From: Linventif Date: Tue, 27 Feb 2024 23:55:44 +0100 Subject: [PATCH 42/66] add: server filter maintenance --- lua/gmod_integration/client/cl_gui_admin.lua | 12 ++++++++ lua/gmod_integration/server/sv_filtrers.lua | 31 ++++++++++---------- 2 files changed, 28 insertions(+), 15 deletions(-) diff --git a/lua/gmod_integration/client/cl_gui_admin.lua b/lua/gmod_integration/client/cl_gui_admin.lua index f0b0f59..e29d825 100644 --- a/lua/gmod_integration/client/cl_gui_admin.lua +++ b/lua/gmod_integration/client/cl_gui_admin.lua @@ -63,6 +63,18 @@ local possibleConfig = { -- end, -- ["category"] = "Main" -- }, + ["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, + ["category"] = "Main" + }, ["filterOnBan"] = { ["label"] = "Block Discord Ban Player", ["description"] = "Block players banned on the discord server.", diff --git a/lua/gmod_integration/server/sv_filtrers.lua b/lua/gmod_integration/server/sv_filtrers.lua index c5a2565..28bcccb 100644 --- a/lua/gmod_integration/server/sv_filtrers.lua +++ b/lua/gmod_integration/server/sv_filtrers.lua @@ -4,25 +4,19 @@ local function filterMessage(reason) local Message = { - "", - "This server has player filtering enabled", - "You are not allowed to join this server", + "\n----------------------------------------\n", + "You cannot join this server", "", "Reason: " .. reason, - "", - "For more information, please contact the server owner", "Help URL: " .. (gmInte.config.supportLink && gmInte.config.supportLink || "No Support Link"), "", - "You can also contact us on our discord server", - "https://gmod-integration.com/discord", - "", "Have a nice day", - "", + "\n----------------------------------------\n", "Service provided by Gmod Integration", } for k, v in pairs(Message) do - Message[k] = v .. "\n" + Message[k] = "\n" .. v end return table.concat(Message) @@ -58,18 +52,25 @@ local function playerFilter(data) gmInte.http.get("/players/" .. data.steamID64, function(code, body) - if (!body || !body.trust) then return end + if (!gmInte.config.maintenance && !body.bypassMaintenance) 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")) + 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")) + 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")) + -- if (!checkTrustFactor(body.trust)) then + -- game.KickID(data.networkid, filterMessage("Your trust factor is too low.")) + -- end + end, + function (err) + 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 ) From de0588d02cf552a2f7aa40c9d00db6c72af6f297 Mon Sep 17 00:00:00 2001 From: Linventif Date: Tue, 27 Feb 2024 23:55:57 +0100 Subject: [PATCH 43/66] add: requestID --- lua/gmod_integration/shared/sh_http.lua | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lua/gmod_integration/shared/sh_http.lua b/lua/gmod_integration/shared/sh_http.lua index 5f7aaf8..94855de 100644 --- a/lua/gmod_integration/shared/sh_http.lua +++ b/lua/gmod_integration/shared/sh_http.lua @@ -33,6 +33,10 @@ local function showableBody(endpoint) return true end +local function genRequestID() + return "gmInte-" .. util.CRC(tostring(SysTime())) +end + function gmInte.http.requestAPI(params) local body = params.body && util.TableToJSON(params.body || {}) || "" local bodyLength = string.len(body) @@ -43,6 +47,7 @@ function gmInte.http.requestAPI(params) local failed = params.failed || function() if (!gmInte.config.debug) then gmInte.log("HTTP Failed, if this error persists please contact support") end end local version = gmInte.config.version local showableBody = showableBody(params.endpoint) + local requestID = genRequestID() local headers = { ["Content-Type"] = "application/json", @@ -54,6 +59,7 @@ function gmInte.http.requestAPI(params) // Log if (gmInte.config.devInstance) then gmInte.log("HTTP Using dev Instance", true) end + gmInte.log("HTTP Request ID: " .. requestID, true) gmInte.log("HTTP Request: " .. method .. " " .. url, true) gmInte.log("HTTP Body: " .. (showableBody && body || "HIDDEN"), true) @@ -66,6 +72,7 @@ function gmInte.http.requestAPI(params) ["type"] = type, ["success"] = function(code, body, headers) // Log + gmInte.log("HTTP Request ID: " .. requestID, true) gmInte.log("HTTP Response: " .. code, true) if (gmInte.config.debug) then gmInte.log("HTTP Body: " .. body, true) end @@ -88,6 +95,7 @@ function gmInte.http.requestAPI(params) end, ["failed"] = function(error) // Log + gmInte.log("HTTP Request ID: " .. requestID, true) gmInte.log("HTTP Failed: " .. error, true) // Return failed From 7dea7d5cce336f827107110a6dc163e3bc1a40c3 Mon Sep 17 00:00:00 2001 From: Linventif Date: Tue, 27 Feb 2024 23:56:13 +0100 Subject: [PATCH 44/66] add: maintenance config --- lua/gmod_integration/sv_config.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/gmod_integration/sv_config.lua b/lua/gmod_integration/sv_config.lua index d905e78..5414279 100644 --- a/lua/gmod_integration/sv_config.lua +++ b/lua/gmod_integration/sv_config.lua @@ -29,6 +29,7 @@ gmInte.config.token = "" // Server Token // 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 From 0eba1f0d4df10cc0dd03a8c86aaa0a8cf1da6c66 Mon Sep 17 00:00:00 2001 From: Linventif Date: Wed, 28 Feb 2024 18:31:48 +0100 Subject: [PATCH 45/66] add: custom FQDN for API and Websocket --- lua/gmod_integration/client/cl_gui_admin.lua | 201 +++++++++++-------- lua/gmod_integration/sv_config.lua | 2 + 2 files changed, 122 insertions(+), 81 deletions(-) diff --git a/lua/gmod_integration/client/cl_gui_admin.lua b/lua/gmod_integration/client/cl_gui_admin.lua index e29d825..132107e 100644 --- a/lua/gmod_integration/client/cl_gui_admin.lua +++ b/lua/gmod_integration/client/cl_gui_admin.lua @@ -13,8 +13,9 @@ local configCat = { } local possibleConfig = { - ["id"] = { - ["label"] = "ID", + { + ["id"] = "id", + ["label"] = "Server ID", ["description"] = "Server ID found on the webpanel.", ["type"] = "textEntry", ["value"] = function(setting, value) @@ -26,8 +27,9 @@ local possibleConfig = { ["onEditDelay"] = 0.5, ["category"] = "Authentication" }, - ["token"] = { - ["label"] = "Token", + { + ["id"]= "token", + ["label"] = "Server Token", ["description"] = "Server Token found on the webpanel.", ["type"] = "textEntry", ["value"] = function(setting, value) @@ -39,7 +41,8 @@ local possibleConfig = { ["onEditDelay"] = 0.5, ["category"] = "Authentication" }, - -- ["sendLog"] = { + -- { + -- ["id"]= "sendLog", -- ["label"] = "Logs", -- ["description"] = "Activate or deactivate logs.", -- ["type"] = "checkbox", @@ -51,7 +54,8 @@ local possibleConfig = { -- end, -- ["category"] = "Main" -- }, - -- ["logBotActions"] = { + -- { + -- ["id"]= "logBotActions", -- ["label"] = "Log Bot Actions", -- ["description"] = "Activate or deactivate logs for bot actions.", -- ["type"] = "checkbox", @@ -63,7 +67,8 @@ local possibleConfig = { -- end, -- ["category"] = "Main" -- }, - ["maintenance"] = { + { + ["id"]= "maintenance", ["label"] = "Maintenance", ["description"] = "Activate or deactivate maintenance mode.", ["type"] = "checkbox", @@ -75,7 +80,8 @@ local possibleConfig = { end, ["category"] = "Main" }, - ["filterOnBan"] = { + { + ["id"]= "filterOnBan", ["label"] = "Block Discord Ban Player", ["description"] = "Block players banned on the discord server.", ["type"] = "checkbox", @@ -87,7 +93,8 @@ local possibleConfig = { end, ["category"] = "Trust & Safety" }, - -- ["filterOnTrust"] = { + -- { + -- ["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", @@ -99,7 +106,8 @@ local possibleConfig = { -- end, -- ["category"] = "Trust & Safety" -- }, - -- ["minimalTrust"] = { + -- { + -- ["id"]= "minimalTrust", -- ["label"] = "Minimal Trust Level", -- ["description"] = "The minimal trust level to be able to join the server.", -- ["type"] = "textEntry", @@ -112,7 +120,8 @@ local possibleConfig = { -- ["onEditDelay"] = 0.5, -- ["category"] = "Trust & Safety" -- }, - -- ["syncChat"] = { + -- { + -- ["id"]= "syncChat", -- ["label"] = "Sync Chat", -- ["description"] = "Sync chat between the server and the discord server.", -- ["websocket"] = true, @@ -126,7 +135,8 @@ local possibleConfig = { -- end, -- ["category"] = "Main" -- }, - -- ["syncBan"] = { + -- { + -- ["id"]= "syncBan", -- ["label"] = "Sync Ban", -- ["description"] = "Sync chat between the server and the discord server.", -- ["type"] = "checkbox", @@ -141,7 +151,8 @@ local possibleConfig = { -- end, -- ["category"] = "Punishment" -- }, - -- ["syncTimeout"] = { + -- { + -- ["id"]= "syncTimeout", -- ["label"] = "Sync Timeout", -- ["description"] = "Sync chat between the server and the discord server.", -- ["type"] = "checkbox", @@ -156,7 +167,8 @@ local possibleConfig = { -- end, -- ["category"] = "Punishment" -- }, - -- ["syncKick"] = { + -- { + -- ["id"]= "syncKick", -- ["label"] = "Sync Kick", -- ["description"] = "Sync chat between the server and the discord server.", -- ["type"] = "checkbox", @@ -171,7 +183,8 @@ local possibleConfig = { -- end, -- ["category"] = "Punishment" -- }, - ["forcePlayerLink"] = { + { + ["id"]= "forcePlayerLink", ["label"] = "Force Player Verif", ["description"] = "Sync chat between the server and the discord server.", ["type"] = "checkbox", @@ -183,7 +196,8 @@ local possibleConfig = { end, ["category"] = "Main" }, - ["supportLink"] = { + { + ["id"]= "supportLink", ["label"] = "Support Link", ["description"] = "Server ID found on the webpanel.", ["type"] = "textEntry", @@ -196,33 +210,48 @@ local possibleConfig = { ["onEditDelay"] = 0.5, ["category"] = "Trust & Safety" }, - ["debug"] = { + { + ["id"]= "debug", ["label"] = "Debug", ["description"] = "Activate or deactivate debug mode.", ["type"] = "checkbox", ["value"] = function(setting, value) return value end, + ["position"] = 1, ["onEdit"] = function(setting, value) saveConfig(setting, value == "Enabled" && true || false) end, ["category"] = "Advanced" }, - ['devInstance'] = { - ["label"] = "Dev Instance", - ["description"] = "Activate or deactivate the dev instance of the API and Websocket.", - ["type"] = "checkbox", + { + ["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, - ["condition"] = function(data) - return data.debug + ["onEdit"] = function(setting, value) + saveConfig(setting, value) + end, + ["onEditDelay"] = 0.5, + ["category"] = "Advanced" + }, + { + ["id"]= "apiFQDN", + ["label"] = "API FQDN", + ["description"] = "API FQDN that will be used for the API connection.", + ["type"] = "textEntry", + ["value"] = function(setting, value) + return value end, ["onEdit"] = function(setting, value) - saveConfig(setting, value == "Enabled" && true || false) + saveConfig(setting, value) end, + ["onEditDelay"] = 0.5, ["category"] = "Advanced" - } + }, } local buttonsInfo = { @@ -358,66 +387,76 @@ function gmInte.openConfigMenu(data) configList:EnableVerticalScrollbar(false) collapsibleCategory:SetContents(configList) + local categoryConfig = {} for k, v in pairs(possibleConfig) do if v.category == catName then - local panel = vgui.Create("DPanel", configList) - panel:Dock(TOP) - panel:SetSize(300, 25) - panel:SetBackgroundColor(Color(0, 0, 0, 0)) - - local label = vgui.Create("DLabel", panel) - label:Dock(LEFT) - label:SetSize(140, 25) - label:SetText(v.label) - label:SetContentAlignment(4) - - local input - - if v.type == "textEntry" then - input = vgui.Create("DTextEntry", panel) - input:SetText(v.value(k, data[k])) - local isLastID = 0 - input.OnChange = function(self) - isLastID = isLastID + 1 - local isLocalLastID = isLastID - timer.Simple(v.onEditDelay || 0.5, function() - if isLocalLastID == isLastID then - v.onEdit(k, self:GetValue()) - end - end) - end - elseif (v.type == "checkbox") then - input = vgui.Create("DComboBox", panel) - if (v.condition && !v.condition(data)) then - input:SetEnabled(false) - end - input:AddChoice("Enabled") - input:AddChoice("Disabled") - input:SetText(v.value(k, data[k]) && "Enabled" || "Disabled") - input.OnSelect = function(self, index, value) - if (v.restart) then - needRestart = true - end - v.onEdit(k, value) - end - end - - input:Dock(FILL) - input:SetSize(150, 25) - - if (v.description) then - if (v.websocket && !data.websocket) then - v.description = v.description .. "\n\nThis feature require a websocket connection to work properly." - end - if (v.disable) then - v.description = v.description .. "\n\nThis feature will be available soon." - end - input:SetTooltip(v.description) - end - - configList:AddItem(panel) + table.insert(categoryConfig, v) end end + + // Sort by position + 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) + input:SetText(actualConfig.value(actualConfig.id, data[actualConfig.id] || "")) + local isLastID = 0 + input.OnChange = function(self) + 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) + end + elseif (actualConfig.type == "checkbox") then + input = vgui.Create("DComboBox", panel) + 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 + 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 + input:SetTooltip(actualConfig.description) + end + + configList:AddItem(panel) + end end local buttonGrid = vgui.Create("DGrid", frame) diff --git a/lua/gmod_integration/sv_config.lua b/lua/gmod_integration/sv_config.lua index 5414279..6a7290e 100644 --- a/lua/gmod_integration/sv_config.lua +++ b/lua/gmod_integration/sv_config.lua @@ -25,6 +25,8 @@ // 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 From 368f7979af75a3c9663f6c3444c4bdd9a83be0c4 Mon Sep 17 00:00:00 2001 From: Linventif Date: Wed, 28 Feb 2024 18:32:10 +0100 Subject: [PATCH 46/66] reformat: move formatName to sync_chat --- lua/gmod_integration/client/cl_main.lua | 10 ---------- lua/gmod_integration/client/cl_sync_chat.lua | 10 ++++++++++ 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/lua/gmod_integration/client/cl_main.lua b/lua/gmod_integration/client/cl_main.lua index 77d95b1..8d9fab2 100644 --- a/lua/gmod_integration/client/cl_main.lua +++ b/lua/gmod_integration/client/cl_main.lua @@ -2,16 +2,6 @@ // Main // -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) - return name -end - function gmInte.chatAddText(data) local args = {} for _, v in ipairs(data) do diff --git a/lua/gmod_integration/client/cl_sync_chat.lua b/lua/gmod_integration/client/cl_sync_chat.lua index cde7b82..3a3f891 100644 --- a/lua/gmod_integration/client/cl_sync_chat.lua +++ b/lua/gmod_integration/client/cl_sync_chat.lua @@ -1,3 +1,13 @@ +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) + return name +end + function gmInte.discordSyncChatPly(data) chat.AddText(Color(92, 105, 255), "(DISCORD) ", Color(12, 151, 12), formatName(data.name) .. ": ", Color(255, 255, 255), data.content) end \ No newline at end of file From eb2a7a2cf333e450764f8eea1311b5e9f242d74a Mon Sep 17 00:00:00 2001 From: Linventif Date: Wed, 28 Feb 2024 18:35:02 +0100 Subject: [PATCH 47/66] fix: don't allow connection if maintenance on and fail api endpoint --- lua/gmod_integration/server/sv_filtrers.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lua/gmod_integration/server/sv_filtrers.lua b/lua/gmod_integration/server/sv_filtrers.lua index 28bcccb..813a253 100644 --- a/lua/gmod_integration/server/sv_filtrers.lua +++ b/lua/gmod_integration/server/sv_filtrers.lua @@ -52,7 +52,7 @@ local function playerFilter(data) gmInte.http.get("/players/" .. data.steamID64, function(code, body) - if (!gmInte.config.maintenance && !body.bypassMaintenance) then + if (gmInte.config.maintenance && !body.bypassMaintenance) then game.KickID(data.networkid, filterMessage("The server is currently under maintenance and you are not whitelisted.")) end @@ -68,8 +68,8 @@ local function playerFilter(data) -- game.KickID(data.networkid, filterMessage("Your trust factor is too low.")) -- end end, - function (err) - if (!gmInte.config.maintenance) then + 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 From b6600612d8dd8f70d401cb31a929bfe73bdf6f85 Mon Sep 17 00:00:00 2001 From: Linventif Date: Wed, 28 Feb 2024 18:39:52 +0100 Subject: [PATCH 48/66] add: custom DQDN for API and Websocket --- lua/gmod_integration/server/sv__websocket.lua | 5 +---- lua/gmod_integration/server/sv_settings.lua | 3 ++- lua/gmod_integration/shared/sh_http.lua | 17 +++++++---------- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/lua/gmod_integration/server/sv__websocket.lua b/lua/gmod_integration/server/sv__websocket.lua index 5a5ddb9..02f17b9 100644 --- a/lua/gmod_integration/server/sv__websocket.lua +++ b/lua/gmod_integration/server/sv__websocket.lua @@ -1,6 +1,3 @@ -local websocketFQDN = "ws.gmod-integration.com" -local websocketDevFQDN = "dev-ws.gmod-integration.com" - // // WebSocket // @@ -33,7 +30,7 @@ if (!GWSockets) then end local function getWebSocketURL() - return "wss://" .. (gmInte.config.devInstance and websocketDevFQDN or websocketFQDN) + return "wss://" .. gmInte.config.websocketFQDN end local socket = GWSockets.createWebSocket(getWebSocketURL()) diff --git a/lua/gmod_integration/server/sv_settings.lua b/lua/gmod_integration/server/sv_settings.lua index 6f7f9aa..d8aed59 100644 --- a/lua/gmod_integration/server/sv_settings.lua +++ b/lua/gmod_integration/server/sv_settings.lua @@ -57,7 +57,8 @@ function gmInte.publicGetConfig(ply) gmInte.SendNet("publicConfig", { ["debug"] = gmInte.config.debug, - ["devInstance"] = gmInte.config.devInstance + ["apiFQDN"] = gmInte.config.apiFQDN, + ["websocketFQDN"] = gmInte.config.websocketFQDN, }, ply) end diff --git a/lua/gmod_integration/shared/sh_http.lua b/lua/gmod_integration/shared/sh_http.lua index 94855de..8a7918e 100644 --- a/lua/gmod_integration/shared/sh_http.lua +++ b/lua/gmod_integration/shared/sh_http.lua @@ -1,7 +1,4 @@ local apiVersion = "v3" -local apiFQDN = "api.gmod-integration.com" -local apiDevFQDN = "dev-api.gmod-integration.com" - gmInte.http = gmInte.http || {} // @@ -9,7 +6,7 @@ gmInte.http = gmInte.http || {} // local function getAPIURL(endpoint) - local url = "https://" .. (gmInte.config.devInstance && apiDevFQDN || apiFQDN) .. "/" .. apiVersion + local url = "https://" .. gmInte.config.apiFQDN .. "/" .. apiVersion if (SERVER) then url = url .. "/servers/" .. gmInte.config.id @@ -58,7 +55,7 @@ function gmInte.http.requestAPI(params) local type = "application/json" // Log - if (gmInte.config.devInstance) then gmInte.log("HTTP Using dev Instance", true) end + gmInte.log("HTTP FQDN: " .. gmInte.config.apiFQDN, true) gmInte.log("HTTP Request ID: " .. requestID, true) gmInte.log("HTTP Request: " .. method .. " " .. url, true) gmInte.log("HTTP Body: " .. (showableBody && body || "HIDDEN"), true) @@ -76,11 +73,6 @@ function gmInte.http.requestAPI(params) gmInte.log("HTTP Response: " .. code, true) if (gmInte.config.debug) then gmInte.log("HTTP Body: " .. body, true) end - // if not 2xx return failed - if (code < 200 || code >= 300) then - return failed(body, code, headers) - end - // if not application/json return failed if (string.sub(headers["Content-Type"], 1, 16) != "application/json") then gmInte.log("HTTP Failed: Invalid Content-Type", true) @@ -90,6 +82,11 @@ function gmInte.http.requestAPI(params) // Parse body body = util.JSONToTable(body || "{}") + // if not 2xx return failed + if (code < 200 || code >= 300) then + return failed(code, body, headers) + end + // Return success return success(code, body) end, From 015dee7d38ebe295fd3be427b745185c8cace625 Mon Sep 17 00:00:00 2001 From: Linventif Date: Sat, 2 Mar 2024 08:23:17 +0100 Subject: [PATCH 49/66] fix: double debug message --- lua/gmod_integration/server/sv__websocket.lua | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/lua/gmod_integration/server/sv__websocket.lua b/lua/gmod_integration/server/sv__websocket.lua index 02f17b9..a460907 100644 --- a/lua/gmod_integration/server/sv__websocket.lua +++ b/lua/gmod_integration/server/sv__websocket.lua @@ -46,14 +46,12 @@ end // log on message function socket:onMessage(txt) gmInte.log("WebSocket Message: " .. txt, true) + local data = util.JSONToTable(txt) - if (gmInte.config.debug) then - gmInte.log("WebSocket Message: " .. txt, true) - end if (gmInte[data.method]) then gmInte[data.method](data) else - gmInte.logError("WebSocket Message: " .. txt .. " is not a valid method !") + gmInte.logError("WebSocket Message: " .. txt .. " is not a valid method !", true) end end From 000340cd04cff9b6a1470691ae0a041c8c1954c6 Mon Sep 17 00:00:00 2001 From: Linventif Date: Sat, 2 Mar 2024 08:23:25 +0100 Subject: [PATCH 50/66] add: sync roles --- lua/gmod_integration/server/sv_sync_roles.lua | 91 ++++++++++++++++--- 1 file changed, 78 insertions(+), 13 deletions(-) diff --git a/lua/gmod_integration/server/sv_sync_roles.lua b/lua/gmod_integration/server/sv_sync_roles.lua index 6baff9e..d4a7a7c 100644 --- a/lua/gmod_integration/server/sv_sync_roles.lua +++ b/lua/gmod_integration/server/sv_sync_roles.lua @@ -2,34 +2,99 @@ // Websocket // -function gmInte.wsSyncRoles(data) +local cachedPlayers = {} + +function gmInte.wsPlayerUpdateGroup(data) + 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:IsValid()) then - ply:SetUserGroup(data.role) + if (ply && ply:IsValid()) then + ply:SetUserGroup(data.group) end // ULX if (ULib) then - ULib.ucl.addUser(data.steamID, nil, nil, data.role) - end - - // FAdmin - if (CAMI) then - CAMI.PlayerRank(data.steamID64, data.role, "user") + ULib.ucl.addUser(data.steamID, nil, nil, data.group) end // ServerGuard if (serverguard) then - serverguard.player:SetRank(data.steamID64, data.role) + local ply = player.GetBySteamID(data.steamID) + if (ply) then + local rankData = serverguard.ranks:GetRank(data.group) + serverguard.player:SetRank(ply, data.group) + serverguard.player:SetImmunity(ply, rankData.immunity) + serverguard.player:SetTargetableRank(ply, rankData.targetable) + serverguard.player:SetBanLimit(ply, rankData.banlimit) + else + serverguard.player:SetRank(data.steamID, data.group) + end end // Evolve if (evolve) then - evolve:RankPlayer(data.steamID64, data.role) + evolve:RankPlayer(data.steamID64, data.group) end // SAM if (SAM) then - SAM:PlayerSetRank(data.steamID64, data.role) + SAM:PlayerSetRank(data.steamID64, data.group) end -end \ No newline at end of file + + // sam (wtf another one?) + if (sam) then + sam.player.setRank(data.steamID64, data.group) + end + + // xAdmin + if (xAdmin) then + xAdmin.SetRank(data.steamID64, data.group) + end + + // maestro + if (maestro) then + maestro.userrank(data.steamID64, data.group) + end + + // D3A + if (D3A) then + D3A.Ranks.SetSteamIDRank(data.steamID, data.group) + end + + // Mercury + if (Mercury) then + RunConsoleCommand("hg", "setrank", data.steamID, data.group) + end + + // FAdmin + 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 + cachedPlayers[steamID64] = newGroup + + gmInte.http.post("/players/" .. steamID64 .. "/group", { + oldGroup = oldGroup || "user", + newGroup = newGroup + }) +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 + gmInte.playerChangeGroup(SteamID64, old, new) +end) \ No newline at end of file From 9e2566731e0ab41884bf3279f8d21491cfe7b7d8 Mon Sep 17 00:00:00 2001 From: Linventif Date: Tue, 5 Mar 2024 06:51:16 +0100 Subject: [PATCH 51/66] add: steamID64 in ban --- lua/gmod_integration/server/sv_sync_bans.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/gmod_integration/server/sv_sync_bans.lua b/lua/gmod_integration/server/sv_sync_bans.lua index b74837e..522d46a 100644 --- a/lua/gmod_integration/server/sv_sync_bans.lua +++ b/lua/gmod_integration/server/sv_sync_bans.lua @@ -15,6 +15,7 @@ end // function gmInte.playerBan(data) + data.steamID64 = util.SteamIDTo64(data.networkid) gmInte.http.post("/players/" .. util.SteamIDTo64(data.networkid) .. "/ban", data) end From 007838d7a3fdedc1e992b4e96ae3c514ed9f1eb1 Mon Sep 17 00:00:00 2001 From: Linventif Date: Tue, 5 Mar 2024 06:51:37 +0100 Subject: [PATCH 52/66] remove: warn move to a further update --- lua/gmod_integration/server/sv_sync_warns.lua | 15 --------------- 1 file changed, 15 deletions(-) delete mode 100644 lua/gmod_integration/server/sv_sync_warns.lua diff --git a/lua/gmod_integration/server/sv_sync_warns.lua b/lua/gmod_integration/server/sv_sync_warns.lua deleted file mode 100644 index 3167988..0000000 --- a/lua/gmod_integration/server/sv_sync_warns.lua +++ /dev/null @@ -1,15 +0,0 @@ -// -// Websocket -// - -function gmInte.wsSyncWarns(data) - // -end - -// -// Methods -// - -function gmInte.playerWarn(data) - // -end \ No newline at end of file From d80e92607da56be6f53b3c2861631af35cadc01f Mon Sep 17 00:00:00 2001 From: Linventif Date: Tue, 5 Mar 2024 06:52:35 +0100 Subject: [PATCH 53/66] edt: kick message detection --- lua/gmod_integration/server/sv_sync_kicks.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/gmod_integration/server/sv_sync_kicks.lua b/lua/gmod_integration/server/sv_sync_kicks.lua index 72aaf59..f6b8a76 100644 --- a/lua/gmod_integration/server/sv_sync_kicks.lua +++ b/lua/gmod_integration/server/sv_sync_kicks.lua @@ -15,7 +15,7 @@ end // function gmInte.playerKick(data) - if (data.reason != "Kicked by console" || data.reason != "No reason given") then + if (string.StartWith(data.reason, "Kicked by ") || data.reason == "No reason provided.") then return end From 471d0ca0a21d8965671279fd1213ce4c1cd0f398 Mon Sep 17 00:00:00 2001 From: Linventif Date: Tue, 5 Mar 2024 06:52:55 +0100 Subject: [PATCH 54/66] add: player in data --- lua/gmod_integration/server/sv_sync_roles.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lua/gmod_integration/server/sv_sync_roles.lua b/lua/gmod_integration/server/sv_sync_roles.lua index d4a7a7c..f965fab 100644 --- a/lua/gmod_integration/server/sv_sync_roles.lua +++ b/lua/gmod_integration/server/sv_sync_roles.lua @@ -84,8 +84,9 @@ function gmInte.playerChangeGroup(steamID64, oldGroup, newGroup) cachedPlayers[steamID64] = newGroup gmInte.http.post("/players/" .. steamID64 .. "/group", { - oldGroup = oldGroup || "user", - newGroup = newGroup + ["player"] = gmInte.getPlayerFormat(ply), + ["oldGroup"] = oldGroup || "user", + ["newGroup"] = newGroup }) end From 58d6477d4b07033e0948c57d9ddf7852a0e4dcab Mon Sep 17 00:00:00 2001 From: Linventif Date: Sun, 10 Mar 2024 03:40:45 +0100 Subject: [PATCH 55/66] fix: if error in the start then wait 1 sec and retry --- lua/gmod_integration/shared/sh_errors.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lua/gmod_integration/shared/sh_errors.lua b/lua/gmod_integration/shared/sh_errors.lua index ad97d81..95c8359 100644 --- a/lua/gmod_integration/shared/sh_errors.lua +++ b/lua/gmod_integration/shared/sh_errors.lua @@ -4,7 +4,18 @@ function gmInte.sendLuaErrorReport(err, realm, stack, name, id, uptime) if (name != "gmod_integration") then return end - if (SERVER && math.Round(RealTime()) == 0) then return timer.Simple(1, function() gmInte.sendLuaErrorReport(err, realm, stack, name, id, math.Round(RealTime())) end) end + + if (SERVER && math.Round(RealTime()) == 0) then + return timer.Simple(1, function() + gmInte.sendLuaErrorReport(err, realm, stack, name, id, math.Round(RealTime())) + end) + end + + if (CLIENT && (!IsValid(LocalPlayer()) || !gmInte.config.token)) then + return timer.Simple(1, function() + gmInte.sendLuaErrorReport(err, realm, stack, name, id, math.Round(RealTime())) + end) + end gmInte.http.post("/errors", { From 299b07a9edacf8caa04263df40964995163aa1a0 Mon Sep 17 00:00:00 2001 From: Linventif Date: Sun, 10 Mar 2024 03:42:31 +0100 Subject: [PATCH 56/66] add: new player temp token --- lua/gmod_integration/client/cl_net.lua | 10 +--- .../server/sv_players_tokens.lua | 27 ---------- lua/gmod_integration/server/sv_settings.lua | 1 + lua/gmod_integration/server/sv_tokens.lua | 50 +++++++++++++++++++ lua/gmod_integration/shared/sh_http.lua | 2 +- 5 files changed, 53 insertions(+), 37 deletions(-) delete mode 100644 lua/gmod_integration/server/sv_players_tokens.lua create mode 100644 lua/gmod_integration/server/sv_tokens.lua diff --git a/lua/gmod_integration/client/cl_net.lua b/lua/gmod_integration/client/cl_net.lua index 28d2c52..261594b 100644 --- a/lua/gmod_integration/client/cl_net.lua +++ b/lua/gmod_integration/client/cl_net.lua @@ -10,8 +10,6 @@ local netSend = { ["takeScreenShot"] = 4, ["restartMap"] = 5, ["verifyMe"] = 6, - ["getSingleUseToken"] = 7, - ["getMultiUseToken"] = 8 } function gmInte.SendNet(id, args, func) @@ -36,9 +34,6 @@ local netReceive = { [3] = function(data) gmInte.showTestConnection(data) end, - [4] = function(data) - gmInte.takeScreenShot(data.serverID, data.authToken) - end, [5] = function(data) gmInte.config = data end, @@ -49,10 +44,7 @@ local netReceive = { gmInte.openVerifPopup() end, [8] = function(data) - gmInte.singleUseToken(data) - end, - [9] = function(data) - gmInte.multiUseToken(data) + gmInte.config.token = data.token end } diff --git a/lua/gmod_integration/server/sv_players_tokens.lua b/lua/gmod_integration/server/sv_players_tokens.lua deleted file mode 100644 index 9397a3d..0000000 --- a/lua/gmod_integration/server/sv_players_tokens.lua +++ /dev/null @@ -1,27 +0,0 @@ -// -// Methods -// - -function gmInte.getClientOneTimeToken(ply, callback) - if (!ply:IsValid() || !ply:IsPlayer()) then return end - - gmInte.http.get("/players/" .. ply:SteamID64() .. "/single-token", function(code, data) - if (callback) then callback(data) end - end) -end - -function gmInte.createClientToken(ply, callback) - if (!ply:IsValid() || !ply:IsPlayer()) then return end - - gmInte.http.get("/players/" .. ply:SteamID64() .. "/tokens", function(code, data) - if (callback) then callback(data) end - end) -end - -function gmInte.revokeClientToken(ply, callback) - if (!ply:IsValid() || !ply:IsPlayer()) then return end - - gmInte.http.delete("/players/" .. ply:SteamID64() .. "/tokens", function(code, data) - if (callback) then callback(data) end - end) -end \ No newline at end of file diff --git a/lua/gmod_integration/server/sv_settings.lua b/lua/gmod_integration/server/sv_settings.lua index d8aed59..1d4b09d 100644 --- a/lua/gmod_integration/server/sv_settings.lua +++ b/lua/gmod_integration/server/sv_settings.lua @@ -56,6 +56,7 @@ function gmInte.publicGetConfig(ply) if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end gmInte.SendNet("publicConfig", { + ["id"] = gmInte.config.id, ["debug"] = gmInte.config.debug, ["apiFQDN"] = gmInte.config.apiFQDN, ["websocketFQDN"] = gmInte.config.websocketFQDN, diff --git a/lua/gmod_integration/server/sv_tokens.lua b/lua/gmod_integration/server/sv_tokens.lua new file mode 100644 index 0000000..250b744 --- /dev/null +++ b/lua/gmod_integration/server/sv_tokens.lua @@ -0,0 +1,50 @@ +// +// Methods +// + +gmInte.serverPublicToken = gmInte.serverPublicToken || nil +function gmInte.getPublicServerToken(callback) + if (gmInte.serverPublicToken) then + if (callback) then callback(gmInte.serverPublicToken) end + return + end + + gmInte.http.get("/public-token", function(code, data) + gmInte.serverPublicToken = data.publicTempToken + callback(data.publicTempToken) + 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 + 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() } + callback(token) + end) +end + +function sendPlayerToken(ply) + gmInte.getPlayerTempToken(ply, function(token) + gmInte.SendNet("savePlayerToken", { + token = token, + }, ply) + end) +end + +hook.Add("gmInte:PlayerReady", "gmInte:Verif:PlayerReady", function(ply) + sendPlayerToken(ply) +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 8a7918e..fd848b5 100644 --- a/lua/gmod_integration/shared/sh_http.lua +++ b/lua/gmod_integration/shared/sh_http.lua @@ -15,7 +15,7 @@ local function getAPIURL(endpoint) return url .. endpoint end - url = url .. "/clients/" .. LocalPlayer():SteamID64() + url = url .. "/clients/" .. LocalPlayer():SteamID64() .. "/servers/" .. gmInte.config.id end return url .. endpoint From b654535813a5e75075534baf19183cc48dc83a0a Mon Sep 17 00:00:00 2001 From: Linventif Date: Sun, 10 Mar 2024 03:45:45 +0100 Subject: [PATCH 57/66] edit: screenshot take system --- .../client/cl_screenshots.lua | 20 ++++---- lua/gmod_integration/client/cl_steaming.lua | 51 ++++++++++--------- lua/gmod_integration/server/sv_net.lua | 7 ++- .../server/sv_screenshots.lua | 24 --------- 4 files changed, 42 insertions(+), 60 deletions(-) delete mode 100644 lua/gmod_integration/server/sv_screenshots.lua diff --git a/lua/gmod_integration/client/cl_screenshots.lua b/lua/gmod_integration/client/cl_screenshots.lua index 2bdbd5b..a13a517 100644 --- a/lua/gmod_integration/client/cl_screenshots.lua +++ b/lua/gmod_integration/client/cl_screenshots.lua @@ -17,6 +17,11 @@ hook.Add("PostRender", "gmInteScreenshot", function() } local screenCapture = render.Capture(captureData) + if (!screenCapture) then + 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 + screenCapture = util.Base64Encode(screenCapture) local size = math.Round(string.len(screenCapture) / 1024) @@ -31,6 +36,7 @@ hook.Add("PostRender", "gmInteScreenshot", function() }, 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) @@ -42,13 +48,8 @@ end) // Methods // -function gmInte.takeScreenShot(serverID, authToken) - gmInte.config.id = serverID - gmInte.config.token = authToken - - timer.Simple(0.2, function() - ScreenshotRequested = true - end) +function gmInte.takeScreenShot() + ScreenshotRequested = true end // @@ -56,7 +57,7 @@ end // concommand.Add("gmod_integration_screenshot", function() - gmInte.SendNet("takeScreenShot") + gmInte.takeScreenShot() end) // @@ -69,6 +70,7 @@ hook.Add("OnPlayerChat", "gmInteChatCommands", function(ply, text, teamChat, isD text = string.sub(text, 2) if (text == "screen") then - gmInte.SendNet("takeScreenShot") + 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 index 51b377c..e2c3275 100644 --- a/lua/gmod_integration/client/cl_steaming.lua +++ b/lua/gmod_integration/client/cl_steaming.lua @@ -23,6 +23,7 @@ hook.Add("PostRender", "gmInte:PostRender:Stream:Frame", function() } local screenCapture = render.Capture(captureConfig) + if (!screenCapture) then return end screenCapture = util.Base64Encode(screenCapture) local size = math.Round(string.len(screenCapture) / 1024) @@ -45,33 +46,33 @@ hook.Add("PostRender", "gmInte:PostRender:Stream:Frame", function() StreamsRequeted = false end) -// -// Methods -// +-- // +-- // Methods +-- // -function gmInte.takeScreenShot(serverID, authToken) - gmInte.config.id = serverID - gmInte.config.token = authToken - StreamsRequeted = true -end +-- function gmInte.takeScreenShot(serverID, authToken) +-- gmInte.config.id = serverID +-- gmInte.config.token = authToken +-- StreamsRequeted = true +-- end -function gmInte.stopScreenShot() - StreamsRequeted = false -end +-- function gmInte.stopScreenShot() +-- StreamsRequeted = false +-- end -// -// Console Commands -// +-- // +-- // Console Commands +-- // -concommand.Add("gmod_integration_stream", function() - StreamsRequeted = !StreamsRequeted - gmInte.log("Streaming frames to WebPanel: " .. tostring(StreamsRequeted)) +-- concommand.Add("gmod_integration_stream", function() +-- StreamsRequeted = !StreamsRequeted +-- gmInte.log("Streaming frames to WebPanel: " .. tostring(StreamsRequeted)) - -- if (StreamsRequeted) then - -- gmInte.stopScreenShot() - -- gmInte.log("Stopped streaming frames to WebPanel") - -- else - -- gmInte.SendNet("getSingleUseToken") - -- gmInte.log("Started streaming frames to WebPanel") - -- end -end) \ No newline at end of file +-- -- if (StreamsRequeted) then +-- -- gmInte.stopScreenShot() +-- -- gmInte.log("Stopped streaming frames to WebPanel") +-- -- else +-- -- gmInte.SendNet("getSingleUseToken") +-- -- gmInte.log("Started streaming frames to WebPanel") +-- -- end +-- 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 bd9b3d6..aa32f56 100644 --- a/lua/gmod_integration/server/sv_net.lua +++ b/lua/gmod_integration/server/sv_net.lua @@ -12,10 +12,10 @@ local netSend = { ["wsRelayDiscordChat"] = 1, ["adminConfig"] = 2, ["testApiConnection"] = 3, - ["screenshotToken"] = 4, ["publicConfig"] = 5, ["chatColorMessage"] = 6, - ["openVerifPopup"] = 7 + ["openVerifPopup"] = 7, + ["savePlayerToken"] = 8 } // Send @@ -59,6 +59,9 @@ local netReceive = { end, [6] = function(ply) gmInte.verifyPlayer(ply) + end, + [7] = function(ply, data) + sendPlayerToken(ply) end } diff --git a/lua/gmod_integration/server/sv_screenshots.lua b/lua/gmod_integration/server/sv_screenshots.lua deleted file mode 100644 index 9d160bf..0000000 --- a/lua/gmod_integration/server/sv_screenshots.lua +++ /dev/null @@ -1,24 +0,0 @@ -// -// Websocket -// - -function gmInte.wsPlayerScreen(data) - for _, ply in pairs(player.GetAll()) do - if (ply:SteamID64() == data.steamID64) then - gmInte.takeScreenshot(ply) - end - end -end - -// -// Methods -// - -function gmInte.takeScreenshot(ply) - gmInte.getClientOneTimeToken(ply, function(oneTime) - gmInte.SendNet("screenshotToken", { - ["serverID"] = gmInte.config.id, - ["oneTimeToken"] = oneTime - }, ply) - end) -end \ No newline at end of file From b8c04246b906891054db9f2ec7f31fe7772fde70 Mon Sep 17 00:00:00 2001 From: Linventif Date: Sun, 10 Mar 2024 03:53:41 +0100 Subject: [PATCH 58/66] add: timer of 0.5 before taking screenshot --- lua/gmod_integration/client/cl_screenshots.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/gmod_integration/client/cl_screenshots.lua b/lua/gmod_integration/client/cl_screenshots.lua index a13a517..6068250 100644 --- a/lua/gmod_integration/client/cl_screenshots.lua +++ b/lua/gmod_integration/client/cl_screenshots.lua @@ -49,7 +49,9 @@ end) // function gmInte.takeScreenShot() - ScreenshotRequested = true + timer.Simple(0.5, function() + ScreenshotRequested = true + end) end // From f6f47e2525268324a6910c03a1f4ac0138d3e01b Mon Sep 17 00:00:00 2001 From: Linventif Date: Wed, 13 Mar 2024 19:41:02 +0100 Subject: [PATCH 59/66] add: default reason / support link --- lua/gmod_integration/server/sv_filtrers.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/gmod_integration/server/sv_filtrers.lua b/lua/gmod_integration/server/sv_filtrers.lua index 813a253..4eefce9 100644 --- a/lua/gmod_integration/server/sv_filtrers.lua +++ b/lua/gmod_integration/server/sv_filtrers.lua @@ -7,8 +7,8 @@ local function filterMessage(reason) "\n----------------------------------------\n", "You cannot join this server", "", - "Reason: " .. reason, - "Help URL: " .. (gmInte.config.supportLink && gmInte.config.supportLink || "No Support Link"), + "Reason: " .. (reason && reason || "none"), + "Help URL: " .. (gmInte.config.supportLink && gmInte.config.supportLink || "none"), "", "Have a nice day", "\n----------------------------------------\n", From ce4d1be66774343dc55d2cb40db2ee51bdfb8163 Mon Sep 17 00:00:00 2001 From: Linventif Date: Wed, 13 Mar 2024 20:04:57 +0100 Subject: [PATCH 60/66] add: try 3 time for the screenshot before cancel --- .../client/cl_screenshots.lua | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/lua/gmod_integration/client/cl_screenshots.lua b/lua/gmod_integration/client/cl_screenshots.lua index 6068250..505cd71 100644 --- a/lua/gmod_integration/client/cl_screenshots.lua +++ b/lua/gmod_integration/client/cl_screenshots.lua @@ -3,6 +3,7 @@ // local ScreenshotRequested = false +local FailAttempts = 0 hook.Add("PostRender", "gmInteScreenshot", function() if (!ScreenshotRequested) then return end ScreenshotRequested = false @@ -18,19 +19,29 @@ hook.Add("PostRender", "gmInteScreenshot", function() local screenCapture = render.Capture(captureData) if (!screenCapture) then - chat.AddText(Color(255, 130, 92), "[Gmod Integration] ", Color(102, 63, 63), "Failed to take screenshot, your system may not support this feature.") - return + 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 - screenCapture = util.Base64Encode(screenCapture) + local base64Capture = util.Base64Encode(screenCapture) - local size = math.Round(string.len(screenCapture) / 1024) + local size = math.Round(string.len(base64Capture) / 1024) gmInte.log("Screenshot Taken - " .. size .. "KB", true) gmInte.http.post("/screenshots", { ["player"] = gmInte.getPlayerFormat(LocalPlayer()), - ["screenshot"] = screenCapture, + ["screenshot"] = base64Capture, ["captureData"] = captureData, ["size"] = size .. "KB" }, From 3bb44ccbc0888047854f2e4be4b8d3c86e400b91 Mon Sep 17 00:00:00 2001 From: Linventif Date: Wed, 13 Mar 2024 20:30:23 +0100 Subject: [PATCH 61/66] fix: send public config on modif --- lua/gmod_integration/client/cl_net.lua | 2 +- lua/gmod_integration/server/sv_settings.lua | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lua/gmod_integration/client/cl_net.lua b/lua/gmod_integration/client/cl_net.lua index 261594b..ddf4fe1 100644 --- a/lua/gmod_integration/client/cl_net.lua +++ b/lua/gmod_integration/client/cl_net.lua @@ -35,7 +35,7 @@ local netReceive = { gmInte.showTestConnection(data) end, [5] = function(data) - gmInte.config = data + gmInte.config = table.Merge(gmInte.config, data) end, [6] = function(data) gmInte.chatAddText(data) diff --git a/lua/gmod_integration/server/sv_settings.lua b/lua/gmod_integration/server/sv_settings.lua index 1d4b09d..baa0850 100644 --- a/lua/gmod_integration/server/sv_settings.lua +++ b/lua/gmod_integration/server/sv_settings.lua @@ -14,6 +14,14 @@ function gmInte.saveSetting(setting, value) gmInte.config[setting] = value file.Write("gm_integration/config.json", util.TableToJSON(gmInte.config, true)) gmInte.log("Setting Saved") + + // send to all players if it's a public setting + for _, ply in pairs(player.GetAll()) do + if (ply:IsValid() && ply:IsPlayer(ply)) then + gmInte.log("Sending new Public Config to " .. ply:Nick()) + gmInte.publicGetConfig(ply) + end + end end function gmInte.tryConfig() From 6699c9f4ae2bf1dd45d2dca27f21172540fc196a Mon Sep 17 00:00:00 2001 From: Linventif Date: Wed, 13 Mar 2024 20:35:13 +0100 Subject: [PATCH 62/66] fix: curtime --- lua/gmod_integration/client/cl_steaming.lua | 51 ++++++--------------- 1 file changed, 15 insertions(+), 36 deletions(-) diff --git a/lua/gmod_integration/client/cl_steaming.lua b/lua/gmod_integration/client/cl_steaming.lua index e2c3275..c68a02d 100644 --- a/lua/gmod_integration/client/cl_steaming.lua +++ b/lua/gmod_integration/client/cl_steaming.lua @@ -3,14 +3,9 @@ // local StreamsRequeted = false -local LastFrame = 0 - hook.Add("PostRender", "gmInte:PostRender:Stream:Frame", function() if (!StreamsRequeted) then return end - - // Limit frame rate - if (LastFrame > CurTime()) then return end - LastFrame = CurTime() + 0.25 + StreamsRequeted = false // Capture frame local captureConfig = { @@ -19,7 +14,7 @@ hook.Add("PostRender", "gmInte:PostRender:Stream:Frame", function() y = 0, w = ScrW(), h = ScrH(), - quality = 50, + quality = 30, } local screenCapture = render.Capture(captureConfig) @@ -43,36 +38,20 @@ hook.Add("PostRender", "gmInte:PostRender:Stream:Frame", function() gmInte.log("Failed to send frame to WebPanel", true) end ) - StreamsRequeted = false end) --- // --- // Methods --- // +local Steam = false +timer.Create("gmInte:Stream:Frame", 0.5, 0, function() + if (Steam) then + StreamsRequeted = true + end +end) --- function gmInte.takeScreenShot(serverID, authToken) --- gmInte.config.id = serverID --- gmInte.config.token = authToken --- StreamsRequeted = true --- end +// +// Console Commands +// --- function gmInte.stopScreenShot() --- StreamsRequeted = false --- end - --- // --- // Console Commands --- // - --- concommand.Add("gmod_integration_stream", function() --- StreamsRequeted = !StreamsRequeted --- gmInte.log("Streaming frames to WebPanel: " .. tostring(StreamsRequeted)) - --- -- if (StreamsRequeted) then --- -- gmInte.stopScreenShot() --- -- gmInte.log("Stopped streaming frames to WebPanel") --- -- else --- -- gmInte.SendNet("getSingleUseToken") --- -- gmInte.log("Started streaming frames to WebPanel") --- -- end --- end) \ No newline at end of file +concommand.Add("gmod_integration_stream", function() + Steam = !Steam + gmInte.log("Streaming frames to WebPanel: " .. tostring(Steam)) +end) \ No newline at end of file From ffe83a66e45aad26f69255196696cc91b25e112e Mon Sep 17 00:00:00 2001 From: Linventif Date: Wed, 13 Mar 2024 20:39:15 +0100 Subject: [PATCH 63/66] fix: kick detection --- lua/gmod_integration/server/sv_sync_kicks.lua | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lua/gmod_integration/server/sv_sync_kicks.lua b/lua/gmod_integration/server/sv_sync_kicks.lua index f6b8a76..14a9724 100644 --- a/lua/gmod_integration/server/sv_sync_kicks.lua +++ b/lua/gmod_integration/server/sv_sync_kicks.lua @@ -15,10 +15,6 @@ end // function gmInte.playerKick(data) - if (string.StartWith(data.reason, "Kicked by ") || data.reason == "No reason provided.") then - return - end - gmInte.http.post("/players/" .. util.SteamIDTo64(data.networkid) .. "/kick", data) end @@ -28,5 +24,7 @@ end gameevent.Listen("player_disconnect") hook.Add("player_disconnect", "gmInte:SyncKick:Disconnect", function(data) - gmInte.playerKick(data) -end) + if (string.StartWith(data.reason, "Kicked by ") || data.reason == "No reason provided.") then + gmInte.playerKick(data) + end +end) \ No newline at end of file From 2bdf0383dd39c759bbca8df0bfc08f98078a99ba Mon Sep 17 00:00:00 2001 From: Linventif Date: Wed, 13 Mar 2024 20:44:42 +0100 Subject: [PATCH 64/66] fix: player ready player format --- lua/gmod_integration/server/sv_players.lua | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lua/gmod_integration/server/sv_players.lua b/lua/gmod_integration/server/sv_players.lua index e5d5358..f1bffd2 100644 --- a/lua/gmod_integration/server/sv_players.lua +++ b/lua/gmod_integration/server/sv_players.lua @@ -18,7 +18,9 @@ end) function gmInte.playerReady(ply) if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end - gmInte.http.post("/players/" .. ply:SteamID64() .. "/ready", gmInte.getPlayerFormat(ply)) + gmInte.http.post("/players/" .. ply:SteamID64() .. "/ready", { + ["player"] = gmInte.getPlayerFormat(ply) + }) end function gmInte.playerConnect(data) From 75001c3ddc28a58baf554a5db6b9a8a3294afb8e Mon Sep 17 00:00:00 2001 From: Linventif Date: Wed, 13 Mar 2024 20:47:56 +0100 Subject: [PATCH 65/66] fix: remove log tempoary --- lua/gmod_integration/server/sv_players.lua | 231 ++++++++++----------- 1 file changed, 114 insertions(+), 117 deletions(-) diff --git a/lua/gmod_integration/server/sv_players.lua b/lua/gmod_integration/server/sv_players.lua index f1bffd2..8a7d6bb 100644 --- a/lua/gmod_integration/server/sv_players.lua +++ b/lua/gmod_integration/server/sv_players.lua @@ -2,7 +2,7 @@ // Methods // -hook.Add("gmInte:PlayerReady", "gmInte:Player:Ready", function(ply) +function gmInte.playerReady(ply) if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end // Initialize Time @@ -11,13 +11,6 @@ hook.Add("gmInte:PlayerReady", "gmInte:Player:Ready", function(ply) // Send Public Config gmInte.publicGetConfig(ply) - // Send Player Ready - gmInte.playerReady(ply) -end) - -function gmInte.playerReady(ply) - if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end - gmInte.http.post("/players/" .. ply:SteamID64() .. "/ready", { ["player"] = gmInte.getPlayerFormat(ply) }) @@ -38,98 +31,102 @@ function gmInte.playerDisconnected(ply) ) end -function gmInte.playerSpawn(ply) - if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end +-- function gmInte.playerSpawn(ply) +-- if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end - gmInte.http.post("/players/" .. ply:SteamID64() .. "/spawn", - { - ["player"] = gmInte.getPlayerFormat(ply) - } - ) -end +-- gmInte.http.post("/players/" .. ply:SteamID64() .. "/spawn", +-- { +-- ["player"] = gmInte.getPlayerFormat(ply) +-- } +-- ) +-- end -function gmInte.postLogPlayerDeath(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 +-- function gmInte.postLogPlayerDeath(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("/logs/playerDeath", - { - ["player"] = gmInte.getPlayerFormat(ply), - ["inflictor"] = gmInte.getEntityFormat(inflictor), - ["attacker"] = gmInte.getPlayerFormat(attacker) - } - ) -end +-- gmInte.http.post("/logs/playerDeath", +-- { +-- ["player"] = gmInte.getPlayerFormat(ply), +-- ["inflictor"] = gmInte.getEntityFormat(inflictor), +-- ["attacker"] = gmInte.getPlayerFormat(attacker) +-- } +-- ) +-- end -function gmInte.postLogPlayerInitialSpawn(ply) - if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end +-- function gmInte.postLogPlayerInitialSpawn(ply) +-- if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end - gmInte.http.post("/logs/playerInitialSpawn", - { - ["ply"] = gmInte.getPlayerFormat(ply) - } - ) -end +-- gmInte.http.post("/logs/playerInitialSpawn", +-- { +-- ["ply"] = 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 +-- 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 - // 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 +-- // 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 - ply.gmodInteTotalDamage = ply.gmodInteTotalDamage || 0 - ply.gmodInteTotalDamage = ply.gmodInteTotalDamage + damageTaken - return - end +-- timer.Simple(1, function() +-- if (ply.gmodInteLastHurt[attacker:SteamID64()] != locCurTime) then +-- ply.gmodInteTotalDamage = ply.gmodInteTotalDamage || 0 +-- ply.gmodInteTotalDamage = ply.gmodInteTotalDamage + damageTaken +-- return +-- end - gmInte.http.post("/logs/playerHurt", - { - ["victim"] = gmInte.getPlayerFormat(ply), - ["attacker"] = gmInte.getPlayerFormat(attacker), - ["healthRemaining"] = healthRemaining, - ["damageTaken"] = ply.gmodInteTotalDamage - } - ) - end) -end +-- gmInte.http.post("/logs/playerHurt", +-- { +-- ["victim"] = gmInte.getPlayerFormat(ply), +-- ["attacker"] = gmInte.getPlayerFormat(attacker), +-- ["healthRemaining"] = healthRemaining, +-- ["damageTaken"] = ply.gmodInteTotalDamage +-- } +-- ) +-- end) +-- end -function gmInte.postLogPlayerSpawnedSomething(object, ply, ent, model) - if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end - if (!ent:IsValid()) then return 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("/logs/playerSpawnedSomething", - { - ["object"] = object, - ["player"] = gmInte.getPlayerFormat(ply), - ["entity"] = gmInte.getEntityFormat(ent), - ["model"] = model || "" - } - ) -end +-- gmInte.http.post("/logs/playerSpawnedSomething", +-- { +-- ["object"] = object, +-- ["player"] = gmInte.getPlayerFormat(ply), +-- ["entity"] = gmInte.getEntityFormat(ent), +-- ["model"] = model || "" +-- } +-- ) +-- end -function gmInte.postLogPlayerGivet(ply, class, swep) - if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end +-- function gmInte.postLogPlayerGivet(ply, class, swep) +-- if (!ply:IsValid() || !ply:IsPlayer(ply)) then return end - gmInte.http.post("/logs/playerGive", - { - ["player"] = gmInte.getPlayerFormat(ply), - ["class"] = class, - ["swep"] = swep - } - ) -end +-- gmInte.http.post("/logs/playerGive", +-- { +-- ["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("ShutDown", "gmInte:Server:Shutdown:SavePlayers", function() for ply, ply in pairs(player.GetAll()) do gmInte.playerDisconnected(ply) @@ -145,50 +142,50 @@ 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("PlayerSpawn", "gmInte:Player:Spawn", function(ply) +-- gmInte.playerSpawn(ply) +-- end) -hook.Add("PlayerInitialSpawn", "gmInte:Player:InitialSpawn", function(ply) - gmInte.postLogPlayerInitialSpawn(ply) -end) +-- hook.Add("PlayerInitialSpawn", "gmInte:Player:InitialSpawn", function(ply) +-- gmInte.postLogPlayerInitialSpawn(ply) +-- end) -hook.Add("PlayerGiveSWEP", "gmInte:Player:SWEPs", function( ply, class, swep ) - gmInte.postLogPlayerGivet(ply, class, swep) -end) +-- hook.Add("PlayerGiveSWEP", "gmInte:Player:SWEPs", function( ply, class, swep ) +-- gmInte.postLogPlayerGivet(ply, class, swep) +-- end) -hook.Add("PlayerDeath", "gmInte:Player:Death", function(ply, inflictor, attacker) - gmInte.postLogPlayerDeath(ply, inflictor, attacker) -end) +-- hook.Add("PlayerDeath", "gmInte:Player:Death", function(ply, inflictor, attacker) +-- gmInte.postLogPlayerDeath(ply, inflictor, attacker) +-- end) -hook.Add("PlayerHurt", "gmInte:Player:Hurt", function(ply, attacker, healthRemaining, damageTaken) - gmInte.postLogPlayerHurt(ply, attacker, healthRemaining, damageTaken) -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("SENT", ply, ent, model) -end) +-- hook.Add("PlayerSpawnedProp", "gmInte:Player:SpawnedProp", function(ply, model, ent) +-- gmInte.postLogPlayerSpawnedSomething("SENT", ply, ent, model) +-- end) -hook.Add("PlayerSpawnedSENT", "gmInte:Player:SpawnedSENT", function(ply, ent) - gmInte.postLogPlayerSpawnedSomething("SENT", ply, ent) -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("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("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("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("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("PlayerSpawnedSWEP", "gmInte:Player:SpawnedSWEP", function(ply, ent) +-- gmInte.postLogPlayerSpawnedSomething("SWEP", ply, ent) +-- end) \ No newline at end of file From c53952f1632ee6bad261ad4e1e3fd4ef738a5f82 Mon Sep 17 00:00:00 2001 From: Linventif Date: Wed, 13 Mar 2024 21:43:56 +0100 Subject: [PATCH 66/66] fix: add verification for api format --- lua/gmod_integration/shared/sh_api_format.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lua/gmod_integration/shared/sh_api_format.lua b/lua/gmod_integration/shared/sh_api_format.lua index 1a4b603..df07d83 100644 --- a/lua/gmod_integration/shared/sh_api_format.lua +++ b/lua/gmod_integration/shared/sh_api_format.lua @@ -1,4 +1,5 @@ function gmInte.getPlayerFormat(ply) + if (!IsValid(ply) || !ply:IsPlayer()) then return end return { ["steamID"] = ply:SteamID(), ["steamID64"] = ply:SteamID64(), @@ -29,6 +30,7 @@ function gmInte.getServerFormat() end function gmInte.getWeaponFormat(weapon) + if (!IsValid(weapon) || !weapon:IsWeapon()) then return end return { ["class"] = weapon:GetClass(), ["printName"] = weapon:GetPrintName() @@ -36,6 +38,7 @@ function gmInte.getWeaponFormat(weapon) end function gmInte.getEntityFormat(ent) + if (!IsValid(ent)) then return end return { ["class"] = ent:GetClass(), ["model"] = ent:GetModel(), @@ -45,6 +48,7 @@ function gmInte.getEntityFormat(ent) end function gmInte.getVectorFormat(vec) + if (!isvector(vec)) then return end return { ["x"] = vec.x, ["y"] = vec.y, @@ -53,6 +57,7 @@ function gmInte.getVectorFormat(vec) end function gmInte.getAngleFormat(ang) + if (!isangle(ang)) then return end return { ["p"] = ang.p, ["y"] = ang.y, @@ -61,6 +66,7 @@ function gmInte.getAngleFormat(ang) end function gmInte.getTeamFormat(teamID) + if (!isnumber(teamID)) then return end return { ["id"] = teamID, ["name"] = team.GetName(teamID)