Skip to content
Merged
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
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
*
!Builds/Release/DedicatedServer/
3 changes: 3 additions & 0 deletions Assets/Backend/Client/ApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,9 @@ private async Task<ApiResponse<T>> ExecAsync<T>(
await tsc.Task;
}

// Log the path and response
Debug.Log($"Backend request {request.method} {path} ({request.responseCode}): {request.downloadHandler.text}");

if (request.result == UnityWebRequest.Result.ConnectionError ||
request.result == UnityWebRequest.Result.DataProcessingError)
{
Expand Down
7 changes: 6 additions & 1 deletion Assets/Examples/LobbiesServers/Scripts/UI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ private BackendClient TEMPBackendClient()
return new BackendClient(config.BackendEndpoint);
}

private string TEMPGameVersion() {
var config = new Configuration();
return config.GameVersion;
}

private void Start()
{
_networkManager = FindObjectOfType<NetworkManager>();
Expand Down Expand Up @@ -61,7 +66,7 @@ public async void OnClick_Find()
joinMenuPanel.SetActive(false);

var response = await TEMPBackendClient().Lobbies.FindOrCreate(new Backend.Model.Lobbies.FindOrCreateRequest(
varVersion: "default",
varVersion: TEMPGameVersion(),
regions: new List<string> { "local" },
tags: new Dictionary<string, string>
{
Expand Down
13 changes: 9 additions & 4 deletions Assets/Rivet/Editor/BuildPipeline.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,16 @@ public void OnPreprocessBuild(BuildReport report)

public void OnPostprocessBuild(BuildReport report)
{
// Delete asset file
string filePath = Path.Combine(Application.streamingAssetsPath, "rivet_config.json");
if (File.Exists(filePath))
string jsonFilePath = Path.Combine(Application.streamingAssetsPath, "rivet_config.json");
if (File.Exists(jsonFilePath))
{
File.Delete(jsonFilePath);
}

string metaFilePath = jsonFilePath + ".meta";
if (File.Exists(metaFilePath))
{
File.Delete(filePath);
File.Delete(metaFilePath);
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions Assets/Rivet/Editor/PluginSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ public static string GameVersion
set => SetAndSave(ref gameVersion, value, "GameVersion");
}

public static void LoadSettings() {
public static void LoadSettings()
{
backendEndpoint = PlayerPrefs.GetString("BackendEndpoint");
gameVersion = PlayerPrefs.GetString("GameVersion");
}
Expand All @@ -144,10 +145,9 @@ public static void UpdateFromPlugin()
_ => throw new System.NotImplementedException(),
};

// TODO:
GameVersion = "TODO";
GameVersion = plugin.GameVersion ?? "unknown";

RivetLogger.Log($"Update Shared Settings: BackendEndpoint={BackendEndpoint} GameVersion={GameVersion}");
RivetLogger.Log($"Update Shared Settings [BackendEndpoint={BackendEndpoint} GameVersion={GameVersion}]");
}
}
}
Expand Down
12 changes: 10 additions & 2 deletions Assets/Rivet/Editor/Task.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public enum LogType { STDOUT, STDERR }

// State
public bool IsRunning { get; private set; } = false;
public bool IsFinished { get; private set; } = false;
private StateFiles _stateFiles;
private CancellationTokenSource _cts;
private FileStream _logFileStream;
Expand Down Expand Up @@ -74,6 +75,7 @@ public async Task<Result<JObject>> RunAsync(CancellationToken cancellationToken
var logPollingTask = StartLogPolling(_cts.Token);
var result = await Task.Run(() => RunTask(_name, _input, runConfig), _cts.Token);
IsRunning = false;
IsFinished = true;

// Read end of logs immediately. Log polling task will cancel
// itself.
Expand All @@ -84,6 +86,7 @@ public async Task<Result<JObject>> RunAsync(CancellationToken cancellationToken
finally
{
IsRunning = false;
IsFinished = true;
FinishLogs();
Dispose(); // Self-dispose after the task is complete
}
Expand Down Expand Up @@ -244,6 +247,11 @@ private StateFiles GenerateStateFilesDir()
}
}

private string StripAnsiCodes(string input)
{
return System.Text.RegularExpressions.Regex.Replace(input, @"\x1b\[[0-9;]*m", string.Empty);
}

private void ReadLogTail()
{
if (_logFileStream == null)
Expand All @@ -269,11 +277,11 @@ private void ReadLogTail()
var parsed = JsonConvert.DeserializeObject<Dictionary<string, string>>(line);
if (parsed.ContainsKey("Stdout"))
{
OnLog?.Invoke(parsed["Stdout"], LogType.STDOUT);
OnLog?.Invoke(StripAnsiCodes(parsed["Stdout"]), LogType.STDOUT);
}
else if (parsed.ContainsKey("Stderr"))
{
OnLog?.Invoke(parsed["Stderr"], LogType.STDERR);
OnLog?.Invoke(StripAnsiCodes(parsed["Stderr"]), LogType.STDERR);
}
}
catch (JsonException)
Expand Down
14 changes: 14 additions & 0 deletions Assets/Rivet/Editor/UI/RivetPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@ public int LocalBackendPort {
}
}

// MARK: Deployed
public string? GameVersion;

// MARK: Tasks
public TaskManager LocalGameServerManager;
public TaskManager BackendManager;
Expand Down Expand Up @@ -94,6 +97,17 @@ public void SetScreen(Screen screen)
_screen = screen;
_screenLogin.style.display = screen == Screen.Login ? DisplayStyle.Flex : DisplayStyle.None;
_screenMain.style.display = screen == Screen.Main ? DisplayStyle.Flex : DisplayStyle.None;

// Notify the appropriate controller
switch (screen)
{
case Screen.Login:
LoginController.OnShow();
break;
case Screen.Main:
MainController.OnShow();
break;
}
}

