Ejemplo n.º 1
0
        protected override void Run()
        {
            Console.WriteLine("Creating a PlayerIdentityToken");
            var playerIdentityTokenResponse = _playerAuthServiceClient.CreatePlayerIdentityToken(
                new CreatePlayerIdentityTokenRequest
            {
                Provider         = "provider",
                PlayerIdentifier = "player_identifier",
                ProjectName      = ProjectName
            });

            Console.WriteLine("Choosing a deployment");
            var suitableDeployment = _deploymentServiceClient.ListDeployments(new ListDeploymentsRequest
            {
                ProjectName    = ProjectName,
                DeploymentName = DeploymentName
            }).First(d => d.Tag.Contains(ScenarioDeploymentTag));

            Console.WriteLine("Creating a LoginToken for the selected deployment");
            var createLoginTokenResponse = _playerAuthServiceClient.CreateLoginToken(
                new CreateLoginTokenRequest
            {
                PlayerIdentityToken = playerIdentityTokenResponse.PlayerIdentityToken,
                DeploymentId        = suitableDeployment.Id,
                LifetimeDuration    = Duration.FromTimeSpan(new TimeSpan(0, 0, 30, 0)),
                WorkerType          = ScenarioWorkerType
            });

            Console.WriteLine("Connecting to the deployment using the LoginToken and PlayerIdentityToken");
            var locatorParameters = new LocatorParameters
            {
                PlayerIdentity = new PlayerIdentityCredentials
                {
                    PlayerIdentityToken = playerIdentityTokenResponse.PlayerIdentityToken,
                    LoginToken          = createLoginTokenResponse.LoginToken
                }
            };
            var locator = new Locator(LocatorServerAddress, LocatorServerPort, locatorParameters);

            using (var connectionFuture = locator.ConnectAsync(new ConnectionParameters
            {
                WorkerType = ScenarioWorkerType,
                Network = { ConnectionType = NetworkConnectionType.Tcp, UseExternalIp = true }
            }))
            {
                var connFuture = connectionFuture.Get(Convert.ToUInt32(Defaults.ConnectionTimeoutMillis));
                if (!connFuture.HasValue || !connFuture.Value.IsConnected)
                {
                    throw new Exception("No connection or connection not established");
                }
                Console.WriteLine($"Assigned worker ID: {connFuture.Value.GetWorkerId()}");
            }
        }
Ejemplo n.º 2
0
 public async Task <object> CreateLoginToken(dynamic data)
 {
     return(await Task.Run(() => {
         PlatformRefreshTokenCredential CredentialWithProvidedToken = new PlatformRefreshTokenCredential(data._RefreshToken);
         PlayerAuthServiceClient _playerAuthServiceClient = PlayerAuthServiceClient.Create(credentials: CredentialWithProvidedToken);
         var createLoginTokenResponse = _playerAuthServiceClient.CreateLoginToken(
             new CreateLoginTokenRequest
         {
             PlayerIdentityToken = data._PlayerIdentityToken,
             DeploymentId = data._DeploymentID,
             LifetimeDuration = Duration.FromTimeSpan(TimeSpan.FromSeconds(data._Duration)),
             WorkerType = data._ScenarioWorkerType
         });
         return createLoginTokenResponse.LoginToken;
     }));
 }
 private Any CreateJoinResponse(PlayerJoinRequest request)
 {
     try
     {
         var loginTokenResp = _playerAuthServiceClient.CreateLoginToken(new CreateLoginTokenRequest
         {
             DeploymentId        = request.DeploymentId,
             PlayerIdentityToken = request.PlayerIdentityToken
         });
         var response = new JoinResponse
         {
             DeploymentName = request.DeploymentName,
             LoginToken     = loginTokenResp.LoginToken
         };
         return(Any.Pack(response));
     }
     catch (Exception e)
     {
         Log.Error(e, "encountered an error creating a login token");
         throw new RpcException(new Status(StatusCode.Internal, "encountered an error creating a login token"));
     }
 }
