class Overlook::Csgo::MatchInfoDecoder
Public Instance Methods
decode(io)
click to toggle source
# File lib/overlook/csgo/match_info_decoder.rb, line 6 def decode(io) match = ::Csgo::CDataGCCStrike15_v2_MatchInfo.decode(io.read) decoded = {} decoded.merge!(extract_match_meta(match)) decoded.merge!(extract_replay_info(match)) decoded.merge!(extract_stats(match)) decoded.merge!(extract_end_results(match)) decoded end
Private Instance Methods
extract_end_results(match)
click to toggle source
1 - T 2 - CT
# File lib/overlook/csgo/match_info_decoder.rb, line 21 def extract_end_results(match) official_results = match.roundstatsall.last.to_hash winner = official_results[:match_result] results = { winner: winner, score: official_results[:team_scores], duration: official_results[:match_duration] } { results: results } end
extract_match_meta(match)
click to toggle source
# File lib/overlook/csgo/match_info_decoder.rb, line 35 def extract_match_meta(match) { match: { matchid: match.matchid.to_s, matchtime: match.matchtime } } end
extract_replay_info(match)
click to toggle source
# File lib/overlook/csgo/match_info_decoder.rb, line 44 def extract_replay_info(match) { replay: { ip: match.watchablematchinfo.server_ip, port: match.watchablematchinfo.tv_port, reservation_id: match.roundstatsall.last.reservationid.to_s } } end
extract_round_stats(round)
click to toggle source
# File lib/overlook/csgo/match_info_decoder.rb, line 66 def extract_round_stats(round) players = round.reservation.account_ids.collect! { |id| Steam3Id.parse("[U:1:#{id}]").to_i.to_s } raise RuntimeError, "Invalid player list, expected 10 players got #{players.count}" unless players.count == 10 players.each.with_index.inject({}) do |memo, (community_id, player_index)| memo[community_id] ||= {} %w(enemy_kills enemy_headshots kills deaths assists scores mvps).each do |property| memo[community_id].merge!(property.to_sym => round.send(property)[player_index]) end memo[community_id][:team] = player_index <= 4 ? 1 : 2 memo end end
extract_stats(match)
click to toggle source
# File lib/overlook/csgo/match_info_decoder.rb, line 54 def extract_stats(match) stats = match.roundstatsall.map.with_index do |round, round_index| { round: round_index, timestamp: match.matchtime + round.match_duration, scores: extract_round_stats(round) } end { stats: stats } end