public void AllowAJoinRequestToBeDeleted()
        {
            // Create a solo party.
            _partyClient.CreateParty(new CreatePartyRequest(), _leaderMetadata);

            // 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);

            // Clean-up.
            _partyClient.DeleteParty(new DeletePartyRequest(), _leaderMetadata);
        }
Ejemplo n.º 2
0
        public void AllowAJoinRequestToBeDeleted()
        {
            // Create a solo party.
            _partyClient.CreateParty(new CreatePartyRequest(), _leaderMetadata);

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

            Assert.AreEqual(LeaderPlayerId, op.Name);
            Assert.False(op.Done);

            // Verify that the party has not been matched yet.
            var fetchedOp = _operationsClient.GetOperation(LeaderPlayerId,
                                                           CallSettings.FromHeader(PitRequestHeaderName, _leaderPit));

            Assert.AreEqual(LeaderPlayerId, fetchedOp.Name);
            Assert.False(fetchedOp.Done);

            // Cancel matchmaking.
            _operationsClient.DeleteOperation(LeaderPlayerId,
                                              CallSettings.FromHeader(PitRequestHeaderName, _leaderPit));

            // Verify that there is no more information within the matchmaking system about the party/player.
            var rpcException = Assert.Throws <RpcException>(() =>
                                                            _operationsClient.GetOperation(LeaderPlayerId,
                                                                                           CallSettings.FromHeader(PitRequestHeaderName, _leaderPit)));

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

            // Clean-up.
            _partyClient.DeleteParty(new DeletePartyRequest(), _leaderMetadata);
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            Parser.Default.ParseArguments <SampleClientArguments>(args)
            .WithParsed(parsedArgs =>
            {
                var gatewayServiceUrl = parsedArgs.Local
                        ? string.Format(LocalEndPointUrlFormat, "4040")
                        : string.Format(CloudEndPointUrlFormat, "gateway", parsedArgs.GoogleProject);

                var partyServiceUrl = parsedArgs.Local
                        ? string.Format(LocalEndPointUrlFormat, "4041")
                        : string.Format(CloudEndPointUrlFormat, "party", parsedArgs.GoogleProject);

                var authServiceUrl = parsedArgs.Local
                        ? string.Format(LocalEndPointUrlFormat, "4042")
                        : string.Format(CloudEndPointUrlFormat, "playfab-auth", parsedArgs.GoogleProject);

                var playerId = RandomString(15);
                Console.WriteLine($"Using a randomly generated PlayFab player ID: {playerId}");
                Console.WriteLine($"authServiceUrl: {authServiceUrl}");

                //This is the type of code i would put into the game because it is responsible
                // for talking directly to steam for encrypted app ticket and then sending it
                // to my servers to authenticate and exchange got a player identity token
                // First, get a token from PlayFab.
                PlayFabSettings.staticSettings.TitleId = parsedArgs.PlayFabTitleId;
                var playFabLoginTask = PlayFabClientAPI.LoginWithCustomIDAsync(new LoginWithCustomIDRequest
                {
                    TitleId       = parsedArgs.PlayFabTitleId,
                    CustomId      = playerId,
                    CreateAccount = true
                });
                var playFabLoginResult = playFabLoginTask.GetAwaiter().GetResult();
                if (playFabLoginResult.Error != null)
                {
                    Console.WriteLine($"Got login error from PlayFab: {playFabLoginResult.Error.ErrorMessage}");
                    Environment.Exit(1);
                    return;
                }

                var playFabId = playFabLoginResult.Result.PlayFabId;
                Console.WriteLine($"Got a token for PlayFab ID {playFabId}.");

                // Next, exchange the token with our auth service for a PIT.
                var playFabAuthClient = new AuthService.AuthServiceClient(
                    new Channel(authServiceUrl, ChannelCredentials.Insecure));
                var authResult = playFabAuthClient.ExchangePlayFabToken(new ExchangePlayFabTokenRequest
                {
                    PlayfabToken = playFabLoginResult.Result.SessionTicket
                });
                Console.WriteLine("Got a PIT.");
                var pitMetadata = new Metadata {
                    { PitRequestHeaderName, authResult.PlayerIdentityToken }
                };
                Console.WriteLine($"authResult.PlayerIdentityToken: {authResult.PlayerIdentityToken}");

                // Create a single-player party for the player.
                var partyClient = new PartyService.PartyServiceClient(
                    new Channel(partyServiceUrl, ChannelCredentials.Insecure));
                var partyResponse =
                    partyClient.CreateParty(new CreatePartyRequest {
                    MinMembers = 1, MaxMembers = 1
                }, pitMetadata);
                Console.WriteLine($"Created a new party with id {partyResponse.PartyId}.");

                var gatewayEndpoint = gatewayServiceUrl;
                var gatewayClient   =
                    new GatewayService.GatewayServiceClient(new Channel(gatewayEndpoint,
                                                                        ChannelCredentials.Insecure));

                gatewayClient.Join(new JoinRequest
                {
                    MatchmakingType = "match"
                }, pitMetadata);
                Console.WriteLine("Joined queue; waiting for match.");

                GetJoinStatusResponse resp = null;
                while (resp == null || !resp.Complete)
                {
                    Thread.Sleep(1000);
                    resp = gatewayClient.GetJoinStatus(new GetJoinStatusRequest {
                        PlayerId = playFabId
                    }, pitMetadata);
                }

                Console.WriteLine(
                    $"Got deployment: {resp.DeploymentName}. Login token: [{resp.LoginToken}].");
            });
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            Parser.Default.ParseArguments <SampleClientArguments>(args)
            .WithParsed(parsedArgs =>
            {
                var gatewayServiceUrl = parsedArgs.Local
                        ? string.Format(LocalEndPointUrlFormat, "4040")
                        : string.Format(CloudEndPointUrlFormat, "gateway", parsedArgs.GoogleProject);

                var partyServiceUrl = parsedArgs.Local
                        ? string.Format(LocalEndPointUrlFormat, "4041")
                        : string.Format(CloudEndPointUrlFormat, "party", parsedArgs.GoogleProject);

                var authServiceUrl = parsedArgs.Local
                        ? string.Format(LocalEndPointUrlFormat, "4042")
                        : string.Format(CloudEndPointUrlFormat, "playfab-auth", parsedArgs.GoogleProject);

                var playerId = RandomString(15);
                Console.WriteLine($"Using a randomly generated PlayFab player ID: {playerId}");

                // First, get a token from PlayFab.
                PlayFabSettings.staticSettings.TitleId = parsedArgs.PlayFabTitleId;
                var playFabLoginTask = PlayFabClientAPI.LoginWithCustomIDAsync(new LoginWithCustomIDRequest
                {
                    TitleId       = parsedArgs.PlayFabTitleId,
                    CustomId      = playerId,
                    CreateAccount = true
                });
                var playFabLoginResult = playFabLoginTask.GetAwaiter().GetResult();
                if (playFabLoginResult.Error != null)
                {
                    Console.WriteLine($"Got login error from PlayFab: {playFabLoginResult.Error.ErrorMessage}");
                    Environment.Exit(1);
                    return;
                }

                var playFabId = playFabLoginResult.Result.PlayFabId;

                Console.WriteLine($"Got a token for PlayFab ID {playFabId}.");

                // Next, exchange the token with our auth service for a PIT.
                var playFabAuthClient = new AuthService.AuthServiceClient(
                    new Channel(authServiceUrl, ChannelCredentials.Insecure));
                var authResult = playFabAuthClient.ExchangePlayFabToken(new ExchangePlayFabTokenRequest
                {
                    PlayfabToken = playFabLoginResult.Result.SessionTicket
                });
                Console.WriteLine("Got a PIT.");
                var pitMetadata = new Metadata {
                    { PitRequestHeaderName, authResult.PlayerIdentityToken }
                };

                // Create a single-player party for the player.
                var partyClient = new PartyService.PartyServiceClient(
                    new Channel(partyServiceUrl, ChannelCredentials.Insecure));
                var partyResponse =
                    partyClient.CreateParty(new CreatePartyRequest {
                    MinMembers = 1, MaxMembers = 1
                }, pitMetadata);
                Console.WriteLine($"Created a new party with id {partyResponse.PartyId}.");

                var gatewayEndpoint = gatewayServiceUrl;
                var gatewayClient   =
                    new GatewayService.GatewayServiceClient(new Channel(gatewayEndpoint,
                                                                        ChannelCredentials.Insecure));
                var operationsClient =
                    new Operations.OperationsClient(new Channel(gatewayEndpoint, ChannelCredentials.Insecure));

                var op = gatewayClient.Join(new JoinRequest
                {
                    MatchmakingType = "match"
                }, pitMetadata);
                Console.WriteLine("Joined queue; waiting for match.");

                while (!op.Done)
                {
                    Thread.Sleep(1000);
                    op = operationsClient.GetOperation(new GetOperationRequest
                    {
                        Name = op.Name
                    }, pitMetadata);
                }

                var response = op.Response.Unpack <JoinResponse>();
                Console.WriteLine(
                    $"Got deployment: {response.DeploymentName}. Login token: [{response.LoginToken}].");
            });
        }
