Sha256: cfa84292cde5ee0acf4370fa125e34d0275307ffd82f0717ba5a1965a6f4ce84

Contents?: true

Size: 1.82 KB

Versions: 1

Compression:

Stored size: 1.82 KB

Contents

#!/usr/bin/env ruby

require 'acpc_table_manager'
require 'json'
require 'optparse'

ARGV << '-h' if ARGV.empty?

options = {}
OptionParser.new do |opts|
  opts.banner = "Usage: #{$0} [options]"

  opts.version = AcpcTableManager::VERSION

  opts.on_tail("-h", "--help", "Show this message") do
    puts opts
    exit
  end

  opts.on("-i", "--id ID", "This proxie's ID. Used as its messaging channel name.") do |c|
    options[:id] = c
  end
  opts.on("-s", "--seat SEAT", "This proxie's seat at the table (zero indexed).") do |c|
    options[:seat] = c.to_i
  end
  opts.on("-t", "--config TABLE MANAGER CONFIG", "Table manager configuration file.") do |c|
    options[:table_manager_config] = File.expand_path c, Dir.pwd
  end
  opts.on("-p", "--port PORT", "The dealer port on which to connect.") do |c|
    options[:port] = c.to_i
  end
  opts.on("-g", "--game GAME DEF KEY", "The game to be played.") do |c|
    options[:game] = c
  end
end.parse!

raise OptionParser::MissingArgument.new('ID') unless options[:id]
raise OptionParser::MissingArgument.new('SEAT') unless options[:seat]
raise OptionParser::MissingArgument.new('PORT') unless options[:port]
raise OptionParser::MissingArgument.new('TABLE MANAGER CONFIG') unless options[:table_manager_config]
raise OptionParser::MissingArgument.new('GAME DEF KEY') unless options[:game]

raise OptionParser::ArgumentError.new("#{options[:table_manager_config]} doesn't exist.") unless File.exist?(options[:table_manager_config])
raise OptionParser::ArgumentError.new("SEAT must be non-negative, received #{options[:seat] } instead.") unless options[:seat] >= 0

CONFIG_FILE = options[:table_manager_config]

AcpcTableManager.load! CONFIG_FILE

Signal.trap("INT") { exit }
Signal.trap("TERM") { exit }

app = AcpcTableManager::AcpcProxy.new(options[:id], options[:game])
app.start(options[:seat], options[:port])

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
acpc_table_manager-4.0.2 exe/acpc_proxy