warsow 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/warsow.rb +2 -2
- data/library/warsow/connection.rb +3 -1
- data/library/warsow/server.rb +9 -4
- metadata +2 -2
data/library/warsow.rb
CHANGED
@@ -2,6 +2,8 @@
|
|
2
2
|
|
3
3
|
module Warsow
|
4
4
|
class Connection
|
5
|
+
Header = [0xFF, 0xFF, 0xFF, 0xFF].pack 'C*'
|
6
|
+
|
5
7
|
def initialize host, port
|
6
8
|
@host, @port = host, port
|
7
9
|
@socket = UDPSocket.new
|
@@ -16,7 +18,7 @@ module Warsow
|
|
16
18
|
end
|
17
19
|
|
18
20
|
def transmit data
|
19
|
-
@socket.send data, 0
|
21
|
+
@socket.send Header + data, 0
|
20
22
|
end
|
21
23
|
end
|
22
24
|
end
|
data/library/warsow/server.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Warsow
|
4
4
|
class Server
|
5
|
-
attr_accessor :attributes
|
5
|
+
attr_accessor :attributes, :rcon_password
|
6
6
|
|
7
7
|
def self.attr name, value; define_method(name) { @attributes["#{value}"] } end
|
8
8
|
|
@@ -12,8 +12,8 @@ module Warsow
|
|
12
12
|
attr :hostname, :sv_hostname
|
13
13
|
attr :max_players, :sv_maxclients
|
14
14
|
|
15
|
-
def initialize host, port = 44400
|
16
|
-
@host, @port = host, port
|
15
|
+
def initialize host, port = 44400, opts = {}
|
16
|
+
@host, @port, @options = host, port, opts
|
17
17
|
|
18
18
|
@connection = Connection.new host, port
|
19
19
|
end
|
@@ -23,10 +23,15 @@ module Warsow
|
|
23
23
|
@attributes = retrieve_attributes
|
24
24
|
end
|
25
25
|
|
26
|
+
def rcon command
|
27
|
+
@connection.transmit "rcon #{@options[:rcon]} #{command}"
|
28
|
+
@connection.read
|
29
|
+
end
|
30
|
+
|
26
31
|
private
|
27
32
|
|
28
33
|
def retrieve_attributes
|
29
|
-
@connection.transmit "
|
34
|
+
@connection.transmit "getinfo \x0A\x0D\x0F"
|
30
35
|
@connection.read[18..-1].tap do |response|
|
31
36
|
return Hash[*response.split('\\')]
|
32
37
|
end
|