mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
Remove NetworkConnection.lastMessageTime & IsClientAlive
This commit is contained in:
parent
de6b63ef2f
commit
aec2a71802
@ -55,12 +55,6 @@ public abstract class NetworkConnection : IDisposable
|
||||
/// </summary>
|
||||
public abstract string address { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The last time that a message was received on this connection.
|
||||
/// <para>This includes internal system messages (such as Commands and ClientRpc calls) and user messages.</para>
|
||||
/// </summary>
|
||||
public float lastMessageTime;
|
||||
|
||||
/// <summary>
|
||||
/// The NetworkIdentity for this connection.
|
||||
/// </summary>
|
||||
@ -78,11 +72,7 @@ public abstract class NetworkConnection : IDisposable
|
||||
/// <summary>
|
||||
/// Creates a new NetworkConnection
|
||||
/// </summary>
|
||||
internal NetworkConnection()
|
||||
{
|
||||
// set lastTime to current time when creating connection to make sure it isn't instantly kicked for inactivity
|
||||
lastMessageTime = Time.time;
|
||||
}
|
||||
internal NetworkConnection() {}
|
||||
|
||||
/// <summary>
|
||||
/// Creates a new NetworkConnection with the specified connectionId
|
||||
@ -261,10 +251,7 @@ internal void TransportReceive(ArraySegment<byte> buffer, int channelId)
|
||||
// Debug.Log("ConnectionRecv " + this + " msgType:" + msgType + " content:" + BitConverter.ToString(buffer.Array, buffer.Offset, buffer.Count));
|
||||
|
||||
// try to invoke the handler for that message
|
||||
if (InvokeHandler(msgType, networkReader, channelId))
|
||||
{
|
||||
lastMessageTime = Time.time;
|
||||
}
|
||||
InvokeHandler(msgType, networkReader, channelId);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -274,17 +261,6 @@ internal void TransportReceive(ArraySegment<byte> buffer, int channelId)
|
||||
}
|
||||
}
|
||||
|
||||
// Failsafe to kick clients that have stopped sending anything to the server.
|
||||
// Clients Ping the server every 2 seconds but transports are unreliable
|
||||
// when it comes to properly generating Disconnect messages to the server.
|
||||
// This cannot be abstract because then NetworkConnectionToServer
|
||||
// would require and override that would never be called
|
||||
// This is overriden in NetworkConnectionToClient.
|
||||
internal virtual bool IsClientAlive()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
internal void AddOwnedObject(NetworkIdentity obj)
|
||||
{
|
||||
clientOwnedObjects.Add(obj);
|
||||
|
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Mirror
|
||||
{
|
||||
@ -14,11 +13,6 @@ public NetworkConnectionToClient(int networkConnectionId) : base(networkConnecti
|
||||
// the client. they would be detected as a message. send messages instead.
|
||||
readonly List<int> singleConnectionId = new List<int> { -1 };
|
||||
|
||||
// Failsafe to kick clients that have stopped sending anything to the server.
|
||||
// Clients ping the server every 2 seconds but transports are unreliable
|
||||
// when it comes to properly generating Disconnect messages to the server.
|
||||
internal override bool IsClientAlive() => Time.time - lastMessageTime < NetworkServer.disconnectInactiveTimeout;
|
||||
|
||||
internal override bool Send(ArraySegment<byte> segment, int channelId = Channels.DefaultReliable)
|
||||
{
|
||||
//Debug.Log("ConnectionSend " + this + " bytes:" + BitConverter.ToString(segment.Array, segment.Offset, segment.Count));
|
||||
|
@ -104,23 +104,6 @@ public class NetworkManager : MonoBehaviour
|
||||
[Tooltip("Maximum number of concurrent connections.")]
|
||||
public int maxConnections = 4;
|
||||
|
||||
// This value is passed to NetworkServer in SetupServer
|
||||
/// <summary>
|
||||
/// Should the server disconnect remote connections that have gone silent for more than Server Idle Timeout?
|
||||
/// </summary>
|
||||
[Tooltip("Server Only - Disconnects remote connections that have been silent for more than Server Idle Timeout")]
|
||||
public bool disconnectInactiveConnections;
|
||||
|
||||
// This value is passed to NetworkServer in SetupServer
|
||||
/// <summary>
|
||||
/// Timeout in seconds since last message from a client after which server will auto-disconnect.
|
||||
/// <para>By default, clients send at least a Ping message every 2 seconds.</para>
|
||||
/// <para>The Host client is immune from idle timeout disconnection.</para>
|
||||
/// <para>Default value is 60 seconds.</para>
|
||||
/// </summary>
|
||||
[Tooltip("Timeout in seconds since last message from a client after which server will auto-disconnect if Disconnect Inactive Connections is enabled.")]
|
||||
public float disconnectInactiveTimeout = 60f;
|
||||
|
||||
[Header("Authentication")]
|
||||
[Tooltip("Authentication component attached to this object")]
|
||||
public NetworkAuthenticator authenticator;
|
||||
@ -313,10 +296,6 @@ void SetupServer()
|
||||
|
||||
ConfigureServerFrameRate();
|
||||
|
||||
// Copy auto-disconnect settings to NetworkServer
|
||||
NetworkServer.disconnectInactiveTimeout = disconnectInactiveTimeout;
|
||||
NetworkServer.disconnectInactiveConnections = disconnectInactiveConnections;
|
||||
|
||||
// start listening to network connections
|
||||
NetworkServer.Listen(maxConnections);
|
||||
|
||||
|
@ -43,12 +43,6 @@ public static class NetworkServer
|
||||
/// </summary>
|
||||
public static bool active { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Should the server disconnect remote connections that have gone silent for more than Server Idle Timeout?
|
||||
/// <para>This value is initially set from NetworkManager in SetupServer and can be changed at runtime</para>
|
||||
/// </summary>
|
||||
public static bool disconnectInactiveConnections;
|
||||
|
||||
/// <summary>
|
||||
/// Timeout in seconds since last message from a client after which server will auto-disconnect.
|
||||
/// <para>This value is initially set from NetworkManager in SetupServer and can be changed at runtime</para>
|
||||
@ -406,20 +400,6 @@ public static void Update()
|
||||
if (!active)
|
||||
return;
|
||||
|
||||
// Check for dead clients but exclude the host client because it
|
||||
// doesn't ping itself and therefore may appear inactive.
|
||||
if (disconnectInactiveConnections)
|
||||
{
|
||||
foreach (NetworkConnectionToClient conn in connections.Values)
|
||||
{
|
||||
if (!conn.IsClientAlive())
|
||||
{
|
||||
Debug.LogWarning($"Disconnecting {conn} for inactivity!");
|
||||
conn.Disconnect();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// update all server objects
|
||||
foreach (KeyValuePair<uint, NetworkIdentity> kvp in NetworkIdentity.spawned)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user