Class: Sc2::Client
- Inherits:
-
Object
- Object
- Sc2::Client
- Includes:
- ConfigurableOptions
- Defined in:
- lib/sc2ai/local_play/client.rb,
lib/sc2ai/local_play/client/configurable_options.rb
Overview
Manages client connection to the Api
Defined Under Namespace
Modules: ConfigurableOptions
Instance Attribute Summary collapse
-
#base_build ⇒ Integer
Sc2 build number determines where to look for correct executable version binary.
-
#data_version ⇒ String
Sc2 data param, typically only required when launching older versions and Linux Launch param: -dataVersion “B89B5D6FA7CBF6452E721311BFBC6CB2”.
-
#port ⇒ Integer
Sc2 port param on which to listen for connections, default is randomly selected
Launch param: -port 12345.
Attributes included from ConfigurableOptions
#data_dir, #display_mode, #egl_path, #host, #osmesa_path, #temp_dir, #verbose, #version, #windowheight, #windowwidth, #windowx, #windowy
Class Method Summary collapse
-
.versions_json ⇒ Array
Reads bundled versions.json See tact archive or blizztrack for update config file github.com/mdX7/tact_configs/blob/77ecc4176689ab6c50be342e1ad73127ffe358d7/tpr/sc2/config/08/b3/08b331b39d9fbe95c338ec370e63f2e2#L4 blizztrack.com/config/s2/bc/8453c2f1c98b955334c7284215429c36.
Instance Method Summary collapse
-
#initialize(host:, port:, **options) ⇒ Client
constructor
Initialize new Sc2 client (starts with #launch).
-
#launch ⇒ Object
Launches and returns pid or proc.
-
#running? ⇒ Boolean
Whether the Sc2 process is running or not.
-
#stop ⇒ void
Stops the Sc2 instance<br/> This naturally disconnects attached players too.
-
#use_version(version) ⇒ Object
Reads “base-version” and “data-hash” for corresponding version return [Array<Integer,String>] tuple base_build and data_version.
Methods included from ConfigurableOptions
Constructor Details
#initialize(host:, port:, **options) ⇒ Client
Initialize new Sc2 client (starts with #launch)
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/sc2ai/local_play/client.rb', line 58 def initialize(host:, port:, **) raise Error, "Invalid port: #{port}" if port.to_s.empty? .each do |key, value| instance_variable_set(:"@#{key}", value) end # Require these at a minimum @port = port @host = host return if @version.nil? use_version(@version.to_s) end |
Instance Attribute Details
#base_build ⇒ Integer
Sc2 build number determines where to look for correct executable version binary
40 41 42 |
# File 'lib/sc2ai/local_play/client.rb', line 40 def base_build @base_build end |
#data_version ⇒ String
Sc2 data param, typically only required when launching older versions and Linux Launch param: -dataVersion “B89B5D6FA7CBF6452E721311BFBC6CB2”
46 47 48 |
# File 'lib/sc2ai/local_play/client.rb', line 46 def data_version @data_version end |
#port ⇒ Integer
Sc2 port param on which to listen for connections, default is randomly selected
Launch param: -port 12345
35 36 37 |
# File 'lib/sc2ai/local_play/client.rb', line 35 def port @port end |
Class Method Details
.versions_json ⇒ Array
Reads bundled versions.json See tact archive or blizztrack for update config file github.com/mdX7/tact_configs/blob/77ecc4176689ab6c50be342e1ad73127ffe358d7/tpr/sc2/config/08/b3/08b331b39d9fbe95c338ec370e63f2e2#L4 blizztrack.com/config/s2/bc/8453c2f1c98b955334c7284215429c36
24 25 26 |
# File 'lib/sc2ai/local_play/client.rb', line 24 def versions_json JSON.load_file(Paths.gem_data_versions_path) end |
Instance Method Details
#launch ⇒ Object
Launches and returns pid or proc
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/sc2ai/local_play/client.rb', line 75 def launch cwd = Paths.exec_working_dir @task = Async do |task| = {} if Gem.win_platform? [:new_pgroup] = true else [:pgroup] = true end unless cwd.nil? [:chdir] = cwd end begin ::Async::Process.spawn(command_string, **) rescue Sc2.logger.info("Client exited") task&.stop end end end |
#running? ⇒ Boolean
Whether the Sc2 process is running or not
50 51 52 |
# File 'lib/sc2ai/local_play/client.rb', line 50 def running? !!@task&.running? end |
#stop ⇒ void
This method returns an undefined value.
Stops the Sc2 instance<br/> This naturally disconnects attached players too
100 101 102 |
# File 'lib/sc2ai/local_play/client.rb', line 100 def stop @task&.stop end |
#use_version(version) ⇒ Object
Reads “base-version” and “data-hash” for corresponding version return [Array<Integer,String>] tuple base_build and data_version
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/sc2ai/local_play/client.rb', line 113 def use_version(version) found_base_build = nil found_data_version = nil Sc2::Client.versions_json.each do |node| if version == node["label"] found_base_build = node["base-version"] found_data_version = node["data-hash"] @version = version break end end if found_base_build.nil? || found_data_version.nil? Sc2.logger.warn "Requested version #{version} not found. Omit to auto-discover latest installed version" return false end @base_build = found_base_build @data_version = found_data_version true end |