csstats 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 13cb6102607c11b157ad5deb333f9a29a13b5c45
4
+ data.tar.gz: 84cf541f8779d954539c909422692b3de496cfd4
5
+ SHA512:
6
+ metadata.gz: 81cbc76d5117f2755204de1c5c7d1b3c7194b193969e76face857902fb65d1f6a433ed13375a0619165d27e2112de12d1fce2954cbdd5629efe32e6369cf5dcf
7
+ data.tar.gz: d83d44fb22617edb911519dbab00c1e63747383440d3eaec9a516f0997031fe59085d6aad242588f7ebf66f43aae63ef5077f9cc47d4c6c35fe7ee93167c9794
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ bin/test.rb
19
+ .DS_Store
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --fail-fast
3
+ --order random
@@ -0,0 +1,7 @@
1
+ language: ruby
2
+ rvm:
3
+ - jruby-19mode
4
+ - rbx-19mode
5
+ - 1.9.2
6
+ - 1.9.3
7
+ - 2.0.0
@@ -0,0 +1,38 @@
1
+ # How to contribute
2
+
3
+ I like to encourage you to contribute to the repository.
4
+ This should be as easy as possible for you but there are a few things to consider when contributing.
5
+ The following guidelines for contribution should be followed if you want to submit a pull request.
6
+
7
+ ## How to prepare
8
+
9
+ * You need a [GitHub account](https://github.com/signup/free)
10
+ * Submit an [issue ticket](https://github.com/jpalumickas/csstats/issues) for your issue if the is no one yet.
11
+ * Describe the issue and include steps to reproduce when it's a bug.
12
+ * Ensure to mention the earliest version that you know is affected.
13
+ * Fork the repository on GitHub
14
+
15
+ ## Make Changes
16
+
17
+ * In your forked repository, create a topic branch for your upcoming patch.
18
+ * Usually this is based on the master branch.
19
+ * Create a branch based on master; `git branch
20
+ fix/master/my_contribution master` then checkout the new branch with `git
21
+ checkout fix/master/my_contribution`. Please avoid working directly on the `master` branch.
22
+ * Make commits of logical units and describe them properly.
23
+ * Check for unnecessary whitespace with `git diff --check` before committing.
24
+
25
+ * If possible, submit tests to your patch / new feature so it can be tested easily.
26
+ * Assure nothing is broken by running all the tests.
27
+
28
+ ## Submit Changes
29
+
30
+ * Push your changes to a topic branch in your fork of the repository.
31
+ * Open a pull request to the original repository and choose the right original branch you want to patch.
32
+ * If not done in commit messages (which you really should do) please reference and update your issue with the code changes.
33
+ * Even if you have write access to the repository, do not directly push or merge pull-requests. Let another team member review your pull request and approve.
34
+
35
+ # Additional Resources
36
+
37
+ * [General GitHub documentation](http://help.github.com/)
38
+ * [GitHub pull request documentation](http://help.github.com/send-pull-requests/)
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rake'
4
+
5
+ group :test do
6
+ gem 'rspec', '>= 2.13'
7
+ gem 'simplecov', :require => false
8
+ end
9
+
10
+ gemspec
@@ -0,0 +1,9 @@
1
+ Copyright (c) 2013 Justas Palumickas
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,47 @@
1
+ # CSstats
2
+
3
+ Gem which handle csstats.dat file generated by CSX module
4
+ in AMX Mod X ([http://www.amxmodx.org/][amxx])
5
+
6
+ [![Build Status](https://secure.travis-ci.org/jpalumickas/csstats.png?branch=master)][travis]
7
+ [![Dependency Status](https://gemnasium.com/jpalumickas/csstats.png?travis)][gemnasium]
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ gem 'csstats'
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install csstats
22
+
23
+ ## Usage
24
+
25
+ ```ruby
26
+ require 'csstats'
27
+ ```
28
+
29
+ ## Supported Ruby Versions
30
+
31
+ This library aims to support and is [tested against][travis] the following Ruby
32
+ implementations:
33
+
34
+ * Ruby 1.9.2
35
+ * Ruby 1.9.3
36
+ * Ruby 2.0.0
37
+
38
+ ## Copyright
39
+ Copyright (c) 2013 Justas Palumickas.
40
+ See [LICENSE][] for details.
41
+
42
+ [rubygems]: https://rubygems.org/gems/csstats
43
+ [travis]: http://travis-ci.org/jpalumickas/csstats
44
+ [gemnasium]: https://gemnasium.com/jpalumickas/csstats
45
+
46
+ [amxx]: http://www.amxmodx.org/
47
+ [license]: LICENSE.md
@@ -0,0 +1,8 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task test: :spec
8
+ task default: :spec
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'csstats/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "csstats"
8
+ gem.authors = ["Justas Palumickas"]
9
+ gem.email = ["justas@elish.lt"]
10
+ gem.description = %q{ Gem which handle csstats.dat file generated by CSX module in AMX Mod X (http://www.amxmodx.org/) }
11
+ gem.summary = gem.description
12
+ gem.homepage = "https://github.com/jpalumickas/csstats/"
13
+ gem.licenses = ['MIT']
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ gem.add_development_dependency 'bundler', '~> 1.0'
21
+
22
+ gem.version = CSstats::VERSION
23
+ end
@@ -0,0 +1,11 @@
1
+ require 'csstats/handler'
2
+
3
+ module CSstats
4
+ class << self
5
+
6
+ def new(options={})
7
+ CSstats::Handler.new(options)
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,104 @@
1
+ #encoding: UTF-8
2
+ module CSstats
3
+ class Handler
4
+ attr_accessor :path, :players, :fileversion, :position
5
+
6
+ def initialize(options={})
7
+ @path = options[:path]
8
+ @players = []
9
+ @fileversion = 0x00
10
+ @position = 1
11
+ maxplayers = options[:maxplayers] || 0
12
+
13
+ return if @path.nil?
14
+
15
+ handle = File.new(@path, "r")
16
+
17
+ @fileversion = readShortData(handle);
18
+
19
+ i = 1
20
+ while (!handle.eof? && (maxplayers == 0 || i <= maxplayers))
21
+ player = readPlayer(handle)
22
+ if player
23
+ player['rank'] = i
24
+ players[i] = player
25
+ end
26
+ i = i + 1
27
+ end
28
+ end
29
+
30
+ def readPlayer(handle)
31
+ p = {}
32
+ l = readShortData(handle);
33
+
34
+ return nil if (l == 0)
35
+
36
+ p['nick'] = readStringData(handle, l)
37
+ l = readShortData(handle)
38
+ p['uniq'] = readStringData(handle, l)
39
+
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)
47
+
48
+ p['defusions'] = readIntData(handle)
49
+ p['defused'] = readIntData(handle)
50
+ p['plants'] = readIntData(handle)
51
+ p['explosions'] = readIntData(handle)
52
+
53
+ readIntData(handle) # 0x00000000
54
+
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)
62
+
63
+ readIntData(handle) # 0x00000000
64
+
65
+ return p
66
+ end
67
+
68
+ def readIntData(handle)
69
+ #f = File.new(handle)
70
+ d = handle.read(4)
71
+ d = d.unpack("V")
72
+ return d[0]
73
+ end
74
+
75
+ def readShortData(handle)
76
+ #f = File.new(handle)
77
+ d = handle.read(2)
78
+ #if ($d === false)
79
+ # throw new CSstatsException("Can not read data.");
80
+ d = d.unpack("v")
81
+ return d[0]
82
+ end
83
+
84
+ def readStringData(handle, len)
85
+ d = handle.read(len)
86
+ #if ($d === false)
87
+ # throw new CSstatsException("Can not read data.");
88
+ d = d.strip
89
+ return d
90
+ end
91
+
92
+ def getPlayer(id)
93
+ if (@players[id].present?)
94
+ @players[id]
95
+ else
96
+ nil
97
+ end
98
+ end
99
+
100
+ def countPlayers
101
+ @players.count - 1
102
+ end
103
+ end
104
+ end
@@ -0,0 +1,3 @@
1
+ module CSstats
2
+ VERSION = "0.1.0" unless defined?(CSstats::VERSION)
3
+ end
File without changes
@@ -0,0 +1,11 @@
1
+ require 'spec_helper'
2
+
3
+ describe CSstats do
4
+
5
+ describe ".new" do
6
+ it "is a CSstats::Handler" do
7
+ expect(CSstats.new).to be_a CSstats::Handler
8
+ end
9
+ end
10
+
11
+ end
Binary file
@@ -0,0 +1,23 @@
1
+ require 'simplecov'
2
+
3
+ SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[
4
+ SimpleCov::Formatter::HTMLFormatter
5
+ ]
6
+ SimpleCov.start
7
+
8
+ require 'csstats'
9
+ require 'rspec'
10
+
11
+ RSpec.configure do |config|
12
+ config.expect_with :rspec do |c|
13
+ c.syntax = :expect
14
+ end
15
+ end
16
+
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
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: csstats
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Justas Palumickas
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.0'
27
+ description: ' Gem which handle csstats.dat file generated by CSX module in AMX Mod
28
+ X (http://www.amxmodx.org/) '
29
+ email:
30
+ - justas@elish.lt
31
+ executables: []
32
+ extensions: []
33
+ extra_rdoc_files: []
34
+ files:
35
+ - .gitignore
36
+ - .rspec
37
+ - .travis.yml
38
+ - CONTRIBUTING.md
39
+ - Gemfile
40
+ - LICENSE.md
41
+ - README.md
42
+ - Rakefile
43
+ - csstats.gemspec
44
+ - lib/csstats.rb
45
+ - lib/csstats/handler.rb
46
+ - lib/csstats/version.rb
47
+ - spec/csstats/handler_spec.rb
48
+ - spec/csstats_spec.rb
49
+ - spec/fixtures/csstats.dat
50
+ - spec/spec_helper.rb
51
+ homepage: https://github.com/jpalumickas/csstats/
52
+ licenses:
53
+ - MIT
54
+ metadata: {}
55
+ post_install_message:
56
+ rdoc_options: []
57
+ require_paths:
58
+ - lib
59
+ required_ruby_version: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ requirements: []
70
+ rubyforge_project:
71
+ rubygems_version: 2.0.3
72
+ signing_key:
73
+ specification_version: 4
74
+ summary: Gem which handle csstats.dat file generated by CSX module in AMX Mod X (http://www.amxmodx.org/)
75
+ test_files:
76
+ - spec/csstats/handler_spec.rb
77
+ - spec/csstats_spec.rb
78
+ - spec/fixtures/csstats.dat
79
+ - spec/spec_helper.rb