private GameSession CreateGameSession(string fleetId, string sid) { var props = new List <GameProperty> { new GameProperty { Key = "roomName", Value = RoomName } }; var createReq = new CreateGameSessionRequest { Name = RoomName, FleetId = fleetId, IdempotencyToken = sid, MaximumPlayerSessionCount = 4, GameProperties = props, }; var res = _glClient.CreateGameSessionAsync(createReq).Result; return(res.GameSession); }
public async void CreateRoom() { UnityEngine.Debug.Log("CreateRoom"); String roomName = Guid.NewGuid().ToString(); var request = new CreateGameSessionRequest { AliasId = gameLiftAliasId, MaximumPlayerSessionCount = 20, Name = roomName }; var response = await gameLiftClient.CreateGameSessionAsync(request); if (response.HttpStatusCode == HttpStatusCode.OK) { gameSessionId = response.GameSession.GameSessionId; } DebugUI.text = "CreateRoom: SessionID=" + gameSessionId; JoinRoom(); }
async private Task <GameSession> CreateGameSessionAsync() { Debug.Log("CreateGameSessionAsync"); var createGameSessionRequest = new Amazon.GameLift.Model.CreateGameSessionRequest(); createGameSessionRequest.FleetId = FleetId; // can also use AliasId createGameSessionRequest.CreatorId = _playerUuid; createGameSessionRequest.MaximumPlayerSessionCount = 2; // search for two player game Task <CreateGameSessionResponse> createGameSessionRequestTask = _amazonGameLiftClient.CreateGameSessionAsync(createGameSessionRequest); Debug.Log("after task createGameSessionRequestTask"); CreateGameSessionResponse createGameSessionResponse = await createGameSessionRequestTask; Debug.Log("after createGameSessionRequestTask"); string gameSessionId = createGameSessionResponse.GameSession != null ? createGameSessionResponse.GameSession.GameSessionId : "N/A"; Debug.Log((int)createGameSessionResponse.HttpStatusCode + " GAME SESSION CREATED: " + gameSessionId); return(createGameSessionResponse.GameSession); }
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, }); } }