Example #1
0
        protected override void DoMatch(GatewayInternalService.GatewayInternalServiceClient gatewayClient,
                                        DeploymentServiceClient deploymentServiceClient)
        {
            try
            {
                var resp = gatewayClient.PopWaitingParties(new PopWaitingPartiesRequest
                {
                    Type       = _tag,
                    NumParties = 1
                });
                Console.WriteLine($"Fetched {resp.Parties.Count} from gateway");

                foreach (var party in resp.Parties)
                {
                    Console.WriteLine("Attempting to match a retrieved party.");
                    _analytics.Send("match", "party_matching", new Dictionary <string, string>
                    {
                        { "partyId", party.Party.Id },
                        { "queueType", _tag },
                        { "partyPhase", party.Party.CurrentPhase.ToString() },
                        { "matchRequestId", party.MatchRequestId }
                    }, party.Party.LeaderPlayerId);

                    foreach (var memberId in party.Party.MemberIds)
                    {
                        _analytics.Send("match", "player_matching", new Dictionary <string, string>
                        {
                            { "partyId", party.Party.Id },
                            { "queueType", _tag },
                            { "playerJoinRequestState", "Matching" },
                            { "matchRequestId", party.MatchRequestId }
                        }, memberId);
                    }

                    var deployment = GetDeploymentWithTag(deploymentServiceClient, _tag);
                    if (deployment != null)
                    {
                        var assignRequest = new AssignDeploymentsRequest();
                        Console.WriteLine("Found a deployment, assigning it to the party.");
                        assignRequest.Assignments.Add(new Assignment
                        {
                            DeploymentId   = deployment.Id,
                            DeploymentName = deployment.Name,
                            Result         = Assignment.Types.Result.Matched,
                            Party          = party.Party
                        });
                        MarkDeploymentAsInUse(deploymentServiceClient, deployment);
                        gatewayClient.AssignDeployments(assignRequest);
                        _analytics.Send("deployment", "deployment_in_use", new Dictionary <string, string>
                        {
                            { "spatialProjectId", _project },
                            { "deploymentName", deployment.Name },
                            { "deploymentId", deployment.Id }
                        });
                    }
                    else
                    {
                        Console.WriteLine(
                            $"Unable to find a deployment with tag {_tag} in project {_project}");
                        Console.WriteLine("Requeueing the party");
                        AssignPartyAsRequeued(gatewayClient, party);
                    }
                }
            }
            catch (RpcException e)
            {
                if (e.StatusCode != StatusCode.ResourceExhausted && e.StatusCode != StatusCode.Unavailable)
                {
                    throw;
                }

                /* Unable to get the requested number of parties - ignore. */
                Console.WriteLine("No parties available.");
                Thread.Sleep(TickMs);
            }
        }
Example #2
0
 public void Send <T>(string eventClass, string eventType, Dictionary <string, T> eventAttributes, string playerId = null)
 {
     _wrapped.Send(eventClass, eventType, eventAttributes, playerId);
 }