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
1 change: 0 additions & 1 deletion Assets/Examples/LobbiesServers/Scripts/GameManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public class GameManager : NetworkBehaviour

[SerializeField] private Vector3 cameraOffset = new Vector3(0, 5, -5);
[SerializeField] private float cameraSmoothTime = 0.25f;
[SerializeField] private float cameraAngle = 45f; // Angle of the camera from horizontal

public Player LocalPlayer;
private Vector3 cameraVelocity;
Expand Down
Git LFS file not shown
50 changes: 44 additions & 6 deletions Assets/Rivet/Editor/RivetGlobal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Newtonsoft.Json.Linq;
using Rivet.Editor.Types;
using Rivet.Editor.UI.Dock;
using System.Linq;

namespace Rivet.Editor
{
Expand Down Expand Up @@ -44,7 +45,18 @@ public bool IsAuthenticated
// MARK: Environment
public EnvironmentType EnvironmentType
{
get { return PluginSettings.EnvironmentType; }
get
{
if (IsAuthenticated)
{
// Only allow remote env type if authenticated
return PluginSettings.EnvironmentType;
}
else
{
return EnvironmentType.Local;
}
}
set
{
PluginSettings.EnvironmentType = value;
Expand All @@ -53,7 +65,18 @@ public EnvironmentType EnvironmentType
}
public string? RemoteEnvironmentId
{
get { return PluginSettings.RemoteEnvironmentId; }
get {
var remoteEnvId = PluginSettings.RemoteEnvironmentId;

// Validate plugin is authenticated & the env belongs to this
// game. This prevents returning an env ID from a game that
// isn't linked.
if (CloudData is { } cloudData && cloudData.Environments.Any(x => x.Id == remoteEnvId)) {
return remoteEnvId;
} else {
return null;
}
}
set
{
PluginSettings.RemoteEnvironmentId = value;
Expand Down Expand Up @@ -123,7 +146,15 @@ public string BackendEndpoint
case EnvironmentType.Remote:
if (CloudData is { } cloudData && RemoteEnvironmentId is { } remoteEnvId)
{
return cloudData.Backends[remoteEnvId].Endpoint;
if (cloudData.Backends.TryGetValue(remoteEnvId, out var backend))
{
return backend.Endpoint;
}
else
{
RivetLogger.Error("BackendEndpoint: no backend for environment");
return "";
}
}
else
{
Expand Down Expand Up @@ -158,13 +189,13 @@ public string CurrentBuildSlug
}
else
{
RivetLogger.Error("CurrentBuildSlug: no current build or version in build");
RivetLogger.Log("CurrentBuildSlug: no current build or version in build");
return "";
}
}
else
{
RivetLogger.Error("CurrentBuildSlug: not authenticated");
RivetLogger.Warning("CurrentBuildSlug: not authenticated");
return "";
}
default:
Expand Down Expand Up @@ -194,7 +225,14 @@ public async Task Bootstrap()
SharedSettings.UpdateFromPlugin();

// Emit event
Dock.Singleton?.OnBootstrap();
if (Dock.Singleton is { } dock)
{
dock.OnBootstrap();
}
else
{
RivetLogger.Warning("Dock singleton is null");
}
}
}
}
35 changes: 14 additions & 21 deletions Assets/Rivet/Editor/Task.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ public RivetTask(string name, JObject input)

private void Run(string name, string inputJson)
{
RivetLogger.Log($"starting run");
_taskId = RivetToolchain.RunTask(name, inputJson, OnOutputEvent);
RivetLogger.Log($"run finished");
RivetLogger.Log($"running {_taskId}");
}

private void OnOutputEvent(ulong taskId, IntPtr eventJsonPtr)
Expand All @@ -59,30 +56,26 @@ private void OnOutputEvent(ulong taskId, IntPtr eventJsonPtr)

private void HandleOnOutputEvent(string eventJson)
{
RivetLogger.Log($"got event {eventJson}");

var eventObj = JObject.Parse(eventJson);
if (eventObj.ContainsKey("log"))
{
OnLogEvent(eventObj);
OnLogEvent((string)eventObj["log"]);
}
else if (eventObj.ContainsKey("result"))
{
RivetLogger.Log("got result");
// 1st result = event enum type
// 2nd result = result enum type
_logResult = eventObj["result"]["result"] as JObject;
OnFinish();
}
else if (eventObj.ContainsKey("port_update"))
{
var backendPort = eventObj["port_update"]["backend_port"].Value<int>();
var editorPort = eventObj["port_update"]["editor_port"].Value<int>();
// TODO:
// Assuming you have a similar configuration saving mechanism
// RivetPluginBridge.Instance.LocalBackendPort = port;
// RivetPluginBridge.Instance.SaveConfiguration();
RivetLogger.Log($"Set backend port {backendPort} {editorPort}");
var plugin = RivetGlobal.Singleton;
plugin.LocalBackendPort = eventObj["port_update"]["backend_port"].Value<int>();
plugin.LocalEditorPort = eventObj["port_update"]["editor_port"].Value<int>();
SharedSettings.UpdateFromPlugin();

RivetLogger.Log($"Port update: backend={plugin.LocalBackendPort} editor={plugin.LocalEditorPort}");
}
else if (eventObj.ContainsKey("backend_config_update"))
{
Expand All @@ -95,9 +88,9 @@ private void HandleOnOutputEvent(string eventJson)
}
}

private void OnLogEvent(JObject eventObj)
private void OnLogEvent(string log)
{
TaskLog?.Invoke(eventObj["log"].ToString(), LogType.STDOUT);
TaskLog?.Invoke(log, LogType.STDOUT);
}

private void OnFinish()
Expand All @@ -121,19 +114,19 @@ private void OnFinish()
outputResult = _logResult;
}

RivetLogger.Log($"[{_name}] Response: {outputResult.ToString(Newtonsoft.Json.Formatting.None)}");;

TaskOutput?.Invoke(outputResult);
if (outputResult.ContainsKey("Ok"))
{
RivetLogger.Log($"[{_name}] Success: {outputResult["Ok"]}");
RivetLogger.Log($"[{_name}] Success: {outputResult["Ok"].ToString(Newtonsoft.Json.Formatting.None)}");
TaskOk?.Invoke(outputResult["Ok"] as JObject);
}
else if (outputResult.ContainsKey("Err"))
{
RivetLogger.Error($"[{_name}] Error: {outputResult["Err"]}");
RivetLogger.Error($"[{_name}] Error: {outputResult["Err"].ToString(Newtonsoft.Json.Formatting.None)}");
TaskError?.Invoke(outputResult["Err"].ToString());
} else {
}
else
{
RivetLogger.Error($"[{_name}] Missing Err or Ok in result: {outputResult.ToString(Newtonsoft.Json.Formatting.None)}");

}
Expand Down
Loading