openra 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 34349d5f69e993dc5c62afef3b1faabf20bd56c6
4
- data.tar.gz: ee22bb04ead0b72e1a5526448bc901b9fb447cea
3
+ metadata.gz: 62b93a256a360d12ed36a4b50207648cb78f0db6
4
+ data.tar.gz: 2cd510fb3f3bb34916f1ecc278f3dea352ed31a6
5
5
  SHA512:
6
- metadata.gz: c0f19e0167ac3ec21e7edeab7e58495e8cc3414e56b98da98b3519430510fcce723b5693877777abb68e3da075f6453c0515a4ddbc123dd518b13725a6401626
7
- data.tar.gz: b88312025fe593bd92996790f618b87489dc69a1af381885696424396a4476ef8edc78f1ab9a3ca294fcc65309fd2fbe4e35497eaf2adde163a124bb7f0b0cf8
6
+ metadata.gz: 9d378e1942e96d258d4d96228812435a9404aab7301f7b40e0426167745acb2755c04b6a3c4e09474f04fbec7f8abc2c1fd9d05107995472776ff87ab9137c88
7
+ data.tar.gz: b62c614956326db37a276fdd845264d2bd30ed8babd4c126442a6afd187409f2e54845007c2691af1c0bbfb1c7f907d5f28bc343341e357e90d544e7f552895c
@@ -12,49 +12,87 @@ module Openra
12
12
  def call(replay:, **options)
13
13
  replay = Openra::Replays::Replay.new(replay)
14
14
 
15
- client_index_mapping = {}
16
15
  players = replay.metadata.each_with_object([]) do |(key, value), arr|
17
16
  next unless key.start_with?('Player')
18
- arr << value['Name']
17
+ arr << value
18
+ end
19
+ player_indices = players.map { |player| player['ClientIndex'] }
20
+ player_teams = players.map { |player| player['Team'] }
21
+ team_alignment = player_teams.each_with_object({}) do |team, hash|
22
+ if team == 0
23
+ hash[SecureRandom.uuid] = 1
24
+ else
25
+ hash[team] ||= 0
26
+ hash[team] += 1
27
+ end
19
28
  end
20
29
 
21
30
  replay_data = {
22
31
  mod: replay.mod,
23
32
  version: replay.version,
33
+ server_name: nil,
24
34
  map: {
25
- name: replay.map_title,
35
+ name: utf8(replay.map_title),
26
36
  hash: replay.map_id
27
37
  },
28
38
  game: {
39
+ type: team_alignment.values.join('v'),
29
40
  start_time: replay.start_time,
30
41
  end_time: replay.end_time,
31
- duration: replay.duration
42
+ duration: replay.duration,
43
+ options: {}
32
44
  },
33
45
  clients: [],
34
46
  chat: []
35
47
  }
36
48
 
37
- # Get all clients
38
- replay.orders.select { |order| order.command == 'SyncLobbyClients' }.each do |order|
39
- clients = Openra::YAML.load(order.target)
40
- clients.each_pair do |_, client|
41
- next if client_index_mapping.include?(client['Index'])
49
+ timestep = nil
50
+ sync_info_orders = replay.orders.select do |order|
51
+ order.command == 'SyncInfo'
52
+ end
53
+ num_sync_info_orders = sync_info_orders.length
54
+
55
+ sync_info_orders.each.with_index do |sync_info_order, index|
56
+ sync_info = Openra::YAML.load(sync_info_order.target)
42
57
 
43
- replay_data[:clients] << {
44
- index: client['Index'],
45
- name: client['Name'],
46
- preferred_color: client['PreferredColor'],
47
- color: client['Color'],
48
- faction: client['Faction'],
49
- ip: client['IpAddress'],
50
- team: client['Team'] == 0 ? nil : client['Team'],
51
- is_bot: client['Bot'].nil? ? false : true,
52
- is_admin: client['IsAdmin'] == 'True',
53
- is_player: players.include?(client['Name']),
54
- build: []
55
- }
58
+ # Get all clients
59
+ sync_info.each_pair do |key, data|
60
+ case key
61
+ when /^Client@/
62
+ replay_data[:clients] << {
63
+ index: data['Index'],
64
+ name: utf8(data['Name']),
65
+ preferred_color: data['PreferredColor'],
66
+ color: data['Color'],
67
+ faction: data['Faction'],
68
+ ip: data['IpAddress'],
69
+ team: data['Team'] == 0 ? nil : data['Team'],
70
+ is_bot: data['Bot'].nil? ? false : true,
71
+ is_admin: data['IsAdmin'] == 'True',
72
+ is_player: player_indices.include?(data['Index']),
73
+ build: []
74
+ }
75
+ when 'GlobalSettings'
76
+ next unless index.next == num_sync_info_orders
56
77
 
57
- client_index_mapping[client['Index']] = client
78
+ timestep = data['Timestep']
79
+ replay_data[:server_name] = data['ServerName']
80
+ replay_data[:game][:options] = {
81
+ explored_map: data['Options']['explored']['Value'] == 'True',
82
+ speed: data['Options']['gamespeed']['Value'],
83
+ starting_cash: data['Options']['startingcash']['Value'],
84
+ starting_units: data['Options']['startingunits']['Value'],
85
+ fog_enabled: data['Options']['fog']['Value'] == 'True',
86
+ cheats_enabled: data['Options']['cheats']['Value'] == 'True',
87
+ kill_bounty_enabled: data['Options']['bounty']['Value'] == 'True',
88
+ allow_undeploy: data['Options']['factundeploy']['Value'] == 'True',
89
+ crated_enabled: data['Options']['crates']['Value'] == 'True',
90
+ build_off_allies: data['Options']['allybuild']['Value'] == 'True',
91
+ restrict_build_radius: data['Options']['buildradius']['Value'] == 'True',
92
+ short_game: data['Options']['shortgame']['Value'] == 'True',
93
+ techlevel: data['Options']['techlevel']['Value']
94
+ }
95
+ end
58
96
  end
59
97
  end
60
98
 
@@ -79,7 +117,7 @@ module Openra
79
117
 
80
118
  replay_data[:chat] << {
81
119
  name: client[:name],
82
- message: order.target
120
+ message: utf8(order.target)
83
121
  }
84
122
  end
85
123
  end
@@ -91,6 +129,12 @@ module Openra
91
129
  puts JSON.pretty_generate(replay_data)
92
130
  end
93
131
  end
132
+
133
+ private
134
+
135
+ def utf8(string)
136
+ string.force_encoding('UTF-8')
137
+ end
94
138
  end
95
139
  end
96
140
  end
@@ -1,3 +1,4 @@
1
+ require 'date'
1
2
  require 'bindata'
2
3
  require 'big_integer'
3
4
  require 'pascal_string'
@@ -32,14 +32,14 @@ module Openra
32
32
  end
33
33
 
34
34
  def start_time
35
- @start_time ||= DateTime.strptime(
35
+ @start_time ||= ::DateTime.strptime(
36
36
  metadata['Root']['StartTimeUtc'],
37
37
  '%Y-%m-%d %H-%M-%S'
38
38
  ).to_time
39
39
  end
40
40
 
41
41
  def end_time
42
- @end_time ||= DateTime.strptime(
42
+ @end_time ||= ::DateTime.strptime(
43
43
  metadata['Root']['EndTimeUtc'],
44
44
  '%Y-%m-%d %H-%M-%S'
45
45
  ).to_time
@@ -1,3 +1,3 @@
1
1
  module Openra
2
- VERSION = '0.0.2'.freeze
2
+ VERSION = '0.0.3'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: openra
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andy Holland