acpc_dealer 3.0.2 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6df72da45ec00ef10ab9807e6d541ea45321b3ab
4
- data.tar.gz: e3b27ea957b98c51bfc241dbe9eed5d742d54e9b
3
+ metadata.gz: e1c356e89c512e17dfd0fd11da86d8822cd8dca9
4
+ data.tar.gz: be541dba86e52f4cf1237b06be6717f2913d0d19
5
5
  SHA512:
6
- metadata.gz: e43ae1f310627ed50a5e819f8b9b600f42c03244bd3e189da66cfb89745893503011a0f70164f268a3154672a02c2e047edb8f96c21ab7fedcd01f4bcbed9470
7
- data.tar.gz: 3f8c5fdda3a0c5dddb455ecc96d707710cb7d2f2302e9e6dc8b1cd046543cfbec17f182caebe42be78aefc9667306bf5caedb66b5d823ef645d83213732a7b11
6
+ metadata.gz: 154d40a655e3879b202f46dc0e9b24ac3fca5d17086daba25fcd149bea54fda39e61d9300bee13301851021a1229be5b0001b7155625846c5c8b9d03ae4ad2de
7
+ data.tar.gz: 9a276040319a850c460b588cc7a1099716b5586bfeb04b36b8122aec0df2e2a25563cc422e6a31fc5d720fd6fad1d371d6a3c585b64e3cd2c5c25323ee365f69
@@ -13,7 +13,6 @@ Gem::Specification.new do |gem|
13
13
  gem.platform = Gem::Platform::RUBY
14
14
 
15
15
  gem.add_dependency 'clive', '~> 1.2'
16
- gem.add_dependency 'process_runner', '~> 0.0'
17
16
  gem.add_dependency 'rake-compiler', '~> 0.8'
18
17
  gem.add_dependency 'brick_and_mortar', '~> 0.1'
19
18
 
@@ -155,10 +155,15 @@ class AcpcDealerCli < Clive
155
155
 
156
156
  host_name = if get(:host_name) then get(:host_name) else 'localhost' end
157
157
 
158
- player = AcpcDealer::EXAMPLE_PLAYERS[number_of_players][betting_type]
159
- players_directory = File.dirname(player)
160
- FileUtils.cd players_directory
161
- ProcessRunner.go [player, host_name, get(:port)]
158
+ Process.detach(
159
+ Process.spawn(
160
+ player,
161
+ host_name, get(:port),
162
+ chdir: File.dirname(
163
+ AcpcDealer::EXAMPLE_PLAYERS[number_of_players][betting_type]
164
+ )
165
+ )
166
+ )
162
167
 
163
168
  puts "Example player for #{number_of_players} player #{betting_type}, connected to dealer on #{host_name}:#{get(:port)}"
164
169
  end
@@ -1,5 +1,4 @@
1
1
  require 'socket'
2
- require 'process_runner'
3
2
 
4
3
  module AcpcDealer
5
4
  class DealerRunner
@@ -29,10 +28,14 @@ module AcpcDealer
29
28
  # => Defaults to the ACPC Dealer's default.
30
29
  # @return [Array] The components of the ACPC Dealer command that would be run (the executable, followed by arguments)
31
30
  def self.command_components(dealer_arguments, port_numbers=nil)
32
- dealer_start_command = DEALER_COMMAND_FORMAT.inject([AcpcDealer::DEALER_PATH]) do |command_, parameter|
31
+ dealer_start_command = DEALER_COMMAND_FORMAT.inject(
32
+ [AcpcDealer::DEALER_PATH]
33
+ ) do |command_, parameter|
33
34
  command_ += dealer_arguments[parameter].to_s.split
34
35
  end
35
- dealer_start_command << "-p" << "#{port_numbers.join(',')}" if port_numbers
36
+ if port_numbers
37
+ dealer_start_command << "-p" << "#{port_numbers.join(',')}"
38
+ end
36
39
  dealer_start_command
37
40
  end
38
41
 
@@ -49,49 +52,60 @@ module AcpcDealer
49
52
  # => Defaults to +<dealer_arguments[:match_name]>.logs+.
50
53
  # @param [Array] port_numbers The port numbers to which each player will connect.