public void OnEnable()
Expand Down
3 changes: 3 additions & 0 deletions Assets/Rivet/Editor/UI/Screens/LoginController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ public LoginController(RivetPlugin window, VisualElement root)
_root = root;

InitUI();
}

public void OnShow()
{
_ = CheckLoginState();
}

Expand Down
19 changes: 14 additions & 5 deletions Assets/Rivet/Editor/UI/Screens/MainController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ public RivetEnvironment? RemoteEnvironment
{
get
{
return BootstrapData?.Environments[RemoteEnvironmentIndex];
return RemoteEnvironmentIndex != null ? BootstrapData?.Environments[RemoteEnvironmentIndex.Value] : null;
}
}
public int RemoteEnvironmentIndex
public int? RemoteEnvironmentIndex
{
get
{
Expand All @@ -94,9 +94,9 @@ public int RemoteEnvironmentIndex
}
set
{
if (value >= 0 && value < BootstrapData?.Environments.Count)
if (value != null && value >= 0 && value < BootstrapData?.Environments.Count)
{
RemoteEnvironmentId = BootstrapData?.Environments[value].Id;
RemoteEnvironmentId = BootstrapData?.Environments[value.Value].EnvironmentId;
}
}
}
Expand All @@ -109,7 +109,9 @@ public MainController(RivetPlugin window, VisualElement root)
// UI
InitUI();
SetTab(MainTab.Setup);
}

public void OnShow() {
// Fetch data
_ = GetBootstrapData();
}
Expand Down Expand Up @@ -157,7 +159,7 @@ void SetTab(MainTab tab)
_settingsTabBody.style.display = tab == MainTab.Settings ? DisplayStyle.Flex : DisplayStyle.None;
}

private async Task GetBootstrapData()
public async Task GetBootstrapData()
{
var result = await new RivetTask("get_bootstrap_data", new JObject()).RunAsync();
if (result is ResultErr<JObject> err)
Expand All @@ -168,6 +170,7 @@ private async Task GetBootstrapData()
var data = result.Data.ToObject<BootstrapData>(); ;
BootstrapData = data;

<<<<<<< HEAD
try
{
var data = result.Data.ToObject<BootstrapData>();
Expand All @@ -182,6 +185,12 @@ private async Task GetBootstrapData()
RivetLogger.Error($"Exception in GetBootstrapData: {ex.Message}");
RivetLogger.Error($"Stack trace: {ex.StackTrace}");
}
=======
_developController.OnBootstrap(data);
_deployController.OnBootstrap(data);

SharedSettings.UpdateFromPlugin();
>>>>>>> 3ace6b6 (chore: re-impl deploys)
}

/// <summary>
Expand Down
60 changes: 42 additions & 18 deletions Assets/Rivet/Editor/UI/Tabs/DeployController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
using Rivet.Editor.UI.TaskPopup;

