Skip to content

Commit

Permalink
feat: upgrade to NGO v1.8.1, conversion to universal Rpcs, utility as…
Browse files Browse the repository at this point in the history
…sembly includes Unity.Collections [MTT-8188] (#883)

* upgrade to NGO v1.8.1, conversion to universal Rpcs, utility assembly includes Unity.Collections

* fix for connected clients receiving new shutdown message from host

* Utilities package also upgraded to NGO v1.8.1

* changelog additions

* readme badge with NGO upgrade updated

* added Server/Client prefixes for previous Rpc methods

* update to Utilities changelog

* using RpcTargetUse Temp since clientId may change frequently
  • Loading branch information
fernando-cortez authored Mar 22, 2024
1 parent aa73d28 commit 8160543
Show file tree
Hide file tree
Showing 30 changed files with 113 additions and 104 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using Unity.BossRoom.UnityServices.Lobbies;
using UnityEngine;
using VContainer;
Expand Down Expand Up @@ -27,7 +26,8 @@ public override void Exit() { }
public override void OnClientDisconnect(ulong _)
{
var disconnectReason = m_ConnectionManager.NetworkManager.DisconnectReason;
if (string.IsNullOrEmpty(disconnectReason))
if (string.IsNullOrEmpty(disconnectReason) ||
disconnectReason == "Disconnected due to host shutting down.")
{
m_ConnectStatusPublisher.Publish(ConnectStatus.Reconnecting);
m_ConnectionManager.ChangeState(m_ConnectionManager.m_ClientReconnecting);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public override bool OnStart(ServerCharacter serverCharacter)
// This means we are responsible for triggering reaction-anims ourselves, which we do in PerformAoe()
Data.TargetIds = new ulong[0];
serverCharacter.serverAnimationHandler.NetworkAnimator.SetTrigger(Config.Anim);
serverCharacter.clientCharacter.RecvDoActionClientRPC(Data);
serverCharacter.clientCharacter.ClientPlayActionRpc(Data);
return ActionConclusion.Continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public override bool OnStart(ServerCharacter serverCharacter)
serverCharacter.serverAnimationHandler.NetworkAnimator.SetTrigger(Config.Anim);

// start the "charging up" ActionFX
serverCharacter.clientCharacter.RecvDoActionClientRPC(Data);
serverCharacter.clientCharacter.ClientPlayActionRpc(Data);

// sanity-check our data a bit
Debug.Assert(Config.Projectiles.Length > 1, $"Action {name} has {Config.Projectiles.Length} Projectiles. Expected at least 2!");
Expand Down Expand Up @@ -122,7 +122,7 @@ private void StopChargingUp(ServerCharacter parent)
parent.serverAnimationHandler.NetworkAnimator.SetTrigger(Config.Anim2);
}

parent.clientCharacter.RecvStopChargingUpClientRpc(GetPercentChargedUp());
parent.clientCharacter.ClientStopChargingUpRpc(GetPercentChargedUp());
if (!m_HitByAttack)
{
LaunchProjectile(parent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public override bool OnStart(ServerCharacter serverCharacter)
// raise the start trigger to start the animation loop!
serverCharacter.serverAnimationHandler.NetworkAnimator.SetTrigger(Config.Anim);

serverCharacter.clientCharacter.RecvDoActionClientRPC(Data);
serverCharacter.clientCharacter.ClientPlayActionRpc(Data);
return true;
}

Expand Down Expand Up @@ -145,7 +145,7 @@ private void StopChargingUp(ServerCharacter parent)
if (IsChargingUp())
{
m_StoppedChargingUpTime = Time.time;
parent.clientCharacter.RecvStopChargingUpClientRpc(GetPercentChargedUp());
parent.clientCharacter.ClientStopChargingUpRpc(GetPercentChargedUp());

parent.serverAnimationHandler.NetworkAnimator.SetTrigger(Config.Anim2);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public override bool OnStart(ServerCharacter serverCharacter)
serverCharacter.serverAnimationHandler.NetworkAnimator.SetTrigger(Config.Anim);

// tell clients to visualize this action
serverCharacter.clientCharacter.RecvDoActionClientRPC(Data);
serverCharacter.clientCharacter.ClientPlayActionRpc(Data);

return ActionConclusion.Continue;
}
Expand Down Expand Up @@ -80,7 +80,7 @@ public override void Cancel(ServerCharacter serverCharacter)

// because the client-side visualization of the action moves the character visualization around,
// we need to explicitly end the client-side visuals when we abort
serverCharacter.clientCharacter.RecvCancelActionsByPrototypeIDClientRpc(ActionID);
serverCharacter.clientCharacter.ClientCancelActionsByPrototypeIDRpc(ActionID);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public override bool OnStart(ServerCharacter serverCharacter)

serverCharacter.serverAnimationHandler.NetworkAnimator.SetTrigger(Config.Anim);
// tell clients to visualize this action
serverCharacter.clientCharacter.RecvDoActionClientRPC(Data);
serverCharacter.clientCharacter.ClientPlayActionRpc(Data);
return true;
}

Expand Down Expand Up @@ -84,7 +84,7 @@ public override void Cancel(ServerCharacter serverCharacter)
{
if (!m_ImpactedTarget)
{
serverCharacter.clientCharacter.RecvCancelActionsByPrototypeIDClientRpc(ActionID);
serverCharacter.clientCharacter.ClientCancelActionsByPrototypeIDRpc(ActionID);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public override bool OnStart(ServerCharacter serverCharacter)
serverCharacter.physicsWrapper.Transform.forward = Data.Direction;

serverCharacter.serverAnimationHandler.NetworkAnimator.SetTrigger(Config.Anim);
serverCharacter.clientCharacter.RecvDoActionClientRPC(Data);
serverCharacter.clientCharacter.ClientPlayActionRpc(Data);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public override bool OnStart(ServerCharacter serverCharacter)
}

serverCharacter.serverAnimationHandler.NetworkAnimator.SetTrigger(Config.Anim);
serverCharacter.clientCharacter.RecvDoActionClientRPC(Data);
serverCharacter.clientCharacter.ClientPlayActionRpc(Data);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public override bool OnStart(ServerCharacter serverCharacter)
{
serverCharacter.serverAnimationHandler.NetworkAnimator.SetTrigger(Config.Anim);

serverCharacter.clientCharacter.RecvDoActionClientRPC(Data);
serverCharacter.clientCharacter.ClientPlayActionRpc(Data);

return true;
}
Expand Down Expand Up @@ -90,7 +90,7 @@ private void EndStealth(ServerCharacter parent)
// presses the Stealth button twice in a row: "end this Stealth action and start a new one". If we cancelled
// all actions of this type in Cancel(), we'd end up cancelling both the old AND the new one, because
// the new one would already be in the clients' actionFX queue.
parent.clientCharacter.RecvCancelActionsByPrototypeIDClientRpc(ActionID);
parent.clientCharacter.ClientCancelActionsByPrototypeIDRpc(ActionID);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public override bool OnStart(ServerCharacter serverCharacter)
}

serverCharacter.serverAnimationHandler.NetworkAnimator.SetTrigger(Config.Anim);
serverCharacter.clientCharacter.RecvDoActionClientRPC(Data);
serverCharacter.clientCharacter.ClientPlayActionRpc(Data);
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public override bool OnStart(ServerCharacter serverCharacter)
serverCharacter.serverAnimationHandler.NetworkAnimator.SetTrigger(Config.Anim);
}

serverCharacter.clientCharacter.RecvDoActionClientRPC(Data);
serverCharacter.clientCharacter.ClientPlayActionRpc(Data);
return true;
}

