Beispiel #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);

            DescribeGameSessionsResponse resp = new DescribeGameSessionsResponse();

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

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

                foreach (var obj in resp.GameSessions)
                {
                    AddObject(obj);
                }
            }while (!string.IsNullOrEmpty(resp.NextToken));
        }
        /// <summary>
        /// Unmarshaller the response from the service to the response class.
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context)
        {
            DescribeGameSessionsResponse response = new DescribeGameSessionsResponse();

            context.Read();
            int targetDepth = context.CurrentDepth;

            while (context.ReadAtDepth(targetDepth))
            {
                if (context.TestExpression("GameSessions", targetDepth))
                {
                    var unmarshaller = new ListUnmarshaller <GameSession, GameSessionUnmarshaller>(GameSessionUnmarshaller.Instance);
                    response.GameSessions = unmarshaller.Unmarshall(context);
                    continue;
                }
                if (context.TestExpression("NextToken", targetDepth))
                {
                    var unmarshaller = StringUnmarshaller.Instance;
                    response.NextToken = unmarshaller.Unmarshall(context);
                    continue;
                }
            }

            return(response);
        }
Beispiel #3
0
    public void DescribeGameSessions(object GameSessionID)
    {
        if (clientInit == false)
        {
            LogToMyConsoleMainThread("Need to Initialize Client");
            return;
        }


        //Request must contain either GameSessionID or FleetID, but not both
        var request = new DescribeGameSessionsRequest();

        string myGameSessionID = (string)GameSessionID;

        if (myGameSessionID != null)
        {
            request.GameSessionId = myGameSessionID;
            LogToMyConsoleMainThread("DescribeGameSession " + myGameSessionID);
        }
        else if (localMode == false)
        {
            request.FleetId = staticData.myFleetID;
            LogToMyConsoleMainThread("DescribeGameSessions for fleet " + staticData.myFleetID);
        }
        else
        {
            request.GameSessionId = "gsess-abc";
            LogToMyConsoleMainThread("Local Mode: describing default session");
            LogToMyConsoleMainThread("DescribeGameSession " + myGameSessionID);
        }

        gameSessionlist = null;
        try
        {
            gameSessionlist = m_Client.DescribeGameSessions(request);
        }
        catch (Exception ex)
        {
            Handler(ex);
        }
        if (gameSessionlist == null)
        {
            LogToMyConsoleMainThread("Unable to describe Game Sessions... What now?");
        }
        else
        {
            LogToMyConsoleMainThread("Number of Game Sessions: " + gameSessionlist.GameSessions.Count);

            foreach (GameSession GS in gameSessionlist.GameSessions)
            {
                LogToMyConsoleMainThread("Game Session ID: " + GS.GameSessionId
                                         + " Game Session Status: " + GS.Status.ToString()
                                         + " Game Session Endpoint: " + GS.IpAddress + ":" + GS.Port
                                         + " Game Session Players: " + GS.CurrentPlayerSessionCount + "/" + GS.MaximumPlayerSessionCount

                                         );
            }
        }
    }
    public void DescribeGameSessions()
    {
        if (clientInit == false)
        {
            LogToMyConsoleMainThread("Need to Initialize Client");
            return;
        }

        LogToMyConsoleMainThread("DescribeGameSessions");

        //Request must contain either GameSessionID or FleetID, but not both
        var request = new DescribeGameSessionsRequest();

        if (localMode == false)
        {
            request.FleetId = m_targetFleet;
        }
        else
        {
            request.GameSessionId = "gsess-abc";
        }


        DescribeGameSessionsResponse gameSessionlist = null;

        try
        {
            gameSessionlist = m_Client.DescribeGameSessions(request);
        }
        catch (Exception ex)
        {
            Handler(ex);
        }
        if (gameSessionlist == null)
        {
            LogToMyConsoleMainThread("Unable to describe Game Sessions... What now?");
        }
        else
        {
            myName          = gameSessionlist.GameSessions[0].Name;
            myGameSessionID = gameSessionlist.GameSessions[0].GameSessionId;
            myPort          = gameSessionlist.GameSessions[0].Port;

            LogToMyConsoleMainThread("Number of Game Sessions: " + gameSessionlist.GameSessions.Count);

            foreach (GameSession GS in gameSessionlist.GameSessions)
            {
                LogToMyConsoleMainThread("Game Session ID: + " + GS.GameSessionId
                                         + " Game Session Status: " + GS.StatusReason + " " + GS.StatusReason
                                         + " Game Session Endpoint: " + GS.IpAddress + ":" + GS.Port
                                         + " Game Session Players: " + GS.CurrentPlayerSessionCount + "/" + GS.MaximumPlayerSessionCount

                                         );
            }
        }
    }
