Skip to content
Closed
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
3 changes: 0 additions & 3 deletions Assets/Rivet/Editor/RivetGlobal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,6 @@ public string CurrentBuildSlug
}
}

// MARK: Local Game Server
public string? LocalGameServerExecutablePath;

// MARK: Bootstrap
public async Task Bootstrap()
{
Expand Down
13 changes: 2 additions & 11 deletions Assets/Rivet/Editor/TaskManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,15 +192,11 @@ private void OnTaskLog(string message, RivetTask.LogType type)
RivetTask.LogType.STDERR => LogType.STDERR,
_ => LogType.META
};

// Strip [stdout] and [stderr] prefixes
message = StripLogPrefix(message);

// Filter out Unity stack traces
if (!IsUnityStackTrace(message))
{
AddLogLine(message, logType);
}
AddLogLine(message, logType);
}

private string StripLogPrefix(string message)
Expand All @@ -216,11 +212,6 @@ private string StripLogPrefix(string message)
return message;
}

private bool IsUnityStackTrace(string message)
{
return (message.Contains(" (at ") && message.EndsWith(")")) || message.StartsWith("UnityEngine.");
}

public void AddLogLine(string message, LogType type)
{
LogEntries.Add(new LogEntry(message, type));
Expand Down
26 changes: 11 additions & 15 deletions Assets/Rivet/Editor/UI/Dock/Dock.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,24 +130,20 @@ public void OnEnable()
initMessage: "Open \"Develop\" and press \"Start\" to start game server.",
getStartConfig: () =>
{
if (plugin.LocalGameServerExecutablePath != null)
return Task.FromResult<TaskConfig?>(new TaskConfig
{
return Task.FromResult<TaskConfig?>(new TaskConfig
Name = "game_server.start",
Input = new JObject
{
Name = "game_server.start",
Input = new JObject
{
["cwd"] = Builder.ProjectRoot(),
["cmd"] = plugin.LocalGameServerExecutablePath,
["args"] = new JArray { "-batchmode", "-nographics", "-server" },
["cwd"] = Builder.ProjectRoot(),
["cmd"] = Builder.GetDevDedicatedServerExecutablePath(),
["args"] = new JArray { "-batchmode", "-nographics", "-server" },
["envs"] = new JObject {
["BACKEND_ENDPOINT"] = SharedSettings.BackendEndpoint,
["GAME_VERSION"] = SharedSettings.GameVersion,
}
});
}
else
{
RivetLogger.Warning("LocalGameServerManager.Start: no local game server executable path");
return null;
}
}
});
},
getStopConfig: () =>
{
Expand Down
1 change: 1 addition & 0 deletions Assets/Rivet/Editor/UI/Dock/Tabs/Develop.uxml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<ui:VisualElement name="PlayBody" style="flex-grow: 0; flex-shrink: 0;">
<ui:Label tabindex="-1" text="Test your game on this machine." parse-escape-sequences="true" display-tooltip-when-elided="true" style="overflow: hidden; white-space: normal; margin-bottom: 6px;" />
<ui:DropdownField choices="Run Client &amp; Server,Run Client Only,Run Server Only" index="2" name="TypeDropdown" label="Type" style="height: 19px; margin-bottom: 4px;" />
<ui:DropdownField label="Steps" choices="Build &amp; Run,Only Run" index="0" name="StepsDropdown" />
<ui:SliderInt label="Client Count" high-value="8" low-value="1" direction="Horizontal" show-input-field="true" name="PlayerCountSlider" />
<ui:VisualElement name="ButtonRow" style="flex-grow: 1; flex-direction: row; margin-bottom: 4px;">
<ui:Instance template="IconButton" name="StartButton" style="flex-grow: 1; display: flex;">
Expand Down
60 changes: 49 additions & 11 deletions Assets/Rivet/Editor/UI/Dock/Tabs/DevelopController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class DevelopController
private DropdownField _remoteEnvironmentDropdown;

private DropdownField _playTypeDropdown;
private DropdownField _playStepsDropdown;
private SliderInt _playerCount;
private Button _lgsStart;
private Button _lgsStop;
Expand Down Expand Up @@ -59,6 +60,7 @@ void InitUI()
_remoteEnvironmentDropdown = _root.Q("EnvironmentBody").Q<DropdownField>("EnvironmentDropdown");

_playTypeDropdown = _root.Q("PlayBody").Q<DropdownField>("TypeDropdown");
_playStepsDropdown = _root.Q("PlayBody").Q<DropdownField>("StepsDropdown");
_playerCount = _root.Q("PlayBody").Q<SliderInt>("PlayerCountSlider");

_lgsStart = _root.Q("PlayBody").Q("ButtonRow").Q("StartButton").Q<Button>("Button");
Expand Down Expand Up @@ -152,35 +154,71 @@ private void OnLocalGameServerStart()
{
var canPlayClient = _playTypeDropdown.index == 0 || _playTypeDropdown.index == 1;
var canPlayServer = _playTypeDropdown.index == 0 || _playTypeDropdown.index == 2;
var shouldBuild = _playStepsDropdown.index == 0;

// Server
if (canPlayServer)
{
string serverPath;
try
if (shouldBuild)
{
serverPath = Builder.BuildDevDedicatedServer();
try
{
Builder.BuildDevDedicatedServer();
}
catch (Exception e)
{
EditorUtility.DisplayDialog("Server Build Failed", e.Message, "Dismiss");
return;
}
}
catch (Exception e)
else
{
EditorUtility.DisplayDialog("Server Build Failed", e.Message, "Dismiss");
return;
string serverPath = Builder.GetDevDedicatedServerExecutablePath();
if (!File.Exists(serverPath))
{
EditorUtility.DisplayDialog("Missing Server Build", $"The server needs to be built before running without the build step.\n\nExpected path: {serverPath}", "OK");
return;
}
}

RivetGlobal.Singleton.LocalGameServerExecutablePath = serverPath;

// Start server
_ = _dock.LocalGameServerManager.StartTask();
}

// Client
if (canPlayClient)
{
Builder.BuildAndRunMultipleDevPlayers(_playerCount.value);
if (shouldBuild)
{
try
{
Builder.BuildDevPlayer();
}
catch (Exception e)
{
EditorUtility.DisplayDialog("Player Build Failed", e.Message, "Dismiss");
return;
}
}
else
{
string playerPath = Builder.GetDevPlayerExecutablePath();
if (!File.Exists(playerPath))
{
EditorUtility.DisplayDialog("Missing Player Build", $"The player needs to be built before running without the build step.\n\nExpected path: {playerPath}", "OK");
return;
}
}

// Start players
Builder.RunMultipleDevPlayers(_playerCount.value);
}

// Open game server logs if needed
if (canPlayServer) {
if (!EditorWindow.HasOpenInstances<GameServerWindow>()) {
if (canPlayServer)
{
if (!EditorWindow.HasOpenInstances<GameServerWindow>())
{
GameServerWindow.ShowGameServer();
}
}
Expand Down
64 changes: 44 additions & 20 deletions Assets/Rivet/Editor/Util/Builder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ public static BuildTarget GetLocalBuildTarget()
}
}


/// <summary>
/// Builds and runs multiple instances of the development player, each with its own log file.
/// </summary>
/// <param name="instanceCount">The number of player instances to run.</param>
public static string BuildDevPlayer()
{
// Check if the target platform is supported
Expand All @@ -65,7 +70,7 @@ public static string BuildDevPlayer()
var buildPlayerOptions = new BuildPlayerOptions
{
scenes = GetScenePaths(),
locationPathName = Path.Combine(ProjectRoot(), "Builds", "Development", "Player", GetPlatformArchFolder(GetLocalBuildTarget()), GetBuildName("Player", GetLocalBuildTarget())),
locationPathName = GetDevPlayerBuildPath(),
target = GetLocalBuildTarget(),
options = BuildOptions.Development | BuildOptions.AllowDebugging
};
Expand All @@ -87,19 +92,11 @@ public static string BuildDevPlayer()
}

/// <summary>
/// Builds and runs multiple instances of the development player, each with its own log file.
/// Runs multiple instances of the development player, each with its own log file.
/// </summary>
/// <param name="instanceCount">The number of player instances to run.</param>
public static void BuildAndRunMultipleDevPlayers(int instanceCount)
public static void RunMultipleDevPlayers( int instanceCount)
{
string playerPath;
try {
playerPath = BuildDevPlayer();
} catch (Exception e) {
EditorUtility.DisplayDialog("Player Build Failed", e.Message, "Dismiss");
return;
}

string logDirectory = Path.Combine(ProjectRoot(), "Logs", "DevPlayers");
Directory.CreateDirectory(logDirectory);

Expand All @@ -109,7 +106,7 @@ public static void BuildAndRunMultipleDevPlayers(int instanceCount)
{
string logFilePath = Path.Combine(logDirectory, $"DevPlayer_{i + 1}.log");
var arguments = $"-screen-fullscreen 0 -logFile \"{logFilePath}\"";
var startInfo = new System.Diagnostics.ProcessStartInfo(playerPath)
var startInfo = new System.Diagnostics.ProcessStartInfo(GetDevPlayerBuildPath())
{
Arguments = arguments,
UseShellExecute = false
Expand All @@ -126,10 +123,7 @@ public static void BuildAndRunMultipleDevPlayers(int instanceCount)
}

// MARK: Run Game Server
/// <summary>
/// Builds a server used for local development.
/// </summary>
/// <returns>Returns the task config to run the server.</returns>

public static string BuildDevDedicatedServer()
{
// Check if the target platform is supported
Expand All @@ -148,7 +142,7 @@ public static string BuildDevDedicatedServer()
var buildPlayerOptions = new BuildPlayerOptions
{
scenes = GetScenePaths(),
locationPathName = Path.Combine(ProjectRoot(), "Builds", "Development", "DedicatedServer", GetPlatformArchFolder(GetLocalBuildTarget()), GetBuildName("DedicatedServer", GetLocalBuildTarget(), true)),
locationPathName = GetDevDedicatedServerBuildPath(),
target = GetLocalBuildTarget(),
options = BuildOptions.Development | BuildOptions.CompressWithLz4 | BuildOptions.EnableHeadlessMode,
subtarget = (int)StandaloneBuildSubtarget.Server
Expand Down Expand Up @@ -196,7 +190,7 @@ public static string BuildReleaseDedicatedServer()
var buildPlayerOptions = new BuildPlayerOptions
{
scenes = GetScenePaths(),
locationPathName = Path.Combine(ProjectRoot(), "Builds", "Release", "DedicatedServer", GetPlatformArchFolder(BuildTarget.StandaloneLinux64), GetBuildName("DedicatedServer", BuildTarget.StandaloneLinux64, true)),
locationPathName = GetReleaseDedicatedServerBuildPath(),
target = BuildTarget.StandaloneLinux64,
options = BuildOptions.CompressWithLz4HC | BuildOptions.EnableHeadlessMode,
subtarget = (int)StandaloneBuildSubtarget.Server
Expand All @@ -218,7 +212,7 @@ public static string BuildReleaseDedicatedServer()
}
}

public static string FindServerExecutablePath(string serverPath, BuildTarget buildTarget)
private static string FindServerExecutablePath(string serverPath, BuildTarget buildTarget)
{
string productName = Application.productName;
string executableFile;
Expand Down Expand Up @@ -253,7 +247,7 @@ public static string FindServerExecutablePath(string serverPath, BuildTarget bui
return executableFile;
}

public static string FindPlayerExecutablePath(string buildPath, BuildTarget buildTarget)
private static string FindPlayerExecutablePath(string buildPath, BuildTarget buildTarget)
{
string productName = Application.productName;
string executablePath;
Expand Down Expand Up @@ -324,5 +318,35 @@ public static string ProjectRoot()
var dataPath = Application.dataPath;
return Directory.GetParent(dataPath).FullName;
}

public static string GetDevPlayerExecutablePath()
{
return FindPlayerExecutablePath(GetDevPlayerBuildPath(), GetLocalBuildTarget());
}

public static string GetDevDedicatedServerExecutablePath()
{
return FindServerExecutablePath(GetDevDedicatedServerBuildPath(), GetLocalBuildTarget());
}

public static string GetReleaseDedicatedServerExecutablePath()
{
return FindServerExecutablePath(GetReleaseDedicatedServerBuildPath(), BuildTarget.StandaloneLinux64);
}

private static string GetDevPlayerBuildPath()
{
return Path.Combine(ProjectRoot(), "Builds", "Development", "Player", GetPlatformArchFolder(GetLocalBuildTarget()), GetBuildName("Player", GetLocalBuildTarget()));
}

private static string GetDevDedicatedServerBuildPath()
{
return Path.Combine(ProjectRoot(), "Builds", "Development", "DedicatedServer", GetPlatformArchFolder(GetLocalBuildTarget()), GetBuildName("DedicatedServer", GetLocalBuildTarget(), true));
}

private static string GetReleaseDedicatedServerBuildPath()
{
return Path.Combine(ProjectRoot(), "Builds", "Release", "DedicatedServer", GetPlatformArchFolder(BuildTarget.StandaloneLinux64), GetBuildName("DedicatedServer", BuildTarget.StandaloneLinux64, true));
}
}
}
12 changes: 10 additions & 2 deletions Assets/Scripts/MultiplayerManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,16 @@ public struct ConnectionConfig

private void Awake()
{
IsServer = Array.IndexOf(Environment.GetCommandLineArgs(), "-server") != -1;

if (IsServer)
{
// Disable verbose log stack traces
Application.SetStackTraceLogType(LogType.Log, StackTraceLogType.ScriptOnly);
Application.SetStackTraceLogType(LogType.Warning, StackTraceLogType.ScriptOnly);
// Application.SetStackTraceLogType(LogType.Exception, StackTraceLogType.None);
// Application.SetStackTraceLogType(LogType.Assert, StackTraceLogType.None);
}

// Setup singleton
if (Instance != null && Instance != this)
Expand Down Expand Up @@ -120,8 +130,6 @@ public void SetupMultiplayer()
}
_multiplayerSetup = true;

IsServer = Array.IndexOf(Environment.GetCommandLineArgs(), "-server") != -1;

// Setup events
_networkManager.ClientManager.OnClientConnectionState += OnClientConnectionState;
_networkManager.ServerManager.OnServerConnectionState += OnServerConnectionState;
Expand Down