steamrb 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 99caa4cd2e21acd6cf5b3d53ce3079a6ca6a7a15
4
- data.tar.gz: 3ccd1cc12a21b735f67d42d511b94a3c6a9079e2
3
+ metadata.gz: 4b1b84d1db3f1b16870c6f5ee648e92d63ca80d6
4
+ data.tar.gz: 596e8ec9bcaea8a9416c91055970d04fb668f949
5
5
  SHA512:
6
- metadata.gz: 2593c4948cd249f4464e3baabd18252ee7ba1b616cf81955cf5dddfa5303e63b65db3f3ff3ecc0ebb9c8472c50689a568aeb4fbba99cdf89e7b85aa2dd7753b8
7
- data.tar.gz: 532adb1b7b9e99a5faff2e845d2a6f689b2684b0b88f181d69c77b65378dcac16e2b2704820309045b2a6a4b49e02f6cc9c0e48b1e5aceae41816e41bcac1a9d
6
+ metadata.gz: 61a3e00b660a8b68b8a16fdc65ef4371a355b65c89fb2e9d981072db2c2eb3492fba7125d1a13100f542f35e413947a73eef941e793f99d1e90758090f05e7a1
7
+ data.tar.gz: c88a674ece9968ebb3c9a4079652bd958c75dceae9b4dfa8de1bab2ca8b6655a4332af9d598fcf98896ac56c7d919cf9db7e39c9a540ebca715dfb0485a6683d
data/.yardopts ADDED
@@ -0,0 +1 @@
1
+ --markup=markdown
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # Steam
2
+ [![Build Status](https://travis-ci.org/fastpeek/steam.svg?branch=master)](https://travis-ci.org/fastpeek/steamrb)
3
+ ![Gem Version](https://img.shields.io/gem/v/steamrb.svg)
2
4
 
3
5
  Ruby Client for Steam.
4
6
 
@@ -108,9 +110,17 @@ bot.plugin(:csgo)
108
110
  bot.start
109
111
  ```
110
112
 
113
+ ## Running the tests
114
+
115
+ To run the integration tests you must specify a Steam username and password. For
116
+ the plugin integration test to pass this account must have CS:GO installed.
117
+
118
+ `STEAM_LOG_LEVEL=DEBUG USERNAME=username PASSWORD=password rake spec:all`
119
+
111
120
  ## License
112
121
 
113
- MIT
122
+ [MIT](https://github.com/fastpeek/steam/blob/master/LICENSE)
114
123
 
115
124
  ## References
116
125
  [SteamKit](https://github.com/SteamRE/SteamKit/)
126
+
@@ -6,8 +6,6 @@ module Steam
6
6
  class ByteReader
7
7
  extend Forwardable
8
8
 
9
- attr_reader :io
10
-
11
9
  # Create a ByteReader object
12
10
  #
13
11
  # @param io [:read] an io object
@@ -15,63 +13,29 @@ module Steam
15
13
  @io = io
16
14
  end
17
15
 
18
- # Reads an unsigned 64 bit integer from the stream
19
- #
20
- # @return [Integer] The 64 bit integer
21
- def read_int64
22
- io.read(8).unpack('C*').each_with_index.reduce(0) do |sum, (byte, index)|
23
- sum + byte * (256**index)
24
- end
25
- end
26
- alias int64 read_int64
27
-
28
- # Reads an unsigned short from the stream
29
- #
30
- # @return [Integer] The short
31
- def read_short
32
- io.read(2).unpack('S*').first
33
- end
34
- alias short read_short
35
-
36
16
  # Reads a string of a given length from the stream
37
17
  #
18
+ # @param len [Integer] the number of bytes to read
38
19
  # @return [String] The read string
39
20
  def string(len)
40
- io.read(len)
41
- end
42
-
43
- # Reads a single bytes from the stream
44
- #
45
- # @return [Integer] The byte
46
- def byte
47
- io.read(1).ord
21
+ read(len)
48
22
  end
49
23
 
50
24
  # Reads an unsigned 32 bit integer from the stream
51
25
  #
52
26
  # @return [Integer] The 32 bit integer
53
27
  def unsigned_int32
54
- io.read(4).unpack('<I*').first
28
+ @io.read(4).unpack('<I*').first
55
29
  end
56
30
 
57
31
  # Reads an signed 32 bit integer from the stream
58
32
  #
59
33
  # @return [Integer] The 32 bit integer
60
34
  def signed_int32
61
- io.read(4).unpack('<i*').first
62
- end
63
-
64
- # Reads an signed 16 bit integer from the stream
65
- #
66
- # @return [Integer] The 16 bit integer
67
- def signed_int16
68
- io.read(2).unpack('<s*').first
35
+ @io.read(4).unpack('<i*').first
69
36
  end
70
37
 
71
38
  def_delegator :@io, :read, :read
72
- def_delegator :@io, :readbyte, :readbyte
73
39
  def_delegator :@io, :eof?, :eof?
74
- def_delegator :@io, :tell, :tell
75
- def_delegator :@io, :lineno, :lineno
76
40
  end
77
41
  end
@@ -6,8 +6,6 @@ module Steam
6
6
  class ByteWriter
7
7
  extend Forwardable
8
8
 
9
- attr_reader :io
10
-
11
9
  # Wrap an Int64 allowing the lo and hi
12
10
  # 32 bits to be extracted
13
11
  class Int64Type
@@ -55,11 +53,6 @@ module Steam
55
53
  @io.write([value].pack('<I'))
56
54
  end
57
55
 
58
- # Writes an signed long from the stream
59
- def write_signed_long(value)
60
- @io.write([value].pack('<l_'))
61
- end
62
-
63
56
  # Writes a 32 bit intger to the stream
64
57
  def write_int32(value)
65
58
  @io.write([value].pack('<l'))
@@ -74,16 +67,10 @@ module Steam
74
67
  end
75
68
  end
76
69
 
77
- # Writes a single byte to the stream
78
- def write_byte(byte)
79
- @io.write([byte].pack('C'))
80
- end
81
-
82
70
  # Writes the given bytes to the stream
83
71
  def write(bytes)
84
72
  @io.write(bytes)
85
73
  end
86
- alias write_string write
87
74
 
88
75
  # The byte representation of this writer object
89
76
  #
@@ -3,7 +3,8 @@ module Steam
3
3
  # Utility to provide EMsg convenience. Allows looking up
4
4
  # EMsg name by the EMsg integer value.
5
5
  #
6
- # EMsgUtil.new(123).name # => 'SOME_EMSG'
6
+ # @example Getting an EMsg name from its value
7
+ # EMsgUtil.new(123).name # => 'SOME_EMSG'
7
8
  class EMsgUtil
8
9
  # Instantiate the object
9
10
  #
@@ -22,7 +22,8 @@ module Steam
22
22
  handler = find_handler(packet.msg_type)
23
23
 
24
24
  if handler.nil?
25
- Steam.logger.debug("No hander found for: #{EMsgUtil.new(packet.emsg).name}")
25
+ emsg = EMsgUtil.new(packet.emsg)
26
+ Steam.logger.debug("No hander found for: #{emsg.name}")
26
27
  return false
27
28
  end
28
29
 
data/lib/steam/logger.rb CHANGED
@@ -2,8 +2,16 @@
2
2
  require 'logger'
3
3
 
4
4
  module Steam
5
- # Small wrapper around the Ruby Logger class
5
+ # Small wrapper around the Ruby Logger class. A `STEAM_LOG_LEVEL`
6
+ # environment variable may also dictate the log level.
7
+ #
8
+ # @example Creating a Logger object
9
+ # logger = Logger.new(STDOUT)
10
+ # logger.level = Logger::WARN
6
11
  class Logger < ::Logger
12
+ # Raised when the #env_key env variable is not supported
13
+ InvalidLogLevel = Class.new(StandardError)
14
+
7
15
  # Log level WARN
8
16
  WARN = ::Logger::WARN
9
17
  # Log level INFO
@@ -18,10 +26,31 @@ module Steam
18
26
  # Create a Logger that logs to a given IO object
19
27
  #
20
28
  # @param io [#read] The io object
21
- # @param level [Integer] log lvel
22
- def initialize(io, level = DEBUG)
23
- self.level = level
29
+ def initialize(io)
24
30
  super(io)
31
+ self.level = _level
32
+ end
33
+
34
+ private
35
+
36
+ # @api private
37
+ def _level
38
+ level = ENV[env_key]
39
+ level = 'DEBUG' if level.nil? || level.empty?
40
+ unless allowed_levels.include?(level.to_s)
41
+ raise InvalidLogLevel, "log level #{level} not allowed, must be one of"\
42
+ "#{allowed_levels}"
43
+ end
44
+ self.class.const_get("Logger::#{level}")
45
+ end
46
+
47
+ # @api private
48
+ def allowed_levels
49
+ %w(WARN INFO ERROR DEBUG FATAL)
50
+ end
51
+
52
+ def env_key
53
+ 'STEAM_LOG_LEVEL'
25
54
  end
26
55
  end
27
56
  end
@@ -39,8 +39,8 @@ module Steam
39
39
  def encode
40
40
  stream = ByteWriter.new
41
41
  stream.write_unsigned_int32(body.length)
42
- stream.write_string(TCP_MAGIC)
43
- stream.write_string(body)
42
+ stream.write(TCP_MAGIC)
43
+ stream.write(body)
44
44
  stream.string
45
45
  end
46
46
 
data/lib/steam/plugins.rb CHANGED
@@ -89,18 +89,17 @@ module Steam
89
89
 
90
90
  # @api private
91
91
  def require_plugins
92
- required_plugins = @plugins.map do |plugin|
93
- begin
94
- require "steam/#{plugin}"
95
- plugin
96
- rescue LoadError
97
- msg = "Failed to load #{plugin} plugin. Is it in your Gemfile?"
98
- Steamd.logger.error(msg)
99
- nil
100
- end
101
- end
92
+ @plugins.map { |plugin| _require(plugin) }.compact
93
+ end
102
94
 
103
- required_plugins.compact
95
+ # @api private
96
+ def _require(plugin)
97
+ require "steam/#{plugin}"
98
+ plugin
99
+ rescue LoadError
100
+ msg = "Failed to load steam-#{plugin} plugin. Is it in your Gemfile?"
101
+ Steamd.logger.error(msg)
102
+ nil
104
103
  end
105
104
  end
106
105
  end
data/lib/steam/version.rb CHANGED
@@ -7,7 +7,7 @@ module Steam
7
7
  MINOR = '1'
8
8
 
9
9
  # Patch version of the gem
10
- PATCH = '0'
10
+ PATCH = '1'
11
11
 
12
12
  # Current Steam gem version
13
13
  VERSION = [MAJOR, MINOR, PATCH].join('.')
data/lib/steam.rb CHANGED
@@ -36,11 +36,7 @@ module Steam
36
36
  #
37
37
  # @param io [:read] the io stream
38
38
  # @return [Steam::Logger]
39
- def self.logger(io = STDOUT, level = Steam::Logger::INFO)
40
- @logger ||= begin
41
- logger = Steam::Logger.new(io)
42
- logger.level = level
43
- logger
44
- end
39
+ def self.logger(io = STDOUT)
40
+ @logger ||= Steam::Logger.new(io)
45
41
  end
46
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: steamrb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Taylor Finnell
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-01 00:00:00.000000000 Z
11
+ date: 2016-12-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: steamd
@@ -149,7 +149,9 @@ files:
149
149
  - ".rspec"
150
150
  - ".rubocop.yml"
151
151
  - ".travis.yml"
152
+ - ".yardopts"
152
153
  - Gemfile
154
+ - LICENSE
153
155
  - README.md
154
156
  - Rakefile
155
157
  - bin/console