urbanterror 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.
Files changed (2) hide show
  1. data/lib/urbanterror.rb +77 -0
  2. metadata +55 -0
@@ -0,0 +1,77 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'socket'
4
+ require 'pp'
5
+
6
+ class UrbanTerror
7
+ def initialize(server, port=nil, rcon=nil)
8
+ @server = server
9
+ @port = port.nil? ? 27960 : port
10
+ @rcon = rcon.nil? ? '' : rcon
11
+ @socket = UDPSocket.open
12
+ end
13
+
14
+ def sendCommand(command)
15
+ magic = "\377\377\377\377"
16
+ @socket.send("#{magic}#{command}\n", 0, @server, @port)
17
+ @socket.recv(2048)
18
+ end
19
+
20
+ def get(command)
21
+ sendCommand("get#{command}")
22
+ end
23
+
24
+ def getparts(command, i)
25
+ get(command).split("\n")[i]
26
+ end
27
+
28
+ def rcon(command)
29
+ sendCommand("rcon #{@rcon} #{command}")
30
+ end
31
+
32
+ # settings() returns a hash of settings => values.
33
+ # We /were/ going to accept an optional setting arg, but it would be
34
+ # doing the same thing and just selecting one from the Hash, so
35
+ # why not just let the user do server.settings['map'] or whatever.
36
+ def settings
37
+ result = getparts("status", 1).split("\\").reject(&:empty?)
38
+ Hash[*result]
39
+ end
40
+
41
+ # players() returns a list of hashes. Each hash contains
42
+ # name, score, ping.
43
+ def players
44
+ results = getparts("status", 2..-1)
45
+ results.map do |player|
46
+ player = player.split(" ", 3)
47
+ {
48
+ :name => player[2][1..-2],
49
+ :ping => player[1].to_i,
50
+ :score => player[0].to_i
51
+ }
52
+ end
53
+ end
54
+
55
+ def self.gearCalc(gearArray)
56
+ initial = 63
57
+ selected_i = 0
58
+ selected = []
59
+ gearMaster = {
60
+ 'grenades' => 1,
61
+ 'snipers' => 2,
62
+ 'spas' => 4,
63
+ 'pistols' => 8,
64
+ 'autos' => 16,
65
+ 'negev' => 32
66
+ }
67
+
68
+ gearArray.each do |w|
69
+ if gearMaster.has_key? w
70
+ selected << gearMaster[w]
71
+ end
72
+ end
73
+
74
+ selected_i = selected.inject(:+)
75
+ return initial - selected_i
76
+ end
77
+ end
metadata ADDED
@@ -0,0 +1,55 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: urbanterror
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Ricky Elrod
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-08-22 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Provides a class to access and control Urban Terror servers via RCON over UDP.
17
+ email: ricky@elrod.me
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - lib/urbanterror.rb
26
+ has_rdoc: true
27
+ homepage:
28
+ licenses: []
29
+
30
+ post_install_message:
31
+ rdoc_options: []
32
+
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: "0"
40
+ version:
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: "0"
46
+ version:
47
+ requirements: []
48
+
49
+ rubyforge_project:
50
+ rubygems_version: 1.3.5
51
+ signing_key:
52
+ specification_version: 3
53
+ summary: Provides a class to access and control Urban Terror servers via RCON over UDP.
54
+ test_files: []
55
+