Skip to content

Commit

Permalink
refactor: using interface instead of network client (MirageNet#721)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: fields and parameters using NetworkClient are now using INetworkClient Instead
  • Loading branch information
James-Frowen authored Mar 24, 2021
1 parent 5be7c6a commit 703596a
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 11 deletions.
2 changes: 2 additions & 0 deletions Assets/Mirage/Runtime/INetworkClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public interface INetworkClient : IMessageSender
/// </summary>
bool IsLocalClient { get; }

NetworkTime Time { get; }

void Disconnect();
}
}
2 changes: 1 addition & 1 deletion Assets/Mirage/Runtime/INetworkServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public interface INetworkServer
/// <summary>
/// The host client for this server
/// </summary>
NetworkClient LocalClient { get; }
INetworkClient LocalClient { get; }

/// <summary>
/// True if there is a local client connected to this server (host mode)
Expand Down
4 changes: 2 additions & 2 deletions Assets/Mirage/Runtime/IServerObjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ public interface IServerObjectManager

bool AddCharacter(INetworkPlayer player, GameObject character, Guid assetId);

bool ReplaceCharacter(INetworkPlayer player, NetworkClient client, GameObject character, bool keepAuthority = false);
bool ReplaceCharacter(INetworkPlayer player, INetworkClient client, GameObject character, bool keepAuthority = false);

bool ReplaceCharacter(INetworkPlayer player, NetworkClient client, GameObject character, Guid assetId, bool keepAuthority = false);
bool ReplaceCharacter(INetworkPlayer player, INetworkClient client, GameObject character, Guid assetId, bool keepAuthority = false);

void Spawn(GameObject obj, GameObject owner);

Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirage/Runtime/NetworkBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public abstract class NetworkBehaviour : MonoBehaviour
/// <summary>
/// The <see cref="NetworkClient">NetworkClient</see> associated to this object.
/// </summary>
public NetworkClient Client => NetIdentity.Client;
public INetworkClient Client => NetIdentity.Client;

/// <summary>
/// Quick Reference to the NetworkIdentities ClientObjectManager. Present only for instances instances.
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 @@ -175,7 +175,7 @@ public sealed class NetworkIdentity : MonoBehaviour
/// <summary>
/// The NetworkClient associated with this NetworkIdentity.
/// </summary>
public NetworkClient Client { get; internal set; }
public INetworkClient Client { get; internal set; }

/// <summary>
/// The ClientObjectManager is present only for client instances.
Expand Down
4 changes: 2 additions & 2 deletions Assets/Mirage/Runtime/NetworkServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public class NetworkServer : MonoBehaviour, INetworkServer
/// <summary>
/// The host client for this server
/// </summary>
public NetworkClient LocalClient { get; private set; }
public INetworkClient LocalClient { get; private set; }

/// <summary>
/// True if there is a local client connected to this server (host mode)
Expand Down Expand Up @@ -339,7 +339,7 @@ public void RemoveConnection(INetworkPlayer player)
/// </summary>
/// <param name="client">The local client</param>
/// <param name="tconn">The connection to the client</param>
internal void SetLocalConnection(NetworkClient client, IConnection tconn)
internal void SetLocalConnection(INetworkClient client, IConnection tconn)
{
if (LocalPlayer != null)
{
Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirage/Runtime/NetworkTime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void Reset()
offsetMax = double.MaxValue;
}

internal void UpdateClient(NetworkClient client)
internal void UpdateClient(INetworkClient client)
{
if (UnityEngine.Time.time - lastPingTime >= PingFrequency)
{
Expand Down
6 changes: 3 additions & 3 deletions Assets/Mirage/Runtime/ServerObjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void StartedHost()
/// <param name="assetId"></param>
/// <param name="keepAuthority">Does the previous player remain attached to this connection?</param>
/// <returns></returns>
public bool ReplaceCharacter(INetworkPlayer player, NetworkClient client, GameObject character, Guid assetId, bool keepAuthority = false)
public bool ReplaceCharacter(INetworkPlayer player, INetworkClient client, GameObject character, Guid assetId, bool keepAuthority = false)
{
NetworkIdentity identity = character.GetNetworkIdentity();
identity.AssetId = assetId;
Expand All @@ -214,7 +214,7 @@ public bool ReplaceCharacter(INetworkPlayer player, NetworkClient client, GameOb
/// <param name="character">Player object spawned for the player.</param>
/// <param name="keepAuthority">Does the previous player remain attached to this connection?</param>
/// <returns></returns>
public bool ReplaceCharacter(INetworkPlayer player, NetworkClient client, GameObject character, bool keepAuthority = false)
public bool ReplaceCharacter(INetworkPlayer player, INetworkClient client, GameObject character, bool keepAuthority = false)
{
return InternalReplacePlayerForConnection(player, client, character, keepAuthority);
}
Expand Down Expand Up @@ -329,7 +329,7 @@ void Respawn(NetworkIdentity identity)
}
}

internal bool InternalReplacePlayerForConnection(INetworkPlayer player, NetworkClient client, GameObject character, bool keepAuthority)
internal bool InternalReplacePlayerForConnection(INetworkPlayer player, INetworkClient client, GameObject character, bool keepAuthority)
{
NetworkIdentity identity = character.GetComponent<NetworkIdentity>();
if (identity is null)
Expand Down

0 comments on commit 703596a

Please sign in to comment.