Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions RLBotCS/ManagerTools/ConfigParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public static class Fields
public const string AgentRootDir = "root_dir";
public const string AgentRunCommand = "run_command";
public const string AgentRunCommandLinux = "run_command_linux";
public const string AgentEnvironment = "environment";
public const string AgentHivemind = "hivemind";

public const string LoadoutBlueTable = "blue_loadout";
Expand Down Expand Up @@ -260,6 +261,33 @@ private string GetRunCommand(TomlTable runnableSettings)
#endif
}

private List<EnvironmentVariableT> GetEnvironment(TomlTable runnableSettings)
{
TomlTable environment = GetValue<TomlTable>(
runnableSettings,
Fields.AgentEnvironment,
[]
);

List<EnvironmentVariableT> variables = [];
using (_context.Begin(Fields.AgentEnvironment))
{
foreach (var (key, rawValue) in environment)
{
if (rawValue is not string value)
{
throw new InvalidCastException(
$"{_context.ToStringWithEnd(key)} has value {rawValue}, but a value of type String was expected."
);
}

variables.Add(new() { Name = key, Value = value });
}
}

return variables;
}

private ScriptConfigurationT LoadScriptConfig(string scriptConfigPath)
{
TomlTable scriptToml = LoadTomlFile(scriptConfigPath);
Expand All @@ -276,6 +304,7 @@ private ScriptConfigurationT LoadScriptConfig(string scriptConfigPath)
GetValue(settings, Fields.AgentRootDir, "")
),
RunCommand = GetRunCommand(settings),
Environment = GetEnvironment(settings),
AgentId = GetValue(settings, Fields.AgentAgentId, ""),
};
}
Expand Down Expand Up @@ -511,6 +540,7 @@ bool autoStart
Name = nameOverride ?? GetValue<string>(settings, Fields.AgentName, ""),
Loadout = loadout,
RunCommand = autoStart ? GetRunCommand(settings) : "",
Environment = GetEnvironment(settings),
Hivemind = GetValue(settings, Fields.AgentHivemind, false),
RootDir = rootDir,
};
Expand Down
2 changes: 2 additions & 0 deletions RLBotCS/ManagerTools/ConfigValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ bool surpressWarnings
bot.Name ??= "";
bot.RunCommand ??= "";
bot.RootDir ??= "";
bot.Environment ??= [];
bot.Loadout ??= new();
bot.Loadout.LoadoutPaint ??= new();

Expand Down Expand Up @@ -239,6 +240,7 @@ private static bool ValidateScripts(
script.Name ??= "";
script.RunCommand ??= "";
script.RootDir ??= "";
script.Environment ??= [];
script.ScriptId = $"{script.AgentId}/{Team.Scripts}/{i}".GetHashCode();

if (agentIdTracker.TryGetValue(script.AgentId, out var existing))
Expand Down
13 changes: 13 additions & 0 deletions RLBotCS/ManagerTools/LaunchManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ private static Process RunCommandInShell(string command)
return process;
}

private static void ApplyEnvironment(
ProcessStartInfo startInfo,
List<RLBot.Flat.EnvironmentVariableT> environment
)
{
foreach (var variable in environment)
{
startInfo.EnvironmentVariables[variable.Name] = variable.Value;
}
}

