q2_server_query 0.9.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.travis.yml +5 -0
- data/Gemfile +6 -0
- data/Gemfile.lock +35 -0
- data/LICENSE.txt +21 -0
- data/README.md +87 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/q2_server_query/client.rb +87 -0
- data/lib/q2_server_query/version.rb +3 -0
- data/lib/q2_server_query.rb +2 -0
- data/q2_server_query.gemspec +27 -0
- metadata +100 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: '022917b6430f59e38a4a624e99d0f6fdb372e283'
|
4
|
+
data.tar.gz: '08203c452d60b077f10a4461013b7e1294c34b36'
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 00c295954871ad600ce376711b143336109d583cd0b3b1a97b24adf81ae17ebdd85844c31a3d9d3840bd7f8f9539f811f9bc11c4346ffca5217449528c147d6d
|
7
|
+
data.tar.gz: 38b691f1791a98de781356d657d70e65fdb2c697d0eb38d929bf9a18475130166ece33963889668b9b52944c9b6276bee9d1e4e31afed6ea175fac828ab24343
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
q2_server_query (0.9.5)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
diff-lcs (1.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
rspec (3.7.0)
|
12
|
+
rspec-core (~> 3.7.0)
|
13
|
+
rspec-expectations (~> 3.7.0)
|
14
|
+
rspec-mocks (~> 3.7.0)
|
15
|
+
rspec-core (3.7.1)
|
16
|
+
rspec-support (~> 3.7.0)
|
17
|
+
rspec-expectations (3.7.0)
|
18
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
19
|
+
rspec-support (~> 3.7.0)
|
20
|
+
rspec-mocks (3.7.0)
|
21
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
+
rspec-support (~> 3.7.0)
|
23
|
+
rspec-support (3.7.1)
|
24
|
+
|
25
|
+
PLATFORMS
|
26
|
+
ruby
|
27
|
+
|
28
|
+
DEPENDENCIES
|
29
|
+
bundler (~> 1.16)
|
30
|
+
q2_server_query!
|
31
|
+
rake (~> 10.0)
|
32
|
+
rspec (~> 3.0)
|
33
|
+
|
34
|
+
BUNDLED WITH
|
35
|
+
1.16.1
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2018 Feña Agar
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
# Q2ServerQuery
|
2
|
+
|
3
|
+
I got tired of finding workarounds to query Q2 Servers by using JS libraries or other language implementations, so I created this simple gem.
|
4
|
+
|
5
|
+
**NOTE: This works ONLY with Quake 2 servers, it's not adapted for other protocols, but it might work with game servers that use the same protocol**
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'q2_server_query'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install q2_server_query
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
client = Q2ServerQuery::Client.new("your.serverhostname.com (or IP)", server_port)
|
27
|
+
client.status
|
28
|
+
|
29
|
+
# Using AQ2 Server as example.
|
30
|
+
=> {
|
31
|
+
"*Q2Admin"=>"2.0~fa34812",
|
32
|
+
"_admin"=>"some_admin_name",
|
33
|
+
"actionversion"=>"TNG 2.81 2017-08-25 07abb71",
|
34
|
+
"allitem"=>"0",
|
35
|
+
"allweapon"=>"0",
|
36
|
+
"capturelimit"=>"0",
|
37
|
+
"cheats"=>"0",
|
38
|
+
"ctf"=>"0",
|
39
|
+
"deathmatch"=>"1",
|
40
|
+
"dmflags"=>"768",
|
41
|
+
"fraglimit"=>"0",
|
42
|
+
"game"=>"action",
|
43
|
+
"gamedate"=>"Feb 21 2018",
|
44
|
+
"gamedir"=>"action",
|
45
|
+
"gamename"=>"action",
|
46
|
+
"hostname"=>"AQ2 Server",
|
47
|
+
"items"=>"1",
|
48
|
+
"mapname"=>"teamjungle",
|
49
|
+
"maptime"=>"0:00",
|
50
|
+
"matchmode"=>"0",
|
51
|
+
"maxclients"=>"16",
|
52
|
+
"needpass"=>"0",
|
53
|
+
"port"=>"27910",
|
54
|
+
"protocol"=>"34",
|
55
|
+
"q2a_mvd"=>"1.6hau",
|
56
|
+
"roundlimit"=>"10",
|
57
|
+
"roundtimelimit"=>"2",
|
58
|
+
"t1"=>"0",
|
59
|
+
"t2"=>"0",
|
60
|
+
"t3"=>"0",
|
61
|
+
"teamplay"=>"1",
|
62
|
+
"tgren"=>"1",
|
63
|
+
"timelimit"=>"20",
|
64
|
+
"use_3teams"=>"0",
|
65
|
+
"use_tourney"=>"0",
|
66
|
+
"uptime"=>"1+2:24.11",
|
67
|
+
"players"=>[
|
68
|
+
{"frags"=>"99", "ping"=>"99", "name"=>"some_player"},
|
69
|
+
{"frags"=>"99", "ping"=>"99", "name"=>"another_player"}
|
70
|
+
]
|
71
|
+
}
|
72
|
+
```
|
73
|
+
|
74
|
+
## Development
|
75
|
+
|
76
|
+
1. Fork it.
|
77
|
+
2. Do your thang.
|
78
|
+
3. Push a PR.
|
79
|
+
4. Ping me.
|
80
|
+
|
81
|
+
## Contributing
|
82
|
+
|
83
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/elfenars/q2_server_query.
|
84
|
+
|
85
|
+
## License
|
86
|
+
|
87
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "q2_server_query"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,87 @@
|
|
1
|
+
require 'socket'
|
2
|
+
require 'timeout'
|
3
|
+
|
4
|
+
module Q2ServerQuery
|
5
|
+
class Client
|
6
|
+
attr_accessor :address, :port
|
7
|
+
attr_reader :socket, :raw_response, :parsed_response, :players_list
|
8
|
+
|
9
|
+
def initialize(address, port)
|
10
|
+
@socket = UDPSocket.new
|
11
|
+
@timeout = 2
|
12
|
+
@address = address
|
13
|
+
@port = port
|
14
|
+
@msg = "\xff\xff\xff\xffstatus\x00"
|
15
|
+
end
|
16
|
+
|
17
|
+
def status
|
18
|
+
response = status_query
|
19
|
+
return nil if response.nil?
|
20
|
+
|
21
|
+
@parsed_response = response.first.split("\\")
|
22
|
+
response_header = @parsed_response.shift[4..8]
|
23
|
+
|
24
|
+
return if response_header != "print"
|
25
|
+
|
26
|
+
build_status(@parsed_response)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def build_status(unparsed_info)
|
32
|
+
basic_info = {}
|
33
|
+
unparsed_players = nil
|
34
|
+
|
35
|
+
loop do
|
36
|
+
key = unparsed_info.shift
|
37
|
+
value = unparsed_info.shift
|
38
|
+
|
39
|
+
if value.include? "\n"
|
40
|
+
unparsed_players = value.split("\n")
|
41
|
+
value = unparsed_players.delete_at(0)
|
42
|
+
basic_info[key] = value
|
43
|
+
break
|
44
|
+
else
|
45
|
+
basic_info[key] = value
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
@players_list = build_players(unparsed_players)
|
50
|
+
|
51
|
+
basic_info.merge(players: @players_list).with_indifferent_access
|
52
|
+
end
|
53
|
+
|
54
|
+
def build_players(players)
|
55
|
+
list = []
|
56
|
+
players.each do |player|
|
57
|
+
player_info = player.split(" ")
|
58
|
+
h = {
|
59
|
+
frags: player_info.shift,
|
60
|
+
ping: player_info.shift,
|
61
|
+
name: player_info.shift.delete('\\"')
|
62
|
+
}
|
63
|
+
|
64
|
+
list.push h
|
65
|
+
end
|
66
|
+
|
67
|
+
list
|
68
|
+
end
|
69
|
+
|
70
|
+
def status_query
|
71
|
+
begin
|
72
|
+
@raw_response = nil
|
73
|
+
socket.send(@msg, 0, address, port)
|
74
|
+
|
75
|
+
Timeout.timeout(@timeout) do
|
76
|
+
@raw_response = socket.recvfrom(1000)
|
77
|
+
end
|
78
|
+
|
79
|
+
socket.close
|
80
|
+
rescue => e
|
81
|
+
puts "-- Error with server #{address}:#{port}. Reason: #{e}"
|
82
|
+
ensure
|
83
|
+
return @raw_response
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "q2_server_query/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "q2_server_query"
|
8
|
+
spec.version = Q2ServerQuery::VERSION
|
9
|
+
spec.authors = ["Feña Agar"]
|
10
|
+
spec.email = ["ferliagno@gmail.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Simple gem to do status queries to quake 2 servers.}
|
13
|
+
spec.description = %q{Simple gem to do status queries to quake 2 servers.}
|
14
|
+
spec.homepage = "https://github.com/elfenars/q2_server_query"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
27
|
+
end
|
metadata
ADDED
@@ -0,0 +1,100 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: q2_server_query
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.9.6
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Feña Agar
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-02-23 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.16'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.16'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.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: '3.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
description: Simple gem to do status queries to quake 2 servers.
|
56
|
+
email:
|
57
|
+
- ferliagno@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- ".rspec"
|
64
|
+
- ".travis.yml"
|
65
|
+
- Gemfile
|
66
|
+
- Gemfile.lock
|
67
|
+
- LICENSE.txt
|
68
|
+
- README.md
|
69
|
+
- Rakefile
|
70
|
+
- bin/console
|
71
|
+
- bin/setup
|
72
|
+
- lib/q2_server_query.rb
|
73
|
+
- lib/q2_server_query/client.rb
|
74
|
+
- lib/q2_server_query/version.rb
|
75
|
+
- q2_server_query.gemspec
|
76
|
+
homepage: https://github.com/elfenars/q2_server_query
|
77
|
+
licenses:
|
78
|
+
- MIT
|
79
|
+
metadata: {}
|
80
|
+
post_install_message:
|
81
|
+
rdoc_options: []
|
82
|
+
require_paths:
|
83
|
+
- lib
|
84
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
requirements: []
|
95
|
+
rubyforge_project:
|
96
|
+
rubygems_version: 2.6.14
|
97
|
+
signing_key:
|
98
|
+
specification_version: 4
|
99
|
+
summary: Simple gem to do status queries to quake 2 servers.
|
100
|
+
test_files: []
|