steam_hlds_log_parser 0.4.6 → 0.4.7
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 +4 -4
- data/README.md +78 -29
- data/examples/example-1.rb +5 -15
- data/examples/example-2.rb +15 -16
- data/lib/steam_hlds_log_parser/client.rb +17 -17
- data/lib/steam_hlds_log_parser/handler.rb +18 -14
- data/lib/steam_hlds_log_parser/version.rb +1 -1
- data/spec/client_spec.rb +83 -35
- data/spec/handler_spec.rb +14 -13
- data/spec/helper_spec.rb +9 -7
- data/spec/log_tester_spec.rb +2 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA512:
|
3
|
-
|
4
|
-
|
3
|
+
metadata.gz: d2bd1ead06fc2e944fe5444330d664cdf1b7417163c9f62c4e9a40f86bd5ace016a660d5bb4b7f7f7ddeaae175af51e4c140721dc24c6d6f44f8d856cf0dd05d
|
4
|
+
data.tar.gz: f1d9c090409ddca6135103ddaea5c8c4275bd385e7dd67e79bedec33b3da262df42a09080a505cf21d9ce872915b7d8322bce522c258414ce3fee53c7c48c430
|
5
5
|
SHA1:
|
6
|
-
|
7
|
-
|
6
|
+
metadata.gz: dea6da3483d539c6275bb19b4814913eb8674f84
|
7
|
+
data.tar.gz: d76a18c57ee1aadd6193dcec1ac66a48776683a7
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
# Steam
|
1
|
+
# Steam HLDS Log Parser
|
2
2
|
|
3
|
-
|
3
|
+
##### Log parser for Steam HLDS based games like Counter-Strike
|
4
|
+
|
5
|
+
Steam Hlds Log Parser listens to UDP log packets sent by your _(local or remote)_ HLDS game server, processes data and returns clean and readable (translated) content that you can use for your website, irc channel, match live streaming, bots, database...
|
4
6
|
|
5
7
|
Should work with all Steam HLDS based games, and has been mostly tested on Counter-Strike 1.6.
|
6
8
|
|
@@ -26,41 +28,73 @@ Or install it yourself as:
|
|
26
28
|
|
27
29
|
$ gem install steam_hlds_log_parser
|
28
30
|
|
29
|
-
|
31
|
+
And in your Ruby file:
|
32
|
+
|
33
|
+
require "steam_hlds_log_parser"
|
30
34
|
|
31
|
-
|
32
|
-
Ask this `class` to write a file, send content to IRC or flowdock... whatever... and give it as `:displayer` Hash option
|
33
|
-
2. Create a new client on desired IP / Port / Options
|
34
|
-
3. Of course, you need to have server RCON. In your `server.cfg` (or in server console) add `logaddress 127.0.0.1 27035`. It specifies where the logs will be sent. This must be the IP / Port your ruby client will listen to.
|
35
|
+
## Full working example
|
35
36
|
|
36
|
-
|
37
|
+
By default, Steam HLDS Log Parser runs on `0.0.0.0:27115` _(+100 than default HLDS port which is 27015)_
|
37
38
|
|
38
|
-
|
39
|
+
1 - On your game server, send logs to your Ruby server (in this example, same machine).
|
39
40
|
|
40
|
-
|
41
|
-
|
41
|
+
```
|
42
|
+
logaddres 0.0.0.0 27115
|
43
|
+
```
|
44
|
+
|
45
|
+
or
|
46
|
+
|
47
|
+
```
|
48
|
+
logaddres_add 0.0.0.0 27115
|
49
|
+
```
|
50
|
+
|
51
|
+
2 - Create a file named, for example, `hlds_parser.rb` with this content:
|
52
|
+
|
53
|
+
```ruby
|
54
|
+
require "rubygems"
|
55
|
+
require "steam_hlds_log_parser"
|
42
56
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
57
|
+
# Your displayer Class is what you will do with your data
|
58
|
+
class Formatter
|
59
|
+
def initialize(data)
|
60
|
+
# will 'puts' the translated content, using built-in Displayer
|
61
|
+
SteamHldsLogParser::Displayer.new(data).display_translation
|
62
|
+
end
|
63
|
+
end
|
49
64
|
|
65
|
+
# Setup the Client to use the 'Formatter' Class as displayer callback
|
66
|
+
# Options will be use default values (see example-2.rb)
|
67
|
+
SteamHldsLogParser::Client.new(Formatter).start
|
68
|
+
```
|
50
69
|
|
51
|
-
|
52
|
-
options = {
|
53
|
-
:locale => :en,
|
54
|
-
:display_kills => true,
|
55
|
-
:display_actions => true,
|
56
|
-
:display_changelevel => true,
|
57
|
-
:display_chat => true,
|
58
|
-
:display_team_chat => true,
|
59
|
-
:displayer => Formatter
|
60
|
-
}
|
70
|
+
3 - Now, run the Ruby script to see parsed content inyour console:
|
61
71
|
|
62
|
-
|
63
|
-
|
72
|
+
```
|
73
|
+
ruby hlds_parser.rb
|
74
|
+
```
|
75
|
+
|
76
|
+
Your game server activity should look something like that:
|
77
|
+
|
78
|
+
```
|
79
|
+
[T] Jim_Carrey spawned with the bomb
|
80
|
+
[CT] Tomav says "Com'on guys!"
|
81
|
+
[CT] V0id killed [T] killaruna with deagle
|
82
|
+
[T] Funky Byte killed [CT] Neuromancer with m4a1
|
83
|
+
[CT] Tomav killed [T] Funky Byte with deagle
|
84
|
+
[T] Juliet_Lewis killed [CT] Make my Day with ak47
|
85
|
+
[CT] Alloc killed [T] Juliet_Lewis with famas
|
86
|
+
[T] Jim_Carrey planted the bomb
|
87
|
+
[CT] Tomav killed [T] Jim_Carrey with sg552
|
88
|
+
[CT] Tomav begin bomb defuse with kit
|
89
|
+
[CT] Jim_Carrey says "aaaaaargh!!!" to others [T]
|
90
|
+
[CT] Tomav defused the bomb
|
91
|
+
[CT] 1 - 6 [T]
|
92
|
+
Map ends: CT => 1
|
93
|
+
Map ends: T => 6
|
94
|
+
Loading de_dust2
|
95
|
+
```
|
96
|
+
|
97
|
+
Now customize your Formatter class to make it fit your needs.
|
64
98
|
|
65
99
|
## Documentation
|
66
100
|
|
@@ -73,6 +107,21 @@ Full documentation can be found on [Steam HLDS Parser Log page on Rubydoc](http:
|
|
73
107
|
Steam HLDS Log Parser uses RSpec as test / specification framework and should be 100% tested too.
|
74
108
|
Here again, feel free to improve it.
|
75
109
|
|
110
|
+
## FAQ
|
111
|
+
|
112
|
+
### What do I need to use this gem?
|
113
|
+
|
114
|
+
* Ruby 1.9+
|
115
|
+
* Basic Ruby skill
|
116
|
+
* Steam HLDS Server with SSH access or RCON password
|
117
|
+
|
118
|
+
### My Client is running, but nothing appears in my console?!
|
119
|
+
Common issues are:
|
120
|
+
|
121
|
+
* HLDS with no or miconfigured `logaddress`
|
122
|
+
* Firewall not properly configured (remember that HLDS sends `UDP` packets, not `TCP`)
|
123
|
+
* Have a look to your Displayer Class
|
124
|
+
|
76
125
|
## Contributing
|
77
126
|
|
78
127
|
1. Fork it
|
data/examples/example-1.rb
CHANGED
@@ -1,24 +1,14 @@
|
|
1
1
|
require "rubygems"
|
2
2
|
require "steam_hlds_log_parser"
|
3
3
|
|
4
|
+
# Your displayer Class is what you will do with your data
|
4
5
|
class Formatter
|
5
6
|
def initialize(data)
|
6
|
-
# will 'puts' the translated content
|
7
|
+
# will 'puts' the translated content, using built-in Displayer
|
7
8
|
SteamHldsLogParser::Displayer.new(data).display_translation
|
8
9
|
end
|
9
10
|
end
|
10
11
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
:locale => :en,
|
15
|
-
:display_kills => true,
|
16
|
-
:display_actions => true,
|
17
|
-
:display_changelevel => true,
|
18
|
-
:display_chat => true,
|
19
|
-
:display_team_chat => true,
|
20
|
-
:displayer => Formatter
|
21
|
-
}
|
22
|
-
|
23
|
-
parser = SteamHldsLogParser::Client.new("127.0.0.1", 27035, options)
|
24
|
-
parser.start
|
12
|
+
# Setup the Client to use the 'Formatter' Class
|
13
|
+
# Options will be use default values (see example-2.rb)
|
14
|
+
SteamHldsLogParser::Client.new(Formatter).start
|
data/examples/example-2.rb
CHANGED
@@ -1,26 +1,25 @@
|
|
1
1
|
require "rubygems"
|
2
2
|
require "steam_hlds_log_parser"
|
3
|
-
# require "flowdock"
|
4
3
|
|
5
|
-
|
6
|
-
class
|
4
|
+
# Your displayer Class is what you will do with your data
|
5
|
+
class Formatter
|
7
6
|
def initialize(data)
|
8
|
-
#
|
9
|
-
|
10
|
-
# Source: https://github.com/flowdock/flowdock-api
|
11
|
-
flow = Flowdock::Flow.new(:api_token => "12345678901234567890123456789012", :external_user_name => "HLDS-Live")
|
12
|
-
flow.push_to_chat(:content => content)
|
7
|
+
# will 'puts' the translated content, using built-in Displayer
|
8
|
+
SteamHldsLogParser::Displayer.new(data).display_translation
|
13
9
|
end
|
14
10
|
end
|
15
11
|
|
12
|
+
# These are default options
|
16
13
|
options = {
|
17
|
-
:
|
18
|
-
:
|
19
|
-
:
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
23
|
-
:
|
14
|
+
:host => "0.0.0.0",
|
15
|
+
:port => 27115,
|
16
|
+
:locale => :en,
|
17
|
+
:display_kills => true,
|
18
|
+
:display_actions => true,
|
19
|
+
:display_changelevel => true,
|
20
|
+
:display_chat => true,
|
21
|
+
:display_team_chat => true
|
24
22
|
}
|
25
23
|
|
26
|
-
SteamHldsLogParser::Client.new(
|
24
|
+
parser = SteamHldsLogParser::Client.new(Formatter, options)
|
25
|
+
parser.start
|
@@ -2,37 +2,37 @@ module SteamHldsLogParser
|
|
2
2
|
|
3
3
|
# Listens to HLDS logs received via UDP on configured port
|
4
4
|
#
|
5
|
-
# @attr_reader [String] host Client host / IP
|
6
|
-
# @attr_reader [Integer] port Client port to listen to
|
7
5
|
# @attr_reader [Hash] options Client options
|
6
|
+
#
|
8
7
|
class Client
|
9
8
|
|
10
|
-
attr_reader :
|
9
|
+
attr_reader :displayer, :options
|
11
10
|
|
12
11
|
# Creates a new client
|
13
12
|
#
|
14
|
-
# @param [
|
15
|
-
# @param [
|
16
|
-
# @param [Hash] options Other configuration options
|
13
|
+
# @param [Class] displayer Callback class which will receive parsed content, do what you want with this class
|
14
|
+
# @param [Hash] options Optional parameters to setup your client
|
17
15
|
#
|
16
|
+
# @option options [String] :host (0.0.0.0) IP Address the client will be running, usually localhost
|
17
|
+
# @option options [Integer] :port (27115) Port will be listening to
|
18
18
|
# @option options [Symbol] :locale (:en) Set the language of returned content
|
19
19
|
# @option options [Boolean] :display_kills (true) Enable kills / frags detail
|
20
20
|
# @option options [Boolean] :display_actions (true) Enable players actions / defuse / ... detail
|
21
21
|
# @option options [Boolean] :display_changelevel (true) Enable changelevel (map) display
|
22
22
|
# @option options [Boolean] :display_chat (true) Enable chat ('say') display
|
23
23
|
# @option options [Boolean] :display_team_chat (true) Enable chat ('say_team') display
|
24
|
-
# @option options [Class] :displayer Class that will be use to display content
|
25
24
|
#
|
26
|
-
def initialize(
|
25
|
+
def initialize(displayer, options = {})
|
27
26
|
default_options = {
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:
|
31
|
-
:
|
32
|
-
:
|
33
|
-
:
|
27
|
+
:host => "0.0.0.0",
|
28
|
+
:port => 27115,
|
29
|
+
:locale => :en,
|
30
|
+
:display_kills => true,
|
31
|
+
:display_actions => true,
|
32
|
+
:display_changelevel => true,
|
33
|
+
:display_chat => true,
|
34
|
+
:display_team_chat => true,
|
34
35
|
}
|
35
|
-
@host, @port = host, port
|
36
36
|
@options = default_options.merge(options)
|
37
37
|
end
|
38
38
|
|
@@ -45,13 +45,13 @@ module SteamHldsLogParser
|
|
45
45
|
Signal.trap("INT") { EM.stop }
|
46
46
|
Signal.trap("TERM") { EM.stop }
|
47
47
|
# Let's start
|
48
|
-
EM::open_datagram_socket(@host, @port, Handler, @
|
48
|
+
EM::open_datagram_socket(@options[:host], @options[:port], Handler, @displayer, @options)
|
49
49
|
}
|
50
50
|
end
|
51
51
|
|
52
52
|
# Stops the client
|
53
53
|
def stop
|
54
|
-
puts "## #{@host}:#{@port} => #{I18n.t('client_stop')}"
|
54
|
+
puts "## #{@options[:host]}:#{@options[:port]} => #{I18n.t('client_stop')}"
|
55
55
|
EM::stop_event_loop
|
56
56
|
end
|
57
57
|
|
@@ -2,31 +2,31 @@ module SteamHldsLogParser
|
|
2
2
|
|
3
3
|
# Process data received by 'Client'
|
4
4
|
#
|
5
|
-
# @attr_reader [
|
6
|
-
# @attr_reader [Integer] port Client port to listen to
|
5
|
+
# @attr_reader [Class] displayer Callback
|
7
6
|
# @attr_reader [Hash] options Client options
|
7
|
+
#
|
8
8
|
class Handler < EM::Connection
|
9
9
|
|
10
|
-
attr_reader :
|
10
|
+
attr_reader :displayer, :options
|
11
11
|
|
12
12
|
# Initialize Handler from Client options
|
13
13
|
#
|
14
|
-
# @param [
|
15
|
-
# @param [
|
16
|
-
# @param [Hash] options Other client configuration options
|
14
|
+
# @param [Class] displayer Class to call when data is parsed
|
15
|
+
# @param [Hash] options Client configuration options
|
17
16
|
#
|
18
|
-
def initialize(
|
19
|
-
@
|
17
|
+
def initialize(displayer, options)
|
18
|
+
@displayer = displayer
|
19
|
+
@options = options
|
20
20
|
end
|
21
21
|
|
22
22
|
# Triggered when HLDS connects
|
23
23
|
def post_init
|
24
|
-
puts "## #{@host}:#{@port} => #{I18n.t('client_connect')}"
|
24
|
+
puts "## #{@options[:host]}:#{@options[:port]} => #{I18n.t('client_connect')}"
|
25
25
|
end
|
26
26
|
|
27
27
|
# Triggered when HLDS disconnects
|
28
28
|
def unbind
|
29
|
-
puts "## #{@host}:#{@port} => #{I18n.t('client_disconnect')}"
|
29
|
+
puts "## #{@options[:host]}:#{@options[:port]} => #{I18n.t('client_disconnect')}"
|
30
30
|
end
|
31
31
|
|
32
32
|
# Get data from Client and parse using Regexp
|
@@ -37,6 +37,8 @@ module SteamHldsLogParser
|
|
37
37
|
# * match suicides
|
38
38
|
# * match who did what (defuse, drop the bomb...)
|
39
39
|
# * match changelevel
|
40
|
+
# * match chat (say)
|
41
|
+
# * match team chat (say_team)
|
40
42
|
#
|
41
43
|
# @param [String] data Data received by Client from HLDS server (a line of log)
|
42
44
|
#
|
@@ -86,10 +88,10 @@ module SteamHldsLogParser
|
|
86
88
|
|
87
89
|
# no matching pattern, no output
|
88
90
|
unless content.nil?
|
89
|
-
if @
|
91
|
+
if @displayer.nil?
|
90
92
|
return(content)
|
91
93
|
else
|
92
|
-
@
|
94
|
+
@displayer.new(content)
|
93
95
|
end
|
94
96
|
end
|
95
97
|
|
@@ -105,8 +107,9 @@ module SteamHldsLogParser
|
|
105
107
|
case winner
|
106
108
|
when "T"
|
107
109
|
return "#{I18n.t('full_team_name_te')}"
|
108
|
-
|
110
|
+
when "CT"
|
109
111
|
return "#{I18n.t('full_team_name_ct')}"
|
112
|
+
else
|
110
113
|
end
|
111
114
|
end
|
112
115
|
|
@@ -120,8 +123,9 @@ module SteamHldsLogParser
|
|
120
123
|
case team
|
121
124
|
when "TERRORIST"
|
122
125
|
return "#{I18n.t('short_team_name_te')}"
|
123
|
-
|
126
|
+
when "CT"
|
124
127
|
return "#{I18n.t('short_team_name_ct')}"
|
128
|
+
else
|
125
129
|
end
|
126
130
|
end
|
127
131
|
|
data/spec/client_spec.rb
CHANGED
@@ -4,48 +4,96 @@ module SteamHldsLogParser
|
|
4
4
|
|
5
5
|
describe "SteamHldsLogParser" do
|
6
6
|
|
7
|
-
before :all do
|
8
|
-
@client = Client.new("0.0.0.0", 27035)
|
9
|
-
@options = @client.options
|
10
|
-
@custom_options = custom_options
|
11
|
-
@custom_client = Client.new("127.0.0.1", 27045, @custom_options)
|
12
|
-
end
|
13
|
-
|
14
7
|
describe "Client" do
|
15
8
|
|
16
|
-
|
17
|
-
|
9
|
+
context "when parameters are missing" do
|
10
|
+
it "raises an exception" do
|
11
|
+
expect { Client.new }.to raise_error(ArgumentError)
|
12
|
+
end
|
18
13
|
end
|
19
14
|
|
20
|
-
subject {
|
21
|
-
context "when a 'Client' is created
|
15
|
+
subject(:default_client) { Client.new(RSpecDisplayer) }
|
16
|
+
context "when a 'Client' is created with default options"
|
22
17
|
it { should be_an_instance_of Client }
|
23
|
-
it "has a '
|
24
|
-
|
25
|
-
|
18
|
+
it "has a default 'options' Hash" do
|
19
|
+
default_client.options.should_not be_nil
|
20
|
+
default_client.options.should_not be(nil)
|
21
|
+
default_client.options.class.should be(Hash)
|
26
22
|
end
|
27
|
-
it "has a '
|
28
|
-
|
29
|
-
|
23
|
+
it "has a default 'host'" do
|
24
|
+
default_client.options[:host].should_not be_nil
|
25
|
+
default_client.options[:host].should eq("0.0.0.0")
|
30
26
|
end
|
31
|
-
it "has a default '
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
27
|
+
it "has a default 'port'" do
|
28
|
+
default_client.options[:port].should_not be_nil
|
29
|
+
default_client.options[:port].should eq(27115)
|
30
|
+
end
|
31
|
+
it "has a default 'locale'" do
|
32
|
+
default_client.options[:locale].should_not be_nil
|
33
|
+
default_client.options[:locale].class.should eq(Symbol)
|
34
|
+
default_client.options[:locale].should eq(:en)
|
35
|
+
end
|
36
|
+
it "has a default 'display_kills'" do
|
37
|
+
default_client.options[:display_kills].should_not be_nil
|
38
|
+
default_client.options[:display_kills].should be(true)
|
39
|
+
end
|
40
|
+
it "has a default 'display_actions'" do
|
41
|
+
default_client.options[:display_actions].should_not be_nil
|
42
|
+
default_client.options[:display_actions].should be(true)
|
43
|
+
end
|
44
|
+
it "has a default 'display_changelevel'" do
|
45
|
+
default_client.options[:display_changelevel].should_not be_nil
|
46
|
+
default_client.options[:display_changelevel].should be(true)
|
47
|
+
end
|
48
|
+
it "has a default 'display_chat'" do
|
49
|
+
default_client.options[:display_chat].should_not be_nil
|
50
|
+
default_client.options[:display_chat].should be(true)
|
51
|
+
end
|
52
|
+
it "has a default 'display_team_chat'" do
|
53
|
+
default_client.options[:display_team_chat].should_not be_nil
|
54
|
+
default_client.options[:display_team_chat].should be(true)
|
36
55
|
end
|
37
56
|
|
38
|
-
subject(:custom_client) {
|
39
|
-
context "when custom
|
40
|
-
it
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
57
|
+
subject(:custom_client) { Client.new(RSpecDisplayer, custom_options) }
|
58
|
+
context "when custom parameters are given"
|
59
|
+
it { should be_an_instance_of Client }
|
60
|
+
it "has a default 'options' Hash" do
|
61
|
+
custom_client.options.should_not be_nil
|
62
|
+
custom_client.options.should_not be(nil)
|
63
|
+
custom_client.options.class.should be(Hash)
|
64
|
+
end
|
65
|
+
it "has a custom 'host'" do
|
66
|
+
custom_client.options[:host].should_not be_nil
|
67
|
+
custom_client.options[:host].should eq("127.0.0.1")
|
68
|
+
end
|
69
|
+
it "has a custom 'port'" do
|
70
|
+
custom_client.options[:port].should_not be_nil
|
71
|
+
custom_client.options[:port].should eq(12345)
|
72
|
+
end
|
73
|
+
it "has a custom 'locale'" do
|
74
|
+
custom_client.options[:locale].should_not be_nil
|
75
|
+
custom_client.options[:locale].class.should eq(Symbol)
|
76
|
+
custom_client.options[:locale].should eq(:fr)
|
77
|
+
end
|
78
|
+
it "has a custom 'display_kills'" do
|
79
|
+
custom_client.options[:display_kills].should_not be_nil
|
80
|
+
custom_client.options[:display_kills].should be(false)
|
81
|
+
end
|
82
|
+
it "has a custom 'display_actions'" do
|
83
|
+
custom_client.options[:display_actions].should_not be_nil
|
84
|
+
custom_client.options[:display_actions].should be(false)
|
85
|
+
end
|
86
|
+
it "has a custom 'display_changelevel'" do
|
87
|
+
custom_client.options[:display_changelevel].should_not be_nil
|
88
|
+
custom_client.options[:display_changelevel].should be(false)
|
89
|
+
end
|
90
|
+
it "has a custom 'display_chat'" do
|
91
|
+
custom_client.options[:display_chat].should_not be_nil
|
92
|
+
custom_client.options[:display_chat].should be(false)
|
93
|
+
end
|
94
|
+
it "has a custom 'display_team_chat'" do
|
95
|
+
custom_client.options[:display_team_chat].should_not be_nil
|
96
|
+
custom_client.options[:display_team_chat].should be(false)
|
49
97
|
end
|
50
98
|
|
51
99
|
describe "#start and #stop" do
|
@@ -53,9 +101,9 @@ module SteamHldsLogParser
|
|
53
101
|
context "when 'start' and 'stop' are triggered one after the other"
|
54
102
|
it "starts then stops an eventmachine with appropriate messages" do
|
55
103
|
EM.run {
|
56
|
-
capture_stdout {
|
104
|
+
capture_stdout { default_client.start }.should eq("## 0.0.0.0:27115 => HLDS connected and sending data\n")
|
57
105
|
EM.add_timer(0.2) {
|
58
|
-
capture_stdout {
|
106
|
+
capture_stdout { default_client.stop }.should eq("## 0.0.0.0:27115 => HLDS Log Parser stopped.\n")
|
59
107
|
}
|
60
108
|
}
|
61
109
|
end
|
data/spec/handler_spec.rb
CHANGED
@@ -5,10 +5,9 @@ module SteamHldsLogParser
|
|
5
5
|
describe "SteamHldsLogParser" do
|
6
6
|
|
7
7
|
before :all do
|
8
|
-
@client = Client.new(
|
9
|
-
@
|
10
|
-
@
|
11
|
-
@custom_handler = Handler.new("", "0.0.0.0", 27035, custom_options)
|
8
|
+
@client = Client.new(RSpecDisplayer)
|
9
|
+
@handler = Handler.new("", @client.displayer, @client.options)
|
10
|
+
@custom_handler = Handler.new("", RSpecDisplayer, { :host => "0.0.0.0", :port => 27115, :display_changelevel => true })
|
12
11
|
end
|
13
12
|
|
14
13
|
describe "Handler" do
|
@@ -24,24 +23,24 @@ module SteamHldsLogParser
|
|
24
23
|
|
25
24
|
context "when 'host' and 'port' are given"
|
26
25
|
it { should be_an_instance_of Handler }
|
27
|
-
it "has a 'host'" do
|
28
|
-
@handler.host.should_not be_nil
|
29
|
-
@handler.host.should eq("0.0.0.0")
|
26
|
+
it "has a 'host' option" do
|
27
|
+
@handler.options[:host].should_not be_nil
|
28
|
+
@handler.options[:host].should eq("0.0.0.0")
|
30
29
|
end
|
31
|
-
it "has a 'port'" do
|
32
|
-
@handler.port.should_not be_nil
|
33
|
-
@handler.port.should eq(
|
30
|
+
it "has a 'port' option" do
|
31
|
+
@handler.options[:port].should_not be_nil
|
32
|
+
@handler.options[:port].should eq(27115)
|
34
33
|
end
|
35
34
|
|
36
35
|
describe "#post_init" do
|
37
36
|
it "displays a console message when hlds connects" do
|
38
|
-
capture_stdout { @handler.post_init }.should eq("## 0.0.0.0:
|
37
|
+
capture_stdout { @handler.post_init }.should eq("## 0.0.0.0:27115 => HLDS connected and sending data\n")
|
39
38
|
end
|
40
39
|
end
|
41
40
|
|
42
41
|
describe "#unbind" do
|
43
42
|
it "displays a console message when hlds disconnects" do
|
44
|
-
capture_stdout { @handler.unbind }.should eq("## 0.0.0.0:
|
43
|
+
capture_stdout { @handler.unbind }.should eq("## 0.0.0.0:27115 => HLDS disconnected? No data is received.\n")
|
45
44
|
end
|
46
45
|
end
|
47
46
|
|
@@ -153,11 +152,13 @@ module SteamHldsLogParser
|
|
153
152
|
end
|
154
153
|
end
|
155
154
|
|
155
|
+
subject { @custom_handler }
|
156
156
|
context "when 'displayer' is set" do
|
157
157
|
it "returns Hash on changelevel provided by 'displayer'" do
|
158
158
|
data = '# L 05/10/2000 - 12:34:56: Loading map "de_dust2"'
|
159
159
|
expected = {:type=>"loading_map", :params=>{:map=>"de_dust2"}}
|
160
|
-
@custom_handler.
|
160
|
+
@custom_handler.displayer.should eq(RSpecDisplayer)
|
161
|
+
@custom_handler.options[:display_changelevel].should be(true)
|
161
162
|
@custom_handler.receive_data(data).data.should eq(expected)
|
162
163
|
end
|
163
164
|
end
|
data/spec/helper_spec.rb
CHANGED
@@ -37,12 +37,14 @@ require "steam_hlds_log_parser"
|
|
37
37
|
# Returns custom options as a Hash
|
38
38
|
def custom_options
|
39
39
|
options = {
|
40
|
-
:
|
41
|
-
:
|
42
|
-
:
|
43
|
-
:
|
44
|
-
:
|
45
|
-
:
|
46
|
-
:
|
40
|
+
:host => "127.0.0.1",
|
41
|
+
:port => 12345,
|
42
|
+
:locale => :fr,
|
43
|
+
:display_kills => false,
|
44
|
+
:display_actions => false,
|
45
|
+
:display_changelevel => false,
|
46
|
+
:display_chat => false,
|
47
|
+
:display_team_chat => false,
|
48
|
+
:displayer => RSpecDisplayer
|
47
49
|
}
|
48
50
|
end
|
data/spec/log_tester_spec.rb
CHANGED
@@ -5,9 +5,8 @@ module SteamHldsLogParser
|
|
5
5
|
describe "SteamHldsLogParser" do
|
6
6
|
|
7
7
|
before :all do
|
8
|
-
@client = Client.new(
|
9
|
-
@
|
10
|
-
@handler = Handler.new("", "0.0.0.0", 27035, @options)
|
8
|
+
@client = Client.new(RSpecDisplayer)
|
9
|
+
@handler = Handler.new("", @client.displayer, @client.options)
|
11
10
|
end
|
12
11
|
|
13
12
|
describe "LogTester" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: steam_hlds_log_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas VIAL
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2013-08-
|
12
|
+
date: 2013-08-18 00:00:00 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|