Sha256: 449c914c19e7794b1923b7428ed3cac1798b3e880b4fc9604a89df233cdd8258

Contents?: true

Size: 1.46 KB

Versions: 3

Compression:

Stored size: 1.46 KB

Contents

#!/usr/bin/env ruby

require 'sbpanel'
require 'optparse'
require 'socket'

$options = {
  bind: "0.0.0.0",
  port: 8000,
  address: Socket.gethostname
}

optparse = OptionParser.new do |opts|
  opts.banner = "Usage: sbpanel [$options] STARBOUND_LOG_PATH"

  opts.on("-b", "--bind ADDR", "Address to bind [#{$options[:bind]}]") do |bind|
    $options[:bind] = bind
  end

  opts.on("-p", "--port PORT", "Port to bind [#{$options[:port]}]") do |port|
    $options[:port] = port
  end

  opts.on("-a", "--address ADDR", "Server address to display [#{$options[:address]}]") do |address|
    $options[:address] = address
  end

  opts.on('-h', '--help', 'Display this screen') do
    puts opts
    exit
  end
end

optparse.parse!

if ARGV.empty?
  puts optparse
  exit 1
end

if !File.exists?(ARGV[-1])
  puts "Error: Couldn't find log file: #{ARGV[-1]}"
  puts optparse
  exit 1
end

require 'sinatra/base'

class Panel < Sinatra::Base
  set :port, $options[:port]
  set :bind, $options[:bind]
  set :root, File.join(File.dirname(__FILE__), '..')

  game = SBPanel::Game.load(ARGV[0])
  game.address = $options[:address]

  Thread.new do
    begin
      game.read_logs
    rescue Exception => e
      puts e.message
      puts e.backtrace.join("\n")
    end
  end

  helpers ActionView::Helpers::DateHelper

  get '/' do
    game.update_status
    game.instance_variables.each do |var|
      instance_variable_set var, game.instance_variable_get(var)
    end
    erb :index
  end
end

Panel.run!

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
sbpanel-0.0.5 bin/sbpanel
sbpanel-0.0.4 bin/sbpanel
sbpanel-0.0.3 bin/sbpanel