Properties describing a player session.
コード例 #1
0
    public void GetConnectionInfo(ref string ip, ref int port, ref string auth)
    {
        Debug.Log("GetConnectionInfo()");
        if (aglc != null)
        {
            try
            {
                for (int retry = 0; retry < 4; retry++)
                {
                    Debug.Log("SearchGameSessions retry==" + retry);
                    Amazon.GameLift.Model.GameSession gsession = SearchGameSessions();
                    if (gsession != null)
                    {
                        Debug.Log("GameSession found " + gsession.GameSessionId);
                        Amazon.GameLift.Model.PlayerSession psession = CreatePlayerSession(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} GL545");
                            if (gl != null)
                            {
                                gl.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();
                    if (gsession != null)
                    {
                        for (int psretry = 0; psretry < 4; psretry++)
                        {
                            Debug.Log("CreatePlayerSession: retry==" + psretry);
                            psession = CreatePlayerSession(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} GL574");
                                if (gl != null)
                                {
                                    gl.gameliftStatus = true;
                                }
                                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. GL588");
                Debug.Log(e.Message);
            }
        }

        // something's not working. fall back to local client
        Debug.Log($"CLIENT CONNECT INFO (LOCAL): {ip}, {port}, {auth} GL594");
        if (gl != null)
        {
            gl.gameliftStatus = false;
        }
    }
コード例 #2
0
    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;
        }
    }