#!/usr/bin/env ruby # encoding: utf-8 # Author: kimoto require 'vrowser' require 'optparse' require 'vrowser/http_daemon' require 'fileutils' options = { :host => 'localhost', :port => '3000', :document_root => File.expand_path(File.join(File.dirname(__FILE__), '../public_html')) } parser = OptionParser.new{ |opts| opts.banner = "Usage: #{File.basename($0)}" opts.on("-f", "--config-file=PATH", "specify config file"){ |v| options[:config_path] = v } opts.on("-h", "--host=HOST", "host"){ |v| options[:host] = v } opts.on("-p", "--port=PORT", "port"){ |v| options[:port] = v } opts.on("-r", "--document-root=PATH", "root"){ |v| options[:document_root] = v } } parser.parse! if ARGV.first == "sample" sample_config = File.expand_path(File.join(File.dirname(__FILE__), "../examples/config.yml")) FileUtils.cp(sample_config, "./config.yml", :verbose => true) exit(0) end if options[:config_path].nil? parser.help.display exit(1) end Vrowser.load_file(options[:config_path]) do |vrowser| case sub_command = ARGV.shift when "fetch" vrowser.fetch when "update" vrowser.update vrowser.clear when "list" puts vrowser.servers.map(&:name).join($/) when "json" vrowser.active_servers.select(:name, :host, :ping, :num_players, :type, :map, :players).order(:host).map(&:values).to_json.display when "daemon" unless options[:host] and options[:port] and options[:document_root] raise ArgumentError end Vrowser::HTTPDaemon.start( :Host => options[:host], :Port => options[:port], :DocumentRoot => options[:document_root], :config_path => options[:config_path]) else raise ArgumentError(sub_command) end end