Module: Lich::Common::Authentication::LaunchData

Defined in:
documented/common/authentication/launch_data.rb

Overview

Handles formatting of launch data for different game frontends

Class Method Summary collapse

Class Method Details

.create_entry(char_name:, game_code:, game_name:, user_id:, password:, frontend:, custom_launch: nil, custom_launch_dir: nil) ⇒ 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.

Creates a hash entry for saved login data This standardizes the format of saved login entries

Parameters:

  • char_name (String) —

    Character name

  • game_code (String) —

    Game code

  • game_name (String) —

    Game name

  • user_id (String) —

    User ID

  • password (String) —

    Password

  • frontend (String) —

    Frontend type

  • custom_launch (String, nil) (defaults to: nil) —

    Custom launch command (optional)

  • custom_launch_dir (String, nil) (defaults to: nil) —

    Custom launch directory (optional)

Returns:

  • (Hash) —

    Entry data hash ready for storage



91
92
93
94
95
96
97
98
99
100
101
102
# File 'documented/common/authentication/launch_data.rb', line 91

def self.create_entry(char_name:, game_code:, game_name:, user_id:, password:, frontend:, custom_launch: nil, custom_launch_dir: nil)
  {
    char_name: char_name,
    game_code: game_code,
    game_name: game_name,
    user_id: user_id,
    password: password,
    frontend: frontend,
    custom_launch: custom_launch,
    custom_launch_dir: custom_launch_dir
  }
end

.prepare(auth_data, frontend, custom_launch = nil, custom_launch_dir = nil) ⇒ Array<String>

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.

Prepares launch data from authentication result Formats the authentication data for use with different frontends

Parameters:

  • auth_data (Hash) —

    Authentication data from the authenticate method

  • frontend (String) —

    Frontend type ('wizard', 'stormfront', 'avalon', 'saga', 'suks')

  • custom_launch (String, nil) (defaults to: nil) —

    Custom launch command (optional)

  • custom_launch_dir (String, nil) (defaults to: nil) —

    Custom launch directory (optional)

Returns:

  • (Array<String>) —

    Launch data strings formatted for the selected frontend



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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'documented/common/authentication/launch_data.rb', line 24

def self.prepare(auth_data, frontend, custom_launch = nil, custom_launch_dir = nil)
  launch_data = auth_data.map { |k, v| "#{k.upcase}=#{v}" }
  frontend_id = frontend == :__unset ? '' : Frontend.canonical_name(frontend)
  custom_launch = custom_launch.to_s.strip
  custom_launch = nil if custom_launch.empty?
  custom_launch_dir = custom_launch_dir.to_s.strip if custom_launch
  custom_launch_dir = nil if custom_launch_dir == ''

  definition = begin
    Frontend.definition_for(frontend_id)
  rescue ArgumentError
    nil
  end

  if custom_launch.nil? && definition&.dig(:metadata, :launcher_adapter) == :custom
    custom_launch = FrontendLauncher.command(frontend_id)
    custom_launch_dir = definition.dig(:metadata, :launch_directory)
  end

  launch_data.reject! { |line| line.match?(/\A(?:FRONTEND|CUSTOMLAUNCH|CUSTOMLAUNCHDIR|CUSTOMLAUNCHARGV)=/i) }
  launch_data.push "FRONTEND=#{frontend_id}" unless frontend_id.empty?

  # Modify launch data based on frontend
  case frontend_id
  when 'wizard'
    launch_data.collect! { |line|
      line.sub(/GAMEFILE=.+/, 'GAMEFILE=WIZARD.EXE')
          .sub(/GAME=.+/, 'GAME=WIZ')
          .sub(/FULLGAMENAME=.+/, 'FULLGAMENAME=Wizard Front End')
    }
  when 'avalon'
    launch_data.collect! { |line| line.sub(/GAME=.+/, 'GAME=AVALON') }
  when 'saga'
    launch_data.collect! { |line| line.sub(/GAME=.+/, 'GAME=SAGA') }
  when 'suks'
    launch_data.collect! { |line|
      line.sub(/GAMEFILE=.+/, 'GAMEFILE=WIZARD.EXE')
          .sub(/GAME=.+/, 'GAME=SUKS')
    }
  end

  # Add custom launch information if provided
  if custom_launch
    if custom_launch.is_a?(Array)
      launch_data.push "CUSTOMLAUNCHARGV=#{JSON.generate(custom_launch)}"
    else
      launch_data.push "CUSTOMLAUNCH=#{custom_launch}"
    end
    launch_data.push "CUSTOMLAUNCHDIR=#{custom_launch_dir}" if custom_launch_dir
  end

  launch_data
end