private void FindMatch()

in UltraFrogRoyale/Assets/GameNetworkManager.cs [126:189]


    private void FindMatch()
    {
        Debug.Log("Reaching out to client service Lambda function");

        AWSConfigs.AWSRegion = "us-east-1"; // Your region here
        AWSConfigs.HttpClient = AWSConfigs.HttpClientOption.UnityWebRequest;
        // paste this in from the Amazon Cognito Identity Pool console
        CognitoAWSCredentials credentials = new CognitoAWSCredentials(
            "us-east-1:a70f5010-a4c4-45a7-ba01-8e3d0cc08a9d", // Your identity pool ID here
            RegionEndpoint.USEast1 // Your region here
        );

        // This is a bit of a hack building the JSON by hand as Unity doesn't serialize dictionaries to JSON currently
        // Also as the demo has only one region, we hard code a ping time we get connected to the region
        // In production code this should build a map of AWS region names and their ping times so the matchmaker
        // can find the best region for your customer. 
        // Also the player skill is hard coded, to make the sample more clear. It would be better to maintain
        // a database of player info that includes the player skill level that the client service reads
        // directly
        string matchParams = "{\"latencyMap\":{\"us-east-1\":60}, \"playerSkill\":10}";

        AmazonLambdaClient client = new AmazonLambdaClient(credentials, RegionEndpoint.USEast1);
        InvokeRequest request = new InvokeRequest
        {
            FunctionName = "ConnectUltraFrogRoyaleClient",
            InvocationType = InvocationType.RequestResponse,
            Payload = matchParams
        };

        uiController.ShowStatusText();
        uiController.SetStatusText("Finding match, please wait");

        client.InvokeAsync(request,
            (response) =>
            {
                if (response.Exception == null)
                {
                    if (response.Response.StatusCode == 200)
                    {
                        var payload = Encoding.ASCII.GetString(response.Response.Payload.ToArray()) + "\n";
                        var connectionObj = JsonUtility.FromJson<ConnectionObject>(payload);

                        if (connectionObj.GameSessionConnectionInfo.Port == null)
                        {
                            Debug.Log($"Error in Lambda assume matchmaking failed: {payload}");
                            uiController.SetStatusText("Matchmaking failed");
                        }
                        else
                        {
                            uiController.HideStatusText();
                            Debug.Log($"Connecting! IP Address: {connectionObj.GameSessionConnectionInfo.IpAddress} Port: {connectionObj.GameSessionConnectionInfo.Port}");
                            networkAddress = connectionObj.GameSessionConnectionInfo.IpAddress;
                            networkPort = Int32.Parse(connectionObj.GameSessionConnectionInfo.Port);
                            StartClient();
                        }
                    }
                }
                else
                {
                    Debug.LogError(response.Exception);
                    uiController.SetStatusText($"Client service failed: {response.Exception}");
                }
            });
    }