csstats 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/csstats.gemspec +1 -0
- data/lib/csstats/handler.rb +36 -35
- data/lib/csstats/version.rb +1 -1
- data/spec/csstats/handler_spec.rb +17 -0
- data/spec/spec_helper.rb +4 -0
- metadata +15 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9065ccdcb64130e7cccf2af1c3abfdd313991478
|
4
|
+
data.tar.gz: d814405281dbabd4d3bc638ff5f759927b60bfd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e97ce568ccb03bd622e5d354f5ca5f97e8bf2cfa83975f5e1361e92b30f141de711fe17b5a8873fb69da1d73d5b41d34dbc1a4d2135912abfd6a44aefb804532
|
7
|
+
data.tar.gz: 224d61e39d3cc63c63c1be20b054ed892f568d399a5412a886eae3eb15b92beea9fc96cacad7088a27e1d0dade71612dcc8eb0ca856285f695906c910828e712
|
data/csstats.gemspec
CHANGED
data/lib/csstats/handler.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
|
1
|
+
require 'hashie/mash'
|
2
|
+
|
2
3
|
module CSstats
|
3
4
|
class Handler
|
4
5
|
attr_accessor :path, :players, :fileversion, :position
|
@@ -14,11 +15,11 @@ module CSstats
|
|
14
15
|
|
15
16
|
handle = File.new(@path, "r")
|
16
17
|
|
17
|
-
@fileversion =
|
18
|
+
@fileversion = read_short_data(handle);
|
18
19
|
|
19
20
|
i = 1
|
20
21
|
while (!handle.eof? && (maxplayers == 0 || i <= maxplayers))
|
21
|
-
player =
|
22
|
+
player = read_player(handle)
|
22
23
|
if player
|
23
24
|
player['rank'] = i
|
24
25
|
players[i] = player
|
@@ -27,52 +28,52 @@ module CSstats
|
|
27
28
|
end
|
28
29
|
end
|
29
30
|
|
30
|
-
def
|
31
|
-
p =
|
32
|
-
l =
|
31
|
+
def read_player(handle)
|
32
|
+
p = Hashie::Mash.new
|
33
|
+
l = read_short_data(handle);
|
33
34
|
|
34
35
|
return nil if (l == 0)
|
35
36
|
|
36
|
-
p['nick'] =
|
37
|
-
l =
|
38
|
-
p['uniq'] =
|
37
|
+
p['nick'] = read_string_data(handle, l)
|
38
|
+
l = read_short_data(handle)
|
39
|
+
p['uniq'] = read_string_data(handle, l)
|
39
40
|
|
40
|
-
p['teamkill'] =
|
41
|
-
p['damage'] =
|
42
|
-
p['deaths'] =
|
43
|
-
p['kills'] =
|
44
|
-
p['shots'] =
|
45
|
-
p['hits'] =
|
46
|
-
p['headshots'] =
|
41
|
+
p['teamkill'] = read_int_data(handle)
|
42
|
+
p['damage'] = read_int_data(handle)
|
43
|
+
p['deaths'] = read_int_data(handle)
|
44
|
+
p['kills'] = read_int_data(handle)
|
45
|
+
p['shots'] = read_int_data(handle)
|
46
|
+
p['hits'] = read_int_data(handle)
|
47
|
+
p['headshots'] = read_int_data(handle)
|
47
48
|
|
48
|
-
p['defusions'] =
|
49
|
-
p['defused'] =
|
50
|
-
p['plants'] =
|
51
|
-
p['explosions'] =
|
49
|
+
p['defusions'] = read_int_data(handle)
|
50
|
+
p['defused'] = read_int_data(handle)
|
51
|
+
p['plants'] = read_int_data(handle)
|
52
|
+
p['explosions'] = read_int_data(handle)
|
52
53
|
|
53
|
-
|
54
|
+
read_int_data(handle) # 0x00000000
|
54
55
|
|
55
|
-
p['head'] =
|
56
|
-
p['chest'] =
|
57
|
-
p['stomach'] =
|
58
|
-
p['leftarm'] =
|
59
|
-
p['rightarm'] =
|
60
|
-
p['leftleg'] =
|
61
|
-
p['rightleg'] =
|
56
|
+
p['head'] = read_int_data(handle)
|
57
|
+
p['chest'] = read_int_data(handle)
|
58
|
+
p['stomach'] = read_int_data(handle)
|
59
|
+
p['leftarm'] = read_int_data(handle)
|
60
|
+
p['rightarm'] = read_int_data(handle)
|
61
|
+
p['leftleg'] = read_int_data(handle)
|
62
|
+
p['rightleg'] = read_int_data(handle)
|
62
63
|
|
63
|
-
|
64
|
+
read_int_data(handle) # 0x00000000
|
64
65
|
|
65
66
|
return p
|
66
67
|
end
|
67
68
|
|
68
|
-
def
|
69
|
+
def read_int_data(handle)
|
69
70
|
#f = File.new(handle)
|
70
71
|
d = handle.read(4)
|
71
72
|
d = d.unpack("V")
|
72
73
|
return d[0]
|
73
74
|
end
|
74
75
|
|
75
|
-
def
|
76
|
+
def read_short_data(handle)
|
76
77
|
#f = File.new(handle)
|
77
78
|
d = handle.read(2)
|
78
79
|
#if ($d === false)
|
@@ -81,7 +82,7 @@ module CSstats
|
|
81
82
|
return d[0]
|
82
83
|
end
|
83
84
|
|
84
|
-
def
|
85
|
+
def read_string_data(handle, len)
|
85
86
|
d = handle.read(len)
|
86
87
|
#if ($d === false)
|
87
88
|
# throw new CSstatsException("Can not read data.");
|
@@ -89,15 +90,15 @@ module CSstats
|
|
89
90
|
return d
|
90
91
|
end
|
91
92
|
|
92
|
-
def
|
93
|
-
|
93
|
+
def player(id)
|
94
|
+
unless (@players[id].nil?)
|
94
95
|
@players[id]
|
95
96
|
else
|
96
97
|
nil
|
97
98
|
end
|
98
99
|
end
|
99
100
|
|
100
|
-
def
|
101
|
+
def players_count
|
101
102
|
@players.count - 1
|
102
103
|
end
|
103
104
|
end
|
data/lib/csstats/version.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CSstats::Handler do
|
4
|
+
|
5
|
+
before do
|
6
|
+
@handler = CSstats::Handler.new(path: csstats_file, maxplayers: 15)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should return corrent players count" do
|
10
|
+
expect(@handler.players_count).to eq 15
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should return correct player data" do
|
14
|
+
expect(@handler.player(2).nick).to eq "CHMARSON"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: csstats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justas Palumickas
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - ~>
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: hashie
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
27
41
|
description: ' Gem which handle csstats.dat file generated by CSX module in AMX Mod
|
28
42
|
X (http://www.amxmodx.org/) '
|
29
43
|
email:
|