prevent multiple client or server to start (#2398)

* Return and log warning on start already started client or server

* Apply suggestions from code review, Always check for client and server active state

Co-authored-by: MrGadget <9826063+MrGadget1024@users.noreply.github.com>

* Update Assets/Mirror/Runtime/NetworkManager.cs

* Update Assets/Mirror/Runtime/NetworkManager.cs

* Update Assets/Mirror/Runtime/NetworkManager.cs

* Update Assets/Mirror/Runtime/NetworkManager.cs

* Update Assets/Mirror/Runtime/NetworkManager.cs

* Update Assets/Mirror/Runtime/NetworkManager.cs

Co-authored-by: MrGadget <9826063+MrGadget1024@users.noreply.github.com>
Co-authored-by: vis2k <info@noobtuts.com>
This commit is contained in:
Sulexa 2020-11-07 10:13:47 +01:00 committed by GitHub
parent dbd1afe53b
commit 4d8b02ce35
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -336,6 +336,12 @@ void SetupServer()
/// </summary>
public void StartServer()
{
if (NetworkServer.active)
{
logger.LogWarning("Server already started.")
return;
}
mode = NetworkManagerMode.ServerOnly;
// StartServer is inherently ASYNCHRONOUS (=doesn't finish immediately)
@ -374,6 +380,12 @@ public void StartServer()
/// </summary>
public void StartClient()
{
if (NetworkClient.active)
{
logger.LogWarning("Client already started.")
return;
}
mode = NetworkManagerMode.ClientOnly;
InitializeSingleton();
@ -410,6 +422,12 @@ public void StartClient()
/// <param name="uri">location of the server to connect to</param>
public void StartClient(Uri uri)
{
if (NetworkClient.active)
{
logger.LogWarning("Client already started.")
return;
}
mode = NetworkManagerMode.ClientOnly;
InitializeSingleton();
@ -443,6 +461,12 @@ public void StartClient(Uri uri)
/// </summary>
public void StartHost()
{
if (NetworkServer.active || NetworkClient.active)
{
logger.LogWarning("Server or Client already started.")
return;
}
mode = NetworkManagerMode.Host;
// StartHost is inherently ASYNCHRONOUS (=doesn't finish immediately)