9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/openra/commands/replays/extract_metadata.rb', line 9
def call(filepath)
replay = Openra::Replays::Replay.new(filepath)
{
mod: replay.metadata.mod,
version: replay.metadata.version,
file: {
hash: replay.file_hash
},
map: {
name: utf8(replay.metadata.map_name),
hash: replay.metadata.map_hash
},
game: {
type: replay.players.each_with_object(Hash.new(0)) { |player, hash|
if player.team.nil?
hash[SecureRandom.uuid] += 1
else
hash[player.team] += 1
end
}.values.join('v'),
start_time: replay.metadata.start_time.iso8601,
end_time: replay.metadata.end_time.iso8601,
duration: time((replay.metadata.end_time - replay.metadata.start_time) * 1000)
},
players: replay.players.map { |player|
{
player_index: player.client_index,
name: utf8(player.name),
fingerprint: player.fingerprint,
color: player.color,
spawn: {
random: player&.is_random_spawn,
point: player.spawn_point
},
faction: {
random: player&.is_random_faction,
chosen: player.faction_name.downcase,
actual: player&.faction_id
},
team: player&.team,
is_bot: player&.is_bot || false,
is_winner: player&.outcome == 'Won',
outcome_time: player.outcome_time.iso8601
}
}
}
end
|