rubycon 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rubycon.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 nTraum
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,24 @@
1
+ # Rubycon
2
+
3
+ A fully featured and convenient rcon CLI to manage your Source Dedicated Gameservers.
4
+ This program is not stable. Use at your own risk.
5
+
6
+ Features:
7
+ * Auto completion for server cvars
8
+ * Auto completion for map names when using `changelevel`
9
+
10
+ ## Installation
11
+
12
+ $ gem install rubycon
13
+
14
+ ## Usage
15
+
16
+ $ rubycon
17
+
18
+ ## Contributing
19
+
20
+ 1. Fork it
21
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
22
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
23
+ 4. Push to the branch (`git push origin my-new-feature`)
24
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rubycon'
4
+
5
+ Rubycon::Console.new
@@ -0,0 +1,2 @@
1
+ require 'rubycon/version'
2
+ require 'rubycon/console'
@@ -0,0 +1,119 @@
1
+ require 'steam-condenser'
2
+ require 'readline'
3
+ require 'highline/import'
4
+
5
+ module Rubycon
6
+ class Console
7
+
8
+ attr_accessor :host, :port, :rcon, :server, :commands
9
+
10
+ def initialize(host = nil, port = nil, rcon = nil)
11
+ begin
12
+ @host = host || ask_for_host
13
+ @port = port || ask_for_port
14
+ @rcon = rcon || ask_for_rcon
15
+ rescue EOFError, Interrupt
16
+ exit
17
+ end
18
+
19
+ @server = create_server
20
+ @commands = []
21
+ setup_autocompletion_items
22
+ run_console
23
+ end
24
+
25
+ def ask_for_host
26
+ @host = ask('Host: ') { |q| q.default = 'localhost' }
27
+ end
28
+
29
+ def ask_for_port
30
+ @port = ask('Port: ', Integer) do |q|
31
+ q.default = 27015
32
+ q.above = 0
33
+ end
34
+ end
35
+
36
+ def ask_for_rcon
37
+ @rcon = ask('RCON password: ') { |q| q.echo = false }
38
+ end
39
+
40
+ def create_server
41
+ begin
42
+ SourceServer.new(@host, @port)
43
+ rescue SocketError
44
+ puts "'#{@host}' not found. Wrong host?"
45
+ exit
46
+ end
47
+ end
48
+
49
+ def auth_if_necessary
50
+ unless @server.rcon_authenticated?
51
+ @server.rcon_auth(@rcon)
52
+ end
53
+ end
54
+
55
+ def rcon_exec(line)
56
+ begin
57
+ auth_if_necessary
58
+ @server.rcon_exec(line)
59
+ rescue RCONNoAuthError
60
+ puts 'Could not authenticate with gameserver. Wrong rcon password?'
61
+ exit
62
+ rescue Errno::ECONNREFUSED
63
+ puts 'Connection refused. Wrong host?'
64
+ exit
65
+ rescue SteamCondenser::TimeoutError
66
+ puts 'Connection timed out. Wrong host?'
67
+ exit
68
+ end
69
+ end
70
+
71
+ def setup_autocompletion_items
72
+ add_cvars_from_server
73
+ add_changelevel_commands
74
+ end
75
+
76
+ def add_cvars_from_server
77
+ rcon_exec('cvarlist').each_line do |l|
78
+ if l =~ /.*:.*:.*:.*/
79
+ @commands << (l.split).first
80
+ end
81
+ end
82
+ end
83
+
84
+ def add_changelevel_commands
85
+ rcon_exec('maps *').each_line do |l|
86
+ if l =~ /PENDING.*/
87
+ @commands << "changelevel #{((l.split).last).sub('.bsp', '')}"
88
+ end
89
+ end
90
+ end
91
+
92
+ def run_console
93
+ comp = proc { |s| commands.grep( /^#{Regexp.escape(s)}/ ) }
94
+ Readline.completion_append_character = ' '
95
+ Readline.basic_word_break_characters = ''
96
+ Readline.completion_proc = comp
97
+
98
+ stty_save = `stty -g`.chomp
99
+
100
+ begin
101
+ while line = readline_with_history
102
+ puts rcon_exec(line) unless line.empty?
103
+ end
104
+ rescue Interrupt
105
+ system('stty', stty_save)
106
+ exit
107
+ end
108
+ end
109
+
110
+ def readline_with_history
111
+ line = Readline.readline("#{host}:#{port}> ", true)
112
+ return nil if line.nil?
113
+ if line =~ /^\s*$/ or Readline::HISTORY.to_a[-2] == line
114
+ Readline::HISTORY.pop
115
+ end
116
+ line
117
+ end
118
+ end
119
+ end
@@ -0,0 +1,3 @@
1
+ module Rubycon
2
+ VERSION = "0.1"
3
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rubycon/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "rubycon"
8
+ gem.version = Rubycon::VERSION
9
+ gem.authors = ["nTraum"]
10
+ gem.email = ["philipp.press@googlemail.com"]
11
+ gem.description = "A fully featured and convenient RCON CLI / console to manage your Source dedicated gameserver."
12
+ gem.summary = "A fully featured and convenient RCON CLI / console to manage your Source dedicated gameserver."
13
+ gem.homepage = "http://github.com/nTraum/rubycon"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ gem.add_dependency('steam-condenser')
20
+ gem.add_dependency('highline')
21
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubycon
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - nTraum
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-02-21 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: steam-condenser
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: highline
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: A fully featured and convenient RCON CLI / console to manage your Source
47
+ dedicated gameserver.
48
+ email:
49
+ - philipp.press@googlemail.com
50
+ executables:
51
+ - rubycon
52
+ extensions: []
53
+ extra_rdoc_files: []
54
+ files:
55
+ - .gitignore
56
+ - Gemfile
57
+ - LICENSE.txt
58
+ - README.md
59
+ - Rakefile
60
+ - bin/rubycon
61
+ - lib/rubycon.rb
62
+ - lib/rubycon/console.rb
63
+ - lib/rubycon/version.rb
64
+ - rubycon.gemspec
65
+ homepage: http://github.com/nTraum/rubycon
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project:
85
+ rubygems_version: 1.8.23
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: A fully featured and convenient RCON CLI / console to manage your Source
89
+ dedicated gameserver.
90
+ test_files: []