steam-condenser 1.3.2 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile.lock +3 -3
- data/lib/errors/packet_format_error.rb +0 -8
- data/lib/errors/steam_condenser_error.rb +16 -1
- data/lib/steam-condenser/version.rb +1 -1
- data/lib/steam/community/alien_swarm/alien_swarm_stats.rb +67 -61
- data/lib/steam/community/css/css_stats.rb +45 -40
- data/lib/steam/community/game_leaderboard.rb +19 -15
- data/lib/steam/community/game_stats.rb +1 -1
- data/lib/steam/community/l4d/abstract_l4d_stats.rb +62 -50
- data/lib/steam/community/l4d/l4d2_stats.rb +36 -29
- data/lib/steam/community/steam_group.rb +8 -10
- data/lib/steam/community/steam_id.rb +53 -61
- data/lib/steam/community/xml_data.rb +3 -0
- data/lib/steam/packets/s2a_info2_packet.rb +36 -24
- data/lib/steam/packets/s2a_info_base_packet.rb +3 -13
- data/lib/steam/packets/s2a_info_detailed_packet.rb +26 -28
- data/lib/steam/servers/game_server.rb +2 -2
- data/steam-condenser.gemspec +1 -1
- data/test/core_ext/test_stringio.rb +1 -1
- data/test/steam/servers/test_game_server.rb +2 -2
- metadata +118 -101
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
steam-condenser (1.3.
|
4
|
+
steam-condenser (1.3.3)
|
5
5
|
bzip2-ruby (~> 0.2.7)
|
6
6
|
multi_json (~> 1.5.0)
|
7
7
|
multi_xml (~> 0.5.1)
|
@@ -13,8 +13,8 @@ GEM
|
|
13
13
|
metaclass (0.0.1)
|
14
14
|
mocha (0.13.1)
|
15
15
|
metaclass (~> 0.0.1)
|
16
|
-
multi_json (1.5.
|
17
|
-
multi_xml (0.5.
|
16
|
+
multi_json (1.5.1)
|
17
|
+
multi_xml (0.5.3)
|
18
18
|
rake (10.0.3)
|
19
19
|
shoulda-context (1.0.2)
|
20
20
|
yard (0.8.3)
|
@@ -10,12 +10,4 @@ require 'errors/steam_condenser_error'
|
|
10
10
|
#
|
11
11
|
# @author Sebastian Staudt
|
12
12
|
class PacketFormatError < SteamCondenserError
|
13
|
-
|
14
|
-
# Creates a new `PacketFormatError` instance
|
15
|
-
#
|
16
|
-
# @param [String] message The message to attach to the error
|
17
|
-
def initialize(message)
|
18
|
-
super message
|
19
|
-
end
|
20
|
-
|
21
13
|
end
|
@@ -1,11 +1,26 @@
|
|
1
1
|
# This code is free software; you can redistribute it and/or modify it under
|
2
2
|
# the terms of the new BSD License.
|
3
3
|
#
|
4
|
-
# Copyright (c) 2008-
|
4
|
+
# Copyright (c) 2008-2013, Sebastian Staudt
|
5
5
|
|
6
6
|
# This error class is used as a base class for all errors related to Steam
|
7
7
|
# Condenser's operation
|
8
8
|
#
|
9
9
|
# @author Sebastian Staudt
|
10
10
|
class SteamCondenserError < StandardError
|
11
|
+
|
12
|
+
# Returns the exception that caused this error
|
13
|
+
#
|
14
|
+
# @return [Exception] The exception that caused this error
|
15
|
+
attr_reader :cause
|
16
|
+
|
17
|
+
# Creates a new `SteamCondenserError` instance
|
18
|
+
#
|
19
|
+
# @param [String] message The message to attach to the error
|
20
|
+
# @param [Exception] cause The exception that caused this error
|
21
|
+
def initialize(message, cause = nil)
|
22
|
+
super message
|
23
|
+
@cause = cause
|
24
|
+
end
|
25
|
+
|
11
26
|
end
|
@@ -37,28 +37,30 @@ class AlienSwarmStats < GameStats
|
|
37
37
|
super steam_id, 'alienswarm'
|
38
38
|
|
39
39
|
if public?
|
40
|
-
|
40
|
+
lifetime_data = @xml_data['stats']['lifetime']
|
41
|
+
|
42
|
+
@hours_played = lifetime_data['timeplayed']
|
41
43
|
|
42
44
|
@lifetime_stats = {}
|
43
|
-
@lifetime_stats[:accuracy] =
|
44
|
-
@lifetime_stats[:aliens_burned] =
|
45
|
-
@lifetime_stats[:aliens_killed] =
|
46
|
-
@lifetime_stats[:campaigns] =
|
47
|
-
@lifetime_stats[:damage_taken] =
|
48
|
-
@lifetime_stats[:experience] =
|
49
|
-
@lifetime_stats[:experience_required] =
|
50
|
-
@lifetime_stats[:fast_hacks] =
|
51
|
-
@lifetime_stats[:friendly_fire] =
|
52
|
-
@lifetime_stats[:games_successful] =
|
53
|
-
@lifetime_stats[:healing] =
|
54
|
-
@lifetime_stats[:kills_per_hour] =
|
55
|
-
@lifetime_stats[:level] =
|
56
|
-
@lifetime_stats[:promotion] =
|
57
|
-
@lifetime_stats[:promotion_img] = BASE_URL +
|
58
|
-
@lifetime_stats[:next_unlock] =
|
59
|
-
@lifetime_stats[:next_unlock_img] = BASE_URL +
|
60
|
-
@lifetime_stats[:shots_fired] =
|
61
|
-
@lifetime_stats[:total_games] =
|
45
|
+
@lifetime_stats[:accuracy] = lifetime_data['accuracy'].to_f
|
46
|
+
@lifetime_stats[:aliens_burned] = lifetime_data['aliensburned'].to_i
|
47
|
+
@lifetime_stats[:aliens_killed] = lifetime_data['alienskilled'].to_i
|
48
|
+
@lifetime_stats[:campaigns] = lifetime_data['campaigns'].to_i
|
49
|
+
@lifetime_stats[:damage_taken] = lifetime_data['damagetaken'].to_i
|
50
|
+
@lifetime_stats[:experience] = lifetime_data['experience'].to_i
|
51
|
+
@lifetime_stats[:experience_required] = lifetime_data['xprequired'].to_i
|
52
|
+
@lifetime_stats[:fast_hacks] = lifetime_data['fasthacks'].to_i
|
53
|
+
@lifetime_stats[:friendly_fire] = lifetime_data['friendlyfire'].to_i
|
54
|
+
@lifetime_stats[:games_successful] = lifetime_data['gamessuccess'].to_i
|
55
|
+
@lifetime_stats[:healing] = lifetime_data['healing'].to_i
|
56
|
+
@lifetime_stats[:kills_per_hour] = lifetime_data['killsperhour'].to_f
|
57
|
+
@lifetime_stats[:level] = lifetime_data['level'].to_i
|
58
|
+
@lifetime_stats[:promotion] = lifetime_data['promotion'].to_i
|
59
|
+
@lifetime_stats[:promotion_img] = BASE_URL + lifetime_data['promotionpic'] if @lifetime_stats[:promotion] > 0
|
60
|
+
@lifetime_stats[:next_unlock] = lifetime_data['nextunlock']
|
61
|
+
@lifetime_stats[:next_unlock_img] = BASE_URL + lifetime_data['nextunlockimg']
|
62
|
+
@lifetime_stats[:shots_fired] = lifetime_data['shotsfired'].to_i
|
63
|
+
@lifetime_stats[:total_games] = lifetime_data['totalgames'].to_i
|
62
64
|
|
63
65
|
@lifetime_stats[:games_successful_percentage] = (@lifetime_stats[:total_games] > 0) ? @lifetime_stats[:games_successful].to_f / @lifetime_stats[:total_games] : 0;
|
64
66
|
end
|
@@ -73,27 +75,29 @@ class AlienSwarmStats < GameStats
|
|
73
75
|
return unless public?
|
74
76
|
|
75
77
|
if @favorites.nil?
|
78
|
+
favorites_data = @xml_data['stats']['favorites']
|
79
|
+
|
76
80
|
@favorites = {}
|
77
|
-
@favorites[:class] =
|
78
|
-
@favorites[:class_img] =
|
79
|
-
@favorites[:class_percentage] =
|
80
|
-
@favorites[:difficulty] =
|
81
|
-
@favorites[:difficulty_percentage] =
|
82
|
-
@favorites[:extra] =
|
83
|
-
@favorites[:extra_img] =
|
84
|
-
@favorites[:extra_percentage] =
|
85
|
-
@favorites[:marine] =
|
86
|
-
@favorites[:marine_img] =
|
87
|
-
@favorites[:marine_percentage] =
|
88
|
-
@favorites[:mission] =
|
89
|
-
@favorites[:mission_img] =
|
90
|
-
@favorites[:mission_percentage] =
|
91
|
-
@favorites[:primary_weapon] =
|
92
|
-
@favorites[:primary_weapon_img] =
|
93
|
-
@favorites[:primary_weapon_percentage] =
|
94
|
-
@favorites[:secondary_weapon] =
|
95
|
-
@favorites[:secondary_weapon_img] =
|
96
|
-
@favorites[:secondary_weapon_percentage] =
|
81
|
+
@favorites[:class] = favorites_data['class']
|
82
|
+
@favorites[:class_img] = favorites_data['classimg']
|
83
|
+
@favorites[:class_percentage] = favorites_data['classpct'].to_f
|
84
|
+
@favorites[:difficulty] = favorites_data['difficulty']
|
85
|
+
@favorites[:difficulty_percentage] = favorites_data['difficultypct'].to_f
|
86
|
+
@favorites[:extra] = favorites_data['extra']
|
87
|
+
@favorites[:extra_img] = favorites_data['extraimg']
|
88
|
+
@favorites[:extra_percentage] = favorites_data['extrapct'].to_f
|
89
|
+
@favorites[:marine] = favorites_data['marine']
|
90
|
+
@favorites[:marine_img] = favorites_data['marineimg']
|
91
|
+
@favorites[:marine_percentage] = favorites_data['marinepct'].to_f
|
92
|
+
@favorites[:mission] = favorites_data['mission']
|
93
|
+
@favorites[:mission_img] = favorites_data['missionimg']
|
94
|
+
@favorites[:mission_percentage] = favorites_data['missionpct'].to_f
|
95
|
+
@favorites[:primary_weapon] = favorites_data['primary']
|
96
|
+
@favorites[:primary_weapon_img] = favorites_data['primaryimg']
|
97
|
+
@favorites[:primary_weapon_percentage] = favorites_data['primarypct'].to_f
|
98
|
+
@favorites[:secondary_weapon] = favorites_data['secondary']
|
99
|
+
@favorites[:secondary_weapon_img] = favorites_data['secondaryimg']
|
100
|
+
@favorites[:secondary_weapon_percentage] = favorites_data['secondarypct'].to_f
|
97
101
|
end
|
98
102
|
|
99
103
|
@favorites
|
@@ -109,28 +113,30 @@ class AlienSwarmStats < GameStats
|
|
109
113
|
return unless public?
|
110
114
|
|
111
115
|
if @item_stats.nil?
|
116
|
+
weapons_data = @xml_data['stats']['weapons']
|
117
|
+
|
112
118
|
@item_stats = {}
|
113
|
-
@item_stats[:ammo_deployed] =
|
114
|
-
@item_stats[:sentryguns_deployed] =
|
115
|
-
@item_stats[:sentry_flamers_deployed] =
|
116
|
-
@item_stats[:sentry_freeze_deployed] =
|
117
|
-
@item_stats[:sentry_cannon_deployed] =
|
118
|
-
@item_stats[:medkits_used] =
|
119
|
-
@item_stats[:flares_used] =
|
120
|
-
@item_stats[:adrenaline_used] =
|
121
|
-
@item_stats[:tesla_traps_deployed] =
|
122
|
-
@item_stats[:freeze_grenades_thrown] =
|
123
|
-
@item_stats[:electric_armor_used] =
|
124
|
-
@item_stats[:healgun_heals] =
|
125
|
-
@item_stats[:healgun_heals_self] =
|
126
|
-
@item_stats[:healbeacon_heals] =
|
127
|
-
@item_stats[:healbeacon_heals_self] =
|
128
|
-
@item_stats[:damage_amps_used] =
|
129
|
-
@item_stats[:healbeacons_deployed] =
|
130
|
-
@item_stats[:healbeacon_heals_pct] =
|
131
|
-
@item_stats[:healgun_heals_pct] =
|
132
|
-
@item_stats[:healbeacon_heals_pct_self] =
|
133
|
-
@item_stats[:healgun_heals_pct_self] =
|
119
|
+
@item_stats[:ammo_deployed] = weapons_data['ammo_deployed'].to_i
|
120
|
+
@item_stats[:sentryguns_deployed] = weapons_data['sentryguns_deployed'].to_i
|
121
|
+
@item_stats[:sentry_flamers_deployed] = weapons_data['sentry_flamers_deployed'].to_i
|
122
|
+
@item_stats[:sentry_freeze_deployed] = weapons_data['sentry_freeze_deployed'].to_i
|
123
|
+
@item_stats[:sentry_cannon_deployed] = weapons_data['sentry_cannon_deployed'].to_i
|
124
|
+
@item_stats[:medkits_used] = weapons_data['medkits_used'].to_i
|
125
|
+
@item_stats[:flares_used] = weapons_data['flares_used'].to_i
|
126
|
+
@item_stats[:adrenaline_used] = weapons_data['adrenaline_used'].to_i
|
127
|
+
@item_stats[:tesla_traps_deployed] = weapons_data['tesla_traps_deployed'].to_i
|
128
|
+
@item_stats[:freeze_grenades_thrown] = weapons_data['freeze_grenades_thrown'].to_i
|
129
|
+
@item_stats[:electric_armor_used] = weapons_data['electric_armor_used'].to_i
|
130
|
+
@item_stats[:healgun_heals] = weapons_data['healgun_heals'].to_i
|
131
|
+
@item_stats[:healgun_heals_self] = weapons_data['healgun_heals_self'].to_i
|
132
|
+
@item_stats[:healbeacon_heals] = weapons_data['healbeacon_heals'].to_i
|
133
|
+
@item_stats[:healbeacon_heals_self] = weapons_data['healbeacon_heals_self'].to_i
|
134
|
+
@item_stats[:damage_amps_used] = weapons_data['damage_amps_used'].to_i
|
135
|
+
@item_stats[:healbeacons_deployed] = weapons_data['healbeacons_deployed'].to_i
|
136
|
+
@item_stats[:healbeacon_heals_pct] = weapons_data['healbeacon_heals_pct'].to_f
|
137
|
+
@item_stats[:healgun_heals_pct] = weapons_data['healgun_heals_pct'].to_f
|
138
|
+
@item_stats[:healbeacon_heals_pct_self] = weapons_data['healbeacon_heals_pct_self'].to_f
|
139
|
+
@item_stats[:healgun_heals_pct_self] = weapons_data['healgun_heals_pct_self'].to_f
|
134
140
|
end
|
135
141
|
|
136
142
|
@item_stats
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# This code is free software; you can redistribute it and/or modify it under
|
2
2
|
# the terms of the new BSD License.
|
3
3
|
#
|
4
|
-
# Copyright (c) 2010, Sebastian Staudt
|
4
|
+
# Copyright (c) 2010-2013, Sebastian Staudt
|
5
5
|
|
6
6
|
require 'steam/community/css/css_map'
|
7
7
|
require 'steam/community/css/css_weapon'
|
@@ -44,48 +44,53 @@ class CSSStats < GameStats
|
|
44
44
|
super steam_id, 'cs:s'
|
45
45
|
|
46
46
|
if public?
|
47
|
+
last_match_data = @xml_data['stats']['lastmatch']
|
48
|
+
lifetime_data = @xml_data['stats']['lifetime']
|
49
|
+
summary_data = @xml_data['stats']['summary']
|
50
|
+
|
47
51
|
@last_match_stats = {}
|
48
52
|
@total_stats = {}
|
49
53
|
|
50
|
-
@last_match_stats[:cost_per_kill] =
|
51
|
-
@last_match_stats[:ct_wins] =
|
52
|
-
@last_match_stats[:damage] =
|
53
|
-
@last_match_stats[:deaths] =
|
54
|
-
@last_match_stats[:dominations] =
|
55
|
-
@last_match_stats[:favorite_weapon_id] =
|
56
|
-
@last_match_stats[:kills] =
|
57
|
-
@last_match_stats[:max_players] =
|
58
|
-
@last_match_stats[:money] =
|
59
|
-
@last_match_stats[:revenges] =
|
60
|
-
@last_match_stats[:stars] =
|
61
|
-
@last_match_stats[:t_wins] =
|
62
|
-
@last_match_stats[:wins] =
|
63
|
-
|
64
|
-
@total_stats[:
|
65
|
-
@total_stats[:
|
66
|
-
@total_stats[:
|
67
|
-
@total_stats[:
|
68
|
-
@total_stats[:
|
69
|
-
@total_stats[:
|
70
|
-
@total_stats[:
|
71
|
-
@total_stats[:
|
72
|
-
@total_stats[:
|
73
|
-
@total_stats[:
|
74
|
-
@total_stats[:
|
75
|
-
@total_stats[:
|
76
|
-
@total_stats[:
|
77
|
-
@total_stats[:
|
78
|
-
@total_stats[:
|
79
|
-
@total_stats[:
|
80
|
-
@total_stats[:
|
81
|
-
@total_stats[:
|
82
|
-
@total_stats[:
|
83
|
-
@total_stats[:
|
84
|
-
@total_stats[:
|
85
|
-
@total_stats[:
|
86
|
-
@total_stats[:
|
87
|
-
@total_stats[:
|
88
|
-
@total_stats[:
|
54
|
+
@last_match_stats[:cost_per_kill] = last_match_data['costkill'].to_f
|
55
|
+
@last_match_stats[:ct_wins] = last_match_data['ct_wins'].to_i
|
56
|
+
@last_match_stats[:damage] = last_match_data['dmg'].to_i
|
57
|
+
@last_match_stats[:deaths] = last_match_data['deaths'].to_i
|
58
|
+
@last_match_stats[:dominations] = last_match_data['dominations'].to_i
|
59
|
+
@last_match_stats[:favorite_weapon_id] = last_match_data['favwpnid'].to_i
|
60
|
+
@last_match_stats[:kills] = last_match_data['kills'].to_i
|
61
|
+
@last_match_stats[:max_players] = last_match_data['max_players'].to_i
|
62
|
+
@last_match_stats[:money] = last_match_data['money'].to_i
|
63
|
+
@last_match_stats[:revenges] = last_match_data['revenges'].to_i
|
64
|
+
@last_match_stats[:stars] = last_match_data['stars'].to_i
|
65
|
+
@last_match_stats[:t_wins] = last_match_data['t_wins'].to_i
|
66
|
+
@last_match_stats[:wins] = last_match_data['wins'].to_i
|
67
|
+
|
68
|
+
@total_stats[:blind_kills] = lifetime_data['blindkills'].to_i
|
69
|
+
@total_stats[:bombs_defused] = lifetime_data['bombsdefused'].to_i
|
70
|
+
@total_stats[:bombs_planted] = lifetime_data['bombsplanted'].to_i
|
71
|
+
@total_stats[:damage] = lifetime_data['dmg'].to_i
|
72
|
+
@total_stats[:deaths] = summary_data['deaths'].to_i
|
73
|
+
@total_stats[:domination_overkills] = lifetime_data['dominationoverkills'].to_i
|
74
|
+
@total_stats[:dominations] = lifetime_data['dominations'].to_i
|
75
|
+
@total_stats[:earned_money] = lifetime_data['money'].to_i
|
76
|
+
@total_stats[:enemy_weapon_kills] = lifetime_data['enemywpnkills'].to_i
|
77
|
+
@total_stats[:headshots] = lifetime_data['headshots'].to_i
|
78
|
+
@total_stats[:hits] = summary_data['shotshit'].to_i
|
79
|
+
@total_stats[:hostages_rescued] = lifetime_data['hostagesrescued'].to_i
|
80
|
+
@total_stats[:kills] = summary_data['kills'].to_i
|
81
|
+
@total_stats[:knife_kills] = lifetime_data['knifekills'].to_i
|
82
|
+
@total_stats[:logos_sprayed] = lifetime_data['decals'].to_i
|
83
|
+
@total_stats[:nightvision_damage] = lifetime_data['nvgdmg'].to_i
|
84
|
+
@total_stats[:pistol_rounds_won] = lifetime_data['pistolrounds'].to_i
|
85
|
+
@total_stats[:revenges] = lifetime_data['revenges'].to_i
|
86
|
+
@total_stats[:rounds_played] = summary_data['rounds'].to_i
|
87
|
+
@total_stats[:rounds_won] = summary_data['wins'].to_i
|
88
|
+
@total_stats[:seconds_played] = summary_data['timeplayed'].to_i
|
89
|
+
@total_stats[:shots] = summary_data['shots'].to_i
|
90
|
+
@total_stats[:stars] = summary_data['stars'].to_i
|
91
|
+
@total_stats[:weapons_donated] = lifetime_data['wpndonated'].to_i
|
92
|
+
@total_stats[:windows_broken] = lifetime_data['winbroken'].to_i
|
93
|
+
@total_stats[:zoomed_sniper_kills] = lifetime_data['zsniperkills'].to_i
|
89
94
|
|
90
95
|
@last_match_stats[:kdratio] = (@total_stats[:deaths] > 0) ? @last_match_stats[:kills].to_f / @last_match_stats[:deaths] : 0
|
91
96
|
@total_stats[:accuracy] = (@total_stats[:shots] > 0) ? @total_stats[:hits].to_f / @total_stats[:shots] : 0
|
@@ -1,18 +1,21 @@
|
|
1
1
|
# This code is free software; you can redistribute it and/or modify it under
|
2
2
|
# the terms of the new BSD License.
|
3
3
|
#
|
4
|
-
# Copyright (c) 2011-
|
4
|
+
# Copyright (c) 2011-2013, Sebastian Staudt
|
5
5
|
|
6
6
|
require 'multi_xml'
|
7
7
|
|
8
8
|
require 'steam/community/game_leaderboard_entry'
|
9
9
|
require 'steam/community/steam_id'
|
10
|
+
require 'steam/community/xml_data'
|
10
11
|
|
11
12
|
# The GameLeaderboard class represents a single leaderboard for a specific game
|
12
13
|
#
|
13
14
|
# @author Sebastian Staudt
|
14
15
|
class GameLeaderboard
|
15
16
|
|
17
|
+
include XMLData
|
18
|
+
|
16
19
|
LEADERBOARD_DISPLAY_TYPE_NONE = 0
|
17
20
|
LEADERBOARD_DISPLAY_TYPE_NUMERIC = 1
|
18
21
|
LEADERBOARD_DISPLAY_TYPE_SECONDS = 2
|
@@ -86,13 +89,12 @@ class GameLeaderboard
|
|
86
89
|
def entry_for_steam_id(steam_id)
|
87
90
|
steam_id = steam_id.steam_id64 if steam_id.is_a? SteamId
|
88
91
|
|
89
|
-
|
90
|
-
xml_data = MultiXml.parse(open(url, {:proxy => true})).values.first
|
92
|
+
parse "#@url&steamid=#{steam_id}"
|
91
93
|
|
92
|
-
error = xml_data['error']
|
94
|
+
error = @xml_data['error']
|
93
95
|
raise SteamCondenserError, error unless error.nil?
|
94
96
|
|
95
|
-
xml_data['entries']['entry'].each do |entry_data|
|
97
|
+
@xml_data['entries']['entry'].each do |entry_data|
|
96
98
|
if entry_data['steamid'].to_i == steam_id
|
97
99
|
return GameLeaderboardEntry.new entry_data, self
|
98
100
|
end
|
@@ -113,14 +115,13 @@ class GameLeaderboard
|
|
113
115
|
def entry_for_steam_id_friends(steam_id)
|
114
116
|
steam_id = steam_id.steam_id64 if steam_id.is_a? SteamId
|
115
117
|
|
116
|
-
|
117
|
-
xml_data = MultiXml.parse(open(url, {:proxy => true})).values.first
|
118
|
+
parse "#@url&steamid=#{steam_id}"
|
118
119
|
|
119
|
-
error = xml_data['error']
|
120
|
+
error = @xml_data['error']
|
120
121
|
raise SteamCondenserError, error unless error.nil?
|
121
122
|
|
122
123
|
entries = []
|
123
|
-
xml_data['entries']['entry'].each do |entry_data|
|
124
|
+
@xml_data['entries']['entry'].each do |entry_data|
|
124
125
|
rank = entry_data['rank'].to_i
|
125
126
|
entries[rank] = GameLeaderboardEntry.new entry_data, self
|
126
127
|
end
|
@@ -150,14 +151,13 @@ class GameLeaderboard
|
|
150
151
|
'Leaderboard entry lookup is currently limited to a maximum of 5001 entries per request.'
|
151
152
|
end
|
152
153
|
|
153
|
-
|
154
|
-
xml_data = MultiXml.parse(open(url, {:proxy => true})).values.first
|
154
|
+
parse "#@url&start=#{first}&end=#{last}"
|
155
155
|
|
156
|
-
error = xml_data['error']
|
156
|
+
error = @xml_data['error']
|
157
157
|
raise SteamCondenserError, error unless error.nil?
|
158
158
|
|
159
159
|
entries = []
|
160
|
-
xml_data['entries']['entry'].each do |entry_data|
|
160
|
+
@xml_data['entries']['entry'].each do |entry_data|
|
161
161
|
rank = entry_data['rank'].to_i
|
162
162
|
entries[rank] = GameLeaderboardEntry.new entry_data, self
|
163
163
|
end
|
@@ -185,8 +185,12 @@ class GameLeaderboard
|
|
185
185
|
# @raise [SteamCondenserException] if an error occurs while fetching the
|
186
186
|
# leaderboards
|
187
187
|
def self.load_leaderboards(game_name)
|
188
|
-
|
189
|
-
|
188
|
+
begin
|
189
|
+
url = "http://steamcommunity.com/stats/#{game_name}/leaderboards/?xml=1"
|
190
|
+
boards_data = MultiXml.parse(open(url, {:proxy => true})).values.first
|
191
|
+
rescue
|
192
|
+
raise SteamCondenserError.new 'XML data could not be parsed.', $!
|
193
|
+
end
|
190
194
|
|
191
195
|
error = boards_data['error']
|
192
196
|
raise SteamCondenserError, error unless error.nil?
|
@@ -100,7 +100,7 @@ class GameStats
|
|
100
100
|
# @param [String] game_id The application ID or friendly name of the game
|
101
101
|
# @raise [SteamCondenserError] if the stats cannot be fetched
|
102
102
|
def initialize(user_id, game_id)
|
103
|
-
|
103
|
+
parse "#{self.class.base_url(user_id, game_id)}?xml=all"
|
104
104
|
|
105
105
|
@user = SteamId.new user_id, false
|
106
106
|
|
@@ -1,7 +1,7 @@
|
|
1
1
|
# This code is free software; you can redistribute it and/or modify it under
|
2
2
|
# the terms of the new BSD License.
|
3
3
|
#
|
4
|
-
# Copyright (c) 2009-
|
4
|
+
# Copyright (c) 2009-2013, Sebastian Staudt
|
5
5
|
|
6
6
|
require 'steam/community/game_stats'
|
7
7
|
|
@@ -29,12 +29,14 @@ module AbstractL4DStats
|
|
29
29
|
super steam_id, game_name
|
30
30
|
|
31
31
|
if public?
|
32
|
+
most_recent_game_data = @xml_data['stats']['mostrecentgame']
|
33
|
+
|
32
34
|
@most_recent_game = {}
|
33
|
-
unless
|
34
|
-
@most_recent_game[:difficulty] =
|
35
|
-
@most_recent_game[:escaped] = (
|
36
|
-
@most_recent_game[:movie] =
|
37
|
-
@most_recent_game[:time_played] =
|
35
|
+
unless most_recent_game_data.nil?
|
36
|
+
@most_recent_game[:difficulty] = most_recent_game_data['difficulty']
|
37
|
+
@most_recent_game[:escaped] = (most_recent_game_data['bEscaped'] == 1)
|
38
|
+
@most_recent_game[:movie] = most_recent_game_data['movie']
|
39
|
+
@most_recent_game[:time_played] = most_recent_game_data['time']
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|
@@ -48,15 +50,17 @@ module AbstractL4DStats
|
|
48
50
|
return unless public?
|
49
51
|
|
50
52
|
if @favorites.nil?
|
53
|
+
favorites_data = @xml_data['stats']['favorites']
|
54
|
+
|
51
55
|
@favorites = {}
|
52
|
-
@favorites[:campaign] =
|
53
|
-
@favorites[:campaign_percentage] =
|
54
|
-
@favorites[:character] =
|
55
|
-
@favorites[:character_percentage] =
|
56
|
-
@favorites[:level1_weapon] =
|
57
|
-
@favorites[:level1_weapon_percentage] =
|
58
|
-
@favorites[:level2_weapon] =
|
59
|
-
@favorites[:level2_weapon_percentage] =
|
56
|
+
@favorites[:campaign] = favorites_data['campaign']
|
57
|
+
@favorites[:campaign_percentage] = favorites_data['campaignpct'].to_i
|
58
|
+
@favorites[:character] = favorites_data['character']
|
59
|
+
@favorites[:character_percentage] = favorites_data['characterpct'].to_i
|
60
|
+
@favorites[:level1_weapon] = favorites_data['weapon1']
|
61
|
+
@favorites[:level1_weapon_percentage] = favorites_data['weapon1pct'].to_i
|
62
|
+
@favorites[:level2_weapon] = favorites_data['weapon2']
|
63
|
+
@favorites[:level2_weapon_percentage] = favorites_data['weapon2pct'].to_i
|
60
64
|
end
|
61
65
|
|
62
66
|
@favorites
|
@@ -72,16 +76,18 @@ module AbstractL4DStats
|
|
72
76
|
return unless public?
|
73
77
|
|
74
78
|
if @lifetime_stats.nil?
|
79
|
+
lifetime_data = @xml_data['stats']['lifetime']
|
80
|
+
|
75
81
|
@lifetime_stats = {}
|
76
|
-
@lifetime_stats[:finales_survived] =
|
77
|
-
@lifetime_stats[:games_played] =
|
78
|
-
@lifetime_stats[:infected_killed] =
|
79
|
-
@lifetime_stats[:kills_per_hour] =
|
80
|
-
@lifetime_stats[:avg_kits_shared] =
|
81
|
-
@lifetime_stats[:avg_kits_used] =
|
82
|
-
@lifetime_stats[:avg_pills_shared] =
|
83
|
-
@lifetime_stats[:avg_pills_used] =
|
84
|
-
@lifetime_stats[:time_played] =
|
82
|
+
@lifetime_stats[:finales_survived] = lifetime_data['finales'].to_i
|
83
|
+
@lifetime_stats[:games_played] = lifetime_data['gamesplayed'].to_i
|
84
|
+
@lifetime_stats[:infected_killed] = lifetime_data['infectedkilled'].to_i
|
85
|
+
@lifetime_stats[:kills_per_hour] = lifetime_data['killsperhour'].to_f
|
86
|
+
@lifetime_stats[:avg_kits_shared] = lifetime_data['kitsshared'].to_f
|
87
|
+
@lifetime_stats[:avg_kits_used] = lifetime_data['kitsused'].to_f
|
88
|
+
@lifetime_stats[:avg_pills_shared] = lifetime_data['pillsshared'].to_f
|
89
|
+
@lifetime_stats[:avg_pills_used] = lifetime_data['pillsused'].to_f
|
90
|
+
@lifetime_stats[:time_played] = lifetime_data['timeplayed']
|
85
91
|
|
86
92
|
@lifetime_stats[:finales_survived_percentage] = @lifetime_stats[:finales_survived].to_f / @lifetime_stats[:games_played]
|
87
93
|
end
|
@@ -99,12 +105,14 @@ module AbstractL4DStats
|
|
99
105
|
return unless public?
|
100
106
|
|
101
107
|
if @survival_stats.nil?
|
108
|
+
survival_data = @xml_data['stats']['survival']
|
109
|
+
|
102
110
|
@survival_stats = {}
|
103
|
-
@survival_stats[:gold_medals] =
|
104
|
-
@survival_stats[:silver_medals] =
|
105
|
-
@survival_stats[:bronze_medals] =
|
106
|
-
@survival_stats[:rounds_played] =
|
107
|
-
@survival_stats[:best_time] =
|
111
|
+
@survival_stats[:gold_medals] = survival_data['goldmedals'].to_i
|
112
|
+
@survival_stats[:silver_medals] = survival_data['silvermedals'].to_i
|
113
|
+
@survival_stats[:bronze_medals] = survival_data['bronzemedals'].to_i
|
114
|
+
@survival_stats[:rounds_played] = survival_data['roundsplayed'].to_i
|
115
|
+
@survival_stats[:best_time] = survival_data['besttime'].to_f
|
108
116
|
end
|
109
117
|
|
110
118
|
@survival_stats
|
@@ -120,18 +128,20 @@ module AbstractL4DStats
|
|
120
128
|
return unless public?
|
121
129
|
|
122
130
|
if @teamplay_stats.nil?
|
131
|
+
teamplay_data = @xml_data['stats']['teamplay']
|
132
|
+
|
123
133
|
@teamplay_stats = {}
|
124
|
-
@teamplay_stats[:revived] =
|
125
|
-
@teamplay_stats[:most_revived_difficulty] =
|
126
|
-
@teamplay_stats[:avg_revived] =
|
127
|
-
@teamplay_stats[:avg_was_revived] =
|
128
|
-
@teamplay_stats[:protected] =
|
129
|
-
@teamplay_stats[:most_protected_difficulty] =
|
130
|
-
@teamplay_stats[:avg_protected] =
|
131
|
-
@teamplay_stats[:avg_was_protected] =
|
132
|
-
@teamplay_stats[:friendly_fire_damage] =
|
133
|
-
@teamplay_stats[:most_friendly_fire_difficulty] =
|
134
|
-
@teamplay_stats[:avg_friendly_fire_damage] =
|
134
|
+
@teamplay_stats[:revived] = teamplay_data['revived'].to_i
|
135
|
+
@teamplay_stats[:most_revived_difficulty] = teamplay_data['reviveddiff']
|
136
|
+
@teamplay_stats[:avg_revived] = teamplay_data['revivedavg'].to_f
|
137
|
+
@teamplay_stats[:avg_was_revived] = teamplay_data['wasrevivedavg'].to_f
|
138
|
+
@teamplay_stats[:protected] = teamplay_data['protected'].to_i
|
139
|
+
@teamplay_stats[:most_protected_difficulty] = teamplay_data['protecteddiff']
|
140
|
+
@teamplay_stats[:avg_protected] = teamplay_data['protectedavg'].to_f
|
141
|
+
@teamplay_stats[:avg_was_protected] = teamplay_data['wasprotectedavg'].to_f
|
142
|
+
@teamplay_stats[:friendly_fire_damage] = teamplay_data['ffdamage'].to_i
|
143
|
+
@teamplay_stats[:most_friendly_fire_difficulty] = teamplay_data['ffdamagediff']
|
144
|
+
@teamplay_stats[:avg_friendly_fire_damage] = teamplay_data['ffdamageavg'].to_f
|
135
145
|
end
|
136
146
|
|
137
147
|
@teamplay_stats
|
@@ -147,23 +157,25 @@ module AbstractL4DStats
|
|
147
157
|
return unless public?
|
148
158
|
|
149
159
|
if @versus_stats.nil?
|
160
|
+
versus_data = @xml_data['stats']['versus']
|
161
|
+
|
150
162
|
@versus_stats = {}
|
151
|
-
@versus_stats[:games_played] =
|
152
|
-
@versus_stats[:games_completed] =
|
153
|
-
@versus_stats[:finales_survived] =
|
154
|
-
@versus_stats[:points] =
|
155
|
-
@versus_stats[:most_points_infected] =
|
156
|
-
@versus_stats[:games_won] =
|
157
|
-
@versus_stats[:games_lost] =
|
158
|
-
@versus_stats[:highest_survivor_score] =
|
163
|
+
@versus_stats[:games_played] = versus_data['gamesplayed'].to_i
|
164
|
+
@versus_stats[:games_completed] = versus_data['gamescompleted'].to_i
|
165
|
+
@versus_stats[:finales_survived] = versus_data['finales'].to_i
|
166
|
+
@versus_stats[:points] = versus_data['points'].to_i
|
167
|
+
@versus_stats[:most_points_infected] = versus_data['pointsas']
|
168
|
+
@versus_stats[:games_won] = versus_data['gameswon'].to_i
|
169
|
+
@versus_stats[:games_lost] = versus_data['gameslost'].to_i
|
170
|
+
@versus_stats[:highest_survivor_score] = versus_data['survivorscore'].to_i
|
159
171
|
|
160
172
|
@versus_stats[:finales_survived_percentage] = @versus_stats[:finales_survived].to_f / @versus_stats[:games_played]
|
161
173
|
|
162
174
|
self.class.const_get(:SPECIAL_INFECTED).each do |infected|
|
163
175
|
@versus_stats[infected] = {}
|
164
|
-
@versus_stats[infected][:special_attacks] =
|
165
|
-
@versus_stats[infected][:most_damage] =
|
166
|
-
@versus_stats[infected]['avg_lifespan'] =
|
176
|
+
@versus_stats[infected][:special_attacks] = versus_data["#{infected}special"].to_i
|
177
|
+
@versus_stats[infected][:most_damage] = versus_data["#{infected}dmg"].to_i
|
178
|
+
@versus_stats[infected]['avg_lifespan'] = versus_data["#{infected}lifespan"].to_i
|
167
179
|
end
|
168
180
|
end
|
169
181
|
|