From ef277af0c62f675a0a4f947d9992dd33619e2d77 Mon Sep 17 00:00:00 2001 From: Eric Veilleux Date: Thu, 16 Jan 2025 11:51:37 -0500 Subject: [PATCH] Highlight events where bots & scripts crash (#70) * Highlight events where bots & scripts crash * Don't name unused variables --- RLBotCS/ManagerTools/LaunchManager.cs | 40 ++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 7 deletions(-) diff --git a/RLBotCS/ManagerTools/LaunchManager.cs b/RLBotCS/ManagerTools/LaunchManager.cs index 0450974..41e50b0 100644 --- a/RLBotCS/ManagerTools/LaunchManager.cs +++ b/RLBotCS/ManagerTools/LaunchManager.cs @@ -140,19 +140,32 @@ public static void LaunchBots( int rlbotSocketsPort ) { - foreach (var mainPlayer in processGroups.Values) + foreach (var bot in processGroups.Values) { - if (mainPlayer.RunCommand == "") + if (bot.RunCommand == "") continue; - Process botProcess = RunCommandInShell(mainPlayer.RunCommand); + Process botProcess = RunCommandInShell(bot.RunCommand); - if (mainPlayer.RootDir != "") - botProcess.StartInfo.WorkingDirectory = mainPlayer.RootDir; + if (bot.RootDir != "") + botProcess.StartInfo.WorkingDirectory = bot.RootDir; - botProcess.StartInfo.EnvironmentVariables["RLBOT_AGENT_ID"] = mainPlayer.AgentId; + botProcess.StartInfo.EnvironmentVariables["RLBOT_AGENT_ID"] = bot.AgentId; botProcess.StartInfo.EnvironmentVariables["RLBOT_SERVER_PORT"] = rlbotSocketsPort.ToString(); + botProcess.EnableRaisingEvents = true; + + botProcess.Exited += (_, _) => + { + if (botProcess.ExitCode != 0) + { + Logger.LogError( + "Bot {0} exited with error code {1}. See previous logs for more information.", + bot.Name, + botProcess.ExitCode + ); + } + }; try { @@ -160,7 +173,7 @@ int rlbotSocketsPort } catch (Exception e) { - Logger.LogError($"Failed to launch bot {mainPlayer.Name}: {e.Message}"); + Logger.LogError($"Failed to launch bot {bot.Name}: {e.Message}"); } } } @@ -183,6 +196,19 @@ int rlbotSocketsPort scriptProcess.StartInfo.EnvironmentVariables["RLBOT_AGENT_ID"] = script.AgentId; scriptProcess.StartInfo.EnvironmentVariables["RLBOT_SERVER_PORT"] = rlbotSocketsPort.ToString(); + scriptProcess.EnableRaisingEvents = true; + + scriptProcess.Exited += (_, _) => + { + if (scriptProcess.ExitCode != 0) + { + Logger.LogError( + "Script {0} exited with error code {1}. See previous logs for more information.", + script.Name, + scriptProcess.ExitCode + ); + } + }; try {