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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13cb6102607c11b157ad5deb333f9a29a13b5c45
4
- data.tar.gz: 84cf541f8779d954539c909422692b3de496cfd4
3
+ metadata.gz: 9065ccdcb64130e7cccf2af1c3abfdd313991478
4
+ data.tar.gz: d814405281dbabd4d3bc638ff5f759927b60bfd9
5
5
  SHA512:
6
- metadata.gz: 81cbc76d5117f2755204de1c5c7d1b3c7194b193969e76face857902fb65d1f6a433ed13375a0619165d27e2112de12d1fce2954cbdd5629efe32e6369cf5dcf
7
- data.tar.gz: d83d44fb22617edb911519dbab00c1e63747383440d3eaec9a516f0997031fe59085d6aad242588f7ebf66f43aae63ef5077f9cc47d4c6c35fe7ee93167c9794
6
+ metadata.gz: e97ce568ccb03bd622e5d354f5ca5f97e8bf2cfa83975f5e1361e92b30f141de711fe17b5a8873fb69da1d73d5b41d34dbc1a4d2135912abfd6a44aefb804532
7
+ data.tar.gz: 224d61e39d3cc63c63c1be20b054ed892f568d399a5412a886eae3eb15b92beea9fc96cacad7088a27e1d0dade71612dcc8eb0ca856285f695906c910828e712
data/csstats.gemspec CHANGED
@@ -18,6 +18,7 @@ Gem::Specification.new do |gem|
18
18
  gem.require_paths = ["lib"]
19
19
 
20
20
  gem.add_development_dependency 'bundler', '~> 1.0'
21
+ gem.add_dependency 'hashie', '~> 2.0'
21
22
 
22
23
  gem.version = CSstats::VERSION
23
24
  end
@@ -1,4 +1,5 @@
1
- #encoding: UTF-8
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 = readShortData(handle);
18
+ @fileversion = read_short_data(handle);
18
19
 
19
20
  i = 1
20
21
  while (!handle.eof? && (maxplayers == 0 || i <= maxplayers))
21
- player = readPlayer(handle)
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 readPlayer(handle)
31
- p = {}
32
- l = readShortData(handle);
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'] = readStringData(handle, l)
37
- l = readShortData(handle)
38
- p['uniq'] = readStringData(handle, l)
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'] = readIntData(handle)
41
- p['damage'] = readIntData(handle)
42
- p['deaths'] = readIntData(handle)
43
- p['kills'] = readIntData(handle)
44
- p['shots'] = readIntData(handle)
45
- p['hits'] = readIntData(handle)
46
- p['headshots'] = readIntData(handle)
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'] = readIntData(handle)
49
- p['defused'] = readIntData(handle)
50
- p['plants'] = readIntData(handle)
51
- p['explosions'] = readIntData(handle)
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
- readIntData(handle) # 0x00000000
54
+ read_int_data(handle) # 0x00000000
54
55
 
55
- p['head'] = readIntData(handle)
56
- p['chest'] = readIntData(handle)
57
- p['stomach'] = readIntData(handle)
58
- p['leftarm'] = readIntData(handle)
59
- p['rightarm'] = readIntData(handle)
60
- p['leftleg'] = readIntData(handle)
61
- p['rightleg'] = readIntData(handle)
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
- readIntData(handle) # 0x00000000
64
+ read_int_data(handle) # 0x00000000
64
65
 
65
66
  return p
66
67
  end
67
68
 
68
- def readIntData(handle)
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 readShortData(handle)
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 readStringData(handle, len)
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 getPlayer(id)
93
- if (@players[id].present?)
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 countPlayers
101
+ def players_count
101
102
  @players.count - 1
102
103
  end
103
104
  end
@@ -1,3 +1,3 @@
1
1
  module CSstats
2
- VERSION = "0.1.0" unless defined?(CSstats::VERSION)
2
+ VERSION = "0.2.0" unless defined?(CSstats::VERSION)
3
3
  end
@@ -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
@@ -21,3 +21,7 @@ end
21
21
  def fixture(file)
22
22
  File.new(fixture_path + '/' + file)
23
23
  end
24
+
25
+ def csstats_file
26
+ fixture('csstats.dat').path
27
+ end
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.1.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: