source 1.0.0 → 1.0.1
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 +1 -2
- data/library/source/rcon.rb +48 -0
- data/library/source/server.rb +12 -3
- metadata +6 -5
data/library/source.rb
CHANGED
@@ -0,0 +1,48 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'socket'
|
3
|
+
|
4
|
+
module Source
|
5
|
+
class RCON
|
6
|
+
class ConnectionError < StandardError; end
|
7
|
+
|
8
|
+
attr_accessor :host, :port
|
9
|
+
|
10
|
+
AuthenticationCommand = "challenge rcon"
|
11
|
+
|
12
|
+
def initialize host, port = 27015, password = nil
|
13
|
+
@host, @port, @pass, @challenge = host, port, password, ""
|
14
|
+
end
|
15
|
+
|
16
|
+
def connected?; @socket and not @socket.closed? end
|
17
|
+
|
18
|
+
def connect
|
19
|
+
raise ConnectionError, "Connection has already been established" if connected?
|
20
|
+
|
21
|
+
@socket = UDPSocket.new
|
22
|
+
|
23
|
+
authenticate
|
24
|
+
end
|
25
|
+
|
26
|
+
def transmit packet
|
27
|
+
raise ConnectionError, 'Connection has not been established' unless connected?
|
28
|
+
@socket.send "\xFF\xFF\xFF\xFF#{packet}", 0, @host, @port
|
29
|
+
end
|
30
|
+
|
31
|
+
def read
|
32
|
+
@socket.readpartial 4096
|
33
|
+
end
|
34
|
+
|
35
|
+
def send command
|
36
|
+
transmit "rcon #{@challenge} \"#{@pass}\" #{command}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def authenticated?; @challenge end
|
40
|
+
|
41
|
+
def authenticate
|
42
|
+
transmit AuthenticationCommand
|
43
|
+
|
44
|
+
challenge = @socket.readpartial 1024
|
45
|
+
@challenge = challenge.gsub /[^\d+]/, ""
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/library/source/server.rb
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
module Source
|
4
4
|
class Server
|
5
|
+
class ConnectionError < StandardError; end
|
6
|
+
|
7
|
+
attr_accessor :host, :port, :pass
|
8
|
+
|
5
9
|
PingPacket = "\x69"
|
6
10
|
InfoPacket = "TSource Engine Query\x00"
|
7
11
|
|
@@ -11,8 +15,8 @@ module Source
|
|
11
15
|
end
|
12
16
|
end
|
13
17
|
|
14
|
-
def initialize host, port = 27015
|
15
|
-
@host, @port = host, port
|
18
|
+
def initialize host, port = 27015, password = nil
|
19
|
+
@host, @port, @pass = host, port, password
|
16
20
|
|
17
21
|
@socket, @connected = UDPSocket.new, false
|
18
22
|
end
|
@@ -30,7 +34,7 @@ module Source
|
|
30
34
|
def read
|
31
35
|
raise ConnectionError, 'Not connected to server' unless @connected
|
32
36
|
|
33
|
-
|
37
|
+
@socket.recvfrom(1024)[0][4..-1]
|
34
38
|
end
|
35
39
|
|
36
40
|
def info
|
@@ -41,5 +45,10 @@ module Source
|
|
41
45
|
|
42
46
|
%w{type version name map game description appid players slots bots dedicated os password secure version EDF}.pair response
|
43
47
|
end
|
48
|
+
|
49
|
+
def rcon password = nil
|
50
|
+
@pass ||= password
|
51
|
+
@rcon ||= RCON.new @host, @port, @password
|
52
|
+
end
|
44
53
|
end
|
45
54
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 1
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 1.0.
|
8
|
+
- 1
|
9
|
+
version: 1.0.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Mikkel Kroman
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: executables
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date:
|
17
|
+
date: 2011-08-25 00:00:00 +02:00
|
18
18
|
default_executable:
|
19
19
|
dependencies: []
|
20
20
|
|
@@ -28,8 +28,9 @@ extra_rdoc_files: []
|
|
28
28
|
|
29
29
|
files:
|
30
30
|
- library/source.rb
|
31
|
-
- library/source/server.rb
|
32
31
|
- library/source/extensions.rb
|
32
|
+
- library/source/rcon.rb
|
33
|
+
- library/source/server.rb
|
33
34
|
has_rdoc: true
|
34
35
|
homepage:
|
35
36
|
licenses: []
|
@@ -63,6 +64,6 @@ rubyforge_project:
|
|
63
64
|
rubygems_version: 1.3.7
|
64
65
|
signing_key:
|
65
66
|
specification_version: 3
|
66
|
-
summary: Source engine server
|
67
|
+
summary: Source engine server query library.
|
67
68
|
test_files: []
|
68
69
|
|