From d42cf9373751b6c20642cfd2ebc7787e822bdc1e Mon Sep 17 00:00:00 2001 From: Redox Date: Mon, 14 Aug 2023 05:11:08 +0100 Subject: [PATCH] Add game branch to error log CFC-76 (#34) --- moon/autorun/client/cfc_err_fwd.moon | 4 ++++ moon/autorun/server/cfc_err_fwd.moon | 6 ++++++ moon/cfc_err_forwarder/error_forwarder.moon | 5 +++++ moon/cfc_err_forwarder/formatter/formatter.moon | 7 ++++++- moon/cfc_err_forwarder/formatter/text_helpers.moon | 5 ++++- 5 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 moon/autorun/client/cfc_err_fwd.moon diff --git a/moon/autorun/client/cfc_err_fwd.moon b/moon/autorun/client/cfc_err_fwd.moon new file mode 100644 index 0000000..f9d7b1b --- /dev/null +++ b/moon/autorun/client/cfc_err_fwd.moon @@ -0,0 +1,4 @@ +hook.Add "InitPostEntity", "CFC_ErrForwarder_BranchInit", -> + net.Start "cfc_err_forwarder_clbranch" + net.WriteString BRANCH + net.SendToServer! diff --git a/moon/autorun/server/cfc_err_fwd.moon b/moon/autorun/server/cfc_err_fwd.moon index c3b3fe0..7a8bbb3 100644 --- a/moon/autorun/server/cfc_err_fwd.moon +++ b/moon/autorun/server/cfc_err_fwd.moon @@ -1,6 +1,8 @@ require "luaerror" require "reqwest" +util.AddNetworkString "cfc_err_forwarder_clbranch" + timerName = "CFC_ErrorForwarderQueue" errorForwarder = include "cfc_err_forwarder/error_forwarder.lua" discordBuilder = include "cfc_err_forwarder/discord_interface.lua" @@ -58,4 +60,8 @@ hook.Add "LuaError", "CFC_ServerErrorForwarder", ErrorForwarder\receiveSVError hook.Add "ClientLuaError", "CFC_ClientErrorForwarder", ErrorForwarder\receiveCLError hook.Add "ShutDown", "CFC_ShutdownErrorForwarder", ErrorForwarder\forwardErrors +net.Receive "cfc_err_forwarder_clbranch", (_,ply) -> + if not ply.CFC_ErrorForwarder_CLBranch + ply.CFC_ErrorForwarder_CLBranch = net.ReadString! + logger\info "Loaded!" diff --git a/moon/cfc_err_forwarder/error_forwarder.moon b/moon/cfc_err_forwarder/error_forwarder.moon index 5ba38c9..a9affb5 100644 --- a/moon/cfc_err_forwarder/error_forwarder.moon +++ b/moon/cfc_err_forwarder/error_forwarder.moon @@ -89,9 +89,13 @@ return class ErrorForwarder local plyName local plySteamID + local branch if ply plyName = ply\Nick! plySteamID = ply\SteamID! + branch = ply.CFC_ErrorForwarder_CLBranch or "Not sure yet" + else + branch = BRANCH newError = { :count @@ -106,6 +110,7 @@ return class ErrorForwarder :ply :plyName :plySteamID + :branch reportInterval: @config.groomInterval\GetInt! } diff --git a/moon/cfc_err_forwarder/formatter/formatter.moon b/moon/cfc_err_forwarder/formatter/formatter.moon index 3500e15..d3eb031 100644 --- a/moon/cfc_err_forwarder/formatter/formatter.moon +++ b/moon/cfc_err_forwarder/formatter/formatter.moon @@ -4,7 +4,8 @@ niceStack = include "nice_stack.lua" import bad, bold, getSourceText, code, - steamIDLink, truncate, timestamp + steamIDLink, truncate, timestamp, + gmodBranch from include "text_helpers.lua" nonil = (t) -> [v for v in *t when v ~= nil] @@ -39,6 +40,10 @@ nonil = (t) -> [v for v in *t when v ~= nil] return { name: "Player", value: bold "#{plyName} ( #{steamIDLink plySteamID} )" } if ply return nil + with {:branch} = data + return { name: "Branch", value: bold "`#{gmodBranch branch}`", inline: true } if branch + return nil + { name: "Count" value: bold data.count diff --git a/moon/cfc_err_forwarder/formatter/text_helpers.moon b/moon/cfc_err_forwarder/formatter/text_helpers.moon index 1b042de..d20a24f 100644 --- a/moon/cfc_err_forwarder/formatter/text_helpers.moon +++ b/moon/cfc_err_forwarder/formatter/text_helpers.moon @@ -24,4 +24,7 @@ getSourceText = (data) -> "#{sourceLink}\n#{sourceText}" -:bad, :bold, :code, :steamIDLink, :truncate, :timestamp, :getSourceText +gmodBranch = (branch) -> + branch == "unknown" and "main" or branch + +:bad, :bold, :code, :steamIDLink, :truncate, :timestamp, :getSourceText, :gmodBranch