namespace Rivet.UI.Tabs
{
Expand All @@ -21,6 +22,7 @@ public class DeployController
private MainController _mainController;
private readonly VisualElement _root;

private VisualElement _refreshButton;
private DropdownField _environmentDropdown;
private Button _buildDeployButton;
private DropdownField _stepsDropdown;
Expand All @@ -37,11 +39,14 @@ public DeployController(RivetPlugin window, MainController mainController, Visua
void InitUI()
{
// Query
_refreshButton = _root.Q("DeployHeader").Q("Header").Q("Action");
_environmentDropdown = _root.Q<DropdownField>("EnvironmentDropdown");
_buildDeployButton = _root.Q("BuildDeployButton").Q<Button>("Button");
_stepsDropdown = _root.Q<DropdownField>("StepsDropdown");

// Callbacks
_refreshButton.RegisterCallback<ClickEvent>(ev => { _ = _mainController.GetBootstrapData(); });

_environmentDropdown.RegisterValueChangedCallback(ev =>
{
_mainController.EnvironmentType = EnvironmentType.Remote;
Expand Down Expand Up @@ -74,7 +79,7 @@ public void OnBootstrap(BootstrapData data)

public void OnSelectedEnvironmentChange()
{
_environmentDropdown.index = _mainController.RemoteEnvironmentIndex;
_environmentDropdown.index = _mainController.RemoteEnvironmentIndex ?? -1;
}

private void OnBuildAndDeploy()
Expand All @@ -83,33 +88,52 @@ private void OnBuildAndDeploy()
_mainController.EnvironmentType = EnvironmentType.Remote;
_mainController.OnSelectedEnvironmentChange();

string? serverPath = Builder.BuildReleaseDedicatedServer();
if (serverPath == null)
// Get the selected environment ID
string environmentId = _mainController.RemoteEnvironmentId;
if (environmentId == null)
{
EditorUtility.DisplayDialog("Server Build Failed", "See Unity console for details.", "Dismiss");
return;
throw new System.Exception("Could not get ID for remote env");
}

// Get the selected environment ID
string environmentId = _mainController.RemoteEnvironment?.NameId ?? "";

// Get the selected steps
int stepsIndex = _stepsDropdown.index;
bool deployGameServer = stepsIndex == 0 || stepsIndex == 1;
bool deployBackend = stepsIndex == 0 || stepsIndex == 2;

// Run deploy with CLI
_ = new RivetTask(
"deploy",
new JObject
string? serverPath = null;
if (deployGameServer)
{
serverPath = Builder.BuildReleaseDedicatedServer();
if (serverPath == null)
{
["cwd"] = Path.GetDirectoryName(serverPath),
["environment_id"] = environmentId,
["game_server"] = deployGameServer,
["backend"] = deployBackend,
EditorUtility.DisplayDialog("Server Build Failed", "See Unity console for details.", "Dismiss");
return;
}
).RunAsync();
}
}

// Run deploy with CLI using TaskPopupWindow
var task = TaskPopupWindow.RunTask("Build & Deploy", "deploy", new JObject
{
["cwd"] = serverPath != null ? Path.GetDirectoryName(serverPath) : Builder.ProjectRoot(),
["environment_id"] = environmentId,
["game_server"] = deployGameServer,
["backend"] = deployBackend,
});

// Save version
task.OnTaskOutput += output =>
{
if (output is ResultOk<JObject> ok)
{
var version = ok.Data["version"]?.ToString();
if (!string.IsNullOrEmpty(version))
{
RivetPlugin.Singleton.GameVersion = ok.Data["version"].ToString();
SharedSettings.UpdateFromPlugin();
Debug.Log($"New game version: {RivetPlugin.Singleton.GameVersion}");
}
}
};
}
}
}
4 changes: 2 additions & 2 deletions Assets/Rivet/Editor/UI/Tabs/Develop.uxml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
<AttributeOverrides element-name="Title" text="Environment" />
</ui:Instance>
<ui:VisualElement name="EnvironmentBody" style="flex-grow: 0; flex-shrink: 0;">
<ui:Label tabindex="-1" text="Configure which backend to connect to." parse-escape-sequences="true" display-tooltip-when-elided="true" style="margin-top: 0; margin-bottom: 4px; opacity: 1; white-space: normal;" />
<ui:DropdownField choices="Local,Remote" index="0" name="TypeDropdown" label="Type" style="height: 19px; margin-bottom: 4px;" />
<ui:Label tabindex="-1" text="Specify which backend to connect to." parse-escape-sequences="true" display-tooltip-when-elided="true" style="margin-top: 0; margin-bottom: 4px; opacity: 1; white-space: normal;" />
<ui:DropdownField choices="Local (Development),Remote (Live Servers)" index="0" name="TypeDropdown" label="Type" style="height: 19px; margin-bottom: 4px;" />
<ui:DropdownField name="EnvironmentDropdown" label="Environment" index="0" style="height: 19px;" />
</ui:VisualElement>
<ui:Instance template="Separator" name="Separator" />
Expand Down
Loading