old_gamespy_query 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +10 -0
- data/Rakefile +1 -0
- data/examples/get_all_server_statuses.rb +12 -0
- data/lib/old_gamespy_query/master_server.rb +13 -0
- data/lib/old_gamespy_query/parser.rb +72 -0
- data/lib/old_gamespy_query/server_data.rb +37 -0
- data/lib/old_gamespy_query/version.rb +3 -0
- data/lib/old_gamespy_query.rb +9 -0
- data/old_gamespy_query.gemspec +21 -0
- data/readme.md +25 -0
- metadata +106 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "old_gamespy_query"
|
2
|
+
require "pp"
|
3
|
+
|
4
|
+
@master_server = OldGameSpyQuery::MasterServer.new
|
5
|
+
|
6
|
+
@master_server.list.each do |addr|
|
7
|
+
begin
|
8
|
+
@data = OldGameSpyQuery::ServerData.new("#{addr}").get_server_data("players")
|
9
|
+
pp @data
|
10
|
+
rescue Timeout::Error
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
class OldGameSpyQuery
|
2
|
+
class MasterServer
|
3
|
+
attr_reader :query, :list
|
4
|
+
def initialize(gamename = "ccrenegade", master_server = "renmaster.cncnet.org:28900", enctype = 0)
|
5
|
+
@query = GamespyQuery::Master.new(nil, gamename, nil, nil, master_server, enctype)
|
6
|
+
get_server_list
|
7
|
+
end
|
8
|
+
|
9
|
+
def get_server_list
|
10
|
+
@list = @query.get_server_list
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
class OldGameSpyQuery
|
2
|
+
class Parser
|
3
|
+
def initialize(string, mode = 'status')
|
4
|
+
@string = string
|
5
|
+
@mode = mode
|
6
|
+
@data = {}
|
7
|
+
@array = @string[0].force_encoding('utf-8').strip.split("\\")
|
8
|
+
@array.delete(@array.first) # Remove blank first item
|
9
|
+
parse
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse
|
13
|
+
case @mode
|
14
|
+
when 'status'
|
15
|
+
status_parse
|
16
|
+
when 'players'
|
17
|
+
players_parse
|
18
|
+
when 'rules'
|
19
|
+
status_parse # Status and Rules appear compatible
|
20
|
+
when 'info'
|
21
|
+
status_parse # Status and Info appear compatible
|
22
|
+
end
|
23
|
+
|
24
|
+
@data["_gamespy"] = {
|
25
|
+
"hostname" => "#{@string[1][3]}", "gamespy_port" => @string[1][1]
|
26
|
+
}
|
27
|
+
end
|
28
|
+
|
29
|
+
def status_parse
|
30
|
+
keys = []
|
31
|
+
values = []
|
32
|
+
|
33
|
+
@array.each_with_index do |object, index|
|
34
|
+
keys << object if index.even?
|
35
|
+
values << object if index.odd?
|
36
|
+
end
|
37
|
+
|
38
|
+
keys.each_with_index do |key, index|
|
39
|
+
value = values[index]
|
40
|
+
@data["#{key}"] = value
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def players_parse
|
45
|
+
sub_hash = {}
|
46
|
+
keys = []
|
47
|
+
values = []
|
48
|
+
num = 0
|
49
|
+
|
50
|
+
@array.each_with_index do |object, index|
|
51
|
+
keys << object if index.even?
|
52
|
+
values << object if index.odd?
|
53
|
+
end
|
54
|
+
|
55
|
+
keys.each_with_index do |key, index|
|
56
|
+
value = values[index]
|
57
|
+
if key.end_with?("#{num}")
|
58
|
+
sub_hash["#{key}"] = value
|
59
|
+
elsif key.end_with?("#{num+1}")
|
60
|
+
@data["player_#{num}"] = sub_hash
|
61
|
+
sub_hash = {}
|
62
|
+
num+=1
|
63
|
+
sub_hash["#{key}"] = value
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def data
|
69
|
+
@data
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class OldGameSpyQuery
|
2
|
+
class ServerData
|
3
|
+
def initialize(address = "hostname:port")
|
4
|
+
@address = address
|
5
|
+
end
|
6
|
+
|
7
|
+
def get_server_data(request = "status")
|
8
|
+
case request
|
9
|
+
when 'status'
|
10
|
+
when 'players'
|
11
|
+
when 'rules'
|
12
|
+
when 'info'
|
13
|
+
else
|
14
|
+
raise "#{self.class}: can't parse \\#{request}\\"
|
15
|
+
end
|
16
|
+
|
17
|
+
addr = @address.split(':')
|
18
|
+
@socket = UDPSocket.new
|
19
|
+
@socket.connect("#{addr[0]}", addr[1].to_i)
|
20
|
+
begin
|
21
|
+
timeout(5) {
|
22
|
+
@socket.send("\\#{request}\\", 0)
|
23
|
+
@data = @socket.recvfrom(4096)
|
24
|
+
}
|
25
|
+
rescue Timeout::Error
|
26
|
+
raise Timeout::Error, "#{self.class}: The Server At '#{@address}' Did Not Respond In Time (Within 5 Seconds)"
|
27
|
+
end
|
28
|
+
|
29
|
+
@data[0].sub!("\\final\\", '')
|
30
|
+
@gamespy_query = OldGameSpyQuery::Parser.new(@data, request).data
|
31
|
+
end
|
32
|
+
|
33
|
+
def data
|
34
|
+
@gamespy_query
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'old_gamespy_query/version'
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "old_gamespy_query"
|
7
|
+
spec.version = OldGameSpyQuery::VERSION
|
8
|
+
spec.authors = ["Cyberarm"]
|
9
|
+
spec.email = ["matthewlikesrobots@gmail.com"]
|
10
|
+
spec.summary = %q{Query old GameSpy servers.}
|
11
|
+
spec.description = %q{Query old GameSpy servers.}
|
12
|
+
spec.homepage = "https://github.com/cyberarm/old_gamespy_query"
|
13
|
+
spec.license = "MIT"
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
spec.add_dependency "gamespy_query"
|
19
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
20
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
21
|
+
end
|
data/readme.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Old GameSpy Query
|
2
|
+
Query old GameSpy servers, specifically, Command & Conquer: Renegade servers.
|
3
|
+
|
4
|
+
# Usage
|
5
|
+
|
6
|
+
Example of querying every server.
|
7
|
+
```ruby
|
8
|
+
require "old_gamespy_query"
|
9
|
+
require "pp"
|
10
|
+
|
11
|
+
@master_server = OldGameSpyQuery::MasterServer.new
|
12
|
+
|
13
|
+
@master_server.list.each do |addr|
|
14
|
+
begin
|
15
|
+
@data = OldGameSpyQuery::ServerData.new("#{addr}").get_server_data("players")
|
16
|
+
pp @data
|
17
|
+
rescue Timeout::Error
|
18
|
+
# Mask unresponsive servers
|
19
|
+
end
|
20
|
+
end
|
21
|
+
```
|
22
|
+
|
23
|
+
# Note
|
24
|
+
Querying the master server requires 'gslist' and a modified version of [gamespy_query](https://github.com/SIXNetworks/gamespy_query/pull/1). Also the 'gslist' executable needs to be in the same directory from where your executing your program.
|
25
|
+
See http://aluigi.org/papers.htm#gslist.
|
metadata
ADDED
@@ -0,0 +1,106 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: old_gamespy_query
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Cyberarm
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-01-09 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: gamespy_query
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: bundler
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '1.7'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '1.7'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rake
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '10.0'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
description: Query old GameSpy servers.
|
63
|
+
email:
|
64
|
+
- matthewlikesrobots@gmail.com
|
65
|
+
executables: []
|
66
|
+
extensions: []
|
67
|
+
extra_rdoc_files: []
|
68
|
+
files:
|
69
|
+
- .gitignore
|
70
|
+
- Gemfile
|
71
|
+
- Gemfile.lock
|
72
|
+
- Rakefile
|
73
|
+
- examples/get_all_server_statuses.rb
|
74
|
+
- lib/old_gamespy_query.rb
|
75
|
+
- lib/old_gamespy_query/master_server.rb
|
76
|
+
- lib/old_gamespy_query/parser.rb
|
77
|
+
- lib/old_gamespy_query/server_data.rb
|
78
|
+
- lib/old_gamespy_query/version.rb
|
79
|
+
- old_gamespy_query.gemspec
|
80
|
+
- readme.md
|
81
|
+
homepage: https://github.com/cyberarm/old_gamespy_query
|
82
|
+
licenses:
|
83
|
+
- MIT
|
84
|
+
post_install_message:
|
85
|
+
rdoc_options: []
|
86
|
+
require_paths:
|
87
|
+
- lib
|
88
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
|
+
none: false
|
96
|
+
requirements:
|
97
|
+
- - ! '>='
|
98
|
+
- !ruby/object:Gem::Version
|
99
|
+
version: '0'
|
100
|
+
requirements: []
|
101
|
+
rubyforge_project:
|
102
|
+
rubygems_version: 1.8.29
|
103
|
+
signing_key:
|
104
|
+
specification_version: 3
|
105
|
+
summary: Query old GameSpy servers.
|
106
|
+
test_files: []
|