steam-condenser 1.3.0 → 1.3.1
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/README.md +1 -0
- data/lib/steam-condenser/version.rb +2 -2
- data/lib/steam/community/cacheable.rb +2 -1
- data/lib/steam/community/game_inventory.rb +17 -5
- data/lib/steam/community/game_item.rb +12 -1
- data/lib/steam/community/steam_id.rb +2 -2
- data/lib/steam/servers/source_server.rb +18 -9
- data/lib/steam/sockets/rcon_socket.rb +11 -4
- data/lib/steam/sockets/steam_socket.rb +3 -2
- data/test/steam/community/test_steam_id.rb +11 -0
- data/test/steam/sockets/test_rcon_socket.rb +12 -3
- metadata +2 -2
data/README.md
CHANGED
@@ -1,11 +1,11 @@
|
|
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-
|
4
|
+
# Copyright (c) 2010-2013, Sebastian Staudt
|
5
5
|
|
6
6
|
module SteamCondenser
|
7
7
|
|
8
8
|
# The current version of Steam Condenser
|
9
|
-
VERSION = '1.3.
|
9
|
+
VERSION = '1.3.1'
|
10
10
|
|
11
11
|
end
|
@@ -96,7 +96,8 @@ module Cacheable
|
|
96
96
|
bypass_cache = args.size > arity + 1 ? !!args.pop : false
|
97
97
|
fetch = args.size > arity ? !!args.pop : true
|
98
98
|
|
99
|
-
object =
|
99
|
+
object = self.allocate
|
100
|
+
object.send :initialize, *args
|
100
101
|
cached_object = object.send :cached_instance
|
101
102
|
object = cached_object unless cached_object.nil? || bypass_cache
|
102
103
|
|
@@ -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) 2011-
|
4
|
+
# Copyright (c) 2011-2013, Sebastian Staudt
|
5
5
|
|
6
6
|
require 'steam/community/cacheable'
|
7
7
|
require 'steam/community/game_item'
|
@@ -36,6 +36,11 @@ class GameInventory
|
|
36
36
|
# @return [Array<GameItem>] All items in the backpack
|
37
37
|
attr_reader :items
|
38
38
|
|
39
|
+
# Returns an array of all items that this player just found or traded
|
40
|
+
#
|
41
|
+
# @return [Array<GameItem>] All preliminary items of the inventory
|
42
|
+
attr_reader :preliminary_items
|
43
|
+
|
39
44
|
# Returns the Steam ID of the player owning this inventory
|
40
45
|
#
|
41
46
|
# @return [SteamId] The Steam ID of the owner of this inventory
|
@@ -55,9 +60,11 @@ class GameInventory
|
|
55
60
|
# @return [GameInventory] The inventory for the given user and game
|
56
61
|
# @raise [SteamCondenserException] if creating the inventory fails
|
57
62
|
# @macro cacheable
|
58
|
-
def self.new(app_id, steam_id, *args)
|
59
|
-
args = args.unshift steam_id
|
60
|
-
if self
|
63
|
+
def self.new(app_id, steam_id = nil, *args)
|
64
|
+
args = args.unshift steam_id unless steam_id.nil?
|
65
|
+
if self == GameInventory
|
66
|
+
raise ArgumentError, 'wrong number of arguments (1 for 2)' if args.empty?
|
67
|
+
else
|
61
68
|
args = args.unshift app_id
|
62
69
|
app_id = self::APP_ID
|
63
70
|
end
|
@@ -125,10 +132,15 @@ class GameInventory
|
|
125
132
|
item_class = self.class.send :class_variable_get, :@@item_class
|
126
133
|
|
127
134
|
@items = []
|
135
|
+
@preliminary_items = []
|
128
136
|
result[:items].each do |item_data|
|
129
137
|
unless item_data.nil?
|
130
138
|
item = item_class.new(self, item_data)
|
131
|
-
|
139
|
+
if item.preliminary?
|
140
|
+
@preliminary_items << item
|
141
|
+
else
|
142
|
+
@items[item.backpack_position - 1] = item
|
143
|
+
end
|
132
144
|
end
|
133
145
|
end
|
134
146
|
end
|
@@ -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) 2011-
|
4
|
+
# Copyright (c) 2011-2013, Sebastian Staudt
|
5
5
|
|
6
6
|
require 'steam/community/web_api'
|
7
7
|
|
@@ -99,6 +99,7 @@ module GameItem
|
|
99
99
|
@name = schema_data[:item_name]
|
100
100
|
@origin = inventory.item_schema.origins[item_data[:origin]]
|
101
101
|
@original_id = item_data[:original_id]
|
102
|
+
@preliminary = item_data[:inventory] & 0x40000000 != 0
|
102
103
|
@quality = inventory.item_schema.qualities[item_data[:quality]]
|
103
104
|
@tradeable = !!item_data[:flag_cannot_trade]
|
104
105
|
@type = schema_data[:item_type_name]
|
@@ -125,6 +126,16 @@ module GameItem
|
|
125
126
|
@craftable
|
126
127
|
end
|
127
128
|
|
129
|
+
# Returns whether this item is preliminary
|
130
|
+
#
|
131
|
+
# Preliminary means that this item was just found or traded and has not yet
|
132
|
+
# been added to the inventory
|
133
|
+
#
|
134
|
+
# @return [Boolean] `true` if this item is preliminary
|
135
|
+
def preliminary?
|
136
|
+
@preliminary
|
137
|
+
end
|
138
|
+
|
128
139
|
# Returns the data for this item that's defined in the item schema
|
129
140
|
#
|
130
141
|
# @return [Hash<Symbol, Object>] The schema data for this item
|
@@ -312,8 +312,8 @@ class SteamId
|
|
312
312
|
# @see #friends
|
313
313
|
# @see #initialize
|
314
314
|
def fetch_friends
|
315
|
-
@friends = []
|
316
315
|
friends_data = parse "#{base_url}/friends?xml=1"
|
316
|
+
@friends = []
|
317
317
|
friends_data['friends']['friend'].each do |friend|
|
318
318
|
@friends << SteamId.new(friend.to_i, false)
|
319
319
|
end
|
@@ -327,9 +327,9 @@ class SteamId
|
|
327
327
|
#
|
328
328
|
# @see #games
|
329
329
|
def fetch_games
|
330
|
+
games_data = parse "#{base_url}/games?xml=1"
|
330
331
|
@games = {}
|
331
332
|
@playtimes = {}
|
332
|
-
games_data = parse "#{base_url}/games?xml=1"
|
333
333
|
games_data['games']['game'].each do |game_data|
|
334
334
|
app_id = game_data['appID'].to_i
|
335
335
|
game = SteamGame.new app_id, game_data
|
@@ -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) 2008-
|
4
|
+
# Copyright (c) 2008-2013, Sebastian Staudt
|
5
5
|
|
6
6
|
require 'errors/rcon_no_auth_error'
|
7
7
|
require 'steam/packets/rcon/rcon_auth_request'
|
@@ -72,7 +72,7 @@ class SourceServer
|
|
72
72
|
@rcon_request_id = rand 2**16
|
73
73
|
|
74
74
|
@rcon_socket.send RCONAuthRequest.new(@rcon_request_id, password)
|
75
|
-
|
75
|
+
@rcon_socket.reply
|
76
76
|
reply = @rcon_socket.reply
|
77
77
|
|
78
78
|
@rcon_authenticated = reply.request_id == @rcon_request_id
|
@@ -82,6 +82,9 @@ class SourceServer
|
|
82
82
|
#
|
83
83
|
# @param [String] command The command to execute on the server via RCON
|
84
84
|
# @return [String] The output of the executed command
|
85
|
+
# @raise [RCONBanException] if the IP of the local machine has been banned on
|
86
|
+
# the game server
|
87
|
+
# @raise [RCONNoAuthException] if not authenticated with the server
|
85
88
|
# @see #rcon_auth
|
86
89
|
def rcon_exec(command)
|
87
90
|
raise RCONNoAuthError unless @rcon_authenticated
|
@@ -91,13 +94,19 @@ class SourceServer
|
|
91
94
|
|
92
95
|
response = []
|
93
96
|
begin
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
97
|
+
begin
|
98
|
+
response_packet = @rcon_socket.reply
|
99
|
+
if response_packet.is_a? RCONAuthResponse
|
100
|
+
@rcon_authenticated = false
|
101
|
+
raise RCONNoAuthError
|
102
|
+
end
|
103
|
+
rescue RCONBanError
|
104
|
+
if @rcon_authenticated
|
105
|
+
@rcon_authenticated = false
|
106
|
+
raise RCONNoAuthError
|
107
|
+
end
|
108
|
+
|
109
|
+
raise $!
|
101
110
|
end
|
102
111
|
response << response_packet.response
|
103
112
|
end while response.size < 3 || response_packet.response.size > 0
|
@@ -1,13 +1,14 @@
|
|
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
|
require 'ipaddr'
|
7
7
|
require 'socket'
|
8
8
|
require 'timeout'
|
9
9
|
|
10
10
|
require 'errors/rcon_ban_error'
|
11
|
+
require 'errors/rcon_no_auth_error'
|
11
12
|
require 'errors/timeout_error'
|
12
13
|
require 'steam/packets/rcon/rcon_packet'
|
13
14
|
require 'steam/packets/rcon/rcon_packet_factory'
|
@@ -74,11 +75,17 @@ class RCONSocket
|
|
74
75
|
#
|
75
76
|
# @raise [RCONBanError] if the IP of the local machine has been banned on the
|
76
77
|
# game server
|
78
|
+
# @raise [RCONNoAuthException] if an authenticated connection has been
|
79
|
+
# dropped by the server
|
77
80
|
# @return [RCONPacket] The packet replied from the server
|
78
81
|
def reply
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
+
begin
|
83
|
+
if receive_packet(4) == 0
|
84
|
+
@socket.close
|
85
|
+
raise RCONNoAuthError
|
86
|
+
end
|
87
|
+
rescue Errno::ECONNRESET
|
88
|
+
raise RCONBanError
|
82
89
|
end
|
83
90
|
|
84
91
|
remaining_bytes = @buffer.long
|
@@ -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) 2008-
|
4
|
+
# Copyright (c) 2008-2013, Sebastian Staudt
|
5
5
|
|
6
6
|
require 'ipaddr'
|
7
7
|
require 'socket'
|
@@ -65,7 +65,8 @@ module SteamSocket
|
|
65
65
|
begin
|
66
66
|
data = @socket.recv @buffer.remaining
|
67
67
|
rescue Errno::ECONNRESET
|
68
|
-
|
68
|
+
@socket.close
|
69
|
+
raise $!
|
69
70
|
end
|
70
71
|
bytes_read = @buffer.write data
|
71
72
|
@buffer.truncate bytes_read
|
@@ -123,6 +123,17 @@ class TestSteamId < Test::Unit::TestCase
|
|
123
123
|
end
|
124
124
|
assert_equal 'XML data could not be parsed.', error.message
|
125
125
|
end
|
126
|
+
|
127
|
+
should 'not cache an empty hash when an error is encountered on steam' do
|
128
|
+
SteamId.any_instance.expects(:parse).raises(OpenURI::HTTPError.new('', nil))
|
129
|
+
steam_id = SteamId.new(76561197983311154, false)
|
130
|
+
|
131
|
+
assert_raises OpenURI::HTTPError do
|
132
|
+
steam_id.games
|
133
|
+
end
|
134
|
+
|
135
|
+
assert_equal(nil, steam_id.instance_variable_get("@games"))
|
136
|
+
end
|
126
137
|
|
127
138
|
teardown do
|
128
139
|
SteamId.clear_cache
|
@@ -96,12 +96,21 @@ class TestRCONSocket < Test::Unit::TestCase
|
|
96
96
|
@socket.reply
|
97
97
|
end
|
98
98
|
|
99
|
-
should 'raise an
|
99
|
+
should 'raise an RCONBanError if the client has been banned' do
|
100
|
+
@socket.expects(:receive_packet).with(4).raises Errno::ECONNRESET
|
101
|
+
|
102
|
+
assert_raise RCONBanError do
|
103
|
+
assert_nil @socket.reply
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
should 'raise an RCONNoAuthError if the connection has been dropped' do
|
100
108
|
@socket.expects(:receive_packet).with(4).returns 0
|
101
109
|
@tcp_socket.expects :close
|
102
110
|
|
103
|
-
|
104
|
-
|
111
|
+
assert_raise RCONNoAuthError do
|
112
|
+
assert_nil @socket.reply
|
113
|
+
end
|
105
114
|
end
|
106
115
|
|
107
116
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: steam-condenser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.3.
|
4
|
+
version: 1.3.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-21 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bzip2-ruby
|