in Runtime/Core/GameLiftLocalTesting/GameLiftProcess.cs [26:93]
public StartResponse Start(StartRequest request)
{
try
{
if (request == null || string.IsNullOrWhiteSpace(request.GameLiftLocalFilePath))
{
return Response.Fail(new StartResponse
{
ErrorCode = ErrorCode.InvalidParameters
});
}
string arg = FormatCommand(request);
int processId;
if (request.LocalOperatingSystem == LocalOperatingSystem.MAC_OS)
{
// Starts a bash process to run an Apple script, which activates a new Terminal App window,
// and runs the GameLift local jar.
string activateTerminalScript = $"tell application \\\"Terminal\\\" to activate";
string setGameLiftLocalFilePath = $"set GameLiftLocalFilePathEnvVar to \\\"{request.GameLiftLocalFilePath}\\\"";
string runGameLiftLocalJarScript = $"\\\"java -jar \\\" & quoted form of GameLiftLocalFilePathEnvVar & \\\" -p {request.Port.ToString()}\\\"";
string runGameLiftLocal = $"tell application \\\"Terminal\\\" to do script {runGameLiftLocalJarScript}";
string osaScript = $"osascript -e \'{activateTerminalScript}\' -e \'{setGameLiftLocalFilePath}\' -e \'{runGameLiftLocal}\'";
string bashCommand = $" -c \"{osaScript}\"";
ProcessStartInfo processStartInfo = new ProcessStartInfo
{
UseShellExecute = false,
RedirectStandardOutput = true,
FileName = "/bin/bash",
CreateNoWindow = false,
Arguments = bashCommand,
WorkingDirectory = Path.GetDirectoryName(request.GameLiftLocalFilePath)
};
processId = ExecuteMacOsTerminalCommand(processStartInfo);
}
else
{
ProcessStartInfo processStartInfo = new ProcessStartInfo
{
UseShellExecute = true,
FileName = "java",
Arguments = arg,
WorkingDirectory = Path.GetDirectoryName(request.GameLiftLocalFilePath)
};
processId = _processWrapper.Start(processStartInfo);
}
return Response.Ok(new StartResponse
{
ProcessId = processId
});
}
catch (Exception ex)
{
Logger.LogError(ex, ex.Message);
return Response.Fail(new StartResponse
{
ErrorCode = ErrorCode.UnknownError,
ErrorMessage = ex.Message
});
}
}