void CreateGameSession(object maxPlayers) { LogToMyConsoleMainThread("CreateGameSession"); //Request must contain either GameSessionID or FleetID, but not both var request = new CreateGameSessionRequest() { FleetId = m_targetFleet, MaximumPlayerSessionCount = (int)maxPlayers, //GameSessionId = "gsess-abc" }; CreateGameSessionResponse CGSR = null; try { CGSR = m_Client.CreateGameSession(request); } catch (Exception ex) { Handler(ex); } if (CGSR == null) { LogToMyConsoleMainThread("Can't create game session"); } else { LogToMyConsoleMainThread("Game Session Created: " + CGSR.GameSession.GameSessionId); } }
public GameSession CreateGameSession() { Debug.Log("Creating a game session"); var gameSessionRequest = new CreateGameSessionRequest() { FleetId = m_targetFleet, CreatorId = m_uniqueId, MaximumPlayerSessionCount = 3, //TODO: This needs to be 3, 6, or 9 depending on what mode they selected. We also need to add this information to the GameProperties list so the server knows to initialize itself as a 3, 6, or 9 player server Name = "GameTest", //GameProperties = //List of keyValue pairs for custom properties about our game. Ex: How many players it is??? }; GameSession gameSession = null; try { CreateGameSessionResponse createGameSessionResponse = M_gameLiftClient.CreateGameSession(gameSessionRequest);//TODO: It Fails here gameSession = createGameSessionResponse.GameSession; Debug.Log("Game session created. ID: " + gameSession.GameSessionId); } catch (Exception ex) { Handler(ex); } Debug.Log("Done Creating a gamesession"); return(gameSession); }
public CreateGameSessionResponse CreateGameSession(CreateGameSessionRequest gameSessionRequest) { string content = JsonConvert.SerializeObject(gameSessionRequest); string path = string.Format("/vendoruser/{0}/CreateGameSession", _vendorName); string response = Post(content, path); CreateGameSessionResponse createGameSessionResponse = JsonConvert.DeserializeObject <CreateGameSessionResponse>(response); return(createGameSessionResponse); }
void CreateGameSession(object myCreateGameSessionData) { LogToMyConsoleMainThread("CreateGameSession"); CreateGameSessionData CGSD = (CreateGameSessionData)myCreateGameSessionData; GameProperty GP0 = new GameProperty(); GP0.Key = "BoltPro"; #if !BOLT_CLOUD GP0.Value = "true"; #endif #if BOLT_CLOUD GP0.Value = "false"; #endif List <GameProperty> GPL = new List <GameProperty>(); GPL.Add(GP0); //Request must contain either GameSessionID or FleetID, but not both var request = new CreateGameSessionRequest() { FleetId = staticData.myFleetID, MaximumPlayerSessionCount = CGSD.maxPlayers, CreatorId = UniqueID, GameSessionData = CGSD.GameSessionData, GameProperties = GPL, Name = "Test" + randomNumber //GameSessionId = "gsess-abc" }; CreateGameSessionResponse CGSR = null; try { CGSR = m_Client.CreateGameSession(request); } catch (Exception ex) { Handler(ex); } if (CGSR == null) { LogToMyConsoleMainThread("Can't create game session"); } else { LogToMyConsoleMainThread("Game Session Created: " + CGSR.GameSession.GameSessionId); } }
/// <summary> /// Unmarshaller the response from the service to the response class. /// </summary> /// <param name="context"></param> /// <returns></returns> public override AmazonWebServiceResponse Unmarshall(JsonUnmarshallerContext context) { CreateGameSessionResponse response = new CreateGameSessionResponse(); context.Read(); int targetDepth = context.CurrentDepth; while (context.ReadAtDepth(targetDepth)) { if (context.TestExpression("GameSession", targetDepth)) { var unmarshaller = GameSessionUnmarshaller.Instance; response.GameSession = unmarshaller.Unmarshall(context); continue; } } return(response); }
private void CreateSession() { GD.Print("no session found, creating new one"); CreateGameSessionRequest sessionRequest = new CreateGameSessionRequest() { MaximumPlayerSessionCount = 2, FleetId = PongServer }; try { CreateGameSessionResponse newSession = gameLiftClient.CreateGameSession(sessionRequest); GameSession session = newSession.GameSession; ConnectToSession(session); } catch (Exception e) { GD.Print(e); } }
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, }); } }