protected override IEnumerator ExecuteRoutine() { // request sync to server NetMessageRequestSimSync syncRequest = new NetMessageRequestSimSync(); _sessionInterface.SendNetMessageToServer(syncRequest); // wait for server response _sessionInterface.RegisterNetMessageReceiver <NetMessageSerializedSimulation>(OnNetMessageSerializedSimulation); // wait for _loadPath to be assigned while (_receivedResponseFromServer == false) { yield return(null); } _sessionInterface.UnregisterNetMessageReceiver <NetMessageSerializedSimulation>(OnNetMessageSerializedSimulation); // terminate if load path is invalid if (_simData == null || _simData.Length == 0) { TerminateWithAbnormalFailure($"Invalid simulation data received from the server. Prehaps it failed to serialize it."); yield break; } yield return(ExecuteSubOperationAndWaitForSuccess(new Sim.Operations.SimDeserializationOperation(_simData, _simulationWorld))); TerminateWithSuccess(); }
protected override IEnumerator ExecuteRoutine() { // fbessette NB: As a first iteration, the server will save the simulation to a local text file. // The client (on the same PC) will load the simulation from that text file. // This will only work for "local" multiplayer (server and clients on the same PC). // // In future iterations, the server should upload the simulation directly to the other player. // file name example: SerializedSim-515433 // request sync to server NetMessageRequestSimSync syncRequest = new NetMessageRequestSimSync(); _sessionInterface.SendNetMessageToServer(syncRequest); // wait for server response _sessionInterface.RegisterNetMessageReceiver <NetMessageSimSyncFromFile>(OnNetMessageSimSyncFromFile); // wait for _loadPath to be assigned while (_receivedResponseFromServer == false) { yield return(null); } _sessionInterface.UnregisterNetMessageReceiver <NetMessageSimSyncFromFile>(OnNetMessageSimSyncFromFile); // terminate if load path is invalid if (string.IsNullOrEmpty(_simLoadFile)) { TerminateWithAbnormalFailure($"Invalid simulation load file path received from the server ({_simLoadFile}). Prehaps it failed to serialize it."); yield break; } yield return(ExecuteSubOperationAndWaitForSuccess(new LoadSimulationFromDiskOperation(_simLoadFile, _simulationWorld))); TerminateWithSuccess(); }
private void OnSimSyncRequest(NetMessageRequestSimSync requestSync, INetworkInterfaceConnection source) { LaunchSyncForClient(source); }