zrcon 0.0.1 → 0.0.2
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.
- checksums.yaml +4 -4
- data/bin/zrcon +23 -3
- data/lib/zrcon.rb +10 -3
- data/lib/zrcon/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: '08303a1a804041ed904cf38e17a0733eadea8f88'
|
4
|
+
data.tar.gz: f543b821ba009ac528f982fbcc37757870e4538b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c2ee2e218d003c125f50fc151a6f9ca5d1a30e19b27508383b13f84fcaff4986a4f7df769d16e6ddab512482a3023baa61c666f2cf7100e838149102a2e1435
|
7
|
+
data.tar.gz: 2e10cda86e0dbdab2c3927517a8462021cc47e1a3dbab692e88dd6bae915fb5defc47d49377daf92bf8adf06aaa0b7261cc5dbbffb6763c7a9151f0bd0b98573
|
data/bin/zrcon
CHANGED
@@ -2,12 +2,32 @@
|
|
2
2
|
|
3
3
|
require 'bundler/setup'
|
4
4
|
require 'dotenv'
|
5
|
+
require 'optionparser'
|
6
|
+
require 'ostruct'
|
7
|
+
|
5
8
|
require_relative '../lib/zrcon'
|
6
9
|
|
7
10
|
Dotenv.load
|
8
11
|
|
9
|
-
|
12
|
+
options = OpenStruct.new(
|
13
|
+
host: ENV['RCON_HOST'],
|
14
|
+
port: ENV['RCON_PORT'],
|
15
|
+
password: ENV['RCON_PASSWORD']
|
16
|
+
)
|
17
|
+
|
18
|
+
OptionParser.new { |opts|
|
19
|
+
opts.banner = "Usage: zrcon..."
|
20
|
+
opts.on("-hHOSTNAME", "--host=HOSTNAME", "hostname of rcon server") { |value| options.host = value }
|
21
|
+
opts.on("-pPORT", "--port=PORT", "tcp port") { |value| options.port = value.to_i }
|
22
|
+
opts.on("-PPASS", "--password=PASS", "rcon password") { |value| options.password = value }
|
23
|
+
}.parse!
|
24
|
+
|
25
|
+
begin
|
26
|
+
rcon = Zrcon.new options.to_h
|
27
|
+
rcon.auth
|
10
28
|
|
11
|
-
rcon.
|
12
|
-
|
29
|
+
puts rcon.command(ARGV.join(' '))
|
30
|
+
rescue Zrcon::ConnectError => e
|
31
|
+
puts "Connect error: #{e}"
|
32
|
+
end
|
13
33
|
|
data/lib/zrcon.rb
CHANGED
@@ -4,9 +4,11 @@ require_relative 'zrcon/packet'
|
|
4
4
|
require_relative 'zrcon/version'
|
5
5
|
|
6
6
|
class Zrcon
|
7
|
+
ConnectError = Class.new(StandardError)
|
8
|
+
|
7
9
|
attr_accessor :host, :port, :password
|
8
10
|
|
9
|
-
def initialize(host
|
11
|
+
def initialize(host: ENV['RCON_HOST'], port: ENV['RCON_PORT'], password: ENV['RCON_PASSWORD'])
|
10
12
|
@host = host.to_s
|
11
13
|
@port = port.to_i
|
12
14
|
@password = password.to_s
|
@@ -27,12 +29,17 @@ class Zrcon
|
|
27
29
|
response.data
|
28
30
|
end
|
29
31
|
|
30
|
-
private
|
31
|
-
|
32
32
|
def conn
|
33
33
|
@conn ||= TCPSocket.new host, port
|
34
|
+
rescue SocketError
|
35
|
+
raise ConnectError.new "bad hostname perhaps? (#{host})"
|
36
|
+
rescue Errno::ETIMEDOUT
|
37
|
+
raise ConnectError.new "timed out connecting to #{host}:#{port}"
|
38
|
+
rescue Errno::ECONNREFUSED
|
39
|
+
raise ConnectError.new "connection refused"
|
34
40
|
end
|
35
41
|
|
42
|
+
|
36
43
|
def next_id
|
37
44
|
@id ||= 0
|
38
45
|
@id += 1
|
data/lib/zrcon/version.rb
CHANGED