Ejemplo n.º 5
0
        public void ReturnPermissionDeniedErrorIfPitNotProvided()
        {
            var exception = Assert.Throws <RpcException>(() => _partyClient.CreateParty(new CreatePartyRequest()));

            Assert.AreEqual(StatusCode.PermissionDenied, exception.StatusCode);
        }
Ejemplo n.º 6
0
        public void AllowPlayersToSendInvites()
        {
            // Create a party.
            var senderPit = CreatePlayerIdentityTokenForPlayer(LeaderPlayerId);
            var partyId   = _partyClient
                            .CreateParty(new CreatePartyRequest(), new Metadata {
                { PitRequestHeaderName, senderPit }
            }).PartyId;

            // Send invites to other players.
            var createInviteRequest = new CreateInviteRequest {
                ReceiverPlayerId = PlayerId1
            };
            var inviteId1 = _inviteClient
                            .CreateInvite(createInviteRequest, new Metadata {
                { PitRequestHeaderName, senderPit }
            })
                            .InviteId;

            Assert.NotNull(inviteId1);

            createInviteRequest = new CreateInviteRequest {
                ReceiverPlayerId = PlayerId2
            };
            var inviteId2 = _inviteClient
                            .CreateInvite(createInviteRequest, new Metadata {
                { PitRequestHeaderName, senderPit }
            })
                            .InviteId;

            Assert.NotNull(inviteId2);

            // Verify that the invites were successfully stored.
            var invite1 = _inviteClient.GetInvite(new GetInviteRequest {
                InviteId = inviteId1
            },
                                                  new Metadata {
                { PitRequestHeaderName, senderPit }
            }).Invite;

            Assert.AreEqual(inviteId1, invite1.Id);
            Assert.AreEqual(LeaderPlayerId, invite1.SenderPlayerId);
            Assert.AreEqual(PlayerId1, invite1.ReceiverPlayerId);
            Assert.AreEqual(partyId, invite1.PartyId);
            Assert.AreEqual(Invite.Types.Status.Pending, invite1.CurrentStatus);

            var invite2 = _inviteClient.GetInvite(new GetInviteRequest {
                InviteId = inviteId2
            },
                                                  new Metadata {
                { PitRequestHeaderName, senderPit }
            }).Invite;

            Assert.AreEqual(inviteId2, invite2.Id);
            Assert.AreEqual(LeaderPlayerId, invite2.SenderPlayerId);
            Assert.AreEqual(PlayerId2, invite2.ReceiverPlayerId);
            Assert.AreEqual(partyId, invite2.PartyId);
            Assert.AreEqual(Invite.Types.Status.Pending, invite2.CurrentStatus);

            // Verify that the sender has the invites in its outbound invites.
            var senderPlayerInvites = _inviteClient.ListAllInvites(new ListAllInvitesRequest(),
                                                                   new Metadata {
                { PitRequestHeaderName, senderPit }
            });

            Assert.AreEqual(2, senderPlayerInvites.OutboundInvites.Count);
            Assert.AreEqual(invite1, senderPlayerInvites.OutboundInvites[0]);
            Assert.AreEqual(invite2, senderPlayerInvites.OutboundInvites[1]);

            // Verify that both receivers have the invite in their inbound invites.
            var receiverPit1           = CreatePlayerIdentityTokenForPlayer(PlayerId1);
            var receiverPlayerInvites1 = _inviteClient.ListAllInvites(new ListAllInvitesRequest(),
                                                                      new Metadata {
                { PitRequestHeaderName, receiverPit1 }
            });

            Assert.AreEqual(1, receiverPlayerInvites1.InboundInvites.Count);
            Assert.AreEqual(invite1, receiverPlayerInvites1.InboundInvites[0]);

            var receiverPit2           = CreatePlayerIdentityTokenForPlayer(PlayerId2);
            var receiverPlayerInvites2 = _inviteClient.ListAllInvites(new ListAllInvitesRequest(),
                                                                      new Metadata {
                { PitRequestHeaderName, receiverPit2 }
            });

            Assert.AreEqual(1, receiverPlayerInvites2.InboundInvites.Count);
            Assert.AreEqual(invite2, receiverPlayerInvites2.InboundInvites[0]);

            // Cleanup.
            _inviteClient.DeleteInvite(new DeleteInviteRequest {
                InviteId = inviteId1
            },
                                       new Metadata {
                { PitRequestHeaderName, senderPit }
            });
            _inviteClient.DeleteInvite(new DeleteInviteRequest {
                InviteId = inviteId2
            },
                                       new Metadata {
                { PitRequestHeaderName, senderPit }
            });
            _partyClient.DeleteParty(new DeletePartyRequest(), new Metadata {
                { PitRequestHeaderName, senderPit }
            });
        }