/// <summary> /// For best performance you will want to call this method with 15-20 match ids and retryFailures set to false. /// With these settings you can achieve 15+ matches downloaded per second. /// </summary> /// <param name="matchIds">List of match ids to retrieve</param> /// <param name="retryFailures">If true then we retry all hte failures and return why they failed</param> /// <returns>An array of MatchResult objects</returns> public MatchFetchResult[] FetchGames(ulong[] matchIds, bool retryFailures = false) { var messages = matchIds.Select(id => this.BuildMessage(id)).ToArray(); byte[][] responses = this.messenger.SendMessagesAndWaitForReplies(MatchFetcher.MsgType, messages); var validResponses = responses.Where(r => r.Length > 19); List<MatchFetchResult> matches = new List<MatchFetchResult>(); foreach (var r in validResponses) { MatchFetchResult result = new MatchFetchResult(); try { var m = MatchSerializer.FromBytes(r); result.MatchId = m.Id; result.Match = m; result.Result = ResultType.Success; result.Raw = r; } catch { continue; } matches.Add(result); } if (retryFailures) { var idSet = new HashSet<ulong>(matchIds); var missingIds = idSet.Except(matches.Select(m => m.MatchId)); foreach (var id in missingIds) { var message = this.BuildMessage(id); var result = this.FetchGame(id); MatchFetchResult mr = new MatchFetchResult() { MatchId = id, Raw = result, }; if (result.Length <= 19) { mr.Result = ResultType.NotFound; } else { try { var m = MatchSerializer.FromBytes(result); mr.Match = m; mr.Result = ResultType.Success; } catch (Exception e) { mr.Exception = e; mr.Result = ResultType.Exception; } } matches.Add(mr); } } return matches.ToArray(); }
/// <summary> /// For best performance you will want to call this method with 15-20 match ids and retryFailures set to false. /// With these settings you can achieve 15+ matches downloaded per second. /// </summary> /// <param name="matchIds">List of match ids to retrieve</param> /// <param name="retryFailures">If true then we retry all hte failures and return why they failed</param> /// <returns>An array of MatchResult objects</returns> public MatchFetchResult[] FetchGames(ulong[] matchIds, bool retryFailures = false) { var messages = matchIds.Select(id => this.BuildMessage(id)).ToArray(); byte[][] responses = this.messenger.SendMessagesAndWaitForReplies(MatchFetcher.MsgType, messages); var validResponses = responses.Where(r => r.Length > 19); List <MatchFetchResult> matches = new List <MatchFetchResult>(); foreach (var r in validResponses) { MatchFetchResult result = new MatchFetchResult(); try { var m = MatchSerializer.FromBytes(r); result.MatchId = m.Id; result.Match = m; result.Result = ResultType.Success; result.Raw = r; } catch { continue; } matches.Add(result); } if (retryFailures) { var idSet = new HashSet <ulong>(matchIds); var missingIds = idSet.Except(matches.Select(m => m.MatchId)); foreach (var id in missingIds) { var message = this.BuildMessage(id); var result = this.FetchGame(id); MatchFetchResult mr = new MatchFetchResult() { MatchId = id, Raw = result, }; if (result.Length <= 19) { mr.Result = ResultType.NotFound; } else { try { var m = MatchSerializer.FromBytes(result); mr.Match = m; mr.Result = ResultType.Success; } catch (Exception e) { mr.Exception = e; mr.Result = ResultType.Exception; } } matches.Add(mr); } } return(matches.ToArray()); }