public void OneTimeSetUp()
        {
            _projectName = Environment.GetEnvironmentVariable("SPATIAL_PROJECT");
            if (string.IsNullOrEmpty(_projectName))
            {
                Assert.Fail("Project name is missing from environment.");
            }

            var refreshToken = Environment.GetEnvironmentVariable("SPATIAL_REFRESH_TOKEN");

            if (string.IsNullOrEmpty(refreshToken))
            {
                Assert.Fail("Refresh token is missing from environment.");
            }
            _authServiceClient = PlayerAuthServiceClient.Create(
                credentials: new PlatformRefreshTokenCredential(refreshToken));
            _leaderPit     = CreatePlayerIdentityTokenForPlayer(LeaderPlayerId);
            _partyClient   = new PartyService.PartyServiceClient(new Channel(PartyTarget, ChannelCredentials.Insecure));
            _inviteClient  = new InviteService.InviteServiceClient(new Channel(PartyTarget, ChannelCredentials.Insecure));
            _gatewayClient =
                new GatewayService.GatewayServiceClient(new Channel(GatewayTarget, ChannelCredentials.Insecure));
            _leaderMetadata = new Metadata {
                { PitRequestHeaderName, _leaderPit }
            };
        }
Exemple #2
0
        public void OneTimeSetUp()
        {
            _projectName = Environment.GetEnvironmentVariable("SPATIAL_PROJECT");
            if (string.IsNullOrEmpty(_projectName))
            {
                Assert.Fail("Project name is missing from environment.");
            }

            var refreshToken = Environment.GetEnvironmentVariable("SPATIAL_REFRESH_TOKEN");

            if (string.IsNullOrEmpty(refreshToken))
            {
                Assert.Fail("Refresh token is missing from environment.");
            }
            _authServiceClient =
                PlayerAuthServiceClient.Create(credentials: new PlatformRefreshTokenCredential(refreshToken));
            var channel = new Channel(PartyServerTarget, ChannelCredentials.Insecure);

            _partyClient  = new PartyService.PartyServiceClient(channel);
            _inviteClient = new InviteService.InviteServiceClient(channel);
        }
Exemple #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}].");
            });
        }
        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}].");
            });
        }