mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 02:50:32 +00:00
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:
parent
dbd1afe53b
commit
4d8b02ce35
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user