Beispiel #1
0
        private PlayerSession CreatePlayerSession(GameSession session)
        {
            var pid   = Guid.NewGuid().ToString();
            var psReq = new CreatePlayerSessionRequest {
                GameSessionId = session.GameSessionId, PlayerId = pid
            };
            var task = _glClient.CreatePlayerSessionAsync(psReq);

            try
            {
                var cpRes = task.Result;
                var pSess = cpRes.PlayerSession;
                Console.WriteLine("create player session: {0}", pSess.PlayerSessionId);
                return(pSess);
            }
            catch (AggregateException e)
            {
                var exception = e.InnerExceptions.First();
                if (exception.GetType() != typeof(GameSessionFullException))
                {
                    throw;
                }
                Console.WriteLine("session[{0}] is full: {1}", session.GameSessionId, pid);
                return(null);
            }
            catch (Exception e)
            {
                Console.WriteLine("cannot create player session: {0}, {1}", pid, e);
                return(null);
            }
        }
    public async void JoinRoom()
    {
        string sessionId = gameSessionId;

        System.Random rnd = new System.Random();

        UnityEngine.Debug.Log("JoinRoom");
        var response = await gameLiftClient.CreatePlayerSessionAsync(new CreatePlayerSessionRequest {
            GameSessionId = sessionId,
            PlayerId      = SystemInfo.deviceUniqueIdentifier,
        });

        var playerSession = response.PlayerSession;

        playsersessionId = playerSession.PlayerSessionId;
        var ClientudpPort = SearchAvailableUdpPort(33400, 33400 + 100);

        realTimeClient = new RealTimeClient(
            playerSession.DnsName,
            playerSession.Port,
            ClientudpPort,
            ConnectionType.RT_OVER_WS_UDP_UNSECURED,
            playerSession.PlayerSessionId,
            null);
        realTimeClient.OnDataReceivedCallback = ReceivedServerPushedDataCallback;

        DebugUI.text = DebugUI.text + "\n" + "Room Joined: playsersessionId=" + playsersessionId;
    }
Beispiel #3
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 #4
0
    async private Task <PlayerSession> CreatePlayerSessionAsync(GameSession gameSession)
    {
        var createPlayerSessionRequest = new CreatePlayerSessionRequest();

        createPlayerSessionRequest.GameSessionId = gameSession.GameSessionId;
        createPlayerSessionRequest.PlayerId      = _playerUuid;

        Task <CreatePlayerSessionResponse> createPlayerSessionResponseTask = _amazonGameLiftClient.CreatePlayerSessionAsync(createPlayerSessionRequest);
        CreatePlayerSessionResponse        createPlayerSessionResponse     = await createPlayerSessionResponseTask;

        string playerSessionId = createPlayerSessionResponse.PlayerSession != null ? createPlayerSessionResponse.PlayerSession.PlayerSessionId : "N/A";

        Debug.Log((int)createPlayerSessionResponse.HttpStatusCode + " PLAYER SESSION CREATED: " + playerSessionId);
        return(createPlayerSessionResponse.PlayerSession);
    }
Beispiel #5
0
        public async Task <APIGatewayProxyResponse> Post(APIGatewayProxyRequest request, ILambdaContext context)
        {
            CreateGameRequest    body         = JsonSerializer.Deserialize <CreateGameRequest>(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;

            CreateGameSessionRequest req = new CreateGameSessionRequest();

            req.MaximumPlayerSessionCount = 2;
            req.FleetId   = fleetId;
            req.CreatorId = body.playerId;
            req.GameProperties.Add(new GameProperty()
            {
                Key   = "IsPrivate",
                Value = body.isPrivate.ToString()
            });
            req.GameProperties.Add(new GameProperty()
            {
                Key   = "Password",
                Value = body.password == null ? "" : body.password
            });
            try
            {
                CreateGameSessionResponse res = await amazonClient.CreateGameSessionAsync(req);

                GameSession gameSession = res.GameSession;
                int         retries     = 0;
                while (gameSession.Status.Equals(GameSessionStatus.ACTIVATING) && retries < 100)
                {
                    DescribeGameSessionsRequest describeReq = new DescribeGameSessionsRequest();
                    describeReq.GameSessionId = res.GameSession.GameSessionId;
                    gameSession = (await amazonClient.DescribeGameSessionsAsync(describeReq)).GameSessions[0];
                    retries++;
                }

                CreatePlayerSessionRequest playerSessionRequest = new CreatePlayerSessionRequest();
                playerSessionRequest.PlayerId      = body.playerId;
                playerSessionRequest.GameSessionId = gameSession.GameSessionId;
                CreatePlayerSessionResponse playerSessionResponse = await amazonClient.CreatePlayerSessionAsync(playerSessionRequest);

                CreateGameResponse response = new CreateGameResponse {
                    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" }
                    }
                });
            }
            catch (NotFoundException e)
            {
                return(new APIGatewayProxyResponse
                {
                    StatusCode = (int)HttpStatusCode.NotFound,
                    Body = "Your game is out of date! Download the newest version\n" + e.Message,
                });
            }
            catch (FleetCapacityExceededException e)
            {
                return(new APIGatewayProxyResponse
                {
                    StatusCode = (int)HttpStatusCode.InternalServerError,
                    Body = "Our game servers are too busy right now, come back later!\n" + e.Message,
                });
            }
            catch (Exception e)
            {
                return(new APIGatewayProxyResponse
                {
                    StatusCode = (int)HttpStatusCode.InternalServerError,
                    Body = "An unexpected error occurred! Please notify the developers.\n" + e.Message,
                });
            }
        }