mirror of
https://github.com/MirrorNetworking/Mirror.git
synced 2024-11-18 11:00:32 +00:00
StartServer split into SetupServer and spawning. Prepares for local connection removal.
This commit is contained in:
commit
d9b77ec4d0
@ -273,15 +273,10 @@ bool IsServerOnlineSceneChangeNeeded()
|
||||
return !string.IsNullOrEmpty(onlineScene) && onlineScene != loadedSceneName && onlineScene != offlineScene;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This starts a new server.
|
||||
/// <para>This uses the networkPort property as the listen port.</para>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public void StartServer()
|
||||
// full server setup code, without spawning objects yet
|
||||
void SetupServer()
|
||||
{
|
||||
if (LogFilter.Debug) Debug.Log("NetworkManager StartServer");
|
||||
|
||||
if (LogFilter.Debug) Debug.Log("NetworkManager SetupServer");
|
||||
InitializeSingleton();
|
||||
|
||||
if (runInBackground)
|
||||
@ -312,6 +307,16 @@ public void StartServer()
|
||||
RegisterServerMessages();
|
||||
|
||||
isNetworkActive = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// This starts a new server.
|
||||
/// <para>This uses the networkPort property as the listen port.</para>
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public void StartServer()
|
||||
{
|
||||
SetupServer();
|
||||
|
||||
// scene change needed? then change scene and spawn afterwards.
|
||||
if (IsServerOnlineSceneChangeNeeded())
|
||||
@ -394,13 +399,15 @@ public void StartClient(Uri uri)
|
||||
/// </summary>
|
||||
public virtual void StartHost()
|
||||
{
|
||||
// setup server first
|
||||
OnStartHost();
|
||||
SetupServer();
|
||||
|
||||
// SetupLocalConnection needs to be called BEFORE StartServer:
|
||||
// SetupLocalConnection needs to be called BEFORE SpawnObjects:
|
||||
// https://github.com/vis2k/Mirror/pull/1249/
|
||||
// -> this sets NetworkServer.localConnection.
|
||||
// -> localConnection needs to be set before StartServer because:
|
||||
// -> StartServer calls OnStartServer
|
||||
// -> localConnection needs to be set before SpawnObjects because:
|
||||
// -> SpawnObjects calls OnStartServer in all NetworkBehaviours
|
||||
// -> OnStartServer might spawn an object and set [SyncVar(hook="OnColorChanged")] object.color = green;
|
||||
// -> this calls SyncVar.set (generated by Weaver), which has
|
||||
// a custom case for host mode (because host mode doesn't
|
||||
@ -421,7 +428,20 @@ public virtual void StartHost()
|
||||
// -> localClientActive needs to be true, otherwise the hook
|
||||
// isn't called in host mode!
|
||||
NetworkClient.SetupLocalConnection();
|
||||
StartServer();
|
||||
|
||||
// scene change needed? then change scene and spawn afterwards.
|
||||
if (IsServerOnlineSceneChangeNeeded())
|
||||
{
|
||||
ServerChangeScene(onlineScene);
|
||||
}
|
||||
// otherwise spawn directly
|
||||
else
|
||||
{
|
||||
NetworkServer.SpawnObjects();
|
||||
}
|
||||
|
||||
// connect client and call OnStartClient AFTER any possible server
|
||||
// scene changes.
|
||||
ConnectLocalClient();
|
||||
OnStartClient();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user