public Task PrepareMatchResolution(MatchmakingResult matchmakingResult) { //_logger.Log(LogLevel.Trace, "matchmaking.resolver", "Preparing matchmaking resolution.", new { }); if (_useMatchmakerStub) { return(Task.FromResult(true)); } var result = new Dictionary <string, player>(); foreach (var p in matchmakingResult.Matches.SelectMany(match => match.AllPlayers)) { result.Add(p.UserId, new player { playerId = p.UserId, pseudo = ((PlayerProfile)p.Data).Name ?? "" }); // Add custom player info in response here. } //if (!_useSteamMockup) //{ //key: steamId, value: userId //var steamIdsDictionary = (await Task.WhenAll(matchmakingResult.Matches.SelectMany(match => match.AllPlayers).Select(async p => new { p.UserId, SteamId = await ExtractSteamId(p.UserId) }))).ToDictionary(r => r.SteamId, r => r.UserId); //var steamProfiles = await _steamService.GetPlayerSummaries(steamIdsDictionary.Keys); //foreach (var kvp in steamProfiles) //{ // var playerId = steamIdsDictionary[kvp.Key]; // result[playerId] = new player { playerId = playerId, steamId = kvp.Key, steamName = kvp.Value.personaname }; //} //} //else //{ // foreach (var player in matchmakingResult.Matches.SelectMany(match => match.AllPlayers)) // { // result[player.UserId] = new player { playerId = player.UserId }; // } //} foreach (var match in matchmakingResult.Matches) { match.CommonCustomData = result; } return(Task.FromResult(true)); }
public Task <MatchmakingResult> FindMatches(IEnumerable <Group> candidates) { _stopwatch.Restart(); var result = new MatchmakingResult(); if (!candidates.Any()) { return(Task.FromResult(result));; } _logger.Log(LogLevel.Trace, "matchmaking.matchmaker", "matchmaking pass started", new { count = candidates.Count() }); if (_useMatchmakerStub) { result.Matches.AddRange(FindMatchesStub(candidates)); return(Task.FromResult(result));; } var perfectMatches = QuickFindMatches(candidates, true).ToList(); //_logger.Log(LogLevel.Trace, "matchmaking.matchmaker", "Perfect match finished.", new { time = _stopwatch.ElapsedMilliseconds }); var imperfectMatches = QuickFindMatches(candidates, false).ToList(); //_logger.Log(LogLevel.Trace, "matchmaking.matchmaker", "Imperfect match finished.", new { time = _stopwatch.ElapsedMilliseconds }); var retainedMatches = _rulesService.Score(perfectMatches) >= _rulesService.Score(imperfectMatches) ? perfectMatches : imperfectMatches; //_logger.Log(LogLevel.Trace, "matchmaking.matchmaker", "Scores compared.", new { time = _stopwatch.ElapsedMilliseconds }); result.Matches.AddRange(retainedMatches); _logger.Log(LogLevel.Trace, "matchmaking.matchmaker", "matchmaking pass finished", new { matchFound = retainedMatches.Count, count = candidates.Count() }); foreach (var candidate in candidates) { ((MatchmakingGroupData)candidate.GroupData).PastMatchmakingPasses++; } return(Task.FromResult(result));; }
/// <summary> /// Maneja el resultado de un intento a entrar a una partida de juego checkers /// </summary> /// <param name="result"></param> /// <param name="match"></param> /// <param name="playerNumber"></param> public void GetMatchmakingResult(MatchmakingResult result, Match match, int playerNumber) { if (result == MatchmakingResult.MATCH_FOUND) { Game gameWindow = new Game(match, playerNumber); gameWindow.Show(); Menu menu = App.Current.Windows.OfType <Menu>().FirstOrDefault(); menu.ChangeLanguage(); menu.Close(); } else { if (result == MatchmakingResult.MATCH_NOT_FOUND) { Menu menu = App.Current.Windows.OfType <Menu>().FirstOrDefault(); menu.EnableNavigation(); menu.NavigationService.Navigate(new GameStandBy()); } else { MessageBox.Show(Resources.NoMatchFoundErrorMessage); } } }
public void GetMatchmakingResult(MatchmakingResult result, Match match, int playerNumber) { matchmakingResult = result; }
public IEnumerator EnqueueJoinableSession(string @namespace, string accessToken, MatchmakingResult body, ResultCallback callback) { Assert.IsFalse(string.IsNullOrEmpty(accessToken), "RegisterSession failed. accessToken parameter is null!"); Assert.IsNotNull(body, "RegisterSession failed. body parameter is null"); var request = HttpRequestBuilder.CreatePost(this.baseUrl + "/namespaces/{namespace}/sessions") .WithPathParam("namespace", @namespace) .WithBearerAuth(accessToken) .WithContentType(MediaType.ApplicationJson) .Accepts(MediaType.ApplicationJson) .WithBody(body.ToJsonString()) .GetResult(); IHttpResponse response = null; yield return(this.httpClient.SendRequest(request, rsp => response = rsp)); var result = response.TryParse(); callback.Try(result); }
public IEnumerator RemoveUserFromSession(string @namespace, string accessToken, string channelName, string matchId, string userId, MatchmakingResult body, ResultCallback callback) { Assert.IsFalse(string.IsNullOrEmpty(accessToken), "RemoveUserFromSession failed. accessToken parameter is null or empty!"); Assert.IsFalse(string.IsNullOrEmpty(matchId), "RemoveUserFromSession failed. accessToken parameter is null or empty!"); Assert.IsFalse(string.IsNullOrEmpty(channelName), "RemoveUserFromSession failed, channelName is null or empty!"); Assert.IsFalse(string.IsNullOrEmpty(userId), "RemoveUserFromSession failed, userId is null or empty!"); var requestBuilder = HttpRequestBuilder.CreateDelete(this.baseUrl + "/v1/admin/namespaces/{namespace}/channels/{channelName}/sessions/{matchId}/users/{userId}") .WithPathParam("namespace", @namespace) .WithPathParam("channelName", channelName) .WithPathParam("matchId", matchId) .WithPathParam("userId", userId) .WithBearerAuth(accessToken) .WithContentType(MediaType.ApplicationJson) .Accepts(MediaType.ApplicationJson); if (body != null) { requestBuilder.WithBody(body.ToJsonString()); } var request = requestBuilder.GetResult(); IHttpResponse respose = null; yield return(this.httpClient.SendRequest(request, rsp => respose = rsp)); var result = respose.TryParse(); callback.Try(result); }
// Start is called before the first frame update void Start() { MatchMakingResult = null; m_displayDebugNetwork = false; DontDestroyOnLoad(this); }
/// <summary> /// Remove a user from session data /// </summary> /// <param name="channelName">The Channel's Name.</param> /// <param name="matchId">match/session ID.</param> /// <param name="userId">user ID to be removed.</param> /// <param name="callback">the result of this operation.</param> /// <param name="body">optional, the session's data</param> public void RemoveUserFromSession(string channelName, string matchId, string userId, ResultCallback callback, MatchmakingResult body = null) { Report.GetFunctionLog(this.GetType().Name); if (!this.serverSession.IsValid()) { Debug.Log("Server session is not valid"); callback.TryError(ErrorCode.IsNotLoggedIn); return; } coroutineRunner.Run(api.RemoveUserFromSession(this.@namespace, serverSession.AuthorizationToken, channelName, matchId, userId, body, callback)); }