コード例 #1
0
 private static void ClientIsConnected(IMultiplayerSessionConnectionContext sessionConnectionContext)
 {
     if (!sessionConnectionContext.Client.IsConnected)
     {
         throw new InvalidOperationException("Клиент не подключен.");
     }
 }
コード例 #2
0
        public void JoinSessionShouldTransitionToSessionJoinedState()
        {
            // Arrange
            MultiplayerSessionReservation successfulReservation = new MultiplayerSessionReservation(
                TestConstants.TEST_CORRELATION_ID,
                TestConstants.TEST_PLAYER_ID,
                TestConstants.TEST_RESERVATION_KEY);

            IClient serverClient = Substitute.For <IClient>();

            serverClient.IsConnected.Returns(true);

            IMultiplayerSessionConnectionContext connectionContext = Substitute.For <IMultiplayerSessionConnectionContext>();

            connectionContext.Reservation.Returns(successfulReservation);
            connectionContext.Client.Returns(serverClient);

            SessionReserved connection = new SessionReserved();

            // Act
            connection.JoinSession(connectionContext);

            // Assert
            connectionContext.Received().UpdateConnectionState(Arg.Any <SessionJoined>());
        }
コード例 #3
0
 private static void ClientIsConnected(IMultiplayerSessionConnectionContext sessionConnectionContext)
 {
     if (!sessionConnectionContext.Client.IsConnected)
     {
         throw new InvalidOperationException("The client is not connected.");
     }
 }
コード例 #4
0
 private void ReservationPacketIsCorrelated(IMultiplayerSessionConnectionContext sessionConnectionContext)
 {
     if (!reservationCorrelationId.Equals(sessionConnectionContext.Reservation.CorrelationId))
     {
         throw new UncorrelatedPacketException(sessionConnectionContext.Reservation, reservationCorrelationId);
     }
 }
コード例 #5
0
        public void JoinSessionShouldSendPlayerJoiningMultiplayerSessionPacket()
        {
            // Arrange
            MultiplayerSessionReservation successfulReservation = new MultiplayerSessionReservation(
                TestConstants.TEST_CORRELATION_ID,
                TestConstants.TEST_PLAYER_ID,
                TestConstants.TEST_RESERVATION_KEY);

            IClient client = Substitute.For <IClient>();

            client.IsConnected.Returns(true);

            IMultiplayerSessionConnectionContext connectionContext = Substitute.For <IMultiplayerSessionConnectionContext>();

            connectionContext.Reservation.Returns(successfulReservation);
            connectionContext.Client.Returns(client);

            SessionReserved connectionState = new SessionReserved();

            // Act
            connectionState.JoinSession(connectionContext);

            // Assert
            client.Received().Send(Arg.Any <PlayerJoiningMultiplayerSession>());
        }
コード例 #6
0
 private void SessionPolicyPacketCorrelation(IMultiplayerSessionConnectionContext sessionConnectionContext)
 {
     if (!policyRequestCorrelationId.Equals(sessionConnectionContext.SessionPolicy.CorrelationId))
     {
         throw new UncorrelatedPacketException(sessionConnectionContext.SessionPolicy, policyRequestCorrelationId);
     }
 }
コード例 #7
0
        private static void HandleReservation(IMultiplayerSessionConnectionContext sessionConnectionContext)
        {
            IMultiplayerSessionConnectionState nextState = sessionConnectionContext.Reservation.ReservationState == MultiplayerSessionReservationState.Reserved
                ? new SessionReserved()
                : new SessionReservationRejected() as IMultiplayerSessionConnectionState;

            sessionConnectionContext.UpdateConnectionState(nextState);
        }
コード例 #8
0
ファイル: CommunicatingState.cs プロジェクト: EmidioMata/1.2
        public virtual void Disconnect(IMultiplayerSessionConnectionContext sessionConnectionContext)
        {
            sessionConnectionContext.ClearSessionState();
            sessionConnectionContext.Client.Stop();

            Disconnected newConnectionState = new Disconnected();

            sessionConnectionContext.UpdateConnectionState(newConnectionState);
        }
コード例 #9
0
        private void RequestSessionReservation(IMultiplayerSessionConnectionContext sessionConnectionContext, string reservationCorrelationId)
        {
            IClient               client                = sessionConnectionContext.Client;
            PlayerSettings        playerSettings        = sessionConnectionContext.PlayerSettings;
            AuthenticationContext authenticationContext = sessionConnectionContext.AuthenticationContext;

            MultiplayerSessionReservationRequest requestPacket = new MultiplayerSessionReservationRequest(reservationCorrelationId, playerSettings, authenticationContext);

            client.Send(requestPacket);
        }