Expand Down Expand Up @@ -238,7 +238,7 @@ private void StunSelf(ServerCharacter parent)
if (!m_WasStunned)
{
parent.Movement.CancelMove();
parent.clientCharacter.RecvCancelAllActionsClientRpc();
parent.clientCharacter.ClientCancelAllActionsRpc();
}
m_WasStunned = true;
}
Expand Down
2 changes: 1 addition & 1 deletion Assets/Scripts/Gameplay/Action/Input/ChargedActionInput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private void Start()

public override void OnReleaseKey()
{
m_PlayerOwner.RecvStopChargingUpServerRpc();
m_PlayerOwner.ServerStopChargingUpRpc();
Destroy(gameObject);
}

Expand Down
65 changes: 32 additions & 33 deletions Assets/Scripts/Gameplay/DebugCheats/DebugCheatsManager.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System;
using Unity.BossRoom.ConnectionManagement;
using Unity.BossRoom.Gameplay.GameplayObjects;
using Unity.BossRoom.Gameplay.GameplayObjects.Character;
Expand Down Expand Up @@ -77,77 +76,77 @@ static bool AnyTouchDown()

public void SpawnEnemy()
{
SpawnEnemyServerRpc();
ServerSpawnEnemyRpc();
}

public void SpawnBoss()
{
SpawnBossServerRpc();
ServerSpawnBossRpc();
}

public void KillTarget()
{
KillTargetServerRpc();
ServerKillTargetRpc();
}

