Skip to content

Commit

Permalink
refactor: renaming NetworkConnection to NetworkPlayer (#684)
Browse files Browse the repository at this point in the history
* refactor: renaming NetworkConnection to NetworkPlayer

part of Transport rewrite #679

BREAKING CHANGE: renaming NetworkConnection to NetworkPlayer

* renaming types in weaver tests

* fixing test message

* fixing xref in docs
  • Loading branch information
James-Frowen committed Mar 12, 2021
1 parent eb852dc commit 3ecb659
Show file tree
Hide file tree
Showing 54 changed files with 255 additions and 255 deletions.
10 changes: 5 additions & 5 deletions Assets/Mirage/Authenticators/BasicAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ public struct AuthResponseMessage
public string Message;
}

public override void OnServerAuthenticate(INetworkConnection conn)
public override void OnServerAuthenticate(INetworkPlayer conn)
{
// wait for AuthRequestMessage from client
conn.RegisterHandler<AuthRequestMessage>(OnAuthRequestMessage);
}

public override void OnClientAuthenticate(INetworkConnection conn)
public override void OnClientAuthenticate(INetworkPlayer conn)
{
conn.RegisterHandler<AuthResponseMessage>(OnAuthResponseMessage);

Expand All @@ -45,7 +45,7 @@ public override void OnClientAuthenticate(INetworkConnection conn)
conn.Send(authRequestMessage);
}

public void OnAuthRequestMessage(INetworkConnection conn, AuthRequestMessage msg)
public void OnAuthRequestMessage(INetworkPlayer conn, AuthRequestMessage msg)
{
if (logger.LogEnabled()) logger.LogFormat(LogType.Log, "Authentication Request: {0} {1}", msg.AuthUsername, msg.AuthPassword);

Expand Down Expand Up @@ -80,13 +80,13 @@ public void OnAuthRequestMessage(INetworkConnection conn, AuthRequestMessage msg
}
}

public IEnumerator DelayedDisconnect(INetworkConnection conn, float waitTime)
public IEnumerator DelayedDisconnect(INetworkPlayer conn, float waitTime)
{
yield return new WaitForSeconds(waitTime);
conn.Disconnect();
}

public void OnAuthResponseMessage(INetworkConnection conn, AuthResponseMessage msg)
public void OnAuthResponseMessage(INetworkPlayer conn, AuthResponseMessage msg)
{
if (msg.Code == 100)
{
Expand Down
12 changes: 6 additions & 6 deletions Assets/Mirage/Authenticators/TimeoutAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@ public void Awake()
Authenticator.OnServerAuthenticated += HandleServerAuthenticated;
}

private readonly HashSet<INetworkConnection> pendingAuthentication = new HashSet<INetworkConnection>();
private readonly HashSet<INetworkPlayer> pendingAuthentication = new HashSet<INetworkPlayer>();

private void HandleServerAuthenticated(INetworkConnection connection)
private void HandleServerAuthenticated(INetworkPlayer connection)
{
pendingAuthentication.Remove(connection);
base.OnClientAuthenticate(connection);
}

private void HandleClientAuthenticated(INetworkConnection connection)
private void HandleClientAuthenticated(INetworkPlayer connection)
{
pendingAuthentication.Remove(connection);
base.OnServerAuthenticate(connection);
}

public override void OnClientAuthenticate(INetworkConnection conn)
public override void OnClientAuthenticate(INetworkPlayer conn)
{
pendingAuthentication.Add(conn);
Authenticator.OnClientAuthenticate(conn);
Expand All @@ -47,15 +47,15 @@ public override void OnClientAuthenticate(INetworkConnection conn)
StartCoroutine(BeginAuthentication(conn));
}

public override void OnServerAuthenticate(INetworkConnection conn)
public override void OnServerAuthenticate(INetworkPlayer conn)
{
pendingAuthentication.Add(conn);
Authenticator.OnServerAuthenticate(conn);
if (Timeout > 0)
StartCoroutine(BeginAuthentication(conn));
}

IEnumerator BeginAuthentication(INetworkConnection conn)
IEnumerator BeginAuthentication(INetworkPlayer conn)
{
if (logger.LogEnabled()) logger.Log($"Authentication countdown started {conn} {Timeout}");

Expand Down
4 changes: 2 additions & 2 deletions Assets/Mirage/Components/LobbyReady.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class LobbyReady : MonoBehaviour

// just a cached memory area where we can collect connections
// for broadcasting messages
private static readonly List<INetworkConnection> connectionsCache = new List<INetworkConnection>();
private static readonly List<INetworkPlayer> connectionsCache = new List<INetworkPlayer>();

public void SetAllClientsNotReady()
{
Expand All @@ -36,7 +36,7 @@ public void SendToReady<T>(NetworkIdentity identity, T msg, bool includeOwner =
}
}

NetworkConnection.Send(connectionsCache, msg, channelId);
NetworkPlayer.Send(connectionsCache, msg, channelId);
}
}
}
4 changes: 2 additions & 2 deletions Assets/Mirage/Components/NetworkMatchChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ void RebuildMatchObservers(Guid specificMatch)
/// </summary>
/// <param name="conn">Network connection of a player.</param>
/// <returns>True if the player can see this object.</returns>
public override bool OnCheckObserver(INetworkConnection conn)
public override bool OnCheckObserver(INetworkPlayer conn)
{
// Not Visible if not in a match
if (MatchId == Guid.Empty)
Expand All @@ -125,7 +125,7 @@ public override bool OnCheckObserver(INetworkConnection conn)
/// </summary>
/// <param name="observers">The new set of observers for this object.</param>
/// <param name="initialize">True if the set of observers is being built for the first time.</param>
public override void OnRebuildObservers(HashSet<INetworkConnection> observers, bool initialize)
public override void OnRebuildObservers(HashSet<INetworkPlayer> observers, bool initialize)
{
if (currentMatch == Guid.Empty) return;

Expand Down
6 changes: 3 additions & 3 deletions Assets/Mirage/Components/NetworkProximityChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ void RebuildObservers()

/// <param name="conn">Network connection of a player.</param>
/// <returns>True if the player can see this object.</returns>
public override bool OnCheckObserver(INetworkConnection conn)
public override bool OnCheckObserver(INetworkPlayer conn)
{
if (ForceHidden)
return false;
Expand All @@ -72,7 +72,7 @@ public override bool OnCheckObserver(INetworkConnection conn)
/// </summary>
/// <param name="observers">The new set of observers for this object.</param>
/// <param name="initialize">True if the set of observers is being built for the first time.</param>
public override void OnRebuildObservers(HashSet<INetworkConnection> observers, bool initialize)
public override void OnRebuildObservers(HashSet<INetworkPlayer> observers, bool initialize)
{
// if force hidden then return without adding any observers.
if (ForceHidden)
Expand All @@ -88,7 +88,7 @@ public override void OnRebuildObservers(HashSet<INetworkConnection> observers, b
// magnitude faster. if we have 10k monsters and run a sphere
// cast 10k times, we will see a noticeable lag even with physics
// layers. but checking to every connection is fast.
foreach (INetworkConnection conn in Server.connections)
foreach (INetworkPlayer conn in Server.connections)
{
// check distance
if (conn != null && conn.Identity != null && Vector3.Distance(conn.Identity.transform.position, position) < VisibilityRange)
Expand Down
4 changes: 2 additions & 2 deletions Assets/Mirage/Components/NetworkSceneChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void RebuildSceneObservers()
/// </summary>
/// <param name="conn">Network connection of a player.</param>
/// <returns>True if the player can see this object.</returns>
public override bool OnCheckObserver(INetworkConnection conn)
public override bool OnCheckObserver(INetworkPlayer conn)
{
if (forceHidden)
return false;
Expand All @@ -102,7 +102,7 @@ public override bool OnCheckObserver(INetworkConnection conn)
/// </summary>
/// <param name="observers">The new set of observers for this object.</param>
/// <param name="initialize">True if the set of observers is being built for the first time.</param>
public override void OnRebuildObservers(HashSet<INetworkConnection> observers, bool initialize)
public override void OnRebuildObservers(HashSet<INetworkPlayer> observers, bool initialize)
{
// If forceHidden then return without adding any observers.
if (forceHidden)
Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirage/Editor/NetworkInformationPreview.cs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ float DrawObservers(NetworkIdentity identity, float initialX, float Y)
observerRect.x += 20;
observerRect.y += observerRect.height;

foreach (INetworkConnection conn in identity.observers)
foreach (INetworkPlayer conn in identity.observers)
{

GUI.Label(observerRect, conn.Address + ":" + conn, styles.ComponentName);
Expand Down
4 changes: 2 additions & 2 deletions Assets/Mirage/Runtime/ClientObjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public void Start()
}
}

void OnClientConnected(INetworkConnection conn)
void OnClientConnected(INetworkPlayer conn)
{
RegisterSpawnPrefabs();

Expand Down Expand Up @@ -593,7 +593,7 @@ void CheckForLocalPlayer(NetworkIdentity identity)
}
}

private void OnServerRpcReply(INetworkConnection connection, ServerRpcReply reply)
private void OnServerRpcReply(INetworkPlayer connection, ServerRpcReply reply)
{
// find the callback that was waiting for this and invoke it.
if (callbacks.TryGetValue(reply.replyId, out Action<NetworkReader> action))
Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirage/Runtime/INetworkClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public interface INetworkClient : IMessageSender
/// <summary>
/// The NetworkConnection object this client is using.
/// </summary>
INetworkConnection Connection { get; }
INetworkPlayer Connection { get; }

/// <summary>
/// active is true while a client is connecting/connected
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public interface IMessageSender
/// </summary>
public interface IMessageReceiver
{
void RegisterHandler<T>(Action<INetworkConnection, T> handler);
void RegisterHandler<T>(Action<INetworkPlayer, T> handler);

void RegisterHandler<T>(Action<T> handler);

Expand Down Expand Up @@ -56,12 +56,12 @@ public interface INotifyReceiver
/// <summary>
/// Raised when a message is delivered
/// </summary>
event Action<INetworkConnection, object> NotifyDelivered;
event Action<INetworkPlayer, object> NotifyDelivered;

/// <summary>
/// Raised when a message is lost
/// </summary>
event Action<INetworkConnection, object> NotifyLost;
event Action<INetworkPlayer, object> NotifyLost;
}

/// <summary>
Expand Down Expand Up @@ -98,7 +98,7 @@ public interface IObjectOwner
/// A connection to a remote endpoint.
/// May be from the server to client or from client to server
/// </summary>
public interface INetworkConnection : IMessageHandler, IVisibilityTracker, IObjectOwner
public interface INetworkPlayer : IMessageHandler, IVisibilityTracker, IObjectOwner
{
bool IsReady { get; set; }
EndPoint Address { get; }
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions Assets/Mirage/Runtime/INetworkServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public interface INetworkServer
/// <summary>
/// The connection to the host mode client (if any).
/// </summary>
INetworkConnection LocalConnection { get; }
INetworkPlayer LocalConnection { get; }

/// <summary>
/// The host client for this server
Expand All @@ -60,9 +60,9 @@ public interface INetworkServer

void Disconnect();

void AddConnection(INetworkConnection conn);
void AddConnection(INetworkPlayer conn);

void RemoveConnection(INetworkConnection conn);
void RemoveConnection(INetworkPlayer conn);

void SendToAll<T>(T msg, int channelId = Channel.Reliable);
}
Expand Down
12 changes: 6 additions & 6 deletions Assets/Mirage/Runtime/IServerObjectManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ public interface IServerObjectManager
/// </summary>
SpawnEvent UnSpawned { get; }

bool AddPlayerForConnection(INetworkConnection conn, GameObject player);
bool AddPlayerForConnection(INetworkPlayer conn, GameObject player);

bool AddPlayerForConnection(INetworkConnection conn, GameObject player, Guid assetId);
bool AddPlayerForConnection(INetworkPlayer conn, GameObject player, Guid assetId);

bool ReplacePlayerForConnection(INetworkConnection conn, NetworkClient client, GameObject player, bool keepAuthority = false);
bool ReplacePlayerForConnection(INetworkPlayer conn, NetworkClient client, GameObject player, bool keepAuthority = false);

bool ReplacePlayerForConnection(INetworkConnection conn, NetworkClient client, GameObject player, Guid assetId, bool keepAuthority = false);
bool ReplacePlayerForConnection(INetworkPlayer conn, NetworkClient client, GameObject player, Guid assetId, bool keepAuthority = false);

void Spawn(GameObject obj, GameObject ownerPlayer);

void Spawn(GameObject obj, INetworkConnection ownerConnection = null);
void Spawn(GameObject obj, INetworkPlayer ownerConnection = null);

void Spawn(GameObject obj, Guid assetId, INetworkConnection ownerConnection = null);
void Spawn(GameObject obj, Guid assetId, INetworkPlayer ownerConnection = null);

void Destroy(GameObject obj);

Expand Down
12 changes: 6 additions & 6 deletions Assets/Mirage/Runtime/NetworkAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,17 @@ public abstract class NetworkAuthenticator : MonoBehaviour
/// <summary>
/// Notify subscribers on the server when a client is authenticated
/// </summary>
public event Action<INetworkConnection> OnServerAuthenticated;
public event Action<INetworkPlayer> OnServerAuthenticated;

/// <summary>
/// Notify subscribers on the client when the client is authenticated
/// </summary>
public event Action<INetworkConnection> OnClientAuthenticated;
public event Action<INetworkPlayer> OnClientAuthenticated;

#region server

// This will get more code in the near future
internal void OnServerAuthenticateInternal(INetworkConnection conn)
internal void OnServerAuthenticateInternal(INetworkPlayer conn)
{
OnServerAuthenticate(conn);
}
Expand All @@ -31,7 +31,7 @@ internal void OnServerAuthenticateInternal(INetworkConnection conn)
/// Called on server from OnServerAuthenticateInternal when a client needs to authenticate
/// </summary>
/// <param name="conn">Connection to client.</param>
public virtual void OnServerAuthenticate(INetworkConnection conn)
public virtual void OnServerAuthenticate(INetworkPlayer conn)
{
OnServerAuthenticated?.Invoke(conn);
}
Expand All @@ -41,7 +41,7 @@ public virtual void OnServerAuthenticate(INetworkConnection conn)
#region client

// This will get more code in the near future
internal void OnClientAuthenticateInternal(INetworkConnection conn)
internal void OnClientAuthenticateInternal(INetworkPlayer conn)
{
OnClientAuthenticate(conn);
}
Expand All @@ -50,7 +50,7 @@ internal void OnClientAuthenticateInternal(INetworkConnection conn)
/// Called on client from OnClientAuthenticateInternal when a client needs to authenticate
/// </summary>
/// <param name="conn">Connection of the client.</param>
public virtual void OnClientAuthenticate(INetworkConnection conn)
public virtual void OnClientAuthenticate(INetworkPlayer conn)
{
OnClientAuthenticated?.Invoke(conn);
}
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 @@ -107,14 +107,14 @@ public abstract class NetworkBehaviour : MonoBehaviour
public ClientObjectManager ClientObjectManager => NetIdentity.ClientObjectManager;

/// <summary>
/// The <see cref="NetworkConnection">NetworkConnection</see> associated with this <see cref="NetworkIdentity">NetworkIdentity.</see> This is only valid for player objects on the client.
/// The <see cref="NetworkPlayer">NetworkConnection</see> associated with this <see cref="NetworkIdentity">NetworkIdentity.</see> This is only valid for player objects on the client.
/// </summary>
public INetworkConnection ConnectionToServer => NetIdentity.ConnectionToServer;
public INetworkPlayer ConnectionToServer => NetIdentity.ConnectionToServer;

/// <summary>
/// The <see cref="NetworkConnection">NetworkConnection</see> associated with this <see cref="NetworkIdentity">NetworkIdentity.</see> This is only valid for player objects on the server.
/// The <see cref="NetworkPlayer">NetworkConnection</see> associated with this <see cref="NetworkIdentity">NetworkIdentity.</see> This is only valid for player objects on the server.
/// </summary>
public INetworkConnection ConnectionToClient => NetIdentity.ConnectionToClient;
public INetworkPlayer ConnectionToClient => NetIdentity.ConnectionToClient;

/// <summary>
/// Returns the appropriate NetworkTime instance based on if this NetworkBehaviour is running as a Server or Client.
Expand Down Expand Up @@ -321,7 +321,7 @@ protected internal void SendRpcInternal(Type invokeClass, string rpcName, Networ
NetIdentity.SendToObservers(message, includeOwner, channelId);
}

protected internal void SendTargetRpcInternal(INetworkConnection conn, Type invokeClass, string rpcName, NetworkWriter writer, int channelId)
protected internal void SendTargetRpcInternal(INetworkPlayer conn, Type invokeClass, string rpcName, NetworkWriter writer, int channelId)
{
// this was in Weaver before
if (!Server || !Server.Active)
Expand Down

0 comments on commit 3ecb659

Please sign in to comment.