51
54
  # => Defaults to the ACPC's default.
52
- # @return [Hash] The process ID of the started dealer (key +:pid+) and the array of ports that players may
53
- # => use to connect to the new dealer instance (key +:port_numbers+).
54
- # @raise (see ProcessRunner::go)
55
+ # @param [Boolean] save_action_log
56
+ # @param [Hash] options (see Process::spawn)
57
+ # @raise (see Process::detach)
58
+ # @raise (see Process::spawn)
55
59
  # @raise (see FileUtils::mkdir_p)
56
- def self.start(dealer_arguments, log_directory=nil, port_numbers=nil, save_action_log=true)
57
- unless log_directory
58
- log_directory = File.expand_path("../#{dealer_arguments[:match_name]}.logs", __FILE__)
59
- end
60
-
60
+ def self.start(
61
+ dealer_arguments,
62
+ log_directory=nil,
63
+ port_numbers=nil,
64
+ save_action_log=true,
65
+ options={}
66
+ )
67
+ log_directory ||= File.expand_path(
68
+ "../#{dealer_arguments[:match_name]}.logs",
69
+ __FILE__
70
+ )
61
71
  FileUtils.mkdir_p log_directory unless Dir.exist?(log_directory)
62
72
 
73
+ options[:chdir] ||= log_directory
74
+
63
75
  IO.pipe do |read_io, write_io|
64
- pid = if save_action_log
65
- ProcessRunner.go(
66
- command_components(dealer_arguments, port_numbers),
67
- err: [
68
- File.join(log_directory, "#{dealer_arguments[:match_name]}.actions.log"),
69
- File::CREAT|File::WRONLY
70
- ],
71
- out: write_io,
72
- chdir: log_directory
73
- )
74
- else
75
- ProcessRunner.go(
76
- command_components(dealer_arguments, port_numbers),
77
- out: write_io,
78
- chdir: log_directory
79
- )
76
+ options[:out] ||= write_io
77
+ if save_action_log
78
+ options[:err] = [
79
+ File.join(
80
+ log_directory,
81
+ "#{dealer_arguments[:match_name]}.actions.log"
82
+ ),
83
+ File::CREAT|File::WRONLY
84
+ ]
80
85
  end
86
+ pid = Process.detach(
87
+ Process.spawn(
88
+ *command_components(dealer_arguments, port_numbers),
89
+ options
90
+ )
91
+ ).pid
81
92
 
82
- {pid: pid, port_numbers: read_io.gets.split, log_directory: log_directory}
93
+ {
94
+ pid: pid,
95
+ port_numbers: read_io.gets.split.map(&:to_i),
96
+ log_directory: log_directory
97
+ }
83
98
  end
84
99
  end
85
100
 
86
- # @todo How could ports be reserved without starting a server? Would +::ports_for_players+ even want to do this?
87
-
88
- # @return [Array<Integer>] List of random open ports. Does NOT reserve the ports though,
89
- # => so it's possible that the ports will come into use between calling this method and
90
- # => using them.
101
+ # @return [Array<Integer>] List of arbitrary open ports.
102
+ # => Does NOT reserve the ports,
103
+ # => so it's possible that the ports will come into use between calling
104
+ # => this method and using them.
91
105
  def self.ports_for_players(number_of_players)
92
- number_of_players.times.inject([]) do |ports, i|
93
- ports << TCPServer.open('localhost', 0) { |s| s.addr[1] }
106
+ number_of_players.times.map do
107
+ TCPServer.open('localhost', 0) { |s| s.addr[1] }
94
108
  end
95
109
  end
96
110
  end
97
- end
111
+ end
@@ -1,3 +1,3 @@
1
1
  module AcpcDealer
2
- VERSION = "3.0.2"
2
+ VERSION = "3.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: acpc_dealer
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.2
4
+ version: 3.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dustin Morrill
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-16 00:00:00.000000000 Z
11
+ date: 2017-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: clive
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.2'
27
- - !ruby/object:Gem::Dependency
28
- name: process_runner
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '0.0'
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '0.0'
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: rake-compiler
43
29
  requirement: !ruby/object:Gem::Requirement