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.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/zrcon +23 -3
  3. data/lib/zrcon.rb +10 -3
  4. data/lib/zrcon/version.rb +1 -1
  5. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 16c2a60f4c484937922da89c305ce0713fd63eab
4
- data.tar.gz: b0437351606e4d7ddfee24923fe68d46e843731b
3
+ metadata.gz: '08303a1a804041ed904cf38e17a0733eadea8f88'
4
+ data.tar.gz: f543b821ba009ac528f982fbcc37757870e4538b
5
5
  SHA512:
6
- metadata.gz: 68d9a2b53a447a2d4ffb10c3e1d1c440a0fe8ea8d469d489451a721d9d0984bee81afad5bde512399f888423e6eb36423eb0d3a982ccf7c489119a776a04d1fd
7
- data.tar.gz: 415351450dc9400efce7db1676e9b1e3522a4f5ec559d4b2a417603275ba081d606b95b1894adfc2717a83d02e6ab0c5731980e4a6a5773beb198b18dbdf43ba
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
- rcon = Zrcon.new
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.auth
12
- puts rcon.command(ARGV.first || "help")
29
+ puts rcon.command(ARGV.join(' '))
30
+ rescue Zrcon::ConnectError => e
31
+ puts "Connect error: #{e}"
32
+ end
13
33
 
@@ -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=ENV['RCON_HOST'], port=ENV['RCON_PORT'], password=ENV['RCON_PASSWORD'])
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
@@ -1,3 +1,3 @@
1
1
  class Zrcon
2
- VERSION = '0.0.1'.freeze
2
+ VERSION = '0.0.2'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zrcon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Libby