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.
@@ -11,8 +11,8 @@ module Warsow
11
11
 
12
12
  module_function
13
13
 
14
- def connect host, port = 44400
15
- Server.new(host, port).tap do |this|
14
+ def connect host, port = 44400, opts = {}
15
+ Server.new(host, port, opts).tap do |this|
16
16
  this.connect
17
17
 
18
18
  yield this if block_given?
@@ -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
@@ -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 "\xFF\xFF\xFF\xFFgetinfo \x0A\x0D\x0F"
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
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 1
7
7
  - 0
8
- - 0
9
- version: 1.0.0
8
+ - 1
9
+ version: 1.0.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Mikkel Kroman