Module: AcpcTableManager::Dealer

Extended by:
SimpleLogging
Defined in:
lib/acpc_table_manager/dealer.rb

Class Method Summary collapse

Methods included from SimpleLogging

log, log_with, logger

Class Method Details

.start(match, port_numbers: nil) ⇒ Hash<Symbol, Object>

Note:

Saves the actual port numbers used by the dealer instance in match

Returns The dealer information.

Returns:

  • (Hash<Symbol, Object>)

    The dealer information



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/acpc_table_manager/dealer.rb', line 15

def self.start(match, port_numbers: nil)
  @logger ||= ::AcpcTableManager.new_log 'dealer.log'
  log __method__, match: match

  dealer_arguments = {
    match_name: match.sanitized_name,
    game_def_file_name: Shellwords.escape(match.game_definition_file_name),
    hands: Shellwords.escape(match.number_of_hands),
    random_seed: Shellwords.escape(match.random_seed.to_s),
    player_names: match.player_names.map { |name| Shellwords.escape(name.gsub(/\s+/, '_')) }.join(' '),
    options: match.dealer_options
  }

  log __method__, {
    match_id: match.id,
    match_name: match.name,
    dealer_arguments: dealer_arguments,
    log_directory: ::AcpcTableManager.config.match_log_directory,
    port_numbers: port_numbers,
    command: AcpcDealer::DealerRunner.command(dealer_arguments, port_numbers)
  }

  dealer_info = Timeout::timeout(3) do
    AcpcDealer::DealerRunner.start(
      dealer_arguments,
      ::AcpcTableManager.config.match_log_directory,
      port_numbers
    )
  end

  match.dealer_pid = dealer_info[:pid]
  match.port_numbers = dealer_info[:port_numbers].map { |e| e.to_i }
  match.save!

  log __method__, {
    match_id: match.id,
    match_name: match.name,
    dealer_pid: match.dealer_pid,
    saved_port_numbers: match.port_numbers
  }

  dealer_info
end