private static void LaunchGameViaLegendary()
{
Process legendary = RunCommandInShell(
Expand Down Expand Up @@ -186,6 +197,7 @@ int rlbotSocketsPort
Process botProcess = RunCommandInShell(details.RunCommand);

botProcess.StartInfo.WorkingDirectory = details.RootDir;
ApplyEnvironment(botProcess.StartInfo, details.Environment);
botProcess.StartInfo.EnvironmentVariables["RLBOT_AGENT_ID"] = details.AgentId;
botProcess.StartInfo.EnvironmentVariables["RLBOT_SERVER_PORT"] =
rlbotSocketsPort.ToString();
Expand Down Expand Up @@ -233,6 +245,7 @@ int rlbotSocketsPort
if (script.RootDir != "")
scriptProcess.StartInfo.WorkingDirectory = script.RootDir;

ApplyEnvironment(scriptProcess.StartInfo, script.Environment);
scriptProcess.StartInfo.EnvironmentVariables["RLBOT_AGENT_ID"] = script.AgentId;
scriptProcess.StartInfo.EnvironmentVariables["RLBOT_SERVER_PORT"] =
rlbotSocketsPort.ToString();
Expand Down
7 changes: 7 additions & 0 deletions RLBotCS/RLBotCS.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@
>
<Exec Command="../generate-flatbuffers.sh" />
</Target>
<Target
Name="GenerateFlatBuffersMac"
BeforeTargets="PreBuildEvent"
Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::IsOSPlatform($([System.Runtime.InteropServices.OSPlatform]::OSX)))'"
>
<Exec Command="../generate-flatbuffers-mac.sh" />
</Target>
<ItemGroup>
<Compile Include="..\FlatBuffer\RLBot.cs" />
</ItemGroup>
Expand Down
17 changes: 16 additions & 1 deletion RLBotCSTests/ConfigParserTest.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.IO;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using RLBot.Flat;
using RLBotCS.ManagerTools;
Expand Down Expand Up @@ -179,10 +180,24 @@ public void Overrides()

PlayerConfigurationT player = mc.PlayerConfigurations[0];
Assert.AreEqual("New Bot Name", player.Variety.AsCustomBot().Name);
Assert.IsNull(player.Variety.AsCustomBot().Loadout);
CustomBotT bot = player.Variety.AsCustomBot();
Assert.IsNull(bot.Loadout);
Assert.AreEqual("bot-value", bot.Environment.Single(e => e.Name == "BOT_ENV").Value);
Assert.AreEqual(
"bot-shared",
bot.Environment.Single(e => e.Name == "SHARED_ENV").Value
);

ScriptConfigurationT script = mc.ScriptConfigurations[0];
Assert.AreEqual("Normal Test Script", script.Name); // Not overriden
Assert.AreEqual(
"script-value",
script.Environment.Single(e => e.Name == "SCRIPT_ENV").Value
);
Assert.AreEqual(
"script-shared",
script.Environment.Single(e => e.Name == "SHARED_ENV").Value
);
}

[TestMethod]
Expand Down
4 changes: 4 additions & 0 deletions RLBotCSTests/TestTomls/normal.bot.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ run_command_linux = "python bot.py"
loadout_file = "loadout.toml"
logo_file = "normal_logo.png"

[settings.environment]
BOT_ENV = "bot-value"
SHARED_ENV = "bot-shared"

[details]
description = "This is a normal test bot"
fun_fact = "knock knock ..."
Expand Down
4 changes: 4 additions & 0 deletions RLBotCSTests/TestTomls/normal.script.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ run_command_linux = "python script.py"
loadout_file = "loadout.toml"
logo_file = "normal_logo.png"

[settings.environment]
SCRIPT_ENV = "script-value"
SHARED_ENV = "script-shared"

[details]
description = "This is a normal test script"
fun_fact = "knock knock ..."
Expand Down
2 changes: 1 addition & 1 deletion flatbuffers-schema
14 changes: 14 additions & 0 deletions generate-flatbuffers-mac.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/sh

cd "$(dirname "$0")"

echo Generating flatbuffers header file...

./flatbuffers-schema/binaries/flatc_mac --gen-all --csharp --gen-object-api --gen-onefile -o ./FlatBuffer ./flatbuffers-schema/schema/rlbot.fbs

# the file produced is called rlbot_generated.cs, rename it to RLBot.cs after removing the old one
rm -f ./FlatBuffer/RLBot.cs
mv ./FlatBuffer/rlbot_generated.cs ./FlatBuffer/RLBot.cs
sed -i '' 's/rlbot\.flat/RLBot.Flat/g' ./FlatBuffer/RLBot.cs

echo Done.
Loading