public void MatchAMultiPlayerParty()
        {
            // Create a party with multiple players within it.
            var partyId =
                _partyClient.CreateParty(new CreatePartyRequest(), _leaderMetadata)
                .PartyId;
            var pitAnotherMember    = CreatePlayerIdentityTokenForPlayer(MemberPlayerId);
            var inviteAnotherPlayer = _inviteClient.CreateInvite(new CreateInviteRequest {
                ReceiverPlayerId = MemberPlayerId
            },
                                                                 _leaderMetadata).InviteId;

            Assert.NotNull(inviteAnotherPlayer);
            _partyClient.JoinParty(new JoinPartyRequest {
                PartyId = partyId
            },
                                   new Metadata {
                { PitRequestHeaderName, pitAnotherMember }
            });

            // Join matchmaking.
            _gatewayClient.Join(new JoinRequest
            {
                MatchmakingType = "match1"
            }, _leaderMetadata);

            AssertWithinSeconds(10, () =>
            {
                var leaderOp = _operationsClient.GetOperation(LeaderPlayerId,
                                                              CallSettings.FromHeader(PitRequestHeaderName, _leaderPit));
                if (!leaderOp.Done)
                {
                    return(false);
                }

                var assignment = leaderOp.Response.Unpack <JoinResponse>();
                Assert.AreEqual("test_deployment_1", assignment.DeploymentName);
                Assert.False(string.IsNullOrEmpty(assignment.LoginToken));

                // Verify that the other member has been matched into the same deployment as the leader.
                var otherMemberOp = _operationsClient.GetOperation(MemberPlayerId,
                                                                   CallSettings.FromHeader(PitRequestHeaderName, CreatePlayerIdentityTokenForPlayer(MemberPlayerId)));
                Assert.True(otherMemberOp.Done);
                var memberAssignment = otherMemberOp.Response.Unpack <JoinResponse>();
                Assert.AreEqual("test_deployment_1", memberAssignment.DeploymentName);
                Assert.False(string.IsNullOrEmpty(memberAssignment.LoginToken));

                return(true);
            });

            // Clean-up.
            _partyClient.DeleteParty(new DeletePartyRequest(), _leaderMetadata);
            _inviteClient.DeleteInvite(new DeleteInviteRequest {
                InviteId = inviteAnotherPlayer
            }, _leaderMetadata);
        }
        public void AllowAJoinRequestToBeDeletedAndNewMembersInvited()
        {
            // Create a solo party and get its ID to later invite another player.
            var partyId = _partyClient.CreateParty(new CreatePartyRequest(), _leaderMetadata).PartyId;

            // Join matchmaking.
            _gatewayClient.Join(new JoinRequest
            {
                MatchmakingType = "no_match"
            }, _leaderMetadata);

            // Verify that the party has not been matched yet.
            var status = _gatewayClient.GetJoinStatus(new GetJoinStatusRequest {
                PlayerId = LeaderPlayerId
            }, _leaderMetadata);

            Assert.False(status.Complete);

            // Cancel matchmaking.
            _gatewayClient.CancelJoin(new CancelJoinRequest {
                PlayerId = LeaderPlayerId
            }, _leaderMetadata);

            // Verify that there is no more information within the matchmaking system about the party/player.
            var rpcException = Assert.Throws <RpcException>(() =>
                                                            _gatewayClient.GetJoinStatus(new GetJoinStatusRequest {
                PlayerId = LeaderPlayerId
            }, _leaderMetadata));

            Assert.AreEqual(StatusCode.NotFound, rpcException.Status.StatusCode);

            // Verify that we can invite another member to the party
            var pitAnotherMember    = CreatePlayerIdentityTokenForPlayer(MemberPlayerId);
            var inviteAnotherPlayer = _inviteClient.CreateInvite(new CreateInviteRequest {
                ReceiverPlayerId = MemberPlayerId
            },
                                                                 _leaderMetadata).InviteId;

            Assert.NotNull(inviteAnotherPlayer);
            _partyClient.JoinParty(new JoinPartyRequest {
                PartyId = partyId
            },
                                   new Metadata {
                { PitRequestHeaderName, pitAnotherMember }
            });

            // Join matchmaking for the second time.
            _gatewayClient.Join(new JoinRequest
            {
                MatchmakingType = "no_match"
            }, _leaderMetadata);

            // Verify that the party has not been matched yet.
            status = _gatewayClient.GetJoinStatus(new GetJoinStatusRequest {
                PlayerId = LeaderPlayerId
            }, _leaderMetadata);
            Assert.False(status.Complete);

            // Cancel matchmaking.
            _gatewayClient.CancelJoin(new CancelJoinRequest {
                PlayerId = LeaderPlayerId
            }, _leaderMetadata);

            // Clean-up.
            _partyClient.DeleteParty(new DeletePartyRequest(), _leaderMetadata);
        }
        public void LetOtherMembersJoinAParty()
        {
            // Create a party.
            var pitLeader          = CreatePlayerIdentityTokenForPlayer(LeaderPlayerId);
            var createPartyRequest = new CreatePartyRequest {
                MinMembers = MinMembers, MaxMembers = MaxMembers
            };
            var partyId = _partyClient
                          .CreateParty(createPartyRequest, new Metadata {
                { PitRequestHeaderName, pitLeader }
            }).PartyId;

            // Verify that the party was successfully created.
            var partyAssociatedToPlayer = _partyClient
                                          .GetPartyByPlayerId(new GetPartyByPlayerIdRequest(),
                                                              new Metadata {
                { PitRequestHeaderName, pitLeader }
            })
                                          .Party;

            Assert.NotNull(partyAssociatedToPlayer);

            // Verify that another player can successfully join the party.
            var pitAnotherPlayer    = CreatePlayerIdentityTokenForPlayer(PlayerId);
            var inviteAnotherPlayer = _inviteClient.CreateInvite(new CreateInviteRequest {
                ReceiverPlayerId = PlayerId
            },
                                                                 new Metadata {
                { PitRequestHeaderName, pitLeader }
            }).InviteId;

            Assert.NotNull(inviteAnotherPlayer);
            var joinRequest = new JoinPartyRequest {
                PartyId = partyId
            };
            var partyJoined = _partyClient
                              .JoinParty(joinRequest, new Metadata {
                { PitRequestHeaderName, pitAnotherPlayer }
            }).Party;

            Assert.AreEqual(2, partyJoined.MemberIds.Count);

            // Rejoining the same party should be allowed but the number of players should remain the same.
            partyJoined = _partyClient
                          .JoinParty(joinRequest, new Metadata {
                { PitRequestHeaderName, pitAnotherPlayer }
            }).Party;
            Assert.AreEqual(2, partyJoined.MemberIds.Count);

            // Clean up.
            _partyClient.DeleteParty(new DeletePartyRequest(), new Metadata {
                { PitRequestHeaderName, pitLeader }
            });

            // Verify that its former members are no longer associated to the party since it has been deleted.
            var exception = Assert.Throws <RpcException>(() =>
                                                         _partyClient.GetPartyByPlayerId(new GetPartyByPlayerIdRequest(),
                                                                                         new Metadata {
                { PitRequestHeaderName, pitLeader }
            }));

            Assert.AreEqual(StatusCode.NotFound, exception.StatusCode);

            exception = Assert.Throws <RpcException>(() =>
                                                     _partyClient.GetPartyByPlayerId(new GetPartyByPlayerIdRequest(),
                                                                                     new Metadata {
                { PitRequestHeaderName, pitAnotherPlayer }
            }));
            Assert.AreEqual(StatusCode.NotFound, exception.StatusCode);
        }
Esempio n. 4
0
        public void ReturnPermissionDeniedErrorIfPitNotProvided()
        {
            var exception = Assert.Throws <RpcException>(() => _inviteClient.CreateInvite(new CreateInviteRequest()));

            Assert.AreEqual(StatusCode.PermissionDenied, exception.StatusCode);
        }