From 245c94e6b10c3588fbefcc45b1c9c1d04e09ccb3 Mon Sep 17 00:00:00 2001 From: vis2k Date: Sun, 30 Dec 2018 22:04:05 +0100 Subject: [PATCH] Remove NetworkClient/NetworkServer.NetworkConnectionClass magic --- Mirror/Runtime/LocalConnections.cs | 6 ++---- Mirror/Runtime/NetworkClient.cs | 12 +----------- Mirror/Runtime/NetworkConnection.cs | 6 +++++- Mirror/Runtime/NetworkServer.cs | 10 +--------- 4 files changed, 9 insertions(+), 25 deletions(-) diff --git a/Mirror/Runtime/LocalConnections.cs b/Mirror/Runtime/LocalConnections.cs index 348154e50..af3188965 100644 --- a/Mirror/Runtime/LocalConnections.cs +++ b/Mirror/Runtime/LocalConnections.cs @@ -11,9 +11,8 @@ class ULocalConnectionToClient : NetworkConnection public LocalClient localClient { get { return m_LocalClient; } } - public ULocalConnectionToClient(LocalClient localClient) + public ULocalConnectionToClient(LocalClient localClient) : base ("localClient") { - address = "localClient"; m_LocalClient = localClient; } @@ -28,9 +27,8 @@ protected override bool SendBytes(byte[] bytes, int channelId = Channels.Default // send messages on this connection causes the server's handler function to be invoked directly. internal class ULocalConnectionToServer : NetworkConnection { - public ULocalConnectionToServer() + public ULocalConnectionToServer() : base("localServer") { - address = "localServer"; } protected override bool SendBytes(byte[] bytes, int channelId = Channels.DefaultReliable) diff --git a/Mirror/Runtime/NetworkClient.cs b/Mirror/Runtime/NetworkClient.cs index 4d240a7fd..681b98e7e 100644 --- a/Mirror/Runtime/NetworkClient.cs +++ b/Mirror/Runtime/NetworkClient.cs @@ -8,8 +8,6 @@ namespace Mirror { public class NetworkClient { - Type m_NetworkConnectionClass = typeof(NetworkConnection); - static bool s_IsActive; public static List allClients = new List(); @@ -47,13 +45,6 @@ internal void SetHandlers(NetworkConnection conn) public bool isConnected { get { return connectState == ConnectState.Connected; } } - public Type networkConnectionClass { get { return m_NetworkConnectionClass; } } - - public void SetNetworkConnectionClass() where T : NetworkConnection - { - m_NetworkConnectionClass = typeof(T); - } - public NetworkClient() { if (LogFilter.Debug) { Debug.Log("Client created version " + Version.Current); } @@ -86,9 +77,8 @@ public void Connect(string serverIp, ushort serverPort) Transport.layer.ClientConnect(serverIp, serverPort); // setup all the handlers - m_Connection = (NetworkConnection)Activator.CreateInstance(m_NetworkConnectionClass); + m_Connection = new NetworkConnection(m_ServerIp, m_ClientId, 0); m_Connection.SetHandlers(m_MessageHandlers); - m_Connection.Initialize(m_ServerIp, m_ClientId, 0); } void PrepareForConnect() diff --git a/Mirror/Runtime/NetworkConnection.cs b/Mirror/Runtime/NetworkConnection.cs index 416e4c795..1c2fec0ff 100644 --- a/Mirror/Runtime/NetworkConnection.cs +++ b/Mirror/Runtime/NetworkConnection.cs @@ -23,7 +23,11 @@ public class NetworkConnection : IDisposable public bool logNetworkMessages; public bool isConnected { get { return hostId != -1; }} - public virtual void Initialize(string networkAddress, int networkHostId, int networkConnectionId) + public NetworkConnection(string networkAddress) + { + address = networkAddress; + } + public NetworkConnection(string networkAddress, int networkHostId, int networkConnectionId) { address = networkAddress; hostId = networkHostId; diff --git a/Mirror/Runtime/NetworkServer.cs b/Mirror/Runtime/NetworkServer.cs index 66a20543a..11926df04 100644 --- a/Mirror/Runtime/NetworkServer.cs +++ b/Mirror/Runtime/NetworkServer.cs @@ -34,13 +34,6 @@ public sealed class NetworkServer public static bool active { get { return s_Active; } } public static bool localClientActive { get { return s_LocalClientActive; } } - static Type s_NetworkConnectionClass = typeof(NetworkConnection); - public static Type networkConnectionClass { get { return s_NetworkConnectionClass; } } - public static void SetNetworkConnectionClass() where T : NetworkConnection - { - s_NetworkConnectionClass = typeof(T); - } - public static void Reset() { s_Active = false; @@ -369,8 +362,7 @@ static void HandleConnect(int connectionId, byte error) Transport.layer.GetConnectionInfo(connectionId, out address); // add player info - NetworkConnection conn = (NetworkConnection)Activator.CreateInstance(s_NetworkConnectionClass); - conn.Initialize(address, s_ServerHostId, connectionId); + NetworkConnection conn = new NetworkConnection(address, s_ServerHostId, connectionId); AddConnection(conn); OnConnected(conn); }