Skip to content

Commit

Permalink
Remove NetworkConnectionToClient (#155)
Browse files Browse the repository at this point in the history
BREAKING CHANGE: NetworkConnectionToClient and networkConnectionToServer are gone
  • Loading branch information
uweeby committed Apr 7, 2020
1 parent 089fdea commit bd95cea
Show file tree
Hide file tree
Showing 16 changed files with 76 additions and 96 deletions.
6 changes: 3 additions & 3 deletions Assets/Mirror/Authenticators/BasicAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ public class AuthResponseMessage : MessageBase
public string Message;
}

public override void OnServerAuthenticate(NetworkConnectionToClient conn)
public override void OnServerAuthenticate(NetworkConnection conn)
{
// wait for AuthRequestMessage from client
conn.RegisterHandler<NetworkConnectionToClient, AuthRequestMessage>(OnAuthRequestMessage, false);
conn.RegisterHandler<NetworkConnection, AuthRequestMessage>(OnAuthRequestMessage, false);
}

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

public void OnAuthRequestMessage(NetworkConnectionToClient conn, AuthRequestMessage msg)
public void OnAuthRequestMessage(NetworkConnection conn, AuthRequestMessage msg)
{
Debug.LogFormat("Authentication Request: {0} {1}", msg.AuthUsername, msg.AuthPassword);

Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirror/Authenticators/TimeoutAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public override void OnClientAuthenticate(NetworkConnectionToServer conn)
StartCoroutine(BeginAuthentication(conn));
}

public override void OnServerAuthenticate(NetworkConnectionToClient conn)
public override void OnServerAuthenticate(NetworkConnection conn)
{
Authenticator.OnServerAuthenticate(conn);
if (Timeout > 0)
Expand Down
2 changes: 1 addition & 1 deletion Assets/Mirror/Examples/Chat/Scripts/ChatNetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class CreatePlayerMessage : MessageBase

public override void OnServerConnect(NetworkConnection conn)
{
conn.RegisterHandler<NetworkConnectionToClient, CreatePlayerMessage>(OnCreatePlayer);
conn.RegisterHandler<NetworkConnection, CreatePlayerMessage>(OnCreatePlayer);
}

public void OnAuthenticated(NetworkConnection conn)
Expand Down
6 changes: 3 additions & 3 deletions Assets/Mirror/Runtime/NetworkAuthenticator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public abstract class NetworkAuthenticator : MonoBehaviour
/// <summary>
/// Notify subscribers on the server when a client is authenticated
/// </summary>
public event Action<NetworkConnectionToClient> OnServerAuthenticated;
public event Action<NetworkConnection> OnServerAuthenticated;

/// <summary>
/// Notify subscribers on the client when the client is authenticated
Expand All @@ -22,7 +22,7 @@ public abstract class NetworkAuthenticator : MonoBehaviour
#region server

// This will get more code in the near future
internal void OnServerAuthenticateInternal(NetworkConnectionToClient conn)
internal void OnServerAuthenticateInternal(NetworkConnection conn)
{
OnServerAuthenticate(conn);
}
Expand All @@ -31,7 +31,7 @@ internal void OnServerAuthenticateInternal(NetworkConnectionToClient conn)
/// Called on server from OnServerAuthenticateInternal when a client needs to authenticate
/// </summary>
/// <param name="conn">Connection to client.</param>
public virtual void OnServerAuthenticate(NetworkConnectionToClient conn)
public virtual void OnServerAuthenticate(NetworkConnection conn)
{
OnServerAuthenticated?.Invoke(conn);
}
Expand Down
4 changes: 2 additions & 2 deletions Assets/Mirror/Runtime/NetworkConnection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace Mirror
/// <para>NetworkConnection objects also act as observers for networked objects. When a connection is an observer of a networked object with a NetworkIdentity, then the object will be visible to corresponding client for the connection, and incremental state changes will be sent to the client.</para>
/// <para>There are many virtual functions on NetworkConnection that allow its behaviour to be customized. NetworkClient and NetworkServer can both be made to instantiate custom classes derived from NetworkConnection by setting their networkConnectionClass member variable.</para>
/// </remarks>
public abstract class NetworkConnection : INetworkConnection
public class NetworkConnection : INetworkConnection
{
// Handles network messages on client and server
private delegate void NetworkMessageDelegate(NetworkConnection conn, NetworkReader reader, int channelId);
Expand Down Expand Up @@ -97,7 +97,7 @@ public abstract class NetworkConnection : INetworkConnection
/// Creates a new NetworkConnection with the specified address and connectionId
/// </summary>
/// <param name="networkConnectionId"></param>
protected NetworkConnection(IConnection connection)
public NetworkConnection(IConnection connection)
{
this.connection = connection;
}
Expand Down
9 changes: 0 additions & 9 deletions Assets/Mirror/Runtime/NetworkConnectionToClient.cs

This file was deleted.

11 changes: 0 additions & 11 deletions Assets/Mirror/Runtime/NetworkConnectionToClient.cs.meta

This file was deleted.

8 changes: 4 additions & 4 deletions Assets/Mirror/Runtime/NetworkIdentity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ public sealed class NetworkIdentity : MonoBehaviour
/// </summary>
public NetworkClient Client { get; internal set; }

NetworkConnectionToClient _connectionToClient;
NetworkConnection _connectionToClient;

/// <summary>
/// The NetworkConnection associated with this <see cref="NetworkIdentity">NetworkIdentity.</see> This is valid for player and other owned objects in the server.
/// <para>Use it to return details such as the connection&apos;s identity, IP address and ready status.</para>
/// </summary>
public NetworkConnectionToClient ConnectionToClient
public NetworkConnection ConnectionToClient
{
get => _connectionToClient;

Expand Down Expand Up @@ -243,7 +243,7 @@ internal void SetClientOwner(NetworkConnection conn)
}

// otherwise set the owner connection
ConnectionToClient = (NetworkConnectionToClient)conn;
ConnectionToClient = conn;
}

static uint nextNetworkId = 1;
Expand Down Expand Up @@ -1091,7 +1091,7 @@ public void RemoveClientAuthority()
{
clientAuthorityCallback?.Invoke(ConnectionToClient, this, false);

NetworkConnectionToClient previousOwner = ConnectionToClient;
NetworkConnection previousOwner = ConnectionToClient;

ConnectionToClient = null;

Expand Down
6 changes: 3 additions & 3 deletions Assets/Mirror/Runtime/NetworkManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -623,12 +623,12 @@ void FinishLoadSceneServerOnly()

void RegisterServerMessages(NetworkConnection connection)
{
connection.RegisterHandler<NetworkConnectionToClient, ReadyMessage>(OnServerReadyMessageInternal);
connection.RegisterHandler<NetworkConnectionToClient, RemovePlayerMessage>(OnServerRemovePlayerMessageInternal);
connection.RegisterHandler<NetworkConnection, ReadyMessage>(OnServerReadyMessageInternal);
connection.RegisterHandler<NetworkConnection, RemovePlayerMessage>(OnServerRemovePlayerMessageInternal);
}

// called after successful authentication
void OnServerAuthenticated(NetworkConnectionToClient conn)
void OnServerAuthenticated(NetworkConnection conn)
{
// a connection has been established, register for our messages
RegisterServerMessages(conn);
Expand Down
34 changes: 17 additions & 17 deletions Assets/Mirror/Runtime/NetworkServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class NetworkServer : MonoBehaviour
{
bool initialized;

[Serializable] public class NetworkConnectionEvent : UnityEvent<NetworkConnectionToClient> { }
[Serializable] public class NetworkConnectionEvent : UnityEvent<NetworkConnection> { }

/// <summary>
/// The maximum number of concurrent network connections to support.
Expand Down Expand Up @@ -54,7 +54,7 @@ public class NetworkServer : MonoBehaviour
// original HLAPI has .localConnections list with only m_LocalConnection in it
// (for backwards compatibility because they removed the real localConnections list a while ago)
// => removed it for easier code. use .localConnection now!
public NetworkConnectionToClient localConnection { get; private set; }
public NetworkConnection localConnection { get; private set; }

// The host client for this server
public NetworkClient localClient { get; private set; }
Expand All @@ -74,7 +74,7 @@ public class NetworkServer : MonoBehaviour
/// <summary>
/// A list of local connections on the server.
/// </summary>
public readonly HashSet<NetworkConnectionToClient> connections = new HashSet<NetworkConnectionToClient>();
public readonly HashSet<NetworkConnection> connections = new HashSet<NetworkConnection>();

/// <summary>
/// <para>If you enable this, the server will not listen for incoming connections on the regular network port.</para>
Expand Down Expand Up @@ -106,7 +106,7 @@ public class NetworkServer : MonoBehaviour
/// </summary>
public void Disconnect()
{
foreach (NetworkConnectionToClient conn in connections)
foreach (INetworkConnection conn in connections)
{
conn.Disconnect();
}
Expand Down Expand Up @@ -142,12 +142,12 @@ void Initialize()
}


internal void RegisterMessageHandlers(NetworkConnectionToClient connection)
internal void RegisterMessageHandlers(NetworkConnection connection)
{
connection.RegisterHandler<NetworkConnectionToClient, ReadyMessage>(OnClientReadyMessage);
connection.RegisterHandler<NetworkConnectionToClient, CommandMessage>(OnCommandMessage);
connection.RegisterHandler<NetworkConnectionToClient, RemovePlayerMessage>(OnRemovePlayerMessage);
connection.RegisterHandler<NetworkConnectionToClient, NetworkPingMessage>(Time.OnServerPing, false);
connection.RegisterHandler<NetworkConnection, ReadyMessage>(OnClientReadyMessage);
connection.RegisterHandler<NetworkConnection, CommandMessage>(OnCommandMessage);
connection.RegisterHandler<NetworkConnection, RemovePlayerMessage>(OnRemovePlayerMessage);
connection.RegisterHandler<NetworkConnection, NetworkPingMessage>(Time.OnServerPing, false);
}

/// <summary>
Expand Down Expand Up @@ -190,7 +190,7 @@ private async Task AcceptAsync()

while ((connection = await transport.AcceptAsync()) != null)
{
NetworkConnectionToClient networkConnectionToClient = new NetworkConnectionToClient(connection);
NetworkConnection networkConnectionToClient = new NetworkConnection(connection);

_ = ConnectionAcceptedAsync(networkConnectionToClient);
}
Expand Down Expand Up @@ -229,7 +229,7 @@ private void Cleanup()
/// </summary>
/// <param name="conn">Network connection to add.</param>
/// <returns>True if added.</returns>
public void AddConnection(NetworkConnectionToClient conn)
public void AddConnection(NetworkConnection conn)
{
if (!connections.Contains(conn))
{
Expand All @@ -245,7 +245,7 @@ public void AddConnection(NetworkConnectionToClient conn)
/// </summary>
/// <param name="connectionId">The id of the connection to remove.</param>
/// <returns>True if the removal succeeded</returns>
public void RemoveConnection(NetworkConnectionToClient conn)
public void RemoveConnection(NetworkConnection conn)
{
connections.Remove(conn);
}
Expand All @@ -259,7 +259,7 @@ internal void SetLocalConnection(NetworkClient client, IConnection tconn)
return;
}

NetworkConnectionToClient conn = new NetworkConnectionToClient(tconn);
NetworkConnection conn = new NetworkConnection(tconn);
localConnection = conn;
localClient = client;

Expand Down Expand Up @@ -369,7 +369,7 @@ internal void Update()
}
}

async Task ConnectionAcceptedAsync(NetworkConnectionToClient conn)
async Task ConnectionAcceptedAsync(NetworkConnection conn)
{
if (LogFilter.Debug) Debug.Log("Server accepted client:" + conn);

Expand Down Expand Up @@ -408,7 +408,7 @@ async Task ConnectionAcceptedAsync(NetworkConnectionToClient conn)
}


void OnDisconnected(NetworkConnectionToClient connection)
void OnDisconnected(NetworkConnection connection)
{
if (LogFilter.Debug) Debug.Log("Server disconnect client:" + connection);

Expand All @@ -422,7 +422,7 @@ void OnDisconnected(NetworkConnectionToClient connection)
localConnection = null;
}

internal void OnAuthenticated(NetworkConnectionToClient conn)
internal void OnAuthenticated(NetworkConnection conn)
{
if (LogFilter.Debug) Debug.Log("Server authenticate client:" + conn);

Expand Down Expand Up @@ -793,7 +793,7 @@ internal void SpawnObject(GameObject obj, NetworkConnection ownerConnection)
return;
}
identity.Reset();
identity.ConnectionToClient = (NetworkConnectionToClient)ownerConnection;
identity.ConnectionToClient = ownerConnection;
identity.Server = this;
identity.Client = localClient;

Expand Down
6 changes: 3 additions & 3 deletions Assets/Mirror/Runtime/PlayerSpawner.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using UnityEngine;

namespace Mirror
Expand Down Expand Up @@ -34,10 +34,10 @@ public virtual void Start()
client.RegisterPrefab(playerPrefab.gameObject);
}

private void OnServerAuthenticated(NetworkConnectionToClient connection)
private void OnServerAuthenticated(NetworkConnection connection)
{
// wait for client to send us an AddPlayerMessage
connection.RegisterHandler<NetworkConnectionToClient, AddPlayerMessage>(OnServerAddPlayerInternal);
connection.RegisterHandler<NetworkConnection, AddPlayerMessage>(OnServerAddPlayerInternal);
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions Assets/Mirror/Tests/Common/LocalConnections.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
namespace Mirror.Tests
namespace Mirror.Tests
{

public static class LocalConnections
{
public static (NetworkConnectionToServer, NetworkConnectionToClient) PipedConnections(bool authenticated = false)
public static (NetworkConnectionToServer, NetworkConnection) PipedConnections(bool authenticated = false)
{
(IConnection c1, IConnection c2) = PipeConnection.CreatePipe();
var toServer = new NetworkConnectionToServer(c2);
var toClient = new NetworkConnectionToClient(c1);
var toClient = new NetworkConnection(c1);

toServer.isAuthenticated = authenticated;
toClient.isAuthenticated = authenticated;
Expand All @@ -16,4 +16,4 @@ public static (NetworkConnectionToServer, NetworkConnectionToClient) PipedConnec
}

}
}
}

0 comments on commit bd95cea

Please sign in to comment.