Module: Lich::Main::ArgvOptions::SideEffects
- Defined in:
- documented/main/argv_options.rb
Overview
Apply side effects: dark mode, hosts-dir, bind-address, detachable-client
Class Method Summary collapse
-
.announce(level, message) ⇒ Object
Surface a message on both channels every bind handler uses.
-
.die(message) ⇒ Object
Fatal argv problem: tell the user everywhere, then stop.
-
.execute(argv_options) ⇒ Hash
private
Applies side effects from parsed ARGV options: theme, hosts, bind address, detachable client, etc.
-
.handle_bind_address(argv_options) ⇒ Object
--bind-address shares the keyword vocabulary of --detachable-client hosts (tailscale/lan/any).
-
.handle_detachable_client(argv_options) ⇒ void
private
Resolves detachable client bind host and port from --detachable-client= argument.
-
.handle_frontend_caps(argv_options) ⇒ Object
--frontend-caps=LIST: the rich-stream capabilities every client gets unless it declares its own with SET_FRONTEND_CAPS, in place of the catalog's for the frontend (see Lich::Common::ClientCapabilities).
-
.handle_hosts_dir(argv_options) ⇒ void
private
Stores a custom hosts directory path if it exists.
-
.handle_sal_launch(argv_options) ⇒ void
private
Launches a SAL file via the Simutronics launcher or system command.
-
.handle_sentinel(argv_options) ⇒ Object
--sentinel: the running session gets the origin marker whichever frontend it identifies as.
-
.port_in_use?(host, port) ⇒ Boolean
Plain bind probe (no SO_REUSEADDR on Windows), so a live listener fails it.
Class Method Details
.announce(level, message) ⇒ Object
Surface a message on both channels every bind handler uses.
234 235 236 237 |
# File 'documented/main/argv_options.rb', line 234 def self.announce(level, ) $stdout.puts "#{level}: #{}" Lich.log "#{level}: #{}" end |
.die(message) ⇒ Object
Fatal argv problem: tell the user everywhere, then stop.
240 241 242 243 |
# File 'documented/main/argv_options.rb', line 240 def self.die() announce('error', ) exit 1 end |
.execute(argv_options) ⇒ Hash
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Applies side effects from parsed ARGV options: theme, hosts, bind address, detachable client, etc.
Calls handlers in sequence to configure dark mode (StartupTheme), hosts directory, bind address resolution, detachable client settings, sentinel flag, frontend capabilities, and SAL file launch. Returns the modified argv_options hash.
203 204 205 206 207 208 209 210 211 212 |
# File 'documented/main/argv_options.rb', line 203 def self.execute() StartupTheme.apply() handle_hosts_dir() handle_bind_address() handle_detachable_client() handle_sentinel() handle_frontend_caps() handle_sal_launch() end |
.handle_bind_address(argv_options) ⇒ Object
--bind-address shares the keyword vocabulary of --detachable-client hosts (tailscale/lan/any). Resolve it once, up front, so the frontend listener, the --game proxy, and a detachable client that inherits it all bind the same concrete address -- and so the exposure warning appears exactly once.
250 251 252 253 254 255 256 257 |
# File 'documented/main/argv_options.rb', line 250 def self.handle_bind_address() result = BindAddressOption.apply([:bind_address]) die(result.error) if result.error return unless result.host [:bind_address] = result.host announce('warning', result.warning) if result.warning end |
.handle_detachable_client(argv_options) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Resolves detachable client bind host and port from --detachable-client= argument.
Parses the --detachable-client=TARGET argument (e.g., "tailscale", "lan", "127.0.0.1:9000") and resolves the host via BindHostResolver. Stores the resolved host in :detachable_client_host and the port in :detachable_client_port. If no host is specified, defaults to :bind_address or 127.0.0.1. Exits with an error message if parsing or resolution fails.
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'documented/main/argv_options.rb', line 295 def self.handle_detachable_client() [:detachable_client_host] = [:bind_address] || '127.0.0.1' [:detachable_client_port] = nil arg = ARGV.find { |a| a.start_with?('--detachable-client=') } return unless arg begin target = DetachableClientTarget.parse(arg.split('=', 2).last) if target.host resolution = Lich::Common::BindHostResolver.resolve(target.host) [:detachable_client_host] = resolution.host announce('warning', resolution.warning) if resolution.warning end # (The port-only form inherits --bind-address, which # handle_bind_address already resolved and warned about; the # loopback default warrants no warning.) [:detachable_client_port] = target.port rescue DetachableClientTarget::ParseError, Lich::Common::BindHostResolver::Error => e die(e.) end end |
.handle_frontend_caps(argv_options) ⇒ Object
--frontend-caps=LIST: the rich-stream capabilities every client gets unless it declares its own with SET_FRONTEND_CAPS, in place of the catalog's for the frontend (see Lich::Common::ClientCapabilities). An empty LIST (or one with no known name) gives every client the legacy rewrites.
225 226 227 228 229 230 231 |
# File 'documented/main/argv_options.rb', line 225 def self.handle_frontend_caps() return unless .key?(:frontend_caps) capabilities, unknown = Lich::Common::ClientCapabilities.parse([:frontend_caps]) announce('warning', "--frontend-caps: ignoring unknown capabilities: #{unknown.join(', ')}") unless unknown.empty? Lich::Common::ClientCapabilities.launch_capabilities = capabilities end |
.handle_hosts_dir(argv_options) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Stores a custom hosts directory path if it exists.
Searches ARGV for --hosts-dir=PATH. If the path exists as a directory, normalizes it (convert backslashes to forward slashes, ensure trailing slash), removes the argument from ARGV, and stores the path in argv_options. If the path does not exist, logs a warning to stdout.
269 270 271 272 273 274 275 276 277 278 279 280 281 |
# File 'documented/main/argv_options.rb', line 269 def self.handle_hosts_dir() if (arg = ARGV.find { |a| a =~ /^--hosts-dir=(.+)$/i }) hosts_dir = arg[/^--hosts-dir=(.+)$/i, 1] ARGV.delete(arg) if hosts_dir && File.exist?(hosts_dir) hosts_dir = hosts_dir.tr('\\', '/') hosts_dir += '/' unless hosts_dir[-1..-1] == '/' [:hosts_dir] = hosts_dir else $stdout.puts "warning: given hosts directory does not exist: #{hosts_dir}" end end end |
.handle_sal_launch(argv_options) ⇒ void
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
This method returns an undefined value.
Launches a SAL file via the Simutronics launcher or system command.
If argv_options is set, verifies the file exists. If the file does not exist and a detachable client port is in use, appends a message suggesting the port may be held by another Lich. For SGE.sal, retrieves the launcher command via Lich.get_simu_launcher, substitutes the SAL path, and executes via Win32.ShellExecute (Windows), system call under Wine, or bare system call. Exits after launch.
340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'documented/main/argv_options.rb', line 340 def self.handle_sal_launch() return unless [:sal] unless File.exist?([:sal]) msg = "error: launch file does not exist: #{[:sal]}" # A launcher that deletes its .sal once it reaches the detachable port # (e.g. Saga) does so early if something else already holds that port. port = [:detachable_client_port] if port && port_in_use?([:detachable_client_host], port) msg += "\n\nThe detachable client port #{port} is already in use, most likely by another Lich " \ "that is still running. Your launcher may have connected to it and deleted the launch " \ "file. Close that Lich or choose a different port, then try again." end Lich.log msg Lich.msgbox(message: msg, icon: :error) exit end Lich.log "info: launch file: #{[:sal]}" if [:sal] =~ /SGE\.sal/i unless (launcher_cmd = Lich.get_simu_launcher) $stdout.puts 'error: failed to find the Simutronics launcher' Lich.log 'error: failed to find the Simutronics launcher' exit end launcher_cmd.sub!('%1', [:sal]) Lich.log "info: launcher_cmd: #{launcher_cmd}" if defined?(Win32) && launcher_cmd =~ /^"(.*?)"\s*(.*)$/ dir_file = $1 param = $2 dir = dir_file.slice(/^.*[\\\/]/) file = dir_file.sub(/^.*[\\\/]/, '') operation = (Win32.isXP? ? 'open' : 'runas') r = Win32.ShellExecute(lpOperation: operation, lpFile: file, lpDirectory: dir, lpParameters: param) Lich.log "error: Win32.ShellExecute returned #{r}; Win32.GetLastError: #{Win32.GetLastError}" if r < 33 elsif defined?(Wine) system("#{Wine::BIN} #{launcher_cmd}") else system(launcher_cmd) end exit end end |
.handle_sentinel(argv_options) ⇒ Object
--sentinel: the running session gets the origin marker whichever frontend it identifies as.
216 217 218 |
# File 'documented/main/argv_options.rb', line 216 def self.handle_sentinel() Lich::Common::Frontend.sentinel_requested = true if [:sentinel] end |
.port_in_use?(host, port) ⇒ Boolean
Plain bind probe (no SO_REUSEADDR on Windows), so a live listener fails it.
318 319 320 321 322 323 324 325 |
# File 'documented/main/argv_options.rb', line 318 def self.port_in_use?(host, port) TCPServer.new(host, port).close false rescue Errno::EADDRINUSE, Errno::EACCES true rescue StandardError false end |