Module: Lich::Common::Account

Defined in:
documented/common/account.rb

Overview

Namespace for account and character information retrieved from the game server.

Stores the account name, current character, subscription type, game code, and the list of available characters on the account.

Class Method Summary collapse

Class Method Details

.characterString?

Returns the name of the currently logged-in character.

Examples:

Lich::Common::Account.character #=> "Zephyr"

Returns:

  • (String, nil)

    the character name, or nil if not yet initialized



38
39
40
# File 'documented/common/account.rb', line 38

def self.character
  @@character
end

.character=(value) ⇒ String

Sets the name of the currently logged-in character.

Parameters:

  • value (String)

    the character name

Returns:

  • (String)

    the assigned value



46
47
48
# File 'documented/common/account.rb', line 46

def self.character=(value)
  @@character = value
end

.charactersArray<String>

Returns the list of character names available on the account.

Examples:

Lich::Common::Account.characters #=> ["Zephyr", "Elanthia"]

Returns:

  • (Array<String>)

    an array of character names; empty if no characters are stored



136
137
138
# File 'documented/common/account.rb', line 136

def self.characters
  @@members.values
end

.game_codeString?

Returns the game code identifying the current game (GemStone IV or DragonRealms).

Examples:

Lich::Common::Account.game_code #=> "GS"

Returns:

  • (String, nil)

    the game code, or nil if not yet initialized



90
91
92
# File 'documented/common/account.rb', line 90

def self.game_code
  @@game_code
end

.game_code=(value) ⇒ String

Sets the game code.

Parameters:

  • value (String)

    the game code

Returns:

  • (String)

    the assigned value



98
99
100
# File 'documented/common/account.rb', line 98

def self.game_code=(value)
  @@game_code = value
end

.membersHash

Returns a hash mapping character codes to character names for all characters on the account.

Examples:

Lich::Common::Account.members #=> {"1" => "Zephyr", "2" => "Elanthia"}

Returns:

  • (Hash)

    a hash with character codes as keys and character names as values; empty if not yet initialized



107
108
109
# File 'documented/common/account.rb', line 107

def self.members
  @@members
end

.members=(value) ⇒ Hash

Parses and stores the members list from a game server response string.

Expects a tab-delimited format: the first field is discarded (account data), followed by character records of "code\tname". Extracts all character code/name pairs into a hash.

Examples:

Lich::Common::Account.members = "C\t1\t0\t0\t0\t1\tZephyr\t2\tElanthia"
Lich::Common::Account.members #=> {"1" => "Zephyr", "2" => "Elanthia"}

Parameters:

  • value (String)

    the raw member list string from the game server

Returns:

  • (Hash)

    the parsed members hash



122
123
124
125
126
127
128
129
# File 'documented/common/account.rb', line 122

def self.members=(value)
  potential_members = {}
  for code_name in value.sub(/^C\t[0-9]+\t[0-9]+\t[0-9]+\t[0-9]+[\t\n]/, '').scan(/[^\t]+\t[^\t\n]+/)
    char_code, char_name = code_name.split("\t")
    potential_members[char_code] = char_name
  end
  @@members = potential_members
end

.nameString?

Returns the account name.

Examples:

Lich::Common::Account.name #=> "MyAccountName"

Returns:

  • (String, nil)

    the account name, or nil if not yet initialized



21
22
23
# File 'documented/common/account.rb', line 21

def self.name
  @@name
end

.name=(value) ⇒ String

Sets the account name.

Parameters:

  • value (String)

    the account name

Returns:

  • (String)

    the assigned value



29
30
31
# File 'documented/common/account.rb', line 29

def self.name=(value)
  @@name = value
end

.subscriptionString?

Returns the subscription type for the account.

Examples:

Lich::Common::Account.subscription #=> "PREMIUM"

Returns:

  • (String, nil)

    the subscription type ("NORMAL", "PREMIUM", "TRIAL", "INTERNAL", or "FREE"), or nil if not yet set



55
56
57
# File 'documented/common/account.rb', line 55

def self.subscription
  @@subscription
end

.subscription=(value) ⇒ String?

Sets the subscription type, extracting the recognized type from the input string.

Only stores the subscription type if the value contains one of the recognized types: "NORMAL", "PREMIUM", "TRIAL", "INTERNAL", or "FREE". The entire matched word is extracted and stored; the rest of the input is ignored.

Parameters:

  • value (String)

    a string containing a subscription type keyword

Returns:

  • (String, nil)

    the extracted subscription type, or the original @@subscription if no match is found



79
80
81
82
83
# File 'documented/common/account.rb', line 79

def self.subscription=(value)
  if value =~ /(NORMAL|PREMIUM|TRIAL|INTERNAL|FREE)/
    @@subscription = Regexp.last_match(1)
  end
end

.typeString?

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.

Returns the account type from the game server, available only in GemStone IV.

Queries Infomon for the account type via the "account.type" key.

Returns:

  • (String, nil)

    the account type string, or nil if not in GemStone IV or if Infomon returns nil



65
66
67
68
69
# File 'documented/common/account.rb', line 65

def self.type
  if XMLData.game.is_a?(String) && XMLData.game =~ /^GS/
    Infomon.get("account.type")
  end
end