Ejemplo n.º 4
0
        protected override void Run()
        {
            Console.WriteLine("Creating a PlayerIdentityToken");
            var playerIdentityTokenResponse = _playerAuthServiceClient.CreatePlayerIdentityToken(
                new CreatePlayerIdentityTokenRequest
            {
                Provider         = "provider",
                PlayerIdentifier = "player_identifier",
                ProjectName      = ProjectName
            });

            Console.WriteLine("Verifying PlayerIdentityToken");
            var decodePlayerIdentityTokenResponse = _playerAuthServiceClient.DecodePlayerIdentityToken(
                new DecodePlayerIdentityTokenRequest
            {
                PlayerIdentityToken = playerIdentityTokenResponse.PlayerIdentityToken
            });
            var playerIdentityToken = decodePlayerIdentityTokenResponse.PlayerIdentityToken;

            if (playerIdentityToken.Provider != "provider")
            {
                throw new Exception("Provider not recognised.");
            }
            if (playerIdentityToken.ProjectName != ProjectName)
            {
                throw new Exception("Project not recognised.");
            }
            if (DateTime.Now.CompareTo(playerIdentityToken.ExpiryTime.ToDateTime()) > 0)
            {
                throw new Exception("PlayerIdentityToken expired.");
            }

            Console.WriteLine("Choosing a deployment");
            var listDeploymentsRequest = new ListDeploymentsRequest
            {
                ProjectName = ProjectName,
                Filters     = { new Filter
                                {
                                    TagsPropertyFilter = new TagsPropertyFilter
                                    {
                                        Tag      = "player_auth_tag",
                                        Operator = TagsPropertyFilter.Types.Operator.Equal,
                                    },
                                } }
            };
            var suitableDeployment = _deploymentServiceClient.ListDeployments(listDeploymentsRequest).First();

            Console.WriteLine("Creating a LoginToken for the selected deployment");
            var createLoginTokenResponse = _playerAuthServiceClient.CreateLoginToken(
                new CreateLoginTokenRequest
            {
                PlayerIdentityToken = playerIdentityTokenResponse.PlayerIdentityToken,
                DeploymentId        = suitableDeployment.Id.ToString(),
                LifetimeDuration    = Duration.FromTimeSpan(new TimeSpan(0, 0, 30, 0)),
                WorkerType          = ScenarioWorkerType
            });

            Console.WriteLine("Connecting to the deployment using the LoginToken and PlayerIdentityToken");
            var locatorParameters = new LocatorParameters
            {
                PlayerIdentity = new PlayerIdentityCredentials
                {
                    PlayerIdentityToken = playerIdentityTokenResponse.PlayerIdentityToken,
                    LoginToken          = createLoginTokenResponse.LoginToken
                }
            };
            var locator = new Locator(LocatorServerAddress, LocatorServerPort, locatorParameters);

            using (var connectionFuture = locator.ConnectAsync(new ConnectionParameters
            {
                WorkerType = ScenarioWorkerType,
                Network = { ConnectionType = NetworkConnectionType.Tcp, UseExternalIp = true }
            }))
            {
                var connFuture = connectionFuture.Get(Convert.ToUInt32(Defaults.ConnectionTimeoutMillis));
                if (!connFuture.HasValue || !connFuture.Value.IsConnected)
                {
                    throw new Exception("No connection or connection not established");
                }
                Console.WriteLine($"Assigned worker ID: {connFuture.Value.GetWorkerId()}");
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        ///     This contains the implementation of the "Capacity limiting" scenario.
        ///     1. Gets the currently running cloud deployment that has a capacity limit.
        ///     2. Tests that connecting more clients than the capacity limit fails.
        ///     3. Updates the deployment to increase the capacity limit.
        ///     4. Tests that additional clients are now able to connect to the deployment.
        /// </summary>
        protected override void Run()
        {
            Console.WriteLine("Finding current running deployment");
            _deployment = _deploymentServiceClient
                          .ListDeployments(new ListDeploymentsRequest
            {
                ProjectName    = ProjectName,
                DeploymentName = DeploymentName
            })
                          .First(d => d.Status == Deployment.Types.Status.Running);
            Console.WriteLine($"Found deployment {_deployment.Id}");

            Console.WriteLine("Setting capacity limit to 2");
            _deployment.WorkerConnectionCapacities.Clear();
            _deployment.WorkerConnectionCapacities.Add(new WorkerCapacity
            {
                WorkerType  = ScenarioWorkerType,
                MaxCapacity = 2
            });
            _deploymentServiceClient.UpdateDeployment(new UpdateDeploymentRequest {
                Deployment = _deployment
            });

            Console.WriteLine("Creating a PlayerIdentityToken");
            var playerIdentityTokenResponse = _playerAuthServiceClient.CreatePlayerIdentityToken(
                new CreatePlayerIdentityTokenRequest
            {
                Provider         = "provider",
                PlayerIdentifier = "player_identifier",
                ProjectName      = ProjectName
            });

            Console.WriteLine(JsonConvert.SerializeObject(playerIdentityTokenResponse));

            Console.WriteLine("Creating a LoginToken for the selected deployment");
            var createLoginTokenResponse = _playerAuthServiceClient.CreateLoginToken(
                new CreateLoginTokenRequest
            {
                PlayerIdentityToken = playerIdentityTokenResponse.PlayerIdentityToken,
                DeploymentId        = _deployment.Id,
                LifetimeDuration    = Duration.FromTimeSpan(new TimeSpan(0, 0, 30, 0)),
                WorkerType          = ScenarioWorkerType
            });

            Console.WriteLine(JsonConvert.SerializeObject(createLoginTokenResponse));

            Console.WriteLine("Connecting 3 workers to the deployment. Expecting only 2 to succeed");
            var locatorParameters = new LocatorParameters
            {
                PlayerIdentity = new PlayerIdentityCredentials
                {
                    PlayerIdentityToken = playerIdentityTokenResponse.PlayerIdentityToken,
                    LoginToken          = createLoginTokenResponse.LoginToken
                }
            };
            var locator = new Locator(LocatorServerAddress, LocatorServerPort, locatorParameters);

            for (var i = 0; i < 3; i++)
            {
                var connectionSucceeded = TryConnectWorker(locator);
                if (!connectionSucceeded && i != 2)
                {
                    throw new Exception("Expected worker to connect successfully");
                }
                if (connectionSucceeded && i == 2)
                {
                    throw new Exception("Expected worker to fail to connect");
                }
            }

            Console.WriteLine("Increasing capacity limit to 3");
            _deployment.WorkerConnectionCapacities.Clear();
            _deployment.WorkerConnectionCapacities.Add(new WorkerCapacity
            {
                WorkerType  = ScenarioWorkerType,
                MaxCapacity = 3
            });
            _deploymentServiceClient.UpdateDeployment(new UpdateDeploymentRequest {
                Deployment = _deployment
            });

            Console.WriteLine("Connecting another worker");
            if (!TryConnectWorker(locator))
            {
                throw new Exception("Expected worker to be able to connect after capacity increase");
            }
        }