Exemplo n.º 1
0
 public Amazon.GameLift.Model.GameSession SearchGameSessions()
 {
     try
     {
         var sgsreq = new Amazon.GameLift.Model.SearchGameSessionsRequest();
         sgsreq.AliasId          = aliasId;                           // only our game
         sgsreq.FilterExpression = "hasAvailablePlayerSessions=true"; // only ones we can join
         sgsreq.SortExpression   = "creationTimeMillis ASC";          // return oldest first
         sgsreq.Limit            = 1;                                 // only one session even if there are other valid ones
         Amazon.GameLift.Model.SearchGameSessionsResponse sgsres = aglc.SearchGameSessions(sgsreq);
         Debug.Log((int)sgsres.HttpStatusCode + " GAME SESSION SEARCH FOUND " + sgsres.GameSessions.Count + " SESSIONS (on " + aliasId + ")");
         if (sgsres.GameSessions.Count > 0)
         {
             return(sgsres.GameSessions[0]);
         }
         return(null);
     }
     catch (Amazon.GameLift.Model.InvalidRequestException e)
     {
         // EXCEPTION HERE? Your alias does not point to a valid fleet, possibly.
         Debug.Log(e.StatusCode.ToString() + " :( SEARCHGAMESESSIONS FAILED. InvalidRequestException " + e.Message +
                   Environment.NewLine + "Game alias " + aliasId + " may not point to a valid fleet" + Environment.NewLine);
         return(null);
     }
 }
        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);

            SearchGameSessionsResponse resp = new SearchGameSessionsResponse();

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

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

                foreach (var obj in resp.GameSessions)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
Exemplo n.º 3
0
    /// <summary>
    /// GameLift client
    /// </summary>
    public void SearchGameSessions()
    {
        GD.Print("starting search function");

        BasicAWSCredentials credentials = new BasicAWSCredentials("", "");

        gameLiftClient = new AmazonGameLiftClient(credentials, Amazon.RegionEndpoint.SAEast1);

        SearchGameSessionsRequest request = new SearchGameSessionsRequest()
        {
            FilterExpression = "hasAvailablePlayerSessions=true",
            FleetId          = PongServer
        };

        try
        {
            SearchGameSessionsResponse activeSessions = gameLiftClient.SearchGameSessions(request);
            List <GameSession>         sessions       = activeSessions.GameSessions;
            if (sessions.Count == 0)
            {
                CreateSession();
            }
            else
            {
                ConnectToSession(sessions[0]);
            }
        }
        catch (Exception e)
        {
            GD.Print(e);
        }
    }
Exemplo n.º 4
0
    public void FindGameSession()
    {
        Debug.Log("FindGameSessionGameLift");

        //Search for active Game sessions:
        //https://docs.aws.amazon.com/sdkfornet/v3/apidocs/items/GameLift/TSearchGameSessionsRequest.html
        var request = new SearchGameSessionsRequest()
        {
            FilterExpression = "hasAvailablePlayerSessions=true",
            FleetId          = staticData.myFleetID,
            Limit            = 20,
            //FilterExpression = "maximumSessions>=10 AND hasAvailablePlayerSessions=true" // Example filter to limit search results
        };

        SearchGameSessionsResponse gameSessionlist = null;

        try
        {
            Debug.Log("Searching for game sessions");
            gameSessionlist = m_Client.SearchGameSessions(request);
            Debug.Log("Done Searching for game sessions");
        }
        catch (Exception ex)
        {
            Handler(ex);
        }
        if (gameSessionlist == null)
        {
            Debug.Log("Unable to search for Game Sessions... What now?");
            //return null;
        }
        else
        {
            myGameSession = gameSessionlist.GameSessions[0];
            Debug.Log(gameSessionlist.GameSessions.Count + " sessions found");
            Debug.Log(gameSessionlist.GameSessions[0].CurrentPlayerSessionCount + " / " +
                      gameSessionlist.GameSessions[0].MaximumPlayerSessionCount +
                      " players in game session");
            //Debug.Log(gameSessionlist.GameSessions[0].
        }
        //Debug.Log(gameSessionlist.GameSessions[0].Port);

        //gameSessionlist.GameSessions[0].


        //m_Client.CreatePlayerSession()

        var request2 = new CreatePlayerSessionRequest()
        {
            GameSessionId = gameSessionlist.GameSessions[0].GameSessionId,
            PlayerData    = "BoltIsBestNetworking",
            PlayerId      = UniqueID
        };

        //  var response2 = m_Client.CreatePlayerSession(request2);


        CreatePlayerSessionResponse SessionResponse = null;

        try
        {
            Debug.Log("Creating player session");
            SessionResponse = m_Client.CreatePlayerSession(request2);
            Debug.Log("Done Creating player session");
        }
        catch (Exception ex)
        {
            Handler(ex);
        }
        if (SessionResponse == null)
        {
            Debug.Log("Where are my dragons???");
            //return null;
        }

        return;
    }