steam_hlds_log_parser 0.5.0 → 0.5.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 +4 -4
- data/examples/example-2.rb +3 -1
- data/lib/locales/en.yml +2 -0
- data/lib/locales/fr.yml +2 -0
- data/lib/steam_hlds_log_parser/client.rb +4 -0
- data/lib/steam_hlds_log_parser/handler.rb +11 -0
- data/lib/steam_hlds_log_parser/version.rb +1 -1
- data/spec/client_spec.rb +104 -86
- data/spec/displayer_spec.rb +5 -5
- data/spec/handler_spec.rb +20 -1
- data/spec/helper_spec.rb +8 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3e50cd7e02251eb8f005cffa7db04028ef24c230
|
4
|
+
data.tar.gz: 088c9c2ae149c651c7c221885c5df6e3cbcb0b70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fe0846e0981463819ccd9e033c2ed5249fc2b6e0c63c59b5333089f635bfd7bca0660d451e059677aba809a4db8484fd1d11e7da661ea6b8a2b94f6c41617a6d
|
7
|
+
data.tar.gz: 6850d1f8eabfaf9fb55c5e3a3878c90582675d4ffab294a66d34499a1515187b026fd78dee4ef38754a1e35c850776f88019d06452e40f7a4e0a047b35bcb80e
|
data/examples/example-2.rb
CHANGED
@@ -18,7 +18,9 @@ options = {
|
|
18
18
|
:display_actions => true,
|
19
19
|
:display_changelevel => true,
|
20
20
|
:display_chat => true,
|
21
|
-
:display_team_chat => true
|
21
|
+
:display_team_chat => true,
|
22
|
+
:display_connect => true,
|
23
|
+
:display_disconnect => true
|
22
24
|
}
|
23
25
|
|
24
26
|
parser = SteamHldsLogParser::Client.new(Formatter, options)
|
data/lib/locales/en.yml
CHANGED
data/lib/locales/fr.yml
CHANGED
@@ -21,6 +21,8 @@ module SteamHldsLogParser
|
|
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 [Boolean] :display_connect (true) Enable player connection display
|
25
|
+
# @option options [Boolean] :display_disconnect (true) Enable player disconnection display
|
24
26
|
#
|
25
27
|
def initialize(displayer, options = {})
|
26
28
|
default_options = {
|
@@ -32,6 +34,8 @@ module SteamHldsLogParser
|
|
32
34
|
:display_changelevel => true,
|
33
35
|
:display_chat => true,
|
34
36
|
:display_team_chat => true,
|
37
|
+
:display_connect => true,
|
38
|
+
:display_disconnect => true
|
35
39
|
}
|
36
40
|
@options = default_options.merge(options)
|
37
41
|
@displayer = displayer
|
@@ -39,6 +39,7 @@ module SteamHldsLogParser
|
|
39
39
|
# * match changelevel
|
40
40
|
# * match chat (say)
|
41
41
|
# * match team chat (say_team)
|
42
|
+
# * user connections / disconnections
|
42
43
|
#
|
43
44
|
# @param [String] data Data received by Client from HLDS server (a line of log)
|
44
45
|
#
|
@@ -84,6 +85,16 @@ module SteamHldsLogParser
|
|
84
85
|
player, player_team, message = data.match(/: "(.+)<\d+><.+><([A-Z]+)>" say_team "(.+)"/i).captures
|
85
86
|
content = { :type => 'team_chat', :params => { :player => player, :player_team => get_short_team_name(player_team), :chat => message } }
|
86
87
|
|
88
|
+
# L 05/10/2000 - 12:34:56: "Player<73><STEAM_ID_LAN><>" connected, address "192.168.4.186:1339"
|
89
|
+
elsif @options[:display_connect] && data.gsub(/: "(.+)<\d+><.+>" connected, address "(.+):(.+)"/).count > 0
|
90
|
+
player, ip, port = data.match(/: "(.+)<\d+><.+>" connected, address "(.+):(.+)"/i).captures
|
91
|
+
content = { :type => 'connect', :params => { :player => player, :ip => ip, :port => port } }
|
92
|
+
|
93
|
+
# L 05/10/2000 - 12:34:56: "Player<73><STEAM_ID_LAN><TERRORIST>" disconnected
|
94
|
+
elsif @options[:display_disconnect] && data.gsub(/: "(.+)<\d+><.+><(.+)>" disconnected/).count > 0
|
95
|
+
player, player_team = data.match(/: "(.+)<\d+><.+><(.+)>" disconnected/i).captures
|
96
|
+
content = { :type => 'disconnect', :params => { :player => player, :player_team => get_short_team_name(player_team) } }
|
97
|
+
|
87
98
|
end
|
88
99
|
|
89
100
|
# no matching pattern, no output
|
data/spec/client_spec.rb
CHANGED
@@ -6,102 +6,120 @@ module SteamHldsLogParser
|
|
6
6
|
|
7
7
|
describe "Client" do
|
8
8
|
|
9
|
-
context "when
|
9
|
+
context "when 'Displayer' parameter is missing" do
|
10
10
|
it "raises an exception" do
|
11
11
|
expect { Client.new }.to raise_error(ArgumentError)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
15
|
+
context "when 'Displayer' parameter is set" do
|
16
|
+
subject(:default_client) { Client.new(RSpecDisplayer) }
|
17
|
+
it { should be_an_instance_of Client }
|
18
|
+
it "has a 'displayer'" do
|
19
|
+
expect(default_client.displayer).not_to be_nil
|
20
|
+
expect(default_client.displayer.class).to be(Class)
|
21
|
+
expect(default_client.displayer).to be(RSpecDisplayer)
|
22
|
+
end
|
23
|
+
it "has a default 'options' Hash" do
|
24
|
+
expect(default_client.displayer).not_to be_nil
|
25
|
+
expect(default_client.displayer.class).to be(Class)
|
26
|
+
end
|
27
|
+
it "has a default 'host'" do
|
28
|
+
expect(default_client.options[:host]).not_to be_nil
|
29
|
+
expect(default_client.options[:host]).to eq("0.0.0.0")
|
30
|
+
end
|
31
|
+
it "has a default 'port'" do
|
32
|
+
expect(default_client.options[:port]).not_to be_nil
|
33
|
+
expect(default_client.options[:port]).to be(27115)
|
34
|
+
end
|
35
|
+
it "has a default 'locale'" do
|
36
|
+
expect(default_client.options[:locale]).not_to be_nil
|
37
|
+
expect(default_client.options[:locale].class).to be(Symbol)
|
38
|
+
expect(default_client.options[:locale]).to be(:en)
|
39
|
+
end
|
40
|
+
it "has a default 'display_kills'" do
|
41
|
+
expect(default_client.options[:display_kills]).not_to be_nil
|
42
|
+
expect(default_client.options[:display_kills]).to be_true
|
43
|
+
end
|
44
|
+
it "has a default 'display_actions'" do
|
45
|
+
expect(default_client.options[:display_actions]).not_to be_nil
|
46
|
+
expect(default_client.options[:display_actions]).to be_true
|
47
|
+
end
|
48
|
+
it "has a default 'display_changelevel'" do
|
49
|
+
expect(default_client.options[:display_changelevel]).not_to be_nil
|
50
|
+
expect(default_client.options[:display_changelevel]).to be_true
|
51
|
+
end
|
52
|
+
it "has a default 'display_chat'" do
|
53
|
+
expect(default_client.options[:display_chat]).not_to be_nil
|
54
|
+
expect(default_client.options[:display_chat]).to be_true
|
55
|
+
end
|
56
|
+
it "has a default 'display_team_chat'" do
|
57
|
+
expect(default_client.options[:display_team_chat]).not_to be_nil
|
58
|
+
expect(default_client.options[:display_team_chat]).to be_true
|
59
|
+
end
|
60
|
+
it "has a default 'display_connect'" do
|
61
|
+
expect(default_client.options[:display_connect]).not_to be_nil
|
62
|
+
expect(default_client.options[:display_connect]).to be_true
|
63
|
+
end
|
64
|
+
it "has a default 'display_disconnect'" do
|
65
|
+
expect(default_client.options[:display_connect]).not_to be_nil
|
66
|
+
expect(default_client.options[:display_connect]).to be_true
|
67
|
+
end
|
68
|
+
end
|
60
69
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
70
|
+
context "when 'Displayer' parameter is set with custom options" do
|
71
|
+
subject(:custom_client) { Client.new(RSpecDisplayer, custom_options) }
|
72
|
+
it { should be_an_instance_of Client }
|
73
|
+
it "has a default 'options' Hash" do
|
74
|
+
expect(custom_client.options).not_to be_nil
|
75
|
+
expect(custom_client.options.class).to be(Hash)
|
76
|
+
end
|
77
|
+
it "has a custom 'host'" do
|
78
|
+
expect(custom_client.options[:host]).not_to be_nil
|
79
|
+
expect(custom_client.options[:host]).to eq("127.0.0.1")
|
80
|
+
end
|
81
|
+
it "has a custom 'port'" do
|
82
|
+
expect(custom_client.options[:port]).not_to be_nil
|
83
|
+
expect(custom_client.options[:port]).to be(12345)
|
84
|
+
end
|
85
|
+
it "has a custom 'locale'" do
|
86
|
+
expect(custom_client.options[:locale]).not_to be_nil
|
87
|
+
expect(custom_client.options[:locale].class).to be(Symbol)
|
88
|
+
expect(custom_client.options[:locale]).to be(:fr)
|
89
|
+
end
|
90
|
+
it "has a custom 'display_kills'" do
|
91
|
+
expect(custom_client.options[:display_kills]).not_to be_nil
|
92
|
+
expect(custom_client.options[:display_kills]).to be_false
|
93
|
+
end
|
94
|
+
it "has a custom 'display_actions'" do
|
95
|
+
expect(custom_client.options[:display_actions]).not_to be_nil
|
96
|
+
expect(custom_client.options[:display_actions]).to be_false
|
97
|
+
end
|
98
|
+
it "has a custom 'display_changelevel'" do
|
99
|
+
expect(custom_client.options[:display_changelevel]).not_to be_nil
|
100
|
+
expect(custom_client.options[:display_changelevel]).to be_false
|
101
|
+
end
|
102
|
+
it "has a custom 'display_chat'" do
|
103
|
+
expect(custom_client.options[:display_chat]).not_to be_nil
|
104
|
+
expect(custom_client.options[:display_chat]).to be_false
|
105
|
+
end
|
106
|
+
it "has a custom 'display_team_chat'" do
|
107
|
+
expect(custom_client.options[:display_team_chat]).not_to be_nil
|
108
|
+
expect(custom_client.options[:display_team_chat]).to be_false
|
109
|
+
end
|
110
|
+
it "has a custom 'display_connect'" do
|
111
|
+
expect(custom_client.options[:display_connect]).not_to be_nil
|
112
|
+
expect(custom_client.options[:display_connect]).to be_false
|
113
|
+
end
|
114
|
+
it "has a custom 'display_disconnect'" do
|
115
|
+
expect(custom_client.options[:display_disconnect]).not_to be_nil
|
116
|
+
expect(custom_client.options[:display_disconnect]).to be_false
|
117
|
+
end
|
100
118
|
end
|
101
119
|
|
102
120
|
describe "#start and #stop" do
|
121
|
+
subject(:default_client) { Client.new(RSpecDisplayer) }
|
103
122
|
|
104
|
-
context "when 'start' and 'stop' are triggered one after the other"
|
105
123
|
it "starts then stops an eventmachine with appropriate messages" do
|
106
124
|
EM.run {
|
107
125
|
expect(capture_stdout { default_client.start }).to eq("## 0.0.0.0:27115 => HLDS connected and sending data\n")
|
data/spec/displayer_spec.rb
CHANGED
@@ -19,14 +19,14 @@ module SteamHldsLogParser
|
|
19
19
|
|
20
20
|
context "when 'data' is given" do
|
21
21
|
|
22
|
-
|
23
|
-
|
24
|
-
end
|
22
|
+
subject { @displayer }
|
23
|
+
it { should be_an_instance_of Displayer }
|
25
24
|
|
26
25
|
describe "#get_data" do
|
26
|
+
subject { @displayer.get_data }
|
27
27
|
it "returns 'data' given as argument" do
|
28
|
-
|
29
|
-
|
28
|
+
should_not be_nil
|
29
|
+
should be(@data)
|
30
30
|
end
|
31
31
|
end
|
32
32
|
|
data/spec/handler_spec.rb
CHANGED
@@ -57,7 +57,6 @@ module SteamHldsLogParser
|
|
57
57
|
it "returns Hash on map_ends" do
|
58
58
|
data = '# L 05/10/2000 - 12:34:56: Team "CT" scored "17" with "0" players"'
|
59
59
|
expected = {:type=>"map_ends", :params=>{:winner=>"CT", :score=>"17"}}
|
60
|
-
puts @handler.receive_data(data)
|
61
60
|
expect(@handler.receive_data(data).class).to be(RSpecDisplayer)
|
62
61
|
expect(@handler.receive_data(data).data).to eq(expected)
|
63
62
|
expect(@handler.receive_data(data).data.class).to be(Hash)
|
@@ -164,6 +163,26 @@ module SteamHldsLogParser
|
|
164
163
|
end
|
165
164
|
end
|
166
165
|
|
166
|
+
context "when data is 'connect'" do
|
167
|
+
it "returns Hash when a user connects the server" do
|
168
|
+
data = '# L 05/10/2000 - 12:34:56: "Player<73><STEAM_ID_LAN><>" connected, address "192.168.4.186:1339"'
|
169
|
+
expected = {:type=>"connect", :params=>{:player=>"Player", :ip=>"192.168.4.186", :port=>"1339"}}
|
170
|
+
expect(@handler.receive_data(data).class).to be(RSpecDisplayer)
|
171
|
+
expect(@handler.receive_data(data).data).to eq(expected)
|
172
|
+
expect(@handler.receive_data(data).data.class).to be(Hash)
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
context "when data is 'disconnect'" do
|
177
|
+
it "returns Hash when a user disconnects" do
|
178
|
+
data = '# L 05/10/2000 - 12:34:56: "Player<73><STEAM_ID_LAN><TERRORIST>" disconnected'
|
179
|
+
expected = {:type=>"disconnect", :params=>{:player=>"Player", :player_team=>"T"}}
|
180
|
+
expect(@handler.receive_data(data).class).to be(RSpecDisplayer)
|
181
|
+
expect(@handler.receive_data(data).data).to eq(expected)
|
182
|
+
expect(@handler.receive_data(data).data.class).to be(Hash)
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
167
186
|
subject { @custom_handler }
|
168
187
|
context "when 'displayer' is set" do
|
169
188
|
it "returns Hash on changelevel provided by 'displayer'" do
|
data/spec/helper_spec.rb
CHANGED
@@ -2,6 +2,12 @@ require "simplecov"
|
|
2
2
|
require "coveralls"
|
3
3
|
require "rspec"
|
4
4
|
|
5
|
+
RSpec.configure do |config|
|
6
|
+
config.expect_with :rspec do |c|
|
7
|
+
c.syntax = :expect
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
5
11
|
# Simplecov / Coverall configuration
|
6
12
|
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
7
13
|
SimpleCov::Formatter::HTMLFormatter,
|
@@ -45,6 +51,8 @@ def custom_options
|
|
45
51
|
:display_changelevel => false,
|
46
52
|
:display_chat => false,
|
47
53
|
:display_team_chat => false,
|
54
|
+
:display_connect => false,
|
55
|
+
:display_disconnect => false,
|
48
56
|
:displayer => RSpecDisplayer
|
49
57
|
}
|
50
58
|
end
|
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.5.
|
4
|
+
version: 0.5.1
|
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-
|
12
|
+
date: 2013-10-01 00:00:00 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|