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); } }
private void ConnectToSession(GameSession session) { GD.Print("entering a session"); if (session == null) { GD.Print("wtf"); return; } CreatePlayerSessionRequest playerSessionRequest = new CreatePlayerSessionRequest() { GameSessionId = session.GameSessionId, PlayerData = "data", PlayerId = GenerateID() }; try { CreatePlayerSessionResponse playerSessionResponse = gameLiftClient.CreatePlayerSession(playerSessionRequest); InitRealtimeClient(playerSessionResponse.PlayerSession); } catch (Exception e) { GD.Print(e); } }
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", }); } }
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); }
void CreatePlayerSessionLocal() { if (myGameSessionID == null) { LogToMyConsoleMainThread("No Game Sessions"); return; } LogToMyConsoleMainThread("Creating Player Request. Game Session ID: " + myGameSessionID + " PlayerId: "); var request2 = new CreatePlayerSessionRequest() { GameSessionId = myGameSessionID, PlayerData = "dab", PlayerId = UniqueID }; 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; } else { myPlayerSessionID = SessionResponse.PlayerSession.PlayerSessionId; myIP = SessionResponse.PlayerSession.IpAddress; //NotAmazonUnityMainThreadDispatcher.Instance().Enqueue(Test0()); } }
void CreatePlayerSessionLocal(object gameSession) { if (selectedGameSession.GameSessionId == null) { LogToMyConsoleMainThread("No Game Sessions"); return; } LogToMyConsoleMainThread("Creating Player Request. Game Session ID: " + selectedGameSession.GameSessionId + " PlayerId: "); var request2 = new CreatePlayerSessionRequest() { GameSessionId = selectedGameSession.GameSessionId, PlayerData = "BoltIsBestNetworking", PlayerId = UniqueID }; 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("Can't Create Play Session"); } else { myPlayerSessionID = SessionResponse.PlayerSession.PlayerSessionId; } }
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, }); } }
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; }
public void CreatePlayerSessionAsync(CreatePlayerSessionRequest request, AmazonServiceCallback <CreatePlayerSessionRequest, CreatePlayerSessionResponse> callback, AsyncOptions options = null) { throw new System.NotImplementedException(); }