Module: Lich::Common::GUI::Authentication

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

Class Method Summary collapse

Class Method Details

.authenticate(account:, password:, character: nil, game_code: nil, legacy: false) ⇒ Boolean

Authenticates a user account with the provided credentials.

Examples:

Authenticating a user

Lich::Common::GUI::Authentication.authenticate(account: "user", password: "pass")

Parameters:

  • account (String)

    The user account name.

  • password (String)

    The user password.

  • character (String, nil) (defaults to: nil)

    The character name (optional).

  • game_code (String, nil) (defaults to: nil)

    The game code (optional).

  • legacy (Boolean) (defaults to: false)

    Indicates if legacy authentication should be used.

Returns:

  • (Boolean)

    Returns true if authentication is successful, false otherwise.

Raises:

  • (StandardError)

    Raises an error if authentication fails.



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'documented/common/gui/authentication.rb', line 19

def self.authenticate(account:, password:, character: nil, game_code: nil, legacy: false)
  if character && game_code
    EAccess.auth(
      account: ,
      password: password,
      character: character,
      game_code: game_code
    )
  elsif legacy
    EAccess.auth(
      account: ,
      password: password,
      legacy: true
    )
  else
    EAccess.auth(
      account: ,
      password: password
    )
  end
end

.create_entry_data(char_name:, game_code:, game_name:, user_id:, password:, frontend:, custom_launch: nil, custom_launch_dir: nil) ⇒ Hash

Creates a hash of entry data for a character.

Examples:

Creating entry data

entry_data = Lich::Common::GUI::Authentication.create_entry_data(char_name: "Hero", game_code: "123", game_name: "Adventure", user_id: "user1", password: "pass", frontend: "wizard")

Parameters:

  • char_name (String)

    The character name.

  • game_code (String)

    The game code.

  • game_name (String)

    The game name.

  • user_id (String)

    The user ID.

  • password (String)

    The user password.

  • frontend (String)

    The 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)

    Returns a hash containing the entry data.



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

def self.create_entry_data(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_launch_data(auth_data, frontend, custom_launch = nil, custom_launch_dir = nil) ⇒ Array<String>

Prepares launch data for the specified frontend based on authentication data.

Examples:

Preparing launch data

launch_data = Lich::Common::GUI::Authentication.prepare_launch_data(auth_data, 'wizard')

Parameters:

  • auth_data (Hash)

    The authentication data to prepare.

  • frontend (String)

    The frontend type (e.g., ‘wizard’, ‘avalon’).

  • 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>)

    Returns an array of launch data strings.



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/gui/authentication.rb', line 49

def self.prepare_launch_data(auth_data, frontend, custom_launch = nil, custom_launch_dir = nil)
  launch_data = auth_data.map { |k, v| "#{k.upcase}=#{v}" }

  # Modify launch data based on frontend
  case frontend.to_s.downcase
  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 '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
    launch_data.push "CUSTOMLAUNCH=#{custom_launch}"
    launch_data.push "CUSTOMLAUNCHDIR=#{custom_launch_dir}" if custom_launch_dir
  end

  launch_data
end