ConnectHost moved into FinishStartHost

This commit is contained in:
vis2k 2020-01-05 20:42:41 +01:00
parent f33d90a4ca
commit 7776049526

View File

@ -454,6 +454,34 @@ void StartHostClient()
bool finishStartHostPending;
void FinishStartHost()
{
// ConnectHost needs to be called BEFORE SpawnObjects:
// https://github.com/vis2k/Mirror/pull/1249/
// -> this sets NetworkServer.localConnection.
// -> 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
// get OnDeserialize calls, where SyncVar hooks are usually
// called):
//
// if (!SyncVarEqual(value, ref color))
// {
// if (NetworkServer.localClientActive && !getSyncVarHookGuard(1uL))
// {
// setSyncVarHookGuard(1uL, value: true);
// OnColorChangedHook(value);
// setSyncVarHookGuard(1uL, value: false);
// }
// SetSyncVar(value, ref color, 1uL);
// }
//
// -> localClientActive needs to be true, otherwise the hook
// isn't called in host mode!
//
// TODO call this after spawnobjects and worry about the syncvar hook fix later?
NetworkClient.ConnectHost();
// server scene was loaded. now spawn all the objects
NetworkServer.SpawnObjects();
@ -502,34 +530,6 @@ public virtual void StartHost()
// is called after the server is actually properly started.
OnStartHost();
// TODO move this into FinishStartHost! (and test if it still works)
//
// ConnectHost needs to be called BEFORE SpawnObjects:
// https://github.com/vis2k/Mirror/pull/1249/
// -> this sets NetworkServer.localConnection.
// -> 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
// get OnDeserialize calls, where SyncVar hooks are usually
// called):
//
// if (!SyncVarEqual(value, ref color))
// {
// if (NetworkServer.localClientActive && !getSyncVarHookGuard(1uL))
// {
// setSyncVarHookGuard(1uL, value: true);
// OnColorChangedHook(value);
// setSyncVarHookGuard(1uL, value: false);
// }
// SetSyncVar(value, ref color, 1uL);
// }
//
// -> localClientActive needs to be true, otherwise the hook
// isn't called in host mode!
NetworkClient.ConnectHost();
// scene change needed? then change scene and spawn afterwards.
// => BEFORE host client connects. if client auth succeeds then the
// server tells it to load 'onlineScene'. we can't do that if