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>()); }
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>()); }
public void ClearSessionState() { IpAddress = null; SessionPolicy = null; PlayerSettings = null; AuthenticationContext = null; Reservation = null; }
public void ClearSessionState() { IpAddress = null; ServerPort = ServerList.DEFAULT_PORT; SessionPolicy = null; PlayerSettings = null; AuthenticationContext = null; Reservation = null; }
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); }
public void ProcessReservationResponsePacket(MultiplayerSessionReservation reservation) { if (reservation.ReservationState == MultiplayerSessionReservationState.ENQUEUED_IN_JOIN_QUEUE) { Log.InGame(Language.main.Get("Nitrox_Waiting")); return; } Reservation = reservation; CurrentState.NegotiateReservation(this); }
public void ProcessReservationResponsePacketShouldSetTheReservation() { // Arrange MultiplayerSessionReservation successfulReservation = new MultiplayerSessionReservation( TestConstants.TEST_CORRELATION_ID, TestConstants.TEST_PLAYER_ID, TestConstants.TEST_RESERVATION_KEY); IClient client = Substitute.For <IClient>(); IMultiplayerSession multiplayerSession = new MultiplayerSessionManager(client, TestConstants.TEST_CONNECTION_STATE); // Act multiplayerSession.ProcessReservationResponsePacket(successfulReservation); // Assert multiplayerSession.Reservation.ShouldBeEquivalentTo(successfulReservation); }
public void NegotiateShouldTransitionToSessionReservationRejectedAfterReceivingRejectedReservation() { // Arrange MultiplayerSessionReservation rejectedReservation = new MultiplayerSessionReservation(TestConstants.TEST_CORRELATION_ID, TestConstants.TEST_REJECTION_STATE); IMultiplayerSessionConnectionContext connectionContext = Substitute.For <IMultiplayerSessionConnectionContext>(); connectionContext.Reservation.Returns(rejectedReservation); AwaitingSessionReservation connectionState = new AwaitingSessionReservation(TestConstants.TEST_CORRELATION_ID); // Act connectionState.NegotiateReservation(connectionContext); // Assert connectionContext.Received().UpdateConnectionState(Arg.Any <SessionReservationRejected>()); }
public override void Process(MultiplayerSessionReservationRequest packet, NitroxConnection connection) { Log.Info($"Processing reservation request from {packet.AuthenticationContext.Username}"); string correlationId = packet.CorrelationId; PlayerSettings playerSettings = packet.PlayerSettings; AuthenticationContext authenticationContext = packet.AuthenticationContext; MultiplayerSessionReservation reservation = playerManager.ReservePlayerContext( connection, playerSettings, authenticationContext, correlationId); Log.Info($"Reservation processed successfully: Username: {packet.AuthenticationContext.Username} - {reservation} - IP Address: {connection.Endpoint.Address.ToString()}"); connection.SendPacket(reservation); }
public override void Process(MultiplayerSessionReservationRequest packet, Connection connection) { Log.Info("Processing reservation request..."); string correlationId = packet.CorrelationId; PlayerSettings playerSettings = packet.PlayerSettings; AuthenticationContext authenticationContext = packet.AuthenticationContext; MultiplayerSessionReservation reservation = playerManager.ReservePlayerContext( connection, playerSettings, authenticationContext, correlationId); Log.Info($"Reservation processed successfully: {reservation}..."); connection.SendPacket(reservation, null); }
public void NegotiateShouldThrowUncorrelatedPacketExceptionWhenTheReservationHasTheWrongCorrelationId() { // Arrange MultiplayerSessionReservation successfulReservation = new MultiplayerSessionReservation( "wrong", TestConstants.TEST_PLAYER_ID, TestConstants.TEST_RESERVATION_KEY); IMultiplayerSessionConnectionContext connectionContext = Substitute.For <IMultiplayerSessionConnectionContext>(); connectionContext.Reservation.Returns(successfulReservation); AwaitingSessionReservation connectionState = new AwaitingSessionReservation(TestConstants.TEST_CORRELATION_ID); // Act Action action = () => connectionState.NegotiateReservation(connectionContext); // Assert action.Should().Throw <UncorrelatedPacketException>(); }
public void ProcessReservationResponsePacket(MultiplayerSessionReservation reservation) { Reservation = reservation; CurrentState.NegotiateReservation(this); }