Hide host machine UserName when displaying error logs

This commit is contained in:
EvilFactory
2023-12-10 12:26:38 -03:00
parent e5e85e948b
commit c7b8cda902
3 changed files with 38 additions and 6 deletions

View File

@@ -69,6 +69,19 @@ namespace Barotrauma
}
};
new GUITickBox(new RectTransform(new Vector2(0.8f, 0.1f), list.Content.RectTransform), "Hide UserNames In Error Logs")
{
Selected = GameMain.LuaCs.Config.DisableErrorGUIOverlay,
ToolTip = "",
OnSelected = (GUITickBox tick) =>
{
GameMain.LuaCs.Config.HideUserNames = tick.Selected;
GameMain.LuaCs.UpdateConfig();
return true;
}
};
new GUIButton(new RectTransform(new Vector2(1f, 0.1f), list.Content.RectTransform), $"Remove Client-Side LuaCs", style: "GUIButtonSmall")
{
ToolTip = "Remove Client-Side LuaCs.",

View File

@@ -15,6 +15,8 @@ namespace Barotrauma
partial class LuaCsLogger
{
public static bool HideUserNames = true;
#if SERVER
private const string LogPrefix = "SV";
private const int NetMaxLength = 1024;
@@ -32,40 +34,47 @@ namespace Barotrauma
public static void HandleException(Exception ex, LuaCsMessageOrigin origin)
{
string errorString = "";
switch (ex)
{
case NetRuntimeException netRuntimeException:
if (netRuntimeException.DecoratedMessage == null)
{
LogError(netRuntimeException.ToString(), origin);
errorString = netRuntimeException.ToString();
}
else
{
// FIXME: netRuntimeException.ToString() doesn't print the InnerException's stack trace...
LogError($"{netRuntimeException.DecoratedMessage}: {netRuntimeException}", origin);
errorString = $"{netRuntimeException.DecoratedMessage}: {netRuntimeException}";
}
break;
case InterpreterException interpreterException:
if (interpreterException.DecoratedMessage == null)
{
LogError(interpreterException.ToString(), origin);
errorString = interpreterException.ToString();
}
else
{
LogError(interpreterException.DecoratedMessage, origin);
errorString = interpreterException.DecoratedMessage;
}
break;
default:
var msg = ex.StackTrace != null
errorString = ex.StackTrace != null
? ex.ToString()
: $"{ex}\n{Environment.StackTrace}";
LogError(msg, origin);
break;
}
LogError(Environment.UserName + " " + errorString, origin);
}
public static void LogError(string message, LuaCsMessageOrigin origin)
{
if (HideUserNames && !Environment.UserName.IsNullOrEmpty())
{
message = message.Replace(Environment.UserName, "USERNAME");
}
switch (origin)
{
case LuaCsMessageOrigin.LuaCs:

View File

@@ -20,6 +20,7 @@ namespace Barotrauma
public bool TreatForcedModsAsNormal = false;
public bool PreferToUseWorkshopLuaSetup = false;
public bool DisableErrorGUIOverlay = false;
public bool HideUserNames = true;
public LuaCsSetupConfig() { }
}
@@ -121,6 +122,8 @@ namespace Barotrauma
{
Config = new LuaCsSetupConfig();
}
UpdateConfigVars();
}
[Obsolete("Use AssemblyManager::GetTypesByName()")]
@@ -161,6 +164,11 @@ namespace Barotrauma
public void DetachDebugger() => DebugServer.Detach(Lua);
public void UpdateConfigVars()
{
LuaCsLogger.HideUserNames = Config.HideUserNames;
}
public void UpdateConfig()
{
FileStream file;
@@ -168,6 +176,8 @@ namespace Barotrauma
else { file = File.Open(configFileName, FileMode.Truncate, FileAccess.Write); }
LuaCsConfig.Save(file, Config);
file.Close();
UpdateConfigVars();
}
public static ContentPackage GetPackage(ContentPackageId id, bool fallbackToAll = true, bool useBackup = false)