Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Add "Temp" and "Persistent" flags for RpcTarget options #2792

Merged
merged 4 commits into from
Dec 13, 2023
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
Original file line number Diff line number Diff line change
@@ -1,14 +1,35 @@
using System;

namespace Unity.Netcode
{
public abstract class BaseRpcTarget
public abstract class BaseRpcTarget : IDisposable
{
protected NetworkManager m_NetworkManager;
private bool m_Locked;

internal void Lock()
{
m_Locked = true;
}

internal void Unlock()
{
m_Locked = false;
}

internal BaseRpcTarget(NetworkManager manager)
{
m_NetworkManager = manager;
}

protected void CheckLockBeforeDispose()
{
if (m_Locked)
{
throw new Exception($"RPC targets obtained through {nameof(RpcTargetUse)}.{RpcTargetUse.Temp} may not be disposed.");
}
}

public abstract void Dispose();

internal abstract void Send(NetworkBehaviour behaviour, ref RpcMessage message, NetworkDelivery delivery, RpcParams rpcParams);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal class DirectSendRpcTarget : BaseRpcTarget, IIndividualRpcTarget

public override void Dispose()
{

CheckLockBeforeDispose();
}

internal override void Send(NetworkBehaviour behaviour, ref RpcMessage message, NetworkDelivery delivery, RpcParams rpcParams)
Expand All @@ -25,5 +25,10 @@ internal DirectSendRpcTarget(NetworkManager manager) : base(manager)
{

}

internal DirectSendRpcTarget(ulong clientId, NetworkManager manager) : base(manager)
{
ClientId = clientId;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ internal ProxyRpcTargetGroup(NetworkManager manager) : base(manager)

public override void Dispose()
{
CheckLockBeforeDispose();
if (!m_Disposed)
{
TargetClientIds.Dispose();
Expand Down
Loading
Loading