rblock 0.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,45 @@
1
+ # rblock
2
+
3
+ Rblock makes managing Minecraft servers simple and easy.
4
+
5
+ ## Installation
6
+
7
+ Make sure your server has the following installed:
8
+
9
+ * GNU screen
10
+ * Java
11
+
12
+ In your console, type:
13
+
14
+ ```
15
+ gem install rblock
16
+ ```
17
+
18
+ Rblock will install. After it's done, type:
19
+
20
+ ```
21
+ rblock new mynewserver
22
+ ```
23
+
24
+ Rblock will create a new directory called `mynewserver` and install bukkit inside of it.
25
+
26
+ To run your server:
27
+
28
+ ```
29
+ cd mynewserver
30
+ rblock start
31
+ ```
32
+
33
+ Rblock will start your server. Yup! It's that simple.
34
+
35
+ ## Planned Features
36
+
37
+ * install servers, bukkit and native both
38
+ * update bukkit/server (back up first)
39
+ * downgrade bukkit/server? or at least install
40
+ * create complete server backups
41
+ * chat with people on server
42
+ * monitor chats/activity/performance
43
+ * duplicate servers
44
+ * template servers
45
+ * extend with bots and extensions
data/bin/rblock ADDED
@@ -0,0 +1,166 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'colorize'
4
+ require 'fileutils'
5
+ require 'net/http'
6
+ require 'trollop'
7
+ require_relative '../lib/rblock.rb'
8
+
9
+ SUB_COMMANDS = %w(new start stop say console install mv)
10
+ $global_opts = Trollop::options do
11
+ banner "rblock: #{Rblock::tagline}"
12
+ stop_on SUB_COMMANDS
13
+ end
14
+
15
+ $cmd = ARGV.shift # get the subcommand
16
+ $cmd_opts = case $cmd
17
+ when "install" # parse new options
18
+ Trollop::options do
19
+ banner "usage: rblock install [options] <server path>"
20
+ banner ''
21
+ opt :bukkit, "use bukkit", :default => true
22
+ opt :version, "server version", :type => :string, :default => "latest"
23
+ "Options are official, beta, bukkit, bukkit-beta, or a version number."
24
+ end
25
+ when "start" # parse start options
26
+ Trollop::options do
27
+ banner "usage: rblock start"
28
+ banner ''
29
+ end
30
+ when "stop" # parse stop options
31
+ Trollop::options do
32
+ banner "usage: rblock stop"
33
+ banner ''
34
+ end
35
+ when "console" # parse console options
36
+ Trollop::options do
37
+ banner "usage: rblock console"
38
+ banner ''
39
+ end
40
+ when "say" # parse say options
41
+ Trollop::options do
42
+ banner "usage: rblock say"
43
+ banner ''
44
+ end
45
+ when nil
46
+ puts "rblock: minecraft server management"
47
+ puts "usage: rblock new <server_name>"
48
+ puts "Please visit http://github.com/rlord/rblock for more information."
49
+ exit
50
+ else
51
+ Trollop::die "rblock: unknown subcommand #{$cmd.inspect}"
52
+ end
53
+
54
+ def confirm(action)
55
+ if $cmd_opts[:force]
56
+ puts "Forcing #{action}"
57
+ else
58
+ puts "Press enter to #{action}, control-c to cancel..."
59
+ STDIN.gets
60
+ end
61
+ end
62
+
63
+ case $cmd
64
+ when "install"
65
+ if ARGV[0] == nil
66
+ Trollop::die "no server name specified"
67
+ else
68
+ server_path = ARGV[0].split('/')
69
+ end
70
+
71
+ # if multifolder file path, server name is just last bit
72
+ server_name = server_path.last
73
+
74
+ puts "Checking dependencies..."
75
+
76
+ failed = Rblock::test_dependencies
77
+ if failed != []
78
+ failed.each do |name|
79
+ puts "Missing #{name}".red
80
+ end
81
+ puts "Missing dependencies. Please visit TODO PUT URL HERE for more information.".red
82
+ exit false
83
+ end
84
+
85
+ puts "Dependencies all okay!".green
86
+
87
+ puts "\nCreating server directory..."
88
+
89
+ # make the server directory
90
+
91
+ server_path.each_with_index do |value, i|
92
+ begin
93
+ Dir.mkdir server_path[0..i].join('/')
94
+ rescue Errno::EEXIST
95
+ end
96
+ end
97
+
98
+ Dir.chdir(server_path.join('/')) do
99
+ puts "Downloading bukkit..."
100
+ if $cmd_opts[:beta]
101
+ Rblock::fetch_bukkit('http://cbukk.it/craftbukkit-beta.jar', 'craftbukkit.jar')
102
+ else
103
+ Rblock::fetch_bukkit('http://cbukk.it/craftbukkit.jar', 'craftbukkit.jar')
104
+ end
105
+
106
+ puts "Creating server files and world..."
107
+
108
+ # monitor the logfile, so we know when the server's done loading
109
+ log = Rblock::Logfile.new('server.log')
110
+
111
+ # start the minecraft server
112
+ screen = Rblock::Screen.new(server_name)
113
+ screen.start "sh -c 'cd #{Dir.getwd};java -Xms1024M -Xmx1024M -jar craftbukkit.jar -o true'"
114
+
115
+ # now, we wait until the server is done loading.
116
+ # we know it's done when the log file contains the text "Done!"
117
+
118
+ until log.gets =~ /Done/
119
+ sleep 1 if log.line.nil? # wait a second if we're already at the most recent line
120
+ end
121
+
122
+ # okay, server's done creatin' the world and whatnot
123
+ # now, let's stop the server
124
+ puts "Stopping temporary server..."
125
+ screen.send "stop"
126
+
127
+ # just wait for the screen to shut down, and we're done!
128
+ until screen.running? == false
129
+ sleep 2
130
+ end
131
+
132
+ end
133
+
134
+ when 'start'
135
+ s = Rblock::Server.new(Dir.getwd)
136
+ if s.running?
137
+ puts "Already running."
138
+ exit
139
+ end
140
+
141
+ s.start
142
+ puts "Started.".green
143
+ when 'stop'
144
+ s = Rblock::Server.new(Dir.getwd)
145
+ if not s.running?
146
+ puts "Already stopped."
147
+ exit
148
+ end
149
+
150
+ s.stop
151
+ puts "Stopped.".red
152
+ when 'say'
153
+ s = Rblock::Server.new(Dir.getwd)
154
+ s.say ARGV[0]
155
+
156
+ when 'console'
157
+ s = Rblock::Server.new(Dir.getwd)
158
+
159
+ puts "Starting console. Press control-c to exit."
160
+
161
+ while true
162
+ s.log_file.gets
163
+ puts s.log_file.line unless s.log_file.line.nil?
164
+ sleep 1 if s.log_file.line.nil?
165
+ end
166
+ end
data/commands.md ADDED
@@ -0,0 +1,17 @@
1
+ # rblock commands
2
+
3
+ * `rblock install [flags] <directory>`
4
+ * `rblock update [flags]` - almost like install
5
+ * `rblock start [flags]` (like -p 52913 to force switch port)
6
+ * `rblock stop [flags]`
7
+ * `rblock export [flags] <destination>` - Exports worlds to other places
8
+ * `rblock import [flags] <source>` - Imports worlds from other places
9
+ * `rblock backup [flags]`
10
+ * `rblock map [flags]`
11
+ * `rblock console` - opens a command console in the terminal
12
+ * `rblock chat` - opens a chat console in the terminal (cmd console, but all messages are chats)
13
+ * `rblock plugin [plugin name]` - gets plugin info
14
+ * `rblock plugin --install <plugin name>`
15
+ * `rblock plugin` lists installed plugins
16
+
17
+ `-dir ~/Desktop/food` makes the command act like the current directory is ~/Desktop/food
@@ -0,0 +1,22 @@
1
+ class Rblock::Logfile
2
+
3
+ attr_reader :line
4
+
5
+ def initialize(file_name)
6
+ @line = nil
7
+
8
+ FileUtils.touch(file_name)
9
+ @file = File.new(file_name)
10
+
11
+ while @file.gets
12
+ # do nothing, just wait to get to end of log file
13
+ end
14
+
15
+ self
16
+ end
17
+
18
+ def gets
19
+ @line = @file.gets
20
+ end
21
+
22
+ end
@@ -0,0 +1,30 @@
1
+ class Rblock::Screen
2
+
3
+ def initialize(name)
4
+ @name = "rblock_" + name
5
+ @short_name = name
6
+ self
7
+ end
8
+
9
+ def running?
10
+ screen_list = `screen -ls #{@name}`
11
+ screens = screen_list.lines.to_a[1..-3] # [0],[-2], and [-1] are all info text, so ignore
12
+ screens.each do |screen|
13
+ if screen =~ /#{@name}\t/
14
+ return true # found it! return from the function immediately
15
+ end
16
+ end
17
+
18
+ return false # we didn't find any... :(
19
+ end
20
+
21
+ def start(cmd = "")
22
+ system "screen -d -m -S #{@name} #{cmd}" if not running?
23
+ self
24
+ end
25
+
26
+ def send(cmd)
27
+ system "screen -p 0 -S #{@name} -X eval \"stuff '" + cmd + "'\\015\""
28
+ end
29
+
30
+ end
@@ -0,0 +1,40 @@
1
+ class Rblock::Server
2
+ attr_reader :log_file
3
+
4
+ def initialize(dir)
5
+ @dir = dir
6
+ @dir.sub!(/\/$/, "") # remove trailing slashes
7
+ @name = @dir.match(/[a-zA-Z\_0-9]+$/)[0] # get only the final directory name
8
+ Dir.chdir(@dir) do
9
+ @log_file = Rblock::Logfile.new('server.log')
10
+ end
11
+ @screen = Rblock::Screen.new(@name)
12
+ end
13
+
14
+ def running?
15
+ @screen.running?
16
+ end
17
+
18
+ def start
19
+ Dir.chdir(@dir) do
20
+ @screen.start "sh -c 'cd #{Dir.getwd};java -Xms1024M -Xmx1024M -jar craftbukkit.jar -o true'"
21
+ end
22
+ end
23
+
24
+ def player_count
25
+ # TODO
26
+ end
27
+
28
+ def players
29
+ # TODO
30
+ end
31
+
32
+ def stop
33
+ @screen.send "stop"
34
+ end
35
+
36
+ def say(message)
37
+ @screen.send "say #{message}"
38
+ end
39
+
40
+ end
@@ -0,0 +1,47 @@
1
+ def Rblock::test_dependencies
2
+ tests = {
3
+ 'Screen' => 'screen -v',
4
+ 'Java' => 'java -version',
5
+ }
6
+
7
+ failed = []
8
+
9
+ tests.each do |name,command|
10
+ begin
11
+ `#{command}`
12
+ rescue Errno::ENOENT
13
+ failed << name
14
+ end
15
+ end
16
+
17
+ failed
18
+ end
19
+ def Rblock::fetch_bukkit(uri_str, download_location, limit = 10)
20
+ uri = URI(uri_str)
21
+
22
+ raise ArgumentError, 'HTTP redirect too deep' if limit == 0
23
+
24
+ Net::HTTP.start(uri.host, uri.port) do |http|
25
+ request = Net::HTTP::Get.new uri.request_uri
26
+
27
+ http.request request do |response|
28
+ if response['Location'].nil?
29
+ open download_location, 'w' do |io|
30
+ response.read_body do |chunk|
31
+ io.write chunk
32
+ end
33
+ end
34
+ else
35
+ # looks like a redirect...let's follow it...
36
+ fetch_bukkit(response['Location'], download_location, limit - 1)
37
+ end
38
+ end
39
+ end
40
+ end
41
+ def Rblock::tagline
42
+ [
43
+ "taking the pain out of minecraft servers since 2012",
44
+ "because you just want to play the damn game",
45
+ "more minecraft, less server"
46
+ ].sample
47
+ end
data/lib/rblock.rb ADDED
@@ -0,0 +1,23 @@
1
+ require 'fileutils'
2
+ require 'colorize'
3
+
4
+ module Rblock
5
+ end
6
+
7
+ require_relative 'rblock/logfile.rb'
8
+ require_relative 'rblock/screen.rb'
9
+ require_relative 'rblock/server.rb'
10
+ require_relative 'rblock/utilities.rb'
11
+
12
+ # $running = true;
13
+ # Signal.trap("TERM") do
14
+ # $running = false
15
+ # end
16
+ # while($running) do
17
+ # mailing = Mailing.next_for_delivery
18
+ # if mailing
19
+ # mailing.deliver
20
+ # else
21
+ # sleep 15
22
+ # end
23
+ # end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rblock
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Robert Lord
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-30 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Installs and runs Minecraft servers
15
+ email: contact@rl.io
16
+ executables:
17
+ - rblock
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - lib/rblock/logfile.rb
22
+ - lib/rblock/screen.rb
23
+ - lib/rblock/server.rb
24
+ - lib/rblock/utilities.rb
25
+ - lib/rblock.rb
26
+ - bin/rblock
27
+ - commands.md
28
+ - README.md
29
+ homepage: http://rubygems.org/gems/rblock
30
+ licenses: []
31
+ post_install_message:
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ none: false
37
+ requirements:
38
+ - - ! '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 1.8.24
50
+ signing_key:
51
+ specification_version: 3
52
+ summary: RBlock
53
+ test_files: []