Esempio n. 1
0
        /// <summary>
        /// Called on the server when a pause state confirmation message has been received and unpackaged.
        ///
        /// Checks whether all other clients have paused and if so continues its queued process (AddPlayer etc)
        /// </summary>
        /// <param name="networkStateConfirmation"></param>
        /// <param name="conn"></param>
        private void OnServerProcessPauseConfirmation(NetworkStateConfirmation networkStateConfirmation, NetworkConnection conn)
        {
            if (_awaitingConfirmation.Item2 == networkStateConfirmation.NewState)
            {
                // Host connection special rule for removal...could not send the confirmation regular way
                // so instead using local method invoking on the server
                if (conn.connectionId == 0)
                {
                    _awaitingConfirmation.Item3.RemoveAll(x => x.connectionId == 0);
                }
                else
                {
                    _awaitingConfirmation.Item3.Remove(conn);
                }

                // All clients have confirmed that they changed state, now the server must process the new state
                if (_awaitingConfirmation.Item3.Count == 0)
                {
                    StartCoroutine(OnServerProcessNewPlayers());
                }
            }
            // otherwise....what has gone wrong
            else
            {
                Debug.LogError("<color=#4688f2><b>[CustomNetworkManager]</b></color> " +
                               "- OnServerProcessStateConfirmation(NetworkStateConfirmation, NetworkConnection) \n" +
                               $"Fatal Error - A client with connection Id: {conn.connectionId} is trying to change to a different game state.\n" +
                               $"Expected: {_awaitingConfirmation.Item2.ToString()} \n" +
                               $"Received: {networkStateConfirmation.NewState.ToString()}.");
            }
        }
Esempio n. 2
0
        private void OnServerReceiveStateConfirmation(NetworkMessage networkMessage)
        {
            NetworkStateConfirmation networkStateConfirmation = networkMessage.ReadMessage <NetworkStateConfirmation>();

            switch (networkStateConfirmation.NewState)
            {
            case EGameState.Waking:
            {
                OnServerProcessWakingConfirmation(networkMessage.conn);
                break;
            }

            case EGameState.Paused:
            {
                OnServerProcessPauseConfirmation(networkStateConfirmation, networkMessage.conn);
                break;
            }

            default: break;
            }
        }