示例#1
0
        public override void Invoke(AWSCredentials creds, RegionEndpoint region, int maxItems)
        {
            AmazonGameLiftConfig config = new AmazonGameLiftConfig();

            config.RegionEndpoint = region;
            ConfigureClient(config);
            AmazonGameLiftClient client = new AmazonGameLiftClient(creds, config);

            DescribeGameSessionQueuesResponse resp = new DescribeGameSessionQueuesResponse();

            do
            {
                DescribeGameSessionQueuesRequest req = new DescribeGameSessionQueuesRequest
                {
                    NextToken = resp.NextToken
                    ,
                    Limit = maxItems
                };

                resp = client.DescribeGameSessionQueues(req);
                CheckError(resp.HttpStatusCode, "200");

                foreach (var obj in resp.GameSessionQueues)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
    public void CreateGameLiftClient()
    {
        var config = new AmazonGameLiftConfig();

        config.RegionEndpoint = Amazon.RegionEndpoint.USEast1;
        Debug.Log("GL372");
        try
        {
            CredentialProfile profile = null;
            var nscf = new SharedCredentialsFile();
            nscf.TryGetProfile(profileName, out profile);
            AWSCredentials credentials = profile.GetAWSCredentials(null);
            Debug.Log("demo-gamelift-unity profile GL376");
            aglc = new AmazonGameLiftClient(credentials, config);
            Debug.Log("GL378");
        }
        catch (AmazonServiceException)
        {
            Debug.Log("regular profile search GL382");
            try
            {
                aglc = new AmazonGameLiftClient(config);
            }
            catch (AmazonServiceException e)
            {
                Debug.Log("AWS Credentials not found. Cannot connect to GameLift. Start application with -credentials <file> flag where credentials are the credentials.csv or accessKeys.csv file containing the access and secret key. GL390");
                Debug.Log(e.Message);
            }
        }
    }
示例#3
0
        public void UseLocalServer()
        {
            var conf = new AmazonGameLiftConfig {
                ServiceURL = "http://localhost:9080"
            };

            _glClient = new AmazonGameLiftClient(conf);
        }
示例#4
0
        public Client()
        {
            var conf = new AmazonGameLiftConfig {
                RegionEndpoint = RegionEndpoint.APNortheast1
            };

            _glClient = new AmazonGameLiftClient(conf);
            Console.CancelKeyPress += (sender, args) =>
            {
                args.Cancel = true;
                _isRunning  = false;
            };
        }
        protected IAmazonGameLift CreateClient(AWSCredentials credentials, RegionEndpoint region)
        {
            var config = new AmazonGameLiftConfig {
                RegionEndpoint = region
            };

            Amazon.PowerShell.Utils.Common.PopulateConfig(this, config);
            this.CustomizeClientConfig(config);
            var client = new AmazonGameLiftClient(credentials, config);

            client.BeforeRequestEvent += RequestEventHandler;
            client.AfterResponseEvent += ResponseEventHandler;
            return(client);
        }
    // Ends the game session for all and disconnects the players
    public void TerminateGameSession()
    {
        Console.WriteLine("Terminating session and Task");
        // Let FleetIQ know we are done
        var gameLiftConfig = new AmazonGameLiftConfig {
            RegionEndpoint = this.server.regionEndpoint
        };
        var gameLiftClient = new AmazonGameLiftClient(gameLiftConfig);
        var deregisterGameServerRequest = new DeregisterGameServerRequest();

        deregisterGameServerRequest.GameServerGroupName = Server.fleetIqGameServerGroup;
        deregisterGameServerRequest.GameServerId        = this.server.GetGameServerId();
        var response = gameLiftClient.DeregisterGameServerAsync(deregisterGameServerRequest);

        response.Wait();
        Console.WriteLine("Deregistered from FleetIQ, terminate Task...");
        Application.Quit();
    }
示例#7
0
        private static async Task <string> UpdateAlias(string aliasUpdate, string fleetId)
        {
            var config = new AmazonGameLiftConfig();

            config.RegionEndpoint = region;
            using (AmazonGameLiftClient aglc = new AmazonGameLiftClient(config))
            {
                // create a new alias
                var uareq = new Amazon.GameLift.Model.UpdateAliasRequest();
                uareq.AliasId         = aliasUpdate;
                uareq.RoutingStrategy = new RoutingStrategy
                {
                    Type    = RoutingStrategyType.SIMPLE,
                    FleetId = fleetId,
                    Message = ""
                };
                Amazon.GameLift.Model.UpdateAliasResponse cares = await aglc.UpdateAliasAsync(uareq);

                return(cares.Alias.AliasId);
            }
        }
示例#8
0
        static async Task <string> CreateAlias(string name, string fleetId)
        {
            var config = new AmazonGameLiftConfig();

            config.RegionEndpoint = region;
            using (AmazonGameLiftClient aglc = new AmazonGameLiftClient(config))
            {
                // create fleet
                var careq = new Amazon.GameLift.Model.CreateAliasRequest();
                careq.Name            = name;
                careq.Description     = "Alias to direct traffic to " + fleetId;
                careq.RoutingStrategy = new RoutingStrategy
                {
                    Type    = RoutingStrategyType.SIMPLE,
                    FleetId = fleetId,
                    Message = ""
                };
                Amazon.GameLift.Model.CreateAliasResponse cares = await aglc.CreateAliasAsync(careq);

                return(cares.Alias.AliasId);
            }
        }
示例#9
0
    public void DoInitClient()
    {
        if (clientInit == true)
        {
            LogToMyConsoleMainThread("Client Already Initialized");
            return;
        }


        clientInit = true;
        UniqueID   = System.Guid.NewGuid().ToString();

        UnityInitializer.AttachToGameObject(gameObject);

        AWSConfigs.HttpClient = AWSConfigs.HttpClientOption.UnityWebRequest;

        AmazonGameLiftConfig gameLiftConfig = new AmazonGameLiftConfig();

        if (localMode == false)
        {
            gameLiftConfig.RegionEndpoint = RegionEndpoint.USWest2;
        }
        else
        {
            gameLiftConfig.ServiceURL = "http://localhost:9080";
        }



        m_Client = new AmazonGameLiftClient(
            staticData.awsAccessKeyId,
            staticData.awsSecretAccessKey,
            gameLiftConfig);

        LogToMyConsoleMainThread("Client Initialized");
    }
示例#10
0
    private void CreateGameLiftClient()
    {
        Debug.Log("CreateGameLiftClient");

        CognitoAWSCredentials credentials = new CognitoAWSCredentials(
            CognitoIdentityPool,
            RegionEndpoint.USEast1
            );

        if (IsArgFlagPresent(IsProdArg))
        {
            _amazonGameLiftClient = new AmazonGameLiftClient(credentials, RegionEndpoint.USEast1);
        }
        else
        {
            // local testing
            // guide: https://docs.aws.amazon.com/gamelift/latest/developerguide/integration-testing-local.html
            AmazonGameLiftConfig amazonGameLiftConfig = new AmazonGameLiftConfig()
            {
                ServiceURL = "http://localhost:9080"
            };
            _amazonGameLiftClient = new AmazonGameLiftClient("asdfasdf", "asdf", amazonGameLiftConfig);
        }
    }
示例#11
0
        static async Task <string> CreateFleet(string name, string version, string buildId)
        {
            var config = new AmazonGameLiftConfig();

            config.RegionEndpoint = region;
            using (AmazonGameLiftClient aglc = new AmazonGameLiftClient(config))
            {
                // create launch configuration
                var serverProcess = new ServerProcess();
                serverProcess.ConcurrentExecutions = 1;
                serverProcess.LaunchPath           = @"C:\game\GameLiftUnity.exe"; // @"/local/game/ReproGLLinux.x86_64";
                serverProcess.Parameters           = "-batchmode -nographics";

                // create inbound IP permissions
                var permission1 = new IpPermission();
                permission1.FromPort = 1935;
                permission1.ToPort   = 1935;
                permission1.Protocol = IpProtocol.TCP;
                permission1.IpRange  = "0.0.0.0/0";

                // create inbound IP permissions
                var permission2 = new IpPermission();
                permission2.FromPort = 3389;
                permission2.ToPort   = 3389;
                permission2.Protocol = IpProtocol.TCP;
                permission2.IpRange  = "0.0.0.0/0";

                // create fleet
                var cfreq = new CreateFleetRequest();
                cfreq.Name            = name;
                cfreq.Description     = version;
                cfreq.BuildId         = buildId;
                cfreq.EC2InstanceType = EC2InstanceType.C4Large;
                cfreq.EC2InboundPermissions.Add(permission1);
                cfreq.EC2InboundPermissions.Add(permission2);
                cfreq.RuntimeConfiguration = new RuntimeConfiguration();
                cfreq.RuntimeConfiguration.ServerProcesses = new List <ServerProcess>();
                cfreq.RuntimeConfiguration.ServerProcesses.Add(serverProcess);
                cfreq.NewGameSessionProtectionPolicy = ProtectionPolicy.NoProtection;
                CreateFleetResponse cfres = await aglc.CreateFleetAsync(cfreq);

                // set fleet capacity
                var ufcreq = new UpdateFleetCapacityRequest();
                ufcreq.MinSize          = 0;
                ufcreq.DesiredInstances = 1;
                ufcreq.MaxSize          = 1;
                ufcreq.FleetId          = cfres.FleetAttributes.FleetId;
                UpdateFleetCapacityResponse ufcres = await aglc.UpdateFleetCapacityAsync(ufcreq);

                // set scaling rule (switch fleet off after 1 day of inactivity)
                // If [MetricName] is [ComparisonOperator] [Threshold] for [EvaluationPeriods] minutes, then [ScalingAdjustmentType] to/by [ScalingAdjustment].
                var pspreq = new PutScalingPolicyRequest();
                pspreq.Name                  = "Switch fleet off after 1 day of inactivity";
                pspreq.MetricName            = MetricName.ActiveGameSessions;
                pspreq.ComparisonOperator    = ComparisonOperatorType.LessThanOrEqualToThreshold;
                pspreq.Threshold             = 0.0;  // double (don't use int)
                pspreq.EvaluationPeriods     = 1435; // just under 1 day, 1435 appears to be the maximum permitted value now.
                pspreq.ScalingAdjustmentType = ScalingAdjustmentType.ExactCapacity;
                pspreq.ScalingAdjustment     = 0;
                pspreq.FleetId               = cfres.FleetAttributes.FleetId;
                PutScalingPolicyResponse pspres = await aglc.PutScalingPolicyAsync(pspreq);

                return(cfres.FleetAttributes.FleetId);
            }
        }
    public void GetConnectionInfo(ref string ip, ref int port, ref string auth)
    {
        Debug.Log("GetConnectionInfo()");
        var config = new AmazonGameLiftConfig();

        config.RegionEndpoint = Amazon.RegionEndpoint.USEast1;
        AmazonGameLiftClient aglc = null;
        AWSCredentials       credentials;
        var  chain        = new CredentialProfileStoreChain();
        bool profileFound = chain.TryGetAWSCredentials("demo-gamelift-unity", out credentials);

        if (profileFound)
        {
            Debug.Log("demo-gamelift-unity profile");
            aglc = new AmazonGameLiftClient(credentials, config);
        }
        else
        {
            Debug.Log("regular profile search");
            try
            {
                aglc = new AmazonGameLiftClient(config);
            }
            catch (AmazonServiceException e)
            {
                // search failed
                Debug.Log(e.Message);
                Debug.Log("AWS Credentials not found. Cannot connect to GameLift. Start application with -credentials <file> flag where credentials are the credentials.csv file containing the access and secret key.");
            }
        }
        if (aglc != null)
        {
            try
            {
                for (int retry = 0; retry < 4; retry++)
                {
                    Debug.Log("SearchGameSessions retry==" + retry);
                    Amazon.GameLift.Model.GameSession gsession = SearchGameSessions(aglc);
                    if (gsession != null)
                    {
                        Debug.Log("GameSession found " + gsession.GameSessionId);
                        Amazon.GameLift.Model.PlayerSession psession = CreatePlayerSession(aglc, gsession);
                        if (psession != null)
                        {
                            // created a player session in there
                            ip   = psession.IpAddress;
                            port = psession.Port;
                            auth = psession.PlayerSessionId;
                            Debug.Log("CLIENT CONNECT INFO: " + ip + ", " + port + ", " + auth);
                            if (gl.gamelogic != null)
                            {
                                gl.gamelogic.GameliftStatus = true;
                            }
                            aglc.Dispose();
                            return;
                        }

                        // player session creation failed (probably beaten to the session by another player)
                        retry = 0; // start over
                    }
                }

                // no game session, we should create one
                for (int retry = 0; retry < 4; retry++)
                {
                    Debug.Log("GameSession not found. CreateGameSession: retry==" + retry);
                    Amazon.GameLift.Model.GameSession gsession = CreateGameSession(aglc);
                    if (gsession != null)
                    {
                        for (int psretry = 0; psretry < 4; psretry++)
                        {
                            Debug.Log("CreatePlayerSession: retry==" + psretry);
                            psession = CreatePlayerSession(aglc, gsession);
                            if (psession != null)
                            {
                                // created a player session in there
                                ip   = psession.IpAddress;
                                port = psession.Port;
                                auth = psession.PlayerSessionId;
                                Debug.Log("CLIENT CONNECT INFO: " + ip + ", " + port + ", " + auth);
                                if (gl.gamelogic != null)
                                {
                                    gl.gamelogic.GameliftStatus = true;
                                }
                                aglc.Dispose();
                                return;
                            }
                        }

                        // player session creation failed (probably beaten to the session by another player)
                        retry = 0; // start over
                    }
                }
            }
            catch (Exception e)
            {
                Debug.Log("AWS Credentials found but probably invalid. Check IAM permissions for the credentials.");
                Debug.Log(e.Message);
            }
            finally
            {
                aglc.Dispose();
            }
        }

        // something's not working. fall back to local client
        Debug.Log("CLIENT CONNECT INFO (LOCAL): " + ip + ", " + port + ", " + auth);
        if (gl.gamelogic != null)
        {
            gl.gamelogic.GameliftStatus = false;
        }
    }
    public GameLiftClient(GameLift _gl)
    {
        gl       = _gl;
        playerId = Guid.NewGuid().ToString();
        Credentials.Install();

        // Use command line alias if possible, otherwise use default (hard coded alias)
        string[] args = System.Environment.GetCommandLineArgs();
        for (int i = 0; i < args.Length - 1; i++)
        {
            if (args[i] != "--alias")
            {
                //Debug.Log(":( Unrecognized command line parameter: " + args[i] + " (consider --alias <aliasId>)" + Environment.NewLine);
                continue;
            }

            string pattern = @"alias-[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}";
            Match  m       = Regex.Match(args[i + 1], pattern);
            if (m.Success)
            {
                aliasId = m.Value;
                Debug.Log(":) ALIAS RECOGNIZED. Alias " + aliasId + " found on command line");
                break;
            }
        }

        // verify alias exists
        var config = new AmazonGameLiftConfig();

        config.RegionEndpoint = Amazon.RegionEndpoint.USEast1;
        AmazonGameLiftClient aglc = null;
        AWSCredentials       credentials;

        var  chain        = new CredentialProfileStoreChain();
        bool profileFound = chain.TryGetAWSCredentials("demo-gamelift-unity", out credentials);

        if (profileFound)
        {
            Debug.Log("demo-gamelift-unity profile");
            aglc = new AmazonGameLiftClient(credentials, config);
        }
        else
        {
            Debug.Log("regular profile search");
            try
            {
                aglc = new AmazonGameLiftClient(config);
            }
            catch (AmazonServiceException e)
            {
                Debug.Log(e.Message);
                Debug.Log("AWS Credentials not found. Cannot connect to GameLift. Start application with -credentials <file> flag where credentials are the credentials.csv file containing the access and secret key.");
            }
        }
        if (aglc != null)
        {
            try
            {
                var dareq = new Amazon.GameLift.Model.DescribeAliasRequest();
                dareq.AliasId = aliasId;
                Amazon.GameLift.Model.DescribeAliasResponse dares = aglc.DescribeAlias(dareq);
                Amazon.GameLift.Model.Alias alias = dares.Alias;
                Debug.Log((int)dares.HttpStatusCode + " ALIAS NAME: " + alias.Name + " (" + aliasId + ")");
                if (alias.RoutingStrategy.Type == Amazon.GameLift.RoutingStrategyType.TERMINAL)
                {
                    Debug.Log("             (TERMINAL ALIAS)");
                }
            }
            catch (Exception e)
            {
                Debug.Log("AWS Credentials found but probably invalid. Check IAM permissions for the credentials.");
                Debug.Log(e.Message);
            }
            finally
            {
                aglc.Dispose();
            }
        }
    }