rmuh 0.2.5 → 0.2.6
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 +5 -13
- data/.rubocop.yml +5 -0
- data/.travis.yml +1 -0
- data/README.md +14 -0
- data/examples/basic_parsing.rb +1 -2
- data/examples/basic_serverstats.rb +1 -1
- data/examples/serverstats_advanced.rb +1 -1
- data/examples/serverstats_cache.rb +1 -1
- data/examples/uolog_parsing.rb +2 -3
- data/examples/uorpt_parsing.rb +1 -2
- data/lib/rmuh/rpt.rb +4 -0
- data/lib/rmuh/rpt/log/formatters/base.rb +18 -0
- data/lib/rmuh/rpt/log/formatters/unitedoperationslog.rb +51 -0
- data/lib/rmuh/rpt/log/formatters/unitedoperationsrpt.rb +118 -0
- data/lib/rmuh/rpt/log/parsers/unitedoperationslog.rb +13 -2
- data/lib/rmuh/rpt/log/util/unitedoperations.rb +13 -11
- data/lib/rmuh/rpt/log/util/unitedoperationslog.rb +11 -3
- data/lib/rmuh/version.rb +1 -1
- data/rmuh.gemspec +3 -3
- data/spec/functional/examples_spec.rb +1 -1
- data/spec/unit/rmuh/rpt/log/formatters/base_spec.rb +42 -0
- data/spec/unit/rmuh/rpt/log/formatters/unitedoperationslog_spec.rb +198 -0
- data/spec/unit/rmuh/rpt/log/formatters/unitedoperationsrpt_spec.rb +757 -0
- data/spec/unit/rmuh/rpt/log/parsers/unitedoperationslog_spec.rb +43 -25
- data/spec/unit/rmuh/rpt/log/parsers/unitedoperationsrpt_spec.rb +2 -2
- data/spec/unit/rmuh/rpt/log/util/unitedoperations_spec.rb +13 -13
- data/spec/unit/rmuh/rpt/log/util/unitedoperationslog_spec.rb +59 -29
- data/spec/unit/rmuh/rpt_spec.rb +6 -6
- data/spec/unit/rmuh/serverstats/base.rb +10 -9
- metadata +59 -55
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
MTA2NTNkMmJlNzc5NTVmNjFlZDg3MWUwYzRkYjA3ZDJhODI1ODczOQ==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b42ffdde9b6cafc07b106a25dada77df4d37d65e
|
4
|
+
data.tar.gz: 3b7cd60555b39694ec72807656b0e7062def008a
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
MjkwOWRlODgzNGIwYjVjMjQ4YTdmYzcxN2NkMDY1Y2I2YjUwNTU1ZTBiY2Iy
|
11
|
-
MTI0MDgwZDY2M2E4MzA0ZWRlYWFmM2Q2NjgzZWU3MDEyZTlhM2M=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
YTcyZGE2YTk2YzZmODVjMTNkNTM0NTBmNTIxYzkwYTk2NDYwZDIzZWYwMzQx
|
14
|
-
YWE0M2U0MTQwYWY2MWY5MWE4MDYyZWM2YTI2MGVkNzYzOTQ1MTNmNWQ0MjAy
|
15
|
-
NTZlNDJiNmVmYWNmMWRiMmUyZWY4NzQ1NTZmOWRjYzJkODk3MTk=
|
6
|
+
metadata.gz: b786803d70135e98d668d798e46ce6a7651f23c6db297c2c4c6fe0b94167341c57fce1275f21887276970b099fdd25123bfff72c9c2a30bdec4483f767ddbd9c
|
7
|
+
data.tar.gz: b5dae0477bc01d475a710d3cf7d59989cca234f78939941cf756db2d78fe79fb58571d1ae95999bea5a10096924053af83b28eac7fb419425f19412a3ddd60f4
|
data/.rubocop.yml
ADDED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -120,6 +120,20 @@ l = p.parse(f.log)
|
|
120
120
|
At this specific moment `l` would contain an Array of Hashes corresponding to
|
121
121
|
the log lines.
|
122
122
|
|
123
|
+
Log Formatting
|
124
|
+
--------------
|
125
|
+
There are also built-in formatters that allow you to dump the events to a
|
126
|
+
format similar to the original log lines. They were changed a bit to be more
|
127
|
+
readable and relevant.
|
128
|
+
|
129
|
+
The formatters just take an event and return a String. Assuming `event` is a
|
130
|
+
single valid event here:
|
131
|
+
|
132
|
+
```Ruby
|
133
|
+
require 'rmuh'
|
134
|
+
puts RMuh::PRT::Log::Formatters::UnitedOperationsRPT.format(event)
|
135
|
+
```
|
136
|
+
|
123
137
|
Server Stats
|
124
138
|
------------
|
125
139
|
The `RMuh` gem also wraps the
|
data/examples/basic_parsing.rb
CHANGED
data/examples/uolog_parsing.rb
CHANGED
@@ -5,8 +5,7 @@
|
|
5
5
|
#
|
6
6
|
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
|
7
7
|
|
8
|
-
require 'rmuh
|
9
|
-
require 'rmuh/rpt/log/parsers/unitedoperationslog'
|
8
|
+
require 'rmuh'
|
10
9
|
require 'ap'
|
11
10
|
|
12
11
|
# the server log file
|
@@ -16,7 +15,7 @@ URL = 'http://arma2.unitedoperations.net/dump/SRV1/SRV1_LOG.txt'
|
|
16
15
|
f = RMuh::RPT::Log::Fetch.new(URL)
|
17
16
|
|
18
17
|
# instantiate a new UnitedOperationsRPT parser
|
19
|
-
p = RMuh::RPT::Log::Parsers::UnitedOperationsLog.new
|
18
|
+
p = RMuh::RPT::Log::Parsers::UnitedOperationsLog.new(chat: true)
|
20
19
|
|
21
20
|
# parse the log from the server
|
22
21
|
# we are doing it inline
|
data/examples/uorpt_parsing.rb
CHANGED
data/lib/rmuh/rpt.rb
CHANGED
@@ -30,3 +30,7 @@ require 'rmuh/rpt/log/parsers/unitedoperationsrpt'
|
|
30
30
|
require 'rmuh/rpt/log/util/unitedoperations'
|
31
31
|
require 'rmuh/rpt/log/util/unitedoperationslog'
|
32
32
|
require 'rmuh/rpt/log/util/unitedoperationsrpt'
|
33
|
+
|
34
|
+
require 'rmuh/rpt/log/formatters/base'
|
35
|
+
require 'rmuh/rpt/log/formatters/unitedoperationslog'
|
36
|
+
require 'rmuh/rpt/log/formatters/unitedoperationsrpt'
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# -*- coding: UTF-8 -*-
|
2
|
+
|
3
|
+
module RMuh
|
4
|
+
module RPT
|
5
|
+
module Log
|
6
|
+
module Formatters
|
7
|
+
# RPT Log Formatter base class
|
8
|
+
class Base
|
9
|
+
class << self
|
10
|
+
def format(event)
|
11
|
+
"#{event[:message]}" if event[:type] == :log
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# -*- coding: UTF-8 -*-
|
2
|
+
require_relative 'base'
|
3
|
+
|
4
|
+
module RMuh
|
5
|
+
module RPT
|
6
|
+
module Log
|
7
|
+
module Formatters
|
8
|
+
# Formatter for the UnitedOperations Log file
|
9
|
+
class UnitedOperationsLog < RMuh::RPT::Log::Formatters::Base
|
10
|
+
class << self
|
11
|
+
def format(event)
|
12
|
+
case event[:type]
|
13
|
+
when :connect
|
14
|
+
format_connect(event)
|
15
|
+
when :disconnect
|
16
|
+
format_disconnect(event)
|
17
|
+
when :beguid
|
18
|
+
format_beguid(event)
|
19
|
+
when :chat
|
20
|
+
format_chat(event)
|
21
|
+
else
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def format_connect(e)
|
29
|
+
"#{e[:iso8601]} Server: Player ##{e[:player_num]} " \
|
30
|
+
"#{e[:player]} (#{e[:ipaddr]}) connected\n"
|
31
|
+
end
|
32
|
+
|
33
|
+
def format_disconnect(e)
|
34
|
+
"#{e[:iso8601]} Server: Player #{e[:player]} disconnected\n"
|
35
|
+
end
|
36
|
+
|
37
|
+
def format_beguid(e)
|
38
|
+
"#{e[:iso8601]} Server: Verified GUID (#{e[:player_beguid]}) " \
|
39
|
+
"of player ##{e[:player_num]} #{e[:player]}\n"
|
40
|
+
end
|
41
|
+
|
42
|
+
def format_chat(e)
|
43
|
+
"#{e[:iso8601]} Chat: (#{e[:channel]}) #{e[:player]}: " \
|
44
|
+
"#{e[:message]}\n"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,118 @@
|
|
1
|
+
# -*- coding: UTF-8 -*-
|
2
|
+
#
|
3
|
+
# By the end you will be sick of the letter 'e', I sure am...
|
4
|
+
#
|
5
|
+
require_relative 'base'
|
6
|
+
|
7
|
+
module RMuh
|
8
|
+
module RPT
|
9
|
+
module Log
|
10
|
+
module Formatters
|
11
|
+
# Formatter for the UnitedOperations RPT file
|
12
|
+
class UnitedOperationsRPT < RMuh::RPT::Log::Formatters::Base
|
13
|
+
LEVELS ||= [:full, :ext, :simple]
|
14
|
+
|
15
|
+
class << self
|
16
|
+
def format(event, level = :full)
|
17
|
+
validate_and_set_level(level)
|
18
|
+
case event[:type]
|
19
|
+
when :wounded
|
20
|
+
format_wounded(event)
|
21
|
+
when :killed
|
22
|
+
format_killed(event)
|
23
|
+
when :died
|
24
|
+
format_died(event)
|
25
|
+
when :announcement
|
26
|
+
format_announcement(event)
|
27
|
+
else
|
28
|
+
nil
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def validate_and_set_level(level)
|
35
|
+
fail(
|
36
|
+
ArgumentError,
|
37
|
+
"Log level invalid, can be one of #{LEVELS.join(', ')}"
|
38
|
+
) unless LEVELS.include?(level)
|
39
|
+
@level = level
|
40
|
+
end
|
41
|
+
|
42
|
+
def time(e)
|
43
|
+
"#{e[:iso8601]}"
|
44
|
+
end
|
45
|
+
|
46
|
+
def server_time(e)
|
47
|
+
"#{time(e)} \"#{e[:server_time]} seconds:"
|
48
|
+
end
|
49
|
+
|
50
|
+
def nearby_players(e)
|
51
|
+
players = e[:nearby_players]
|
52
|
+
if players.empty?
|
53
|
+
n = 'None'
|
54
|
+
else
|
55
|
+
p = e[:nearby_players].map { |pl| "'#{pl}'" }.join(',')
|
56
|
+
n = "[#{p}]"
|
57
|
+
end
|
58
|
+
". Nearby players (100m): #{n}"
|
59
|
+
end
|
60
|
+
|
61
|
+
def beguid(beguid)
|
62
|
+
" (#{beguid})" unless beguid.nil?
|
63
|
+
end
|
64
|
+
|
65
|
+
def format_wounded(e)
|
66
|
+
l = "#{server_time(e)} #{e[:victim]}"
|
67
|
+
l += "#{beguid(e[:victim_beguid])} (#{e[:victim_team]}) has "
|
68
|
+
l += "been wounded by #{e[:offender]}"
|
69
|
+
l += "#{beguid(e[:offender_beguid])} (#{e[:offender_team]})"
|
70
|
+
l += format_wounded_ext(e) if [:full, :ext].include?(@level)
|
71
|
+
l += "\"\n"
|
72
|
+
l
|
73
|
+
end
|
74
|
+
|
75
|
+
def format_wounded_ext(e)
|
76
|
+
" for #{e[:damage]} damage"
|
77
|
+
end
|
78
|
+
|
79
|
+
def format_killed(e)
|
80
|
+
l = "#{server_time(e)} #{e[:victim]}"
|
81
|
+
l += "#{beguid(e[:victim_beguid])} (#{e[:victim_team]}) "
|
82
|
+
l += "has been killed by #{e[:offender]}"
|
83
|
+
l += "#{beguid(e[:offender_beguid])} (#{e[:offender_team]})"
|
84
|
+
l += format_killed_ext(e) if [:ext, :full].include?(@level)
|
85
|
+
l += nearby_players(e) if @level == :full
|
86
|
+
l += "\"\n"
|
87
|
+
l
|
88
|
+
end
|
89
|
+
|
90
|
+
def format_killed_ext(e)
|
91
|
+
". #{e[:victim]} pos: [#{e[:victim_position]}] (GRID " \
|
92
|
+
"#{e[:victim_grid]}). #{e[:offender]} pos: " \
|
93
|
+
"[#{e[:offender_position]}] (GRID #{e[:offender_grid]}). " \
|
94
|
+
"Distance between: #{e[:distance]}m"
|
95
|
+
end
|
96
|
+
|
97
|
+
def format_died(e)
|
98
|
+
l = "#{server_time(e)} #{e[:victim]}"
|
99
|
+
l += "#{beguid(e[:victim_beguid])} has bled out or died of pain"
|
100
|
+
l += format_died_ext(e) if [:full, :ext].include?(@level)
|
101
|
+
l += nearby_players(e) if @level == :full
|
102
|
+
l += "\"\n"
|
103
|
+
l
|
104
|
+
end
|
105
|
+
|
106
|
+
def format_died_ext(e)
|
107
|
+
" at [#{e[:victim_position]}] (GRID #{e[:victim_grid]})"
|
108
|
+
end
|
109
|
+
|
110
|
+
def format_announcement(e)
|
111
|
+
"#{time(e)} \"#{e[:head]} #{e[:message]} #{e[:tail]}\"\n"
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
@@ -63,10 +63,14 @@ module RMuh
|
|
63
63
|
def regex_matches(loglines)
|
64
64
|
loglines.map do |l|
|
65
65
|
line = nil
|
66
|
-
if
|
67
|
-
line = { type: :
|
66
|
+
if LEFT.match(l)
|
67
|
+
line = { type: :disconnect }.merge(m_to_h($LAST_MATCH_INFO))
|
68
68
|
elsif @include_chat && CHAT.match(l)
|
69
69
|
line = { type: :chat }.merge(m_to_h($LAST_MATCH_INFO))
|
70
|
+
elsif JOINED.match(l)
|
71
|
+
line = { type: :connect }.merge(m_to_h($LAST_MATCH_INFO))
|
72
|
+
elsif GUID.match(l)
|
73
|
+
line = { type: :beguid }.merge(m_to_h($LAST_MATCH_INFO))
|
70
74
|
end
|
71
75
|
line_modifiers(line) unless line.nil?
|
72
76
|
end.compact
|
@@ -76,6 +80,7 @@ module RMuh
|
|
76
80
|
when_am_i!(line)
|
77
81
|
zulu!(line, @timezone)
|
78
82
|
add_guid!(line)
|
83
|
+
strip_port!(line) if line[:type] == :connect
|
79
84
|
line
|
80
85
|
end
|
81
86
|
|
@@ -104,6 +109,12 @@ module RMuh
|
|
104
109
|
line[:day] = time.day
|
105
110
|
line
|
106
111
|
end
|
112
|
+
|
113
|
+
def strip_port!(line)
|
114
|
+
line[:ipaddr] = line[:net].split(':')[0]
|
115
|
+
line.delete(:net)
|
116
|
+
line
|
117
|
+
end
|
107
118
|
end
|
108
119
|
end
|
109
120
|
end
|
@@ -30,7 +30,9 @@ module RMuh
|
|
30
30
|
|
31
31
|
def __line_modifiers(match, match_name)
|
32
32
|
m = match_name
|
33
|
-
if [
|
33
|
+
if [
|
34
|
+
:year, :month, :day, :hour, :min, :sec, :player_num
|
35
|
+
].include?(m.to_sym)
|
34
36
|
return match[m].to_i
|
35
37
|
elsif [:server_time, :damage, :distance, :channel, :nearby_players]
|
36
38
|
.include?(m.to_sym)
|
@@ -107,19 +109,19 @@ module RMuh
|
|
107
109
|
end
|
108
110
|
|
109
111
|
def validate_bool_opt(opts, key)
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
112
|
+
fail(
|
113
|
+
ArgumentError,
|
114
|
+
"#{key} must be a boolean value (true|false)"
|
115
|
+
) if opts.key?(key) && \
|
116
|
+
![TrueClass, FalseClass].include?(opts[key].class)
|
115
117
|
end
|
116
118
|
|
117
119
|
def validate_timezone(opts)
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
120
|
+
fail(
|
121
|
+
ArgumentError,
|
122
|
+
':tiemzone must be an instance of TZInfo::DataTimezone'
|
123
|
+
) if opts.key?(:timezone) &&
|
124
|
+
opts[:timezone].class != TZInfo::DataTimezone
|
123
125
|
end
|
124
126
|
end
|
125
127
|
end
|
@@ -9,16 +9,24 @@ module RMuh
|
|
9
9
|
#
|
10
10
|
module UnitedOperationsLog
|
11
11
|
ONE_DAY ||= 86_400
|
12
|
-
|
13
|
-
|
12
|
+
TIME_SHORT ||= '^\s*?(?<hour>\d+?):(?<min>\d+?):(?<sec>\d+)\s'
|
13
|
+
TIME ||= "#{TIME_SHORT}BattlEye\sServer:\s"
|
14
14
|
GUID ||= Regexp.new(
|
15
|
-
"#{TIME}.*Verified\\sGUID\\s\\((?<player_beguid>.*?)\\)
|
15
|
+
"#{TIME}.*Verified\\sGUID\\s\\((?<player_beguid>.*?)\\).*#" \
|
16
|
+
'(?<player_num>\\d+?)' \
|
16
17
|
'\s(?<player>.+)$'
|
17
18
|
)
|
18
19
|
CHAT ||= Regexp.new(
|
19
20
|
"#{TIME}\\((?<channel>Group|Global|Side|Vehicle|Command|Unknown)" \
|
20
21
|
'\)\s+?(?<player>.+?):\s(?<message>.*)$'
|
21
22
|
)
|
23
|
+
JOINED ||= Regexp.new(
|
24
|
+
"#{TIME}Player\s\#(?<player_num>\\d+)\s(?<player>.*?)\s" \
|
25
|
+
'\\((?<net>.*?)\\)\sconnected'
|
26
|
+
)
|
27
|
+
LEFT ||= Regexp.new(
|
28
|
+
"#{TIME_SHORT}Player\s(?<player>.*?)\sdisconnected\."
|
29
|
+
)
|
22
30
|
end
|
23
31
|
end
|
24
32
|
end
|
data/lib/rmuh/version.rb
CHANGED
data/rmuh.gemspec
CHANGED
@@ -17,11 +17,11 @@ Gem::Specification.new do |g|
|
|
17
17
|
g.license = 'MIT'
|
18
18
|
g.required_ruby_version = '>= 1.9.3'
|
19
19
|
|
20
|
-
g.test_files =
|
21
|
-
g.files =
|
20
|
+
g.test_files = `git ls-files spec/*`.split
|
21
|
+
g.files = `git ls-files`.split
|
22
22
|
|
23
23
|
g.add_development_dependency 'rake', '~>10.1', '>= 10.1.0'
|
24
|
-
g.add_development_dependency 'rspec', '
|
24
|
+
g.add_development_dependency 'rspec', '>= 3.0.0.beta2 '
|
25
25
|
g.add_development_dependency 'rubocop', '~> 0.21', '>= 0.21.0'
|
26
26
|
g.add_development_dependency 'fuubar', '~> 1.3', '>= 1.3.2'
|
27
27
|
g.add_development_dependency 'simplecov', '~> 0.8', '>= 0.8.2'
|