Exemple #1
0
    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();
    }
    public override void SubmitMessage(string message)
    {
        // Build the net message
        NetMessageChatMessageSubmission submission = new NetMessageChatMessageSubmission()
        {
            message = message
        };

        // send to server
        _session.SendNetMessageToServer(submission);
    }
    protected override void Internal_OnGameReady()
    {
        _localPlayerInfo.IsMaster = false;
        _localPlayerInfo.PlayerId = PlayerId.Invalid;

        // Say hello to server ! (this should initiate the process of being added to valid players)
        NetMessageClientHello helloMessage = new NetMessageClientHello()
        {
            playerName = _localPlayerInfo.PlayerName
        };

        _clientSession.SendNetMessageToServer(helloMessage);
        Log.Info("[PlayerRepertoireClient] Hello sent");
    }
    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();
    }