Beispiel #5
0
        public async Task <APIGatewayProxyResponse> Post(APIGatewayProxyRequest request, ILambdaContext context)
        {
            JoinGameRequest      input        = JsonSerializer.Deserialize <JoinGameRequest>(request.Body);
            AmazonGameLiftClient amazonClient = new AmazonGameLiftClient(Amazon.RegionEndpoint.USEast1);

            ListAliasesRequest aliasReq = new ListAliasesRequest();

            aliasReq.Name = "WarshopServer";
            Alias aliasRes = (await amazonClient.ListAliasesAsync(aliasReq)).Aliases[0];
            DescribeAliasRequest describeAliasReq = new DescribeAliasRequest();

            describeAliasReq.AliasId = aliasRes.AliasId;
            string fleetId = (await amazonClient.DescribeAliasAsync(describeAliasReq.AliasId)).Alias.RoutingStrategy.FleetId;

            DescribeGameSessionsResponse gameSession = await amazonClient.DescribeGameSessionsAsync(new DescribeGameSessionsRequest()
            {
                GameSessionId = input.gameSessionId
            });

            bool   IsPrivate = gameSession.GameSessions[0].GameProperties.Find((GameProperty gp) => gp.Key.Equals("IsPrivate")).Value.Equals("True");
            string Password  = IsPrivate ? gameSession.GameSessions[0].GameProperties.Find((GameProperty gp) => gp.Key.Equals("Password")).Value : "";

            if (!IsPrivate || input.password.Equals(Password))
            {
                CreatePlayerSessionRequest playerSessionRequest = new CreatePlayerSessionRequest();
                playerSessionRequest.PlayerId      = input.playerId;
                playerSessionRequest.GameSessionId = input.gameSessionId;
                CreatePlayerSessionResponse playerSessionResponse = amazonClient.CreatePlayerSessionAsync(playerSessionRequest).Result;
                JoinGameResponse            response = new JoinGameResponse
                {
                    playerSessionId = playerSessionResponse.PlayerSession.PlayerSessionId,
                    ipAddress       = playerSessionResponse.PlayerSession.IpAddress,
                    port            = playerSessionResponse.PlayerSession.Port
                };

                return(new APIGatewayProxyResponse
                {
                    StatusCode = (int)HttpStatusCode.OK,
                    Body = JsonSerializer.Serialize(response),
                    Headers = new Dictionary <string, string> {
                        { "Content-Type", "application/json" }
                    }
                });
            }
            else
            {
                return(new APIGatewayProxyResponse
                {
                    StatusCode = (int)HttpStatusCode.BadRequest,
                    Body = "Incorrect password for private game",
                });
            }
        }
Beispiel #6
0
        public async Task <APIGatewayProxyResponse> Get(ILambdaContext context)
        {
            AmazonGameLiftClient amazonClient = new AmazonGameLiftClient(Amazon.RegionEndpoint.USEast1);

            ListAliasesRequest aliasReq = new ListAliasesRequest();

            aliasReq.Name = "WarshopServer";
            Alias aliasRes = (await amazonClient.ListAliasesAsync(aliasReq)).Aliases[0];
            DescribeAliasRequest describeAliasReq = new DescribeAliasRequest();

            describeAliasReq.AliasId = aliasRes.AliasId;
            string fleetId = (await amazonClient.DescribeAliasAsync(describeAliasReq.AliasId)).Alias.RoutingStrategy.FleetId;

            DescribeGameSessionsRequest describeReq = new DescribeGameSessionsRequest();

            describeReq.FleetId      = fleetId;
            describeReq.StatusFilter = GameSessionStatus.ACTIVE;
            DescribeGameSessionsResponse describeRes = await amazonClient.DescribeGameSessionsAsync(describeReq);

            List <GameView> gameViews = describeRes.GameSessions
                                        .FindAll((GameSession g) => g.CurrentPlayerSessionCount < g.MaximumPlayerSessionCount)
                                        .ConvertAll((GameSession g) => new GameView()
            {
                gameSessionId = g.GameSessionId,
                creatorId     = g.CreatorId,
                isPrivate     = true.ToString() == g.GameProperties.Find((GameProperty gp) => gp.Key.Equals("IsPrivate")).Value
            });

            GetGamesResponse response = new GetGamesResponse()
            {
                gameViews = gameViews.ToArray()
            };

            return(new APIGatewayProxyResponse
            {
                StatusCode = (int)HttpStatusCode.OK,
                Body = JsonSerializer.Serialize(response),
                Headers = new Dictionary <string, string> {
                    { "Content-Type", "application/json" }
                }
            });
        }
Beispiel #7
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;
    }