コード例 #10
0
        private static void HandleReservation(IMultiplayerSessionConnectionContext sessionConnectionContext)
        {
            IMultiplayerSessionConnectionState nextState = sessionConnectionContext.Reservation.ReservationState switch
            {
                MultiplayerSessionReservationState.RESERVED => new SessionReserved(),
                _ => new SessionReservationRejected(),
            };

            sessionConnectionContext.UpdateConnectionState(nextState);
        }
コード例 #11
0
 private static void ReservationIsNotNull(IMultiplayerSessionConnectionContext sessionConnectionContext)
 {
     try
     {
         Validate.NotNull(sessionConnectionContext.Reservation);
     }
     catch (ArgumentNullException ex)
     {
         throw new InvalidOperationException("Контекст не имеет резервации.", ex);
     }
 }
コード例 #12
0
 private static void AuthenticationContextIsNotNull(IMultiplayerSessionConnectionContext sessionConnectionContext)
 {
     try
     {
         Validate.NotNull(sessionConnectionContext.AuthenticationContext);
     }
     catch (ArgumentNullException ex)
     {
         throw new InvalidOperationException("Контекст не содержит контекст аутентификации.", ex);
     }
 }
コード例 #13
0
 private static void PlayerSettingsIsNotNull(IMultiplayerSessionConnectionContext sessionConnectionContext)
 {
     try
     {
         Validate.NotNull(sessionConnectionContext.PlayerSettings);
     }
     catch (ArgumentNullException ex)
     {
         throw new InvalidOperationException("Контекст не содержит настроек игрока.", ex);
     }
 }
コード例 #14
0
 private static void SessionPolicyIsNotNull(IMultiplayerSessionConnectionContext sessionConnectionContext)
 {
     try
     {
         Validate.NotNull(sessionConnectionContext.SessionPolicy);
     }
     catch (ArgumentNullException ex)
     {
         throw new InvalidOperationException("The context is missing a session policy.", ex);
     }
 }
コード例 #15
0
 private static void ReservationIsNotNull(IMultiplayerSessionConnectionContext sessionConnectionContext)
 {
     try
     {
         Validate.NotNull(sessionConnectionContext.Reservation);
     }
     catch (ArgumentNullException ex)
     {
         throw new InvalidOperationException("The context does not have a reservation.", ex);
     }
 }
コード例 #16
0
 private static void AuthenticationContextIsNotNull(IMultiplayerSessionConnectionContext sessionConnectionContext)
 {
     try
     {
         Validate.NotNull(sessionConnectionContext.AuthenticationContext);
     }
     catch (ArgumentNullException ex)
     {
         throw new InvalidOperationException("The context does not contain an authentication context.", ex);
     }
 }
コード例 #17
0
ファイル: Disconnected.cs プロジェクト: EmidioMata/1.2
 private static void ValidateClient(IMultiplayerSessionConnectionContext sessionConnectionContext)
 {
     try
     {
         Validate.NotNull(sessionConnectionContext.Client);
     }
     catch (ArgumentNullException ex)
     {
         throw new InvalidOperationException("The client must be set on the connection context before trying to negotiate a session reservation.", ex);
     }
 }
コード例 #18
0
 private static void PlayerSettingsIsNotNull(IMultiplayerSessionConnectionContext sessionConnectionContext)
 {
     try
     {
         Validate.NotNull(sessionConnectionContext.PlayerSettings);
     }
     catch (ArgumentNullException ex)
     {
         throw new InvalidOperationException("The context does not contain player settings.", ex);
     }
 }
コード例 #19
0
        private void EnterMultiplayerSession(IMultiplayerSessionConnectionContext sessionConnectionContext)
        {
            IClient client = sessionConnectionContext.Client;
            MultiplayerSessionReservation reservation = sessionConnectionContext.Reservation;
            string correlationId  = reservation.CorrelationId;
            string reservationKey = reservation.ReservationKey;

            PlayerJoiningMultiplayerSession packet = new PlayerJoiningMultiplayerSession(correlationId, reservationKey);

            client.Send(packet);
        }
コード例 #20
0
        public void DisconnectShouldThrowInvalidOperationException()
        {
            // Arrange
            IMultiplayerSessionConnectionContext connectionContext = Substitute.For <IMultiplayerSessionConnectionContext>();
            Disconnected connectionState = new Disconnected();

            // Act
            Action action = () => connectionState.Disconnect(connectionContext);

            // Assert
            action.ShouldThrow <InvalidOperationException>();
        }
コード例 #21
0
        public void JoinSessionShouldThrowInvalidOperationExcepion()
        {
            // Arrange
            IMultiplayerSessionConnectionContext connectionContext = Substitute.For <IMultiplayerSessionConnectionContext>();
            SessionReservationRejected           connectionState   = new SessionReservationRejected();

            // Act
            Action action = () => connectionState.JoinSession(connectionContext);

            // Assert
            action.ShouldThrow <InvalidOperationException>();
        }