public void KillAllEnemies()
{
KillAllEnemiesServerRpc();
ServerKillAllEnemiesRpc();
}

public void ToggleGodMode()
{
ToggleGodModeServerRpc();
ServerToggleGodModeRpc();
}

public void HealPlayer()
{
HealPlayerServerRpc();
ServerHealPlayerRpc();
}

public void ToggleSuperSpeed()
{
ToggleSuperSpeedServerRpc();
ServerToggleSuperSpeedRpc();
}

public void ToggleTeleportMode()
{
ToggleTeleportModeServerRpc();
ServerToggleTeleportModeRpc();
}

public void ToggleDoor()
{
ToggleDoorServerRpc();
ServerToggleDoorRpc();
}

public void TogglePortals()
{
TogglePortalsServerRpc();
ServerTogglePortalsRpc();
}

public void GoToPostGame()
{
GoToPostGameServerRpc();
}

[ServerRpc(RequireOwnership = false)]
void SpawnEnemyServerRpc(ServerRpcParams serverRpcParams = default)
[Rpc(SendTo.Server, RequireOwnership = false)]
void ServerSpawnEnemyRpc(RpcParams serverRpcParams = default)
{
var newEnemy = Instantiate(m_EnemyPrefab);
newEnemy.SpawnWithOwnership(NetworkManager.Singleton.LocalClientId, true);
PublishCheatUsedMessage(serverRpcParams.Receive.SenderClientId, "SpawnEnemy");
}

[ServerRpc(RequireOwnership = false)]
void SpawnBossServerRpc(ServerRpcParams serverRpcParams = default)
[Rpc(SendTo.Server, RequireOwnership = false)]
void ServerSpawnBossRpc(RpcParams serverRpcParams = default)
{
var newEnemy = Instantiate(m_BossPrefab);
newEnemy.SpawnWithOwnership(NetworkManager.Singleton.LocalClientId, true);
PublishCheatUsedMessage(serverRpcParams.Receive.SenderClientId, "SpawnBoss");
}

[ServerRpc(RequireOwnership = false)]
void KillTargetServerRpc(ServerRpcParams serverRpcParams = default)
[Rpc(SendTo.Server, RequireOwnership = false)]
void ServerKillTargetRpc(RpcParams serverRpcParams = default)
{
ulong clientId = serverRpcParams.Receive.SenderClientId;
var playerServerCharacter = PlayerServerCharacter.GetPlayerServerCharacter(clientId);
Expand All @@ -171,8 +170,8 @@ void KillTargetServerRpc(ServerRpcParams serverRpcParams = default)
}
}

[ServerRpc(RequireOwnership = false)]
void KillAllEnemiesServerRpc(ServerRpcParams serverRpcParams = default)
[Rpc(SendTo.Server, RequireOwnership = false)]
void ServerKillAllEnemiesRpc(RpcParams serverRpcParams = default)
{
foreach (var serverCharacter in FindObjectsOfType<ServerCharacter>())
{
Expand All @@ -187,8 +186,8 @@ void KillAllEnemiesServerRpc(ServerRpcParams serverRpcParams = default)
PublishCheatUsedMessage(serverRpcParams.Receive.SenderClientId, "KillAllEnemies");
}

[ServerRpc(RequireOwnership = false)]
void ToggleGodModeServerRpc(ServerRpcParams serverRpcParams = default)
[Rpc(SendTo.Server, RequireOwnership = false)]
void ServerToggleGodModeRpc(RpcParams serverRpcParams = default)
{
var clientId = serverRpcParams.Receive.SenderClientId;
var playerServerCharacter = PlayerServerCharacter.GetPlayerServerCharacter(clientId);
Expand All @@ -199,8 +198,8 @@ void ToggleGodModeServerRpc(ServerRpcParams serverRpcParams = default)
}
}

[ServerRpc(RequireOwnership = false)]
void HealPlayerServerRpc(ServerRpcParams serverRpcParams = default)
[Rpc(SendTo.Server, RequireOwnership = false)]
void ServerHealPlayerRpc(RpcParams serverRpcParams = default)
{
var clientId = serverRpcParams.Receive.SenderClientId;
var playerServerCharacter = PlayerServerCharacter.GetPlayerServerCharacter(clientId);
Expand All @@ -222,8 +221,8 @@ void HealPlayerServerRpc(ServerRpcParams serverRpcParams = default)
}
}

[ServerRpc(RequireOwnership = false)]
void ToggleSuperSpeedServerRpc(ServerRpcParams serverRpcParams = default)
[Rpc(SendTo.Server, RequireOwnership = false)]
void ServerToggleSuperSpeedRpc(RpcParams serverRpcParams = default)
{
var clientId = serverRpcParams.Receive.SenderClientId;
foreach (var playerServerCharacter in PlayerServerCharacter.GetPlayerServerCharacters())
Expand All @@ -237,8 +236,8 @@ void ToggleSuperSpeedServerRpc(ServerRpcParams serverRpcParams = default)
PublishCheatUsedMessage(clientId, "ToggleSuperSpeed");
}

[ServerRpc(RequireOwnership = false)]
void ToggleTeleportModeServerRpc(ServerRpcParams serverRpcParams = default)
[Rpc(SendTo.Server, RequireOwnership = false)]
void ServerToggleTeleportModeRpc(RpcParams serverRpcParams = default)
{
var clientId = serverRpcParams.Receive.SenderClientId;
foreach (var playerServerCharacter in PlayerServerCharacter.GetPlayerServerCharacters())
Expand All @@ -252,8 +251,8 @@ void ToggleTeleportModeServerRpc(ServerRpcParams serverRpcParams = default)
PublishCheatUsedMessage(serverRpcParams.Receive.SenderClientId, "ToggleTeleportMode");
}

[ServerRpc(RequireOwnership = false)]
void ToggleDoorServerRpc(ServerRpcParams serverRpcParams = default)
[Rpc(SendTo.Server, RequireOwnership = false)]
void ServerToggleDoorRpc(RpcParams serverRpcParams = default)
{
if (SwitchedDoor != null)
{
Expand All @@ -266,8 +265,8 @@ void ToggleDoorServerRpc(ServerRpcParams serverRpcParams = default)
}
}

[ServerRpc(RequireOwnership = false)]
void TogglePortalsServerRpc(ServerRpcParams serverRpcParams = default)
[Rpc(SendTo.Server, RequireOwnership = false)]
void ServerTogglePortalsRpc(RpcParams serverRpcParams = default)
{
foreach (var portal in FindObjectsOfType<EnemyPortal>())
{
Expand All @@ -288,8 +287,8 @@ void TogglePortalsServerRpc(ServerRpcParams serverRpcParams = default)
PublishCheatUsedMessage(serverRpcParams.Receive.SenderClientId, "TogglePortals");
}

[ServerRpc(RequireOwnership = false)]
void GoToPostGameServerRpc(ServerRpcParams serverRpcParams = default)
[Rpc(SendTo.Server, RequireOwnership = false)]
void GoToPostGameServerRpc(RpcParams serverRpcParams = default)
{
SceneLoaderWrapper.Instance.LoadScene("PostGame", useNetworkSceneManager: true);
PublishCheatUsedMessage(serverRpcParams.Receive.SenderClientId, "GoToPostGame");
Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Gameplay/GameState/ClientCharSelectState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -416,7 +416,7 @@ public void OnPlayerClickedSeat(int seatIdx)
{
if (m_NetworkCharSelection.IsSpawned)
{
m_NetworkCharSelection.ChangeSeatServerRpc(NetworkManager.Singleton.LocalClientId, seatIdx, false);
m_NetworkCharSelection.ServerChangeSeatRpc(NetworkManager.Singleton.LocalClientId, seatIdx, false);
}
}

Expand All @@ -428,7 +428,7 @@ public void OnPlayerClickedReady()
if (m_NetworkCharSelection.IsSpawned)
{
// request to lock in or unlock if already locked in
m_NetworkCharSelection.ChangeSeatServerRpc(NetworkManager.Singleton.LocalClientId, m_LastSeatSelected, !m_HasLocalPlayerLockedIn);
m_NetworkCharSelection.ServerChangeSeatRpc(NetworkManager.Singleton.LocalClientId, m_LastSeatSelected, !m_HasLocalPlayerLockedIn);
}
}

Expand Down
4 changes: 2 additions & 2 deletions Assets/Scripts/Gameplay/GameState/NetworkCharSelection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ private void Awake()
/// <summary>
/// RPC to notify the server that a client has chosen a seat.
/// </summary>
[ServerRpc(RequireOwnership = false)]
public void ChangeSeatServerRpc(ulong clientId, int seatIdx, bool lockedIn)
[Rpc(SendTo.Server, RequireOwnership = false)]
public void ServerChangeSeatRpc(ulong clientId, int seatIdx, bool lockedIn)
{
OnClientChangedSeat?.Invoke(clientId, seatIdx, lockedIn);
}
Expand Down
Loading

0 comments on commit 8160543

Please sign in to comment.