csstats 0.2.0 → 1.0.0
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/Gemfile +2 -1
- data/README.md +14 -0
- data/lib/csstats.rb +4 -0
- data/lib/csstats/error.rb +3 -0
- data/lib/csstats/handler.rb +88 -44
- data/lib/csstats/version.rb +1 -1
- data/spec/csstats/handler_spec.rb +5 -0
- data/spec/spec_helper.rb +5 -10
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9da3fbfae32bbf6cae85ac94caf59a66fb9fb4f8
|
4
|
+
data.tar.gz: 76547cef1effba619c15eded091132196cafe537
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a9d31ba0a0059ad47e1d0bf66f7377b29edba4266151c2402cc886dc9690c3beac93aa002e2d3db8e5de0606b84729fd9bf543a5c0bb601da44eb9de78323f54
|
7
|
+
data.tar.gz: e533af087daa8172936c493196263c9f0264dac75966af80e4e3a1ea1ceb33868769106c7fd12991c336ef4a2b34229133762a20cb1cbecf021cf540aeadd164
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -3,8 +3,10 @@
|
|
3
3
|
Gem which handle csstats.dat file generated by CSX module
|
4
4
|
in AMX Mod X ([http://www.amxmodx.org/][amxx])
|
5
5
|
|
6
|
+
[][rubygems]
|
6
7
|
[][travis]
|
7
8
|
[][gemnasium]
|
9
|
+
[][coveralls]
|
8
10
|
|
9
11
|
## Installation
|
10
12
|
|
@@ -24,6 +26,17 @@ Or install it yourself as:
|
|
24
26
|
|
25
27
|
```ruby
|
26
28
|
require 'csstats'
|
29
|
+
|
30
|
+
stats = CSstats.new(path: 'csstats.dat')
|
31
|
+
stats.player(2).nick
|
32
|
+
```
|
33
|
+
|
34
|
+
You can set maxplayers value if you need to get specified number of players.
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
stats = CSstats.new(path: 'csstats.dat', maxplayers: 15)
|
38
|
+
stats.players_count
|
39
|
+
# => 15
|
27
40
|
```
|
28
41
|
|
29
42
|
## Supported Ruby Versions
|
@@ -42,6 +55,7 @@ See [LICENSE][] for details.
|
|
42
55
|
[rubygems]: https://rubygems.org/gems/csstats
|
43
56
|
[travis]: http://travis-ci.org/jpalumickas/csstats
|
44
57
|
[gemnasium]: https://gemnasium.com/jpalumickas/csstats
|
58
|
+
[coveralls]: https://coveralls.io/r/jpalumickas/csstats
|
45
59
|
|
46
60
|
[amxx]: http://www.amxmodx.org/
|
47
61
|
[license]: LICENSE.md
|
data/lib/csstats.rb
CHANGED
data/lib/csstats/handler.rb
CHANGED
@@ -4,6 +4,13 @@ module CSstats
|
|
4
4
|
class Handler
|
5
5
|
attr_accessor :path, :players, :fileversion, :position
|
6
6
|
|
7
|
+
# Initialize file.
|
8
|
+
#
|
9
|
+
# Options:
|
10
|
+
# path - The String of csstats.dat file.
|
11
|
+
# maxplayers - The Integer of how many players to return.
|
12
|
+
#
|
13
|
+
# Returns nothing.
|
7
14
|
def initialize(options={})
|
8
15
|
@path = options[:path]
|
9
16
|
@players = []
|
@@ -17,89 +24,126 @@ module CSstats
|
|
17
24
|
|
18
25
|
@fileversion = read_short_data(handle);
|
19
26
|
|
20
|
-
i =
|
21
|
-
while (!handle.eof? && (maxplayers == 0 || i
|
27
|
+
i = 0
|
28
|
+
while (!handle.eof? && (maxplayers == 0 || i < maxplayers))
|
22
29
|
player = read_player(handle)
|
23
30
|
if player
|
24
|
-
player['rank'] = i
|
31
|
+
player['rank'] = i+1
|
25
32
|
players[i] = player
|
26
33
|
end
|
27
34
|
i = i + 1
|
28
35
|
end
|
29
36
|
end
|
30
37
|
|
38
|
+
# Read player information from file.
|
39
|
+
#
|
40
|
+
# handle - The File which was opened for reading data.
|
41
|
+
#
|
42
|
+
# Returns The Hash (Mash) of player information.
|
31
43
|
def read_player(handle)
|
32
|
-
|
44
|
+
hash = Hashie::Mash.new
|
33
45
|
l = read_short_data(handle);
|
34
46
|
|
35
47
|
return nil if (l == 0)
|
36
48
|
|
37
|
-
|
49
|
+
hash['nick'] = read_string_data(handle, l)
|
38
50
|
l = read_short_data(handle)
|
39
|
-
|
51
|
+
hash['uniq'] = read_string_data(handle, l)
|
40
52
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
53
|
+
hash['teamkill'] = read_int_data(handle)
|
54
|
+
hash['damage'] = read_int_data(handle)
|
55
|
+
hash['deaths'] = read_int_data(handle)
|
56
|
+
hash['kills'] = read_int_data(handle)
|
57
|
+
hash['shots'] = read_int_data(handle)
|
58
|
+
hash['hits'] = read_int_data(handle)
|
59
|
+
hash['headshots'] = read_int_data(handle)
|
48
60
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
61
|
+
hash['defusions'] = read_int_data(handle)
|
62
|
+
hash['defused'] = read_int_data(handle)
|
63
|
+
hash['plants'] = read_int_data(handle)
|
64
|
+
hash['explosions'] = read_int_data(handle)
|
53
65
|
|
54
66
|
read_int_data(handle) # 0x00000000
|
55
67
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
68
|
+
hash['head'] = read_int_data(handle)
|
69
|
+
hash['chest'] = read_int_data(handle)
|
70
|
+
hash['stomach'] = read_int_data(handle)
|
71
|
+
hash['leftarm'] = read_int_data(handle)
|
72
|
+
hash['rightarm'] = read_int_data(handle)
|
73
|
+
hash['leftleg'] = read_int_data(handle)
|
74
|
+
hash['rightleg'] = read_int_data(handle)
|
63
75
|
|
64
76
|
read_int_data(handle) # 0x00000000
|
65
77
|
|
66
|
-
return
|
78
|
+
return hash
|
67
79
|
end
|
68
80
|
|
81
|
+
# Get the 32bit integer from file.
|
82
|
+
#
|
83
|
+
# handle - The File which was opened for reading data.
|
84
|
+
#
|
85
|
+
# Returns the integer.
|
69
86
|
def read_int_data(handle)
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
return
|
87
|
+
data = handle.read(4)
|
88
|
+
raise CSstats::Error, "Cannot read int data." unless data
|
89
|
+
data = data.unpack("V")
|
90
|
+
return data.first
|
74
91
|
end
|
75
92
|
|
93
|
+
# Get the 16bit integer from file.
|
94
|
+
#
|
95
|
+
# handle - The File which was opened for reading data.
|
96
|
+
#
|
97
|
+
# Returns the integer.
|
76
98
|
def read_short_data(handle)
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
d = d.unpack("v")
|
82
|
-
return d[0]
|
99
|
+
data = handle.read(2)
|
100
|
+
raise CSstats::Error, "Cannot read short data." unless data
|
101
|
+
data = data.unpack("v")
|
102
|
+
return data.first
|
83
103
|
end
|
84
104
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
105
|
+
# Get the string from file.
|
106
|
+
#
|
107
|
+
# handle - The File which was opened for reading data.
|
108
|
+
# len - length of string to read.
|
109
|
+
#
|
110
|
+
# Returns the string.
|
111
|
+
def read_string_data(handle, length)
|
112
|
+
data = handle.read(length)
|
113
|
+
raise CSstats::Error, "Cannot read string data." unless data
|
114
|
+
data = data.strip
|
115
|
+
return data
|
91
116
|
end
|
92
117
|
|
118
|
+
# Get the player information of specified id.
|
119
|
+
#
|
120
|
+
# id - The Integer of player id.
|
121
|
+
#
|
122
|
+
# Returns the Hash of player information.
|
93
123
|
def player(id)
|
94
|
-
unless (@players[id].nil?)
|
95
|
-
@players[id]
|
124
|
+
unless (@players[id-1].nil?)
|
125
|
+
@players[id-1]
|
96
126
|
else
|
97
127
|
nil
|
98
128
|
end
|
99
129
|
end
|
100
130
|
|
131
|
+
# Get total players count.
|
132
|
+
#
|
133
|
+
# Returns the Integer of player count.
|
101
134
|
def players_count
|
102
|
-
@players.count
|
135
|
+
@players.count
|
136
|
+
end
|
137
|
+
|
138
|
+
# Get player by specified name.
|
139
|
+
#
|
140
|
+
# name - The String of player name.
|
141
|
+
#
|
142
|
+
# Returns the Hash of player information.
|
143
|
+
def search_by_name(name)
|
144
|
+
@players.each do |player|
|
145
|
+
return player if (name == player.nick)
|
146
|
+
end
|
103
147
|
end
|
104
148
|
end
|
105
149
|
end
|
data/lib/csstats/version.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
require 'simplecov'
|
2
|
+
require 'coveralls'
|
2
3
|
|
3
4
|
SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
|
4
|
-
SimpleCov::Formatter::HTMLFormatter
|
5
|
+
SimpleCov::Formatter::HTMLFormatter,
|
6
|
+
Coveralls::SimpleCov::Formatter
|
5
7
|
]
|
6
8
|
SimpleCov.start
|
7
9
|
|
@@ -14,14 +16,7 @@ RSpec.configure do |config|
|
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
|
-
def fixture_path
|
18
|
-
File.expand_path("../fixtures", __FILE__)
|
19
|
-
end
|
20
|
-
|
21
|
-
def fixture(file)
|
22
|
-
File.new(fixture_path + '/' + file)
|
23
|
-
end
|
24
|
-
|
25
19
|
def csstats_file
|
26
|
-
|
20
|
+
fixtures = File.expand_path("../fixtures", __FILE__)
|
21
|
+
File.new(fixtures + '/csstats.dat').path
|
27
22
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csstats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justas Palumickas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-04-
|
11
|
+
date: 2013-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -56,6 +56,7 @@ files:
|
|
56
56
|
- Rakefile
|
57
57
|
- csstats.gemspec
|
58
58
|
- lib/csstats.rb
|
59
|
+
- lib/csstats/error.rb
|
59
60
|
- lib/csstats/handler.rb
|
60
61
|
- lib/csstats/version.rb
|
61
62
|
- spec/csstats/handler_spec.rb
|