mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
Remove hostId from NetworkServer and NetworkConnection because it was only needed for the old LLAPI. Also added comment for NetworkConnection.isConnected which can be removed later.
This commit is contained in:
parent
74b297819b
commit
619d5f47e3
@ -59,7 +59,7 @@ public void Connect(string ip)
|
|||||||
NetworkManager.singleton.transport.ClientConnect(ip);
|
NetworkManager.singleton.transport.ClientConnect(ip);
|
||||||
|
|
||||||
// setup all the handlers
|
// setup all the handlers
|
||||||
connection = new NetworkConnection(serverIp, 0, 0);
|
connection = new NetworkConnection(serverIp, 0);
|
||||||
connection.SetHandlers(handlers);
|
connection.SetHandlers(handlers);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,7 +11,6 @@ public class NetworkConnection : IDisposable
|
|||||||
|
|
||||||
Dictionary<short, NetworkMessageDelegate> m_MessageHandlers;
|
Dictionary<short, NetworkMessageDelegate> m_MessageHandlers;
|
||||||
|
|
||||||
public int hostId = -1;
|
|
||||||
public int connectionId = -1;
|
public int connectionId = -1;
|
||||||
public bool isReady;
|
public bool isReady;
|
||||||
public string address;
|
public string address;
|
||||||
@ -19,17 +18,20 @@ public class NetworkConnection : IDisposable
|
|||||||
public NetworkIdentity playerController => m_PlayerController;
|
public NetworkIdentity playerController => m_PlayerController;
|
||||||
public HashSet<uint> clientOwnedObjects;
|
public HashSet<uint> clientOwnedObjects;
|
||||||
public bool logNetworkMessages;
|
public bool logNetworkMessages;
|
||||||
public bool isConnected => hostId != -1;
|
|
||||||
|
// this is always true for regular connections, false for local
|
||||||
|
// connections because it's set in the constructor and never reset.
|
||||||
|
public bool isConnected { get; protected set; }
|
||||||
|
|
||||||
public NetworkConnection(string networkAddress)
|
public NetworkConnection(string networkAddress)
|
||||||
{
|
{
|
||||||
address = networkAddress;
|
address = networkAddress;
|
||||||
}
|
}
|
||||||
public NetworkConnection(string networkAddress, int networkHostId, int networkConnectionId)
|
public NetworkConnection(string networkAddress, int networkConnectionId)
|
||||||
{
|
{
|
||||||
address = networkAddress;
|
address = networkAddress;
|
||||||
hostId = networkHostId;
|
|
||||||
connectionId = networkConnectionId;
|
connectionId = networkConnectionId;
|
||||||
|
isConnected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
~NetworkConnection()
|
~NetworkConnection()
|
||||||
@ -82,12 +84,9 @@ public void Disconnect()
|
|||||||
NetworkManager.singleton.transport.ServerDisconnect(connectionId);
|
NetworkManager.singleton.transport.ServerDisconnect(connectionId);
|
||||||
}
|
}
|
||||||
|
|
||||||
// remove observers. original HLAPI has hostId check for that too.
|
// remove observers
|
||||||
if (hostId != -1)
|
|
||||||
{
|
|
||||||
RemoveObservers();
|
RemoveObservers();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
internal void SetHandlers(Dictionary<short, NetworkMessageDelegate> handlers)
|
internal void SetHandlers(Dictionary<short, NetworkMessageDelegate> handlers)
|
||||||
{
|
{
|
||||||
@ -149,7 +148,7 @@ internal virtual bool SendBytes( byte[] bytes, int channelId = Channels.DefaultR
|
|||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return string.Format("hostId: {0} connectionId: {1} isReady: {2}", hostId, connectionId, isReady);
|
return string.Format("connectionId: {0} isReady: {1}", connectionId, isReady);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal void AddToVisList(NetworkIdentity identity)
|
internal void AddToVisList(NetworkIdentity identity)
|
||||||
|
@ -17,8 +17,6 @@ public static class NetworkServer
|
|||||||
// => removed it for easier code. use .localConection now!
|
// => removed it for easier code. use .localConection now!
|
||||||
public static NetworkConnection localConnection => s_LocalConnection;
|
public static NetworkConnection localConnection => s_LocalConnection;
|
||||||
|
|
||||||
public static int serverHostId { get; private set; } = -1;
|
|
||||||
|
|
||||||
// <connectionId, NetworkConnection>
|
// <connectionId, NetworkConnection>
|
||||||
public static Dictionary<int, NetworkConnection> connections = new Dictionary<int, NetworkConnection>();
|
public static Dictionary<int, NetworkConnection> connections = new Dictionary<int, NetworkConnection>();
|
||||||
public static Dictionary<short, NetworkMessageDelegate> handlers = new Dictionary<short, NetworkMessageDelegate>();
|
public static Dictionary<short, NetworkMessageDelegate> handlers = new Dictionary<short, NetworkMessageDelegate>();
|
||||||
@ -46,7 +44,6 @@ public static void Shutdown()
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
NetworkManager.singleton.transport.ServerStop();
|
NetworkManager.singleton.transport.ServerStop();
|
||||||
serverHostId = -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
NetworkManager.singleton.transport.OnServerDisconnected.RemoveListener(OnDisconnected);
|
NetworkManager.singleton.transport.OnServerDisconnected.RemoveListener(OnDisconnected);
|
||||||
@ -94,7 +91,6 @@ public static bool Listen(int maxConnections)
|
|||||||
if (!dontListen)
|
if (!dontListen)
|
||||||
{
|
{
|
||||||
NetworkManager.singleton.transport.ServerStart();
|
NetworkManager.singleton.transport.ServerStart();
|
||||||
serverHostId = 0; // so it doesn't return false
|
|
||||||
if (LogFilter.Debug) { Debug.Log("Server started listening"); }
|
if (LogFilter.Debug) { Debug.Log("Server started listening"); }
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -278,11 +274,11 @@ static void UpdateServerObjects()
|
|||||||
// The user should never need to pump the update loop manually
|
// The user should never need to pump the update loop manually
|
||||||
internal static void Update()
|
internal static void Update()
|
||||||
{
|
{
|
||||||
if (serverHostId == -1)
|
if (active)
|
||||||
return;
|
{
|
||||||
|
|
||||||
UpdateServerObjects();
|
UpdateServerObjects();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void OnConnected(int connectionId)
|
static void OnConnected(int connectionId)
|
||||||
{
|
{
|
||||||
@ -315,7 +311,7 @@ static void OnConnected(int connectionId)
|
|||||||
string address = NetworkManager.singleton.transport.ServerGetClientAddress(connectionId);
|
string address = NetworkManager.singleton.transport.ServerGetClientAddress(connectionId);
|
||||||
|
|
||||||
// add player info
|
// add player info
|
||||||
NetworkConnection conn = new NetworkConnection(address, serverHostId, connectionId);
|
NetworkConnection conn = new NetworkConnection(address, connectionId);
|
||||||
OnConnected(conn);
|
OnConnected(conn);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user