Beispiel #1
0
    async private Task <GameSession> SearchGameSessionsAsync()
    {
        Debug.Log("SearchGameSessions");
        var searchGameSessionsRequest = new SearchGameSessionsRequest();

        searchGameSessionsRequest.FleetId          = FleetId;                           // can also use AliasId
        searchGameSessionsRequest.FilterExpression = "hasAvailablePlayerSessions=true"; // only ones we can join
        searchGameSessionsRequest.SortExpression   = "creationTimeMillis ASC";          // return oldest first
        searchGameSessionsRequest.Limit            = 1;                                 // only one session even if there are other valid ones

        Task <SearchGameSessionsResponse> SearchGameSessionsResponseTask = _amazonGameLiftClient.SearchGameSessionsAsync(searchGameSessionsRequest);
        SearchGameSessionsResponse        searchGameSessionsResponse     = await SearchGameSessionsResponseTask;

        int gameSessionCount = searchGameSessionsResponse.GameSessions.Count;

        Debug.Log($"GameSessionCount:  {gameSessionCount}");

        if (gameSessionCount > 0)
        {
            Debug.Log("We have game sessions!");
            Debug.Log(searchGameSessionsResponse.GameSessions[0].GameSessionId);
            return(searchGameSessionsResponse.GameSessions[0]);
        }
        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));
        }
Beispiel #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);
        }
    }
Beispiel #4
0
        public GameSession SearchSession(string fleetId)
        {
            var req = new SearchGameSessionsRequest
            {
                FleetId          = fleetId,
                FilterExpression =
                    $"gameSessionProperties.roomName = '{RoomName}' AND hasAvailablePlayerSessions = true"
            };
            var res = _glClient.SearchGameSessionsAsync(req).Result;

            if (res.GameSessions.Count < 1)
            {
                return(null);
            }

            foreach (var s in res.GameSessions)
            {
                Console.WriteLine($"session: {s.GameSessionId}, {s.CreationTime}");
            }

            return(res.GameSessions.First());
        }
Beispiel #5
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;
    }
Beispiel #6
0
    public GameSession 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          = m_targetFleet,
            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_gameLiftClient.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);
        }

        int sessionsFound = gameSessionlist.GameSessions.Count;

        Debug.Log("Gamesessions found: " + sessionsFound);
        GameSession gameSession = null;

        for (int i = 0; i < sessionsFound; ++i)
        {
            //TODO: Implement logic here to determine best server.
            //Join first valid result returned
            GameSession gameSessionCandidate = gameSessionlist.GameSessions[i];
            int         currentPlayerCount   = gameSessionCandidate.CurrentPlayerSessionCount;
            int         maxPlayerCount       = gameSessionCandidate.MaximumPlayerSessionCount;
            var         creationPolicy       = gameSessionCandidate.PlayerSessionCreationPolicy; // TODO: This is always null... How do we get the server to set this variable?

            if (currentPlayerCount < maxPlayerCount)                                             // TODO: This if check will be useless once we implement the filter in the search game session request.
            {
                gameSession = gameSessionCandidate;
                break;
            }
        }
        if (gameSession == null)
        {
            Debug.Log("Unable to join any game sessions found. We should create one now...");
            return(null);
            //TODO: Note: If we create a game session here and immediately try to join it, it may fail because the server status will not be set to "ACTIVE" yet.
            //https://gamedev.amazon.com/forums/questions/61279/how-to-add-player-to-server-work-flow-using-gameli.html
        }
        Debug.Log("Game session successfully found");
        return(gameSession);
    }
 public void SearchGameSessionsAsync(SearchGameSessionsRequest request, AmazonServiceCallback <SearchGameSessionsRequest, SearchGameSessionsResponse> callback, AsyncOptions options = null)
 {
     throw new System.NotImplementedException();
 }