urbanterror 1.1 → 3.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/lib/urbanterror.rb +18 -16
- metadata +25 -43
data/lib/urbanterror.rb
CHANGED
@@ -6,27 +6,23 @@ require 'pp'
|
|
6
6
|
class UrbanTerror
|
7
7
|
def initialize(server, port=nil, rcon=nil)
|
8
8
|
@server = server
|
9
|
-
@port = port
|
10
|
-
@rcon = rcon
|
9
|
+
@port = port || 27960
|
10
|
+
@rcon = rcon || ''
|
11
11
|
@socket = UDPSocket.open
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
14
|
+
def send_command(command)
|
15
15
|
magic = "\377\377\377\377"
|
16
16
|
@socket.send("#{magic}#{command}\n", 0, @server, @port)
|
17
17
|
@socket.recv(2048)
|
18
18
|
end
|
19
19
|
|
20
20
|
def get(command)
|
21
|
-
|
21
|
+
send_command("get#{command}")
|
22
22
|
end
|
23
23
|
|
24
|
-
def getparts(command, i)
|
25
|
-
get(command).split("\n")[i]
|
26
|
-
end
|
27
|
-
|
28
24
|
def rcon(command)
|
29
|
-
|
25
|
+
send_command("rcon #{@rcon} #{command}")
|
30
26
|
end
|
31
27
|
|
32
28
|
# settings() returns a hash of settings => values.
|
@@ -34,14 +30,14 @@ class UrbanTerror
|
|
34
30
|
# doing the same thing and just selecting one from the Hash, so
|
35
31
|
# why not just let the user do server.settings['map'] or whatever.
|
36
32
|
def settings
|
37
|
-
result =
|
33
|
+
result = get_parts("status", 1).split("\\").reject(&:empty?)
|
38
34
|
Hash[*result]
|
39
35
|
end
|
40
36
|
|
41
37
|
# players() returns a list of hashes. Each hash contains
|
42
38
|
# name, score, ping.
|
43
39
|
def players
|
44
|
-
results =
|
40
|
+
results = get_parts("status", 2..-1)
|
45
41
|
results.map do |player|
|
46
42
|
player = player.split(" ", 3)
|
47
43
|
{
|
@@ -64,18 +60,19 @@ class UrbanTerror
|
|
64
60
|
|
65
61
|
MAX_GEAR = 63
|
66
62
|
|
67
|
-
def self.
|
68
|
-
|
69
|
-
MAX_GEAR -
|
63
|
+
def self.gear_calc(gear_array)
|
64
|
+
gear_array.each{ |w| raise "No such gear type '#{w}'" unless GEAR_TYPES.has_key?(w) }
|
65
|
+
MAX_GEAR - gear_array.map{|w| GEAR_TYPES[w] }.reduce(:+)
|
70
66
|
end
|
71
67
|
|
72
|
-
def self.
|
68
|
+
def self.reverse_gear_calc(number)
|
73
69
|
raise "#{number} is outside of the range 0 to 63." unless (0..63).include?(number)
|
74
70
|
GEAR_TYPES.select{|weapon, gear_val| number & gear_val == 0 }.map(&:first)
|
75
71
|
end
|
76
72
|
|
77
73
|
GAME_MODES = {
|
78
74
|
0 => ['Free For All', 'FFA'],
|
75
|
+
1 => ['Last Man Standing', 'LMS'],
|
79
76
|
3 => ['Team Death Match', 'TDM'],
|
80
77
|
4 => ['Team Survivor', 'TS'],
|
81
78
|
5 => ['Follow the Leader', 'FTL'],
|
@@ -84,8 +81,13 @@ class UrbanTerror
|
|
84
81
|
8 => ['Bomb mode', 'BOMB']
|
85
82
|
}
|
86
83
|
|
87
|
-
def self.
|
84
|
+
def self.match_type(number, abbreviate=false)
|
88
85
|
raise "#{number} is not a valid gametype." unless GAME_MODES.has_key? number
|
89
86
|
GAME_MODES[number][abbreviate ? 1 : 0]
|
90
87
|
end
|
88
|
+
|
89
|
+
private
|
90
|
+
def get_parts(command, i)
|
91
|
+
get(command).split("\n")[i]
|
92
|
+
end
|
91
93
|
end
|
metadata
CHANGED
@@ -1,66 +1,48 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: urbanterror
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 1
|
9
|
-
version: "1.1"
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 3.0.0
|
5
|
+
prerelease:
|
10
6
|
platform: ruby
|
11
|
-
authors:
|
7
|
+
authors:
|
12
8
|
- Ricky Elrod
|
13
9
|
autorequire:
|
14
10
|
bindir: bin
|
15
11
|
cert_chain: []
|
16
|
-
|
17
|
-
date: 2011-03-20 00:00:00 -04:00
|
18
|
-
default_executable:
|
12
|
+
date: 2012-08-09 00:00:00.000000000 Z
|
19
13
|
dependencies: []
|
20
|
-
|
21
|
-
|
14
|
+
description: Provides a class to access and control Urban Terror servers via RCON
|
15
|
+
over UDP.
|
22
16
|
email: ricky@elrod.me
|
23
17
|
executables: []
|
24
|
-
|
25
18
|
extensions: []
|
26
|
-
|
27
19
|
extra_rdoc_files: []
|
28
|
-
|
29
|
-
files:
|
20
|
+
files:
|
30
21
|
- lib/urbanterror.rb
|
31
|
-
has_rdoc: true
|
32
22
|
homepage:
|
33
|
-
licenses:
|
34
|
-
|
23
|
+
licenses:
|
24
|
+
- MIT
|
35
25
|
post_install_message:
|
36
26
|
rdoc_options: []
|
37
|
-
|
38
|
-
require_paths:
|
27
|
+
require_paths:
|
39
28
|
- lib
|
40
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
41
30
|
none: false
|
42
|
-
requirements:
|
43
|
-
- -
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
|
46
|
-
|
47
|
-
- 0
|
48
|
-
version: "0"
|
49
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ! '>='
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
36
|
none: false
|
51
|
-
requirements:
|
52
|
-
- -
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
|
55
|
-
segments:
|
56
|
-
- 0
|
57
|
-
version: "0"
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
58
41
|
requirements: []
|
59
|
-
|
60
42
|
rubyforge_project:
|
61
|
-
rubygems_version: 1.
|
43
|
+
rubygems_version: 1.8.17
|
62
44
|
signing_key:
|
63
45
|
specification_version: 3
|
64
|
-
summary: Provides a class to access and control Urban Terror servers via RCON over
|
46
|
+
summary: Provides a class to access and control Urban Terror servers via RCON over
|
47
|
+
UDP.
|
65
48
|
test_files: []
|
66
|
-
|