warsow 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.
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ module Warsow
4
+ class Connection
5
+ def initialize host, port
6
+ @host, @port = host, port
7
+ @socket = UDPSocket.new
8
+ end
9
+
10
+ def establish
11
+ @socket.connect @host, @port
12
+ end
13
+
14
+ def read
15
+ @socket.recvfrom(1024)[0]
16
+ end
17
+
18
+ def transmit data
19
+ @socket.send data, 0
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+ module Warsow
4
+ class Server
5
+ attr_accessor :attributes
6
+
7
+ def self.attr name, value; define_method(name) { @attributes["#{value}"] } end
8
+
9
+ attr :map, :mapname
10
+ attr :type, :gametype
11
+ attr :players, :clients
12
+ attr :hostname, :sv_hostname
13
+ attr :max_players, :sv_maxclients
14
+
15
+ def initialize host, port = 44400
16
+ @host, @port = host, port
17
+
18
+ @connection = Connection.new host, port
19
+ end
20
+
21
+ def connect
22
+ @connection.establish
23
+ @attributes = retrieve_attributes
24
+ end
25
+
26
+ private
27
+
28
+ def retrieve_attributes
29
+ @connection.transmit "\xFF\xFF\xFF\xFFgetinfo \x0A\x0D\x0F"
30
+ @connection.read[18..-1].tap do |response|
31
+ return Hash[*response.split('\\')]
32
+ end
33
+ end
34
+ end
35
+ end
data/library/warsow.rb ADDED
@@ -0,0 +1,21 @@
1
+ # encoding: utf-8
2
+
3
+ require 'socket'
4
+ require 'warsow/server'
5
+ require 'warsow/connection'
6
+
7
+ module Warsow
8
+ class << Version = [1,0]
9
+ def to_s; join ?. end
10
+ end
11
+
12
+ module_function
13
+
14
+ def connect host, port = 44400
15
+ Server.new(host, port).tap do |this|
16
+ this.connect
17
+
18
+ yield this if block_given?
19
+ end
20
+ end
21
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: warsow
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-11-26 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/warsow.rb
31
+ - library/warsow/server.rb
32
+ - library/warsow/connection.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: Warsow RCON implementation for ruby.
67
+ test_files: []
68
+