source 1.0.0
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.
- data/library/source.rb +14 -0
- data/library/source/extensions.rb +11 -0
- data/library/source/server.rb +45 -0
- metadata +68 -0
data/library/source.rb
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Source
|
4
|
+
class Server
|
5
|
+
PingPacket = "\x69"
|
6
|
+
InfoPacket = "TSource Engine Query\x00"
|
7
|
+
|
8
|
+
def self.connect *args
|
9
|
+
new(*args).tap do |this|
|
10
|
+
this.connect
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize host, port = 27015
|
15
|
+
@host, @port = host, port
|
16
|
+
|
17
|
+
@socket, @connected = UDPSocket.new, false
|
18
|
+
end
|
19
|
+
|
20
|
+
def connect
|
21
|
+
@connected = true if not @connected and @socket.connect @host, @port
|
22
|
+
end
|
23
|
+
|
24
|
+
def transmit packet
|
25
|
+
raise ConnectionError, 'Not connected to server' unless @connected
|
26
|
+
|
27
|
+
@socket.send "\xFF\xFF\xFF\xFF#{packet}", 0
|
28
|
+
end
|
29
|
+
|
30
|
+
def read
|
31
|
+
raise ConnectionError, 'Not connected to server' unless @connected
|
32
|
+
|
33
|
+
response = @socket.recvfrom(1024)[0][4..-1]
|
34
|
+
end
|
35
|
+
|
36
|
+
def info
|
37
|
+
raise ConnectionError, 'Not connected to server' unless @connected
|
38
|
+
|
39
|
+
transmit InfoPacket
|
40
|
+
response = read.unpack 'CCZ*Z*Z*Z*vc7Z*c'
|
41
|
+
|
42
|
+
%w{type version name map game description appid players slots bots dedicated os password secure version EDF}.pair response
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: source
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 1
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
version: 1.0.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Mikkel Kroman
|
13
|
+
autorequire:
|
14
|
+
bindir: executables
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-12-13 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description:
|
22
|
+
email: mk@maero.dk
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- library/source.rb
|
31
|
+
- library/source/server.rb
|
32
|
+
- library/source/extensions.rb
|
33
|
+
has_rdoc: true
|
34
|
+
homepage:
|
35
|
+
licenses: []
|
36
|
+
|
37
|
+
post_install_message:
|
38
|
+
rdoc_options: []
|
39
|
+
|
40
|
+
require_paths:
|
41
|
+
- library
|
42
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
none: false
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
segments:
|
48
|
+
- 1
|
49
|
+
- 9
|
50
|
+
- 1
|
51
|
+
version: 1.9.1
|
52
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ">="
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 0
|
59
|
+
version: "0"
|
60
|
+
requirements: []
|
61
|
+
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.3.7
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: Source engine server qury library.
|
67
|
+
test_files: []
|
68
|
+
|