コード例 #22
0
ファイル: Disconnected.cs プロジェクト: EmidioMata/1.2
        private static void EstablishSessionPolicy(IMultiplayerSessionConnectionContext sessionConnectionContext, IClient client)
        {
            string policyRequestCorrelationId = Guid.NewGuid().ToString();

            MultiplayerSessionPolicyRequest requestPacket = new MultiplayerSessionPolicyRequest(policyRequestCorrelationId);

            client.Send(requestPacket);

            EstablishingSessionPolicy nextState = new EstablishingSessionPolicy(policyRequestCorrelationId);

            sessionConnectionContext.UpdateConnectionState(nextState);
        }
コード例 #23
0
        public void JoinSessionShouldThrowInvalidOperationException()
        {
            // Arrange
            IMultiplayerSessionConnectionContext connectionContext = Substitute.For <IMultiplayerSessionConnectionContext>();
            AwaitingReservationCredentials       connectionState   = new AwaitingReservationCredentials();

            // Act
            Action action = () => connectionState.JoinSession(connectionContext);

            // Assert
            action.Should().Throw <InvalidOperationException>();
        }
コード例 #24
0
        public void JoinSessionShouldThrowInvalidOperationException()
        {
            // Arrange
            IMultiplayerSessionConnectionContext connectionContext = Substitute.For <IMultiplayerSessionConnectionContext>();
            AwaitingSessionReservation           connectionState   = new AwaitingSessionReservation(TestConstants.TEST_CORRELATION_ID);

            // Act
            Action action = () => connectionState.JoinSession(connectionContext);

            // Assert
            action.Should().Throw <InvalidOperationException>();
        }
コード例 #25
0
 public override void NegotiateReservation(IMultiplayerSessionConnectionContext sessionConnectionContext)
 {
     try
     {
         ValidateState(sessionConnectionContext);
         HandleReservation(sessionConnectionContext);
     }
     catch (Exception)
     {
         Disconnect(sessionConnectionContext);
         throw;
     }
 }
コード例 #26
0
ファイル: Disconnected.cs プロジェクト: EmidioMata/1.2
        private void ValidateState(IMultiplayerSessionConnectionContext sessionConnectionContext)
        {
            ValidateClient(sessionConnectionContext);

            try
            {
                Validate.NotNull(sessionConnectionContext.IpAddress);
            }
            catch (ArgumentNullException ex)
            {
                throw new InvalidOperationException("The context is missing an IP address.", ex);
            }
        }
コード例 #27
0
ファイル: Disconnected.cs プロジェクト: EmidioMata/1.2
        public void NegotiateReservation(IMultiplayerSessionConnectionContext sessionConnectionContext)
        {
            lock (stateLock)
            {
                ValidateState(sessionConnectionContext);

                IClient client    = sessionConnectionContext.Client;
                string  ipAddress = sessionConnectionContext.IpAddress;
                int     port      = sessionConnectionContext.ServerPort;
                StartClient(ipAddress, client, port);
                EstablishSessionPolicy(sessionConnectionContext, client);
            }
        }
コード例 #28
0
 public override void JoinSession(IMultiplayerSessionConnectionContext sessionConnectionContext)
 {
     try
     {
         ValidateState(sessionConnectionContext);
         EnterMultiplayerSession(sessionConnectionContext);
         ChangeState(sessionConnectionContext);
     }
     catch (Exception)
     {
         Disconnect(sessionConnectionContext);
         throw;
     }
 }
コード例 #29
0
        public void UpdateStateShouldRaiseEvent()
        {
            // Arrange
            IClient             client             = Substitute.For <IClient>();
            IMultiplayerSession multiplayerSession = new MultiplayerSessionManager(client);
            IMultiplayerSessionConnectionContext connectionContext = (IMultiplayerSessionConnectionContext)multiplayerSession;
            IMonitor <IMultiplayerSession>       monitor           = multiplayerSession.Monitor();

            // Act
            connectionContext.UpdateConnectionState(TestConstants.TEST_CONNECTION_STATE);

            // Assert
            monitor.Should().Raise("ConnectionStateChanged");
        }
コード例 #30
0
        public void NegotiateShouldThrowInvalidOperationExceptionWhenTheReservationIsNull()
        {
            // Arrange
            IMultiplayerSessionConnectionContext connectionContext = Substitute.For <IMultiplayerSessionConnectionContext>();

            connectionContext.Reservation.Returns((MultiplayerSessionReservation)null);

            AwaitingSessionReservation connectionState = new AwaitingSessionReservation(TestConstants.TEST_CORRELATION_ID);

            // Act
            Action action = () => connectionState.NegotiateReservation(connectionContext);

            // Assert
            action.Should().Throw <InvalidOperationException>();
        }