breaking: NetworkServer.dontListen renamed to 'listen' to avoid double negative "dontListen=false" to listen

This commit is contained in:
mischa 2024-10-14 15:06:41 +02:00 committed by mischa
parent 13db82b347
commit 7ab1b394be
2 changed files with 18 additions and 6 deletions

View File

@ -55,7 +55,7 @@ void StartButtons()
// cant be a server in webgl build // cant be a server in webgl build
if (GUILayout.Button("Single Player")) if (GUILayout.Button("Single Player"))
{ {
NetworkServer.dontListen = true; NetworkServer.listen = false;
manager.StartHost(); manager.StartHost();
} }
#else #else

View File

@ -70,9 +70,21 @@ public static partial class NetworkServer
public static readonly Dictionary<uint, NetworkIdentity> spawned = public static readonly Dictionary<uint, NetworkIdentity> spawned =
new Dictionary<uint, NetworkIdentity>(); new Dictionary<uint, NetworkIdentity>();
/// <summary>Single player mode can use dontListen to not accept incoming connections</summary> /// <summary>Single player mode can set listen=false to not accept incoming connections.</summary>
// see also: https://github.com/vis2k/Mirror/pull/2595 static bool _listen = true;
public static bool dontListen; public static bool listen
{
get { return _listen; }
set { _listen = value; }
}
// DEPRECATED 2024-10-14
[Obsolete("NetworkServer.dontListen was replaced with NetworkServer.listen. The new value is the opposite, and avoids double negatives like 'dontListen=false'")]
public static bool dontListen
{
get => !listen;
set => listen = !value;
}
/// <summary>active checks if the server has been started either has standalone or as host server.</summary> /// <summary>active checks if the server has been started either has standalone or as host server.</summary>
public static bool active { get; internal set; } public static bool active { get; internal set; }
@ -137,7 +149,7 @@ public static void Listen(int maxConns)
maxConnections = maxConns; maxConnections = maxConns;
// only start server if we want to listen // only start server if we want to listen
if (!dontListen) if (listen)
{ {
Transport.active.ServerStart(); Transport.active.ServerStart();
@ -241,7 +253,7 @@ public static void Shutdown()
} }
// Reset all statics here.... // Reset all statics here....
dontListen = false; listen = true;
isLoadingScene = false; isLoadingScene = false;
lastSendTime = 0; lastSendTime = 0;
actualTickRate = 0; actualTickRate = 0;