Skip to content

Commit 3ecb659

Browse files
authored
refactor: renaming NetworkConnection to NetworkPlayer (MirageNet#684)
* refactor: renaming NetworkConnection to NetworkPlayer part of Transport rewrite MirageNet#679 BREAKING CHANGE: renaming NetworkConnection to NetworkPlayer * renaming types in weaver tests * fixing test message * fixing xref in docs
1 parent eb852dc commit 3ecb659

File tree

54 files changed

+255
-255
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+255
-255
lines changed

Assets/Mirage/Authenticators/BasicAuthenticator.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,13 @@ public struct AuthResponseMessage
2626
public string Message;
2727
}
2828

29-
public override void OnServerAuthenticate(INetworkConnection conn)
29+
public override void OnServerAuthenticate(INetworkPlayer conn)
3030
{
3131
// wait for AuthRequestMessage from client
3232
conn.RegisterHandler<AuthRequestMessage>(OnAuthRequestMessage);
3333
}
3434

35-
public override void OnClientAuthenticate(INetworkConnection conn)
35+
public override void OnClientAuthenticate(INetworkPlayer conn)
3636
{
3737
conn.RegisterHandler<AuthResponseMessage>(OnAuthResponseMessage);
3838

@@ -45,7 +45,7 @@ public override void OnClientAuthenticate(INetworkConnection conn)
4545
conn.Send(authRequestMessage);
4646
}
4747

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

@@ -80,13 +80,13 @@ public void OnAuthRequestMessage(INetworkConnection conn, AuthRequestMessage msg
8080
}
8181
}
8282

83-
public IEnumerator DelayedDisconnect(INetworkConnection conn, float waitTime)
83+
public IEnumerator DelayedDisconnect(INetworkPlayer conn, float waitTime)
8484
{
8585
yield return new WaitForSeconds(waitTime);
8686
conn.Disconnect();
8787
}
8888

89-
public void OnAuthResponseMessage(INetworkConnection conn, AuthResponseMessage msg)
89+
public void OnAuthResponseMessage(INetworkPlayer conn, AuthResponseMessage msg)
9090
{
9191
if (msg.Code == 100)
9292
{

Assets/Mirage/Authenticators/TimeoutAuthenticator.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,21 @@ public void Awake()
2424
Authenticator.OnServerAuthenticated += HandleServerAuthenticated;
2525
}
2626

27-
private readonly HashSet<INetworkConnection> pendingAuthentication = new HashSet<INetworkConnection>();
27+
private readonly HashSet<INetworkPlayer> pendingAuthentication = new HashSet<INetworkPlayer>();
2828

29-
private void HandleServerAuthenticated(INetworkConnection connection)
29+
private void HandleServerAuthenticated(INetworkPlayer connection)
3030
{
3131
pendingAuthentication.Remove(connection);
3232
base.OnClientAuthenticate(connection);
3333
}
3434

35-
private void HandleClientAuthenticated(INetworkConnection connection)
35+
private void HandleClientAuthenticated(INetworkPlayer connection)
3636
{
3737
pendingAuthentication.Remove(connection);
3838
base.OnServerAuthenticate(connection);
3939
}
4040

41-
public override void OnClientAuthenticate(INetworkConnection conn)
41+
public override void OnClientAuthenticate(INetworkPlayer conn)
4242
{
4343
pendingAuthentication.Add(conn);
4444
Authenticator.OnClientAuthenticate(conn);
@@ -47,15 +47,15 @@ public override void OnClientAuthenticate(INetworkConnection conn)
4747
StartCoroutine(BeginAuthentication(conn));
4848
}
4949

50-
public override void OnServerAuthenticate(INetworkConnection conn)
50+
public override void OnServerAuthenticate(INetworkPlayer conn)
5151
{
5252
pendingAuthentication.Add(conn);
5353
Authenticator.OnServerAuthenticate(conn);
5454
if (Timeout > 0)
5555
StartCoroutine(BeginAuthentication(conn));
5656
}
5757

58-
IEnumerator BeginAuthentication(INetworkConnection conn)
58+
IEnumerator BeginAuthentication(INetworkPlayer conn)
5959
{
6060
if (logger.LogEnabled()) logger.Log($"Authentication countdown started {conn} {Timeout}");
6161

Assets/Mirage/Components/LobbyReady.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class LobbyReady : MonoBehaviour
1111

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

1616
public void SetAllClientsNotReady()
1717
{
@@ -36,7 +36,7 @@ public void SendToReady<T>(NetworkIdentity identity, T msg, bool includeOwner =
3636
}
3737
}
3838

39-
NetworkConnection.Send(connectionsCache, msg, channelId);
39+
NetworkPlayer.Send(connectionsCache, msg, channelId);
4040
}
4141
}
4242
}

Assets/Mirage/Components/NetworkMatchChecker.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ void RebuildMatchObservers(Guid specificMatch)
105105
/// </summary>
106106
/// <param name="conn">Network connection of a player.</param>
107107
/// <returns>True if the player can see this object.</returns>
108-
public override bool OnCheckObserver(INetworkConnection conn)
108+
public override bool OnCheckObserver(INetworkPlayer conn)
109109
{
110110
// Not Visible if not in a match
111111
if (MatchId == Guid.Empty)
@@ -125,7 +125,7 @@ public override bool OnCheckObserver(INetworkConnection conn)
125125
/// </summary>
126126
/// <param name="observers">The new set of observers for this object.</param>
127127
/// <param name="initialize">True if the set of observers is being built for the first time.</param>
128-
public override void OnRebuildObservers(HashSet<INetworkConnection> observers, bool initialize)
128+
public override void OnRebuildObservers(HashSet<INetworkPlayer> observers, bool initialize)
129129
{
130130
if (currentMatch == Guid.Empty) return;
131131

Assets/Mirage/Components/NetworkProximityChecker.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ void RebuildObservers()
5858

5959
/// <param name="conn">Network connection of a player.</param>
6060
/// <returns>True if the player can see this object.</returns>
61-
public override bool OnCheckObserver(INetworkConnection conn)
61+
public override bool OnCheckObserver(INetworkPlayer conn)
6262
{
6363
if (ForceHidden)
6464
return false;
@@ -72,7 +72,7 @@ public override bool OnCheckObserver(INetworkConnection conn)
7272
/// </summary>
7373
/// <param name="observers">The new set of observers for this object.</param>
7474
/// <param name="initialize">True if the set of observers is being built for the first time.</param>
75-
public override void OnRebuildObservers(HashSet<INetworkConnection> observers, bool initialize)
75+
public override void OnRebuildObservers(HashSet<INetworkPlayer> observers, bool initialize)
7676
{
7777
// if force hidden then return without adding any observers.
7878
if (ForceHidden)
@@ -88,7 +88,7 @@ public override void OnRebuildObservers(HashSet<INetworkConnection> observers, b
8888
// magnitude faster. if we have 10k monsters and run a sphere
8989
// cast 10k times, we will see a noticeable lag even with physics
9090
// layers. but checking to every connection is fast.
91-
foreach (INetworkConnection conn in Server.connections)
91+
foreach (INetworkPlayer conn in Server.connections)
9292
{
9393
// check distance
9494
if (conn != null && conn.Identity != null && Vector3.Distance(conn.Identity.transform.position, position) < VisibilityRange)

Assets/Mirage/Components/NetworkSceneChecker.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ void RebuildSceneObservers()
8888
/// </summary>
8989
/// <param name="conn">Network connection of a player.</param>
9090
/// <returns>True if the player can see this object.</returns>
91-
public override bool OnCheckObserver(INetworkConnection conn)
91+
public override bool OnCheckObserver(INetworkPlayer conn)
9292
{
9393
if (forceHidden)
9494
return false;
@@ -102,7 +102,7 @@ public override bool OnCheckObserver(INetworkConnection conn)
102102
/// </summary>
103103
/// <param name="observers">The new set of observers for this object.</param>
104104
/// <param name="initialize">True if the set of observers is being built for the first time.</param>
105-
public override void OnRebuildObservers(HashSet<INetworkConnection> observers, bool initialize)
105+
public override void OnRebuildObservers(HashSet<INetworkPlayer> observers, bool initialize)
106106
{
107107
// If forceHidden then return without adding any observers.
108108
if (forceHidden)

Assets/Mirage/Editor/NetworkInformationPreview.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ float DrawObservers(NetworkIdentity identity, float initialX, float Y)
181181
observerRect.x += 20;
182182
observerRect.y += observerRect.height;
183183

184-
foreach (INetworkConnection conn in identity.observers)
184+
foreach (INetworkPlayer conn in identity.observers)
185185
{
186186

187187
GUI.Label(observerRect, conn.Address + ":" + conn, styles.ComponentName);

Assets/Mirage/Runtime/ClientObjectManager.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public void Start()
9494
}
9595
}
9696

97-
void OnClientConnected(INetworkConnection conn)
97+
void OnClientConnected(INetworkPlayer conn)
9898
{
9999
RegisterSpawnPrefabs();
100100

@@ -593,7 +593,7 @@ void CheckForLocalPlayer(NetworkIdentity identity)
593593
}
594594
}
595595

596-
private void OnServerRpcReply(INetworkConnection connection, ServerRpcReply reply)
596+
private void OnServerRpcReply(INetworkPlayer connection, ServerRpcReply reply)
597597
{
598598
// find the callback that was waiting for this and invoke it.
599599
if (callbacks.TryGetValue(reply.replyId, out Action<NetworkReader> action))

Assets/Mirage/Runtime/INetworkClient.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public interface INetworkClient : IMessageSender
2323
/// <summary>
2424
/// The NetworkConnection object this client is using.
2525
/// </summary>
26-
INetworkConnection Connection { get; }
26+
INetworkPlayer Connection { get; }
2727

2828
/// <summary>
2929
/// active is true while a client is connecting/connected

Assets/Mirage/Runtime/INetworkConnection.cs Assets/Mirage/Runtime/INetworkPlayer.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public interface IMessageSender
1919
/// </summary>
2020
public interface IMessageReceiver
2121
{
22-
void RegisterHandler<T>(Action<INetworkConnection, T> handler);
22+
void RegisterHandler<T>(Action<INetworkPlayer, T> handler);
2323

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

@@ -56,12 +56,12 @@ public interface INotifyReceiver
5656
/// <summary>
5757
/// Raised when a message is delivered
5858
/// </summary>
59-
event Action<INetworkConnection, object> NotifyDelivered;
59+
event Action<INetworkPlayer, object> NotifyDelivered;
6060

6161
/// <summary>
6262
/// Raised when a message is lost
6363
/// </summary>
64-
event Action<INetworkConnection, object> NotifyLost;
64+
event Action<INetworkPlayer, object> NotifyLost;
6565
}
6666

6767
/// <summary>
@@ -98,7 +98,7 @@ public interface IObjectOwner
9898
/// A connection to a remote endpoint.
9999
/// May be from the server to client or from client to server
100100
/// </summary>
101-
public interface INetworkConnection : IMessageHandler, IVisibilityTracker, IObjectOwner
101+
public interface INetworkPlayer : IMessageHandler, IVisibilityTracker, IObjectOwner
102102
{
103103
bool IsReady { get; set; }
104104
EndPoint Address { get; }

Assets/Mirage/Runtime/INetworkConnection.cs.meta Assets/Mirage/Runtime/INetworkPlayer.cs.meta

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Assets/Mirage/Runtime/INetworkServer.cs

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public interface INetworkServer
4040
/// <summary>
4141
/// The connection to the host mode client (if any).
4242
/// </summary>
43-
INetworkConnection LocalConnection { get; }
43+
INetworkPlayer LocalConnection { get; }
4444

4545
/// <summary>
4646
/// The host client for this server
@@ -60,9 +60,9 @@ public interface INetworkServer
6060

6161
void Disconnect();
6262

63-
void AddConnection(INetworkConnection conn);
63+
void AddConnection(INetworkPlayer conn);
6464

65-
void RemoveConnection(INetworkConnection conn);
65+
void RemoveConnection(INetworkPlayer conn);
6666

6767
void SendToAll<T>(T msg, int channelId = Channel.Reliable);
6868
}

Assets/Mirage/Runtime/IServerObjectManager.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@ public interface IServerObjectManager
1616
/// </summary>
1717
SpawnEvent UnSpawned { get; }
1818

19-
bool AddPlayerForConnection(INetworkConnection conn, GameObject player);
19+
bool AddPlayerForConnection(INetworkPlayer conn, GameObject player);
2020

21-
bool AddPlayerForConnection(INetworkConnection conn, GameObject player, Guid assetId);
21+
bool AddPlayerForConnection(INetworkPlayer conn, GameObject player, Guid assetId);
2222

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

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

2727
void Spawn(GameObject obj, GameObject ownerPlayer);
2828

29-
void Spawn(GameObject obj, INetworkConnection ownerConnection = null);
29+
void Spawn(GameObject obj, INetworkPlayer ownerConnection = null);
3030

31-
void Spawn(GameObject obj, Guid assetId, INetworkConnection ownerConnection = null);
31+
void Spawn(GameObject obj, Guid assetId, INetworkPlayer ownerConnection = null);
3232

3333
void Destroy(GameObject obj);
3434

Assets/Mirage/Runtime/NetworkAuthenticator.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -12,17 +12,17 @@ public abstract class NetworkAuthenticator : MonoBehaviour
1212
/// <summary>
1313
/// Notify subscribers on the server when a client is authenticated
1414
/// </summary>
15-
public event Action<INetworkConnection> OnServerAuthenticated;
15+
public event Action<INetworkPlayer> OnServerAuthenticated;
1616

1717
/// <summary>
1818
/// Notify subscribers on the client when the client is authenticated
1919
/// </summary>
20-
public event Action<INetworkConnection> OnClientAuthenticated;
20+
public event Action<INetworkPlayer> OnClientAuthenticated;
2121

2222
#region server
2323

2424
// This will get more code in the near future
25-
internal void OnServerAuthenticateInternal(INetworkConnection conn)
25+
internal void OnServerAuthenticateInternal(INetworkPlayer conn)
2626
{
2727
OnServerAuthenticate(conn);
2828
}
@@ -31,7 +31,7 @@ internal void OnServerAuthenticateInternal(INetworkConnection conn)
3131
/// Called on server from OnServerAuthenticateInternal when a client needs to authenticate
3232
/// </summary>
3333
/// <param name="conn">Connection to client.</param>
34-
public virtual void OnServerAuthenticate(INetworkConnection conn)
34+
public virtual void OnServerAuthenticate(INetworkPlayer conn)
3535
{
3636
OnServerAuthenticated?.Invoke(conn);
3737
}
@@ -41,7 +41,7 @@ public virtual void OnServerAuthenticate(INetworkConnection conn)
4141
#region client
4242

4343
// This will get more code in the near future
44-
internal void OnClientAuthenticateInternal(INetworkConnection conn)
44+
internal void OnClientAuthenticateInternal(INetworkPlayer conn)
4545
{
4646
OnClientAuthenticate(conn);
4747
}
@@ -50,7 +50,7 @@ internal void OnClientAuthenticateInternal(INetworkConnection conn)
5050
/// Called on client from OnClientAuthenticateInternal when a client needs to authenticate
5151
/// </summary>
5252
/// <param name="conn">Connection of the client.</param>
53-
public virtual void OnClientAuthenticate(INetworkConnection conn)
53+
public virtual void OnClientAuthenticate(INetworkPlayer conn)
5454
{
5555
OnClientAuthenticated?.Invoke(conn);
5656
}

Assets/Mirage/Runtime/NetworkBehaviour.cs

+5-5
Original file line numberDiff line numberDiff line change
@@ -107,14 +107,14 @@ public abstract class NetworkBehaviour : MonoBehaviour
107107
public ClientObjectManager ClientObjectManager => NetIdentity.ClientObjectManager;
108108

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

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

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

324-
protected internal void SendTargetRpcInternal(INetworkConnection conn, Type invokeClass, string rpcName, NetworkWriter writer, int channelId)
324+
protected internal void SendTargetRpcInternal(INetworkPlayer conn, Type invokeClass, string rpcName, NetworkWriter writer, int channelId)
325325
{
326326
// this was in Weaver before
327327
if (!Server || !Server.Active)

0 commit comments

Comments
 (0)