Skip to content

Commit

Permalink
refactor: using interface instead of network server (MirageNet#722)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: fields and parameters using NetworkServer are now using INetworkServer Instead
  • Loading branch information
James-Frowen committed Mar 24, 2021
1 parent 4ff53ec commit 7312bd8
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
5 changes: 5 additions & 0 deletions Assets/Mirage/Runtime/INetworkServer.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Collections.Generic;
using UnityEngine.Events;

namespace Mirage
Expand Down Expand Up @@ -58,6 +59,10 @@ public interface INetworkServer
/// </summary>
bool Active { get; }

NetworkTime Time { get; }

IReadOnlyCollection<INetworkPlayer> Players { get; }

void Disconnect();

void AddConnection(INetworkPlayer player);
Expand Down
10 changes: 5 additions & 5 deletions Assets/Mirage/Runtime/NetworkBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public abstract class NetworkBehaviour : MonoBehaviour
/// <summary>
/// The <see cref="NetworkServer">NetworkClient</see> associated to this object.
/// </summary>
public NetworkServer Server => NetIdentity.Server;
public INetworkServer Server => NetIdentity.Server;

/// <summary>
/// Quick Reference to the NetworkIdentities ServerObjectManager. Present only for server/host instances.
Expand Down Expand Up @@ -291,9 +291,9 @@ protected internal UniTask<T> SendServerRpcWithReturn<T>(Type invokeClass, strin
protected internal void SendRpcInternal(Type invokeClass, string rpcName, NetworkWriter writer, int channelId, bool excludeOwner)
{
// this was in Weaver before
if (!Server || !Server.Active)
if (Server == null || !Server.Active)
{
throw new InvalidOperationException("RPC Function " + rpcName + " called on Client.");
throw new InvalidOperationException($"RPC Function {rpcName} called when server is not active.");
}
// This cannot use Server.active, as that is not specific to this object.
if (!IsServer)
Expand Down Expand Up @@ -322,9 +322,9 @@ protected internal void SendRpcInternal(Type invokeClass, string rpcName, Networ
protected internal void SendTargetRpcInternal(INetworkPlayer player, Type invokeClass, string rpcName, NetworkWriter writer, int channelId)
{
// this was in Weaver before
if (!Server || !Server.Active)
if (Server == null || !Server.Active)
{
throw new InvalidOperationException("RPC Function " + rpcName + " called on client.");
throw new InvalidOperationException($"RPC Function {rpcName} called when server is not active.");
}

// connection parameter is optional. assign if null.
Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirage/Runtime/NetworkIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public sealed class NetworkIdentity : MonoBehaviour
/// <summary>
/// The NetworkServer associated with this NetworkIdentity.
/// </summary>
public NetworkServer Server { get; internal set; }
public INetworkServer Server { get; internal set; }

/// <summary>
/// The ServerObjectManager is present only for server/host instances.
Expand Down
1 change: 1 addition & 0 deletions Assets/Mirage/Runtime/NetworkServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ public class NetworkServer : MonoBehaviour, INetworkServer
/// A list of local connections on the server.
/// </summary>
public readonly HashSet<INetworkPlayer> Players = new HashSet<INetworkPlayer>();
IReadOnlyCollection<INetworkPlayer> INetworkServer.Players => Players;

/// <summary>
/// <para>Checks if the server has been started.</para>
Expand Down

0 comments on commit 7312bd8

Please sign in to comment.