call-of-duty 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: aa03291519ade18a70f7fba2a5a957caa40056a4
4
+ data.tar.gz: fda94e971bbd8452a9f698e767cc16ca11006c28
5
+ SHA512:
6
+ metadata.gz: bd83909e76d831bc20dab0fe1f18e7997bd3c0a391ba3ed9824a52bf928759d9ee997eb592c090b1143d958335610708ecf4cbd3243ef19801360d0ceb29690c
7
+ data.tar.gz: 1985e4116d55c9ab4d008ab8c98d78a6286dde238b819c1c5a41c703d24d02e559c9fedd2f02a9937134d2402176412a2d163bb5237f9b7aa297e87d45cd206e
data/.gitignore ADDED
@@ -0,0 +1,17 @@
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
data/.travis.yml ADDED
@@ -0,0 +1,3 @@
1
+ rvm:
2
+ - 2.0.0
3
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in call-of-duty.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Henry Poydar
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,36 @@
1
+ # Call of Duty
2
+
3
+ Simple gem for interfacing with Call of Duty servers. Starting with a simple query for COD4.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'call-of-duty'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install call-of-duty
18
+
19
+ ## Usage
20
+
21
+ cod4_server = CallOfDuty::Cod4Server.new("192.168.1.1")
22
+ cod4_server.query_server
23
+ cod4_server.mapname
24
+
25
+ ## Development
26
+
27
+ bundle
28
+ bx rspec spec
29
+
30
+ ## Contributing
31
+
32
+ 1. Fork it
33
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
34
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
35
+ 4. Push to the branch (`git push origin my-new-feature`)
36
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new('spec')
5
+
6
+ # If you want to make this the default task
7
+ task :default => :spec
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'call_of_duty/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "call-of-duty"
8
+ spec.version = Call::Of::Duty::VERSION
9
+ spec.authors = ["hpoydar"]
10
+ spec.email = ["hpoydar@gmail.com"]
11
+ spec.summary = %q{Simple gem for querying a Call of Duty 4 server for information}
12
+ spec.description = spec.summary
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+ spec.add_development_dependency "rspec", "~> 2.14.1"
24
+
25
+ end
@@ -0,0 +1,2 @@
1
+ require "call_of_duty/cod4_server"
2
+ require "call_of_duty/version"
@@ -0,0 +1,62 @@
1
+ require 'socket'
2
+
3
+ module CallOfDuty
4
+
5
+ # Thanks Tom Russell
6
+ # http://www.trdev.co.uk/posts/hello-world/
7
+ class Cod4Server
8
+
9
+ QUERY_TIMEOUT = 5 # maximum query of 5 seconds
10
+ QUERY_STRING = "\xFF\xFF\xFF\xFFgetstatus\x00"
11
+
12
+ attr_accessor :ip_address, :port
13
+ attr_accessor :mapname, :players, :servername, :response
14
+ attr_accessor :maxplayers, :currplayers
15
+
16
+ def initialize(ip_address, port = "28960")
17
+ @ip_address = ip_address
18
+ @port = port
19
+ end
20
+
21
+ def query_server
22
+ begin
23
+ socket = UDPSocket.open
24
+ socket.send(QUERY_STRING, 0, @ip_address, @port)
25
+ response = if IO.select([socket], nil, nil, QUERY_TIMEOUT)
26
+ socket.recvfrom(65536) #wait 5 seconds to recieve 65536 bytes of data
27
+ end
28
+ if response
29
+ data = response.first.split("\\")
30
+ players_arr = data.last.split("\n")
31
+ players_arr.shift
32
+ @maxplayers = data[data.index("sv_maxclients")+1]
33
+ @currplayers = players_arr.size
34
+ @players = []
35
+ players_arr.sort! do |a,b|
36
+ t1 = a.split(" ")
37
+ t2 = b.split(" ")
38
+ t2[0].to_i <=> t1[0].to_i
39
+ end
40
+ players_arr.each do |player|
41
+ p = player.split(" ")
42
+ score = p[0]
43
+ ping = p[1]
44
+ p.delete_at(0)
45
+ p.delete_at(0)
46
+ p = p.join(" ")
47
+ @players.push({:score => score, :ping => ping, :name => p.gsub("\"","")})
48
+ end
49
+ @mapname = data[data.index("mapname")+1]
50
+ @servername = data[data.index("sv_hostname")+1]
51
+ @response = response
52
+ end
53
+ rescue IOError, SystemCallError
54
+ #TODO: something smart
55
+ ensure
56
+ socket.close if socket
57
+ end
58
+ response ? true : false
59
+ end
60
+
61
+ end
62
+ end
@@ -0,0 +1,7 @@
1
+ module Call
2
+ module Of
3
+ module Duty
4
+ VERSION = "0.0.1"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,38 @@
1
+ require 'spec_helper'
2
+
3
+ describe CallOfDuty::Cod4Server do
4
+
5
+ #TODO: exceptions
6
+
7
+ describe "#query_server" do
8
+
9
+ before do
10
+ UDPSocket.stub(:open).and_return(
11
+ double(:socket,
12
+ send: true,
13
+ close: true,
14
+ # Pulled from a real COD4 query
15
+ recvfrom:
16
+ ["statusResponse\n\\fs_game\\mods/nyc\\g_compassShowEnemies\\0\\g_gametype\\dm\\gamename\\Call of Duty 4\\mapname\\mp_bloc\\protocol\\6\\shortversion\\1.7\\sv_allowAnonymous\\0\\sv_disableClientConsole\\0\\sv_floodprotect\\4\\sv_hostname\\Kahntax COD\\sv_maxclients\\24\\sv_maxPing\\0\\sv_maxRate\\5000\\sv_minPing\\0\\sv_privateClients\\0\\sv_punkbuster\\0\\sv_pure\\1\\sv_voice\\0\\ui_maxclients\\32\\pswrd\\0\\mod\\1\n", ["AF_INET", 28960, "192.168.32.59", "192.168.32.59"]]
17
+ )
18
+ )
19
+ IO.stub(:select).and_return(true)
20
+ @cod4s = CallOfDuty::Cod4Server.new('192.168.32.59')
21
+ @cod4s.query_server
22
+ end
23
+
24
+
25
+ it "retrieves a response" do
26
+ @cod4s.response.is_a?(Array).should eq true
27
+ @cod4s.response.first.should =~ /^status/
28
+ end
29
+
30
+ %w(mapname players servername maxplayers currplayers).each do |n|
31
+ it "sets #{n} accessor" do
32
+ @cod4s.send(n).should_not be_nil
33
+ end
34
+ end
35
+
36
+ end
37
+
38
+ end
@@ -0,0 +1 @@
1
+ ["\xFF\xFF\xFF\xFFstatusResponse\n\\fs_game\\mods/nyc\\g_compassShowEnemies\\0\\g_gametype\\dm\\gamename\\Call of Duty 4\\mapname\\mp_bloc\\protocol\\6\\shortversion\\1.7\\sv_allowAnonymous\\0\\sv_disableClientConsole\\0\\sv_floodprotect\\4\\sv_hostname\\Kahntax COD\\sv_maxclients\\24\\sv_maxPing\\0\\sv_maxRate\\5000\\sv_minPing\\0\\sv_privateClients\\0\\sv_punkbuster\\0\\sv_pure\\1\\sv_voice\\0\\ui_maxclients\\32\\pswrd\\0\\mod\\1\n", ["AF_INET", 28960, "192.168.32.59", "192.168.32.59"]]
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'call_of_duty'
4
+
5
+ RSpec.configure do |config|
6
+ end
metadata ADDED
@@ -0,0 +1,102 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: call-of-duty
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - hpoydar
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-11-01 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.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ~>
46
+ - !ruby/object:Gem::Version
47
+ version: 2.14.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 2.14.1
55
+ description: Simple gem for querying a Call of Duty 4 server for information
56
+ email:
57
+ - hpoydar@gmail.com
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - .travis.yml
64
+ - Gemfile
65
+ - LICENSE.txt
66
+ - README.md
67
+ - Rakefile
68
+ - call-of-duty.gemspec
69
+ - lib/call_of_duty.rb
70
+ - lib/call_of_duty/cod4_server.rb
71
+ - lib/call_of_duty/version.rb
72
+ - spec/call_of_duty/cod4_server_spec.rb
73
+ - spec/cod4_server_response.txt
74
+ - spec/spec_helper.rb
75
+ homepage: ''
76
+ licenses:
77
+ - MIT
78
+ metadata: {}
79
+ post_install_message:
80
+ rdoc_options: []
81
+ require_paths:
82
+ - lib
83
+ required_ruby_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ requirements:
90
+ - - '>='
91
+ - !ruby/object:Gem::Version
92
+ version: '0'
93
+ requirements: []
94
+ rubyforge_project:
95
+ rubygems_version: 2.0.3
96
+ signing_key:
97
+ specification_version: 4
98
+ summary: Simple gem for querying a Call of Duty 4 server for information
99
+ test_files:
100
+ - spec/call_of_duty/cod4_server_spec.rb
101
+ - spec/cod4_server_response.txt
102
+ - spec/spec_helper.rb