Class: Lich::DragonRealms::GameInstance

Inherits:
GameBase::GameInstance::Base show all
Defined in:
documented/games.rb

Overview

DragonRealms-specific game instance

Constant Summary

Constants inherited from GameBase::GameInstance::Base

GameBase::GameInstance::Base::SPLIT_REFUSAL

Constants included from GameBase::RoomFormatter

GameBase::RoomFormatter::OBVIOUS_EXIT_PATTERN

Instance Method Summary collapse

Methods inherited from GameBase::GameInstance::Base

#atmospherics, #atmospherics=, #buffer_split_line, #combat_count, #handle_atmospherics, #handle_combat_tags, #hold_split_line, #increment_combat_count, #initialize

Constructor Details

This class inherits a constructor from Lich::GameBase::GameInstance::Base

Instance Method Details

#adapt_for_frontend(alt_string, capabilities = nil) ⇒ String

DragonRealms' links and bold go only to clients whose capabilities include them (:game_links, :double_bold); the rest get the legacy line. Without :double_bold a client also loses the single bold around a creature in action and assess lines, which the legacy stream sent plain; it runs first, while the link it keys on is still there. GemStone sends links under both client identities, so it keeps the base no-op. Doubled bold appears only in the GemStone captures recorded under the Saga identity; whether it depends on the identity is not known. Never modifies alt_string.

Parameters:

  • alt_string (String) —

    the server string on its way to the client

  • capabilities (Array<Symbol>, nil) (defaults to: nil) —

    the client's rich-stream capabilities; nil means the session's set

Returns:

  • (String) —

    the string to send

See Also:



2140
2141
2142
2143
2144
2145
2146
# File 'documented/games.rb', line 2140

def adapt_for_frontend(alt_string, capabilities = nil)
  capabilities ||= Lich::Common::ClientCapabilities.session_default
  alt_string = Lich::Common::Markup.strip_link_bold(alt_string) unless capabilities.include?(:double_bold)
  alt_string = Lich::Common::Markup.strip_game_links(alt_string) unless capabilities.include?(:game_links)
  alt_string = Lich::Common::Markup.collapse_double_bold(alt_string) unless capabilities.include?(:double_bold)
  alt_string
end

#clean_serverstring(server_string) ⇒ 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.

Cleans DragonRealms server strings: rejoin split lines, fix XML, handle combat/atmospherics.

Rejoins lines cut by roundtime refusals, removes superfluous combat push/pop pairs, strips invalid characters, fixes malformed XML tags, removes duplicate push streams, and processes combat/atmospherics state via #handle_combat_tags and #handle_atmospherics.

Parameters:

  • server_string (String) —

    the raw server line

Returns:

  • (String) —

    the cleaned line



2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
# File 'documented/games.rb', line 2009

def clean_serverstring(server_string)
  # Rejoin lines cut by a "...wait N seconds." roundtime refusal
  server_string = buffer_split_line(server_string)

  # Clear out superfluous tags
  server_string = server_string.gsub("<pushStream id=\"combat\" /><popStream id=\"combat\" />", "")
  server_string = server_string.gsub("<popStream id=\"combat\" /><pushStream id=\"combat\" />", "")

  # Fix encoding issues
  server_string = GameBase::XMLCleaner.fix_invalid_characters(server_string)

  # Fix combat wrapping components
  server_string = server_string.gsub("<pushStream id=\"combat\" /><component id=", "<component id=")

  # Fix XML tags
  server_string = GameBase::XMLCleaner.fix_xml_tags(server_string)

  # Fix duplicate pushStrings
  while server_string.include?("<pushStream id=\"combat\" /><pushStream id=\"combat\" />")
    server_string = server_string.gsub("<pushStream id=\"combat\" /><pushStream id=\"combat\" />", "<pushStream id=\"combat\" />")
  end

  # Handle combat and atmospherics
  server_string = handle_combat_tags(server_string)
  server_string = handle_atmospherics(server_string)

  server_string
end

#get_documentation_url ⇒ 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.

Returns the DragonRealms installation documentation URL.



2042
2043
2044
# File 'documented/games.rb', line 2042

def get_documentation_url
  "https://github.com/elanthia-online/lich-5/wiki/Documentation-for-Installing-and-Upgrading-Lich"
end

#modify_room_display(alt_string) ⇒ String

Rewrites the room-name line (the "<style id="roomName" />[Title]" chunk) on its way to the client. Two independent concerns:

1. When the player wants the room id/UID in the title (";display roomid title|both"),
 inject Lich's configured id/UID before the closing bracket. The game-supplied
 RealID (present only under the ShowRoomID flag) is preserved GemStone-style so
 ";display lichid" alone reads "[Town Square - 1234] (230008)" - matching how
 Lich::Gemstone::GameInstance#modify_room_display already behaves. It is stripped
 only when Lich is rendering its own UID instead ({#suppress_game_realid?}), so a
 ";display uid" title reads "[Town Square - 1234 - (u230008)]" with no duplicate.
2. Otherwise preserve the historical behavior of hiding the game's inline RealID when
 the player asked to (";display uid" or ";display flaguid").

Edits only this outbound client string; XMLData (and therefore scripts) are untouched, because process_xml_data has already parsed the inbound stream before this runs.

Parameters:

  • alt_string (String) —

    the outbound room-name server string, modified in place

Returns:

  • (String) —

    the rewritten string

See Also:



2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
# File 'documented/games.rb', line 2080

def modify_room_display(alt_string)
  if room_id_in_title?
    alt_string.sub!(/] \((?:\d+|\*\*)\)/) { "]" } if suppress_game_realid?
    room_number = room_number_display
    alt_string.sub!(']') { " - #{room_number}]" } unless room_number.empty?
  elsif suppress_game_realid?
    alt_string.sub!(/] \((?:\d+|\*\*)\)/) { "]" }
  end

  alt_string
end

#process_game_specific_data(server_string, _stripped_server = nil) ⇒ 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.

Parses DragonRealms character data: experiences, injuries, and inline richness.

Calls DRParser.parse, which modifies server_string in place via in-string markup injection (e.g., expanded experience gains, creature bold toggles). The parser operates on the raw XML, allowing inline edits that survive downstream.

Parameters:

  • server_string (String) —

    the raw server line

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

    unused; kept for signature compatibility



2056
2057
2058
2059
2060
2061
# File 'documented/games.rb', line 2056

def process_game_specific_data(server_string, _stripped_server = nil)
  # Parse directly to allow inline modifications (e.g., inline exp display)
  # The parser modifies server_string in place via server_line.replace();
  # its patterns match a link-stripped copy (DRParser.match_line)
  DRParser.parse(server_string)
end

#process_room_display(alt_string) ⇒ String

Prepends the shared exit / StringProc lines, then renders the optional DragonRealms room id/UID. The "Room Number:" line below the room appears for the "line" and "both" placements (honoring the mono toggle). The room-window subtitle (room-window front-ends only) reflects Lich's id/UID for every placement, since the window title bar is itself a title surface. It also re-appends the game-supplied RealID (#synthesized_realid_suffix) whenever the game displayed it (ShowRoomID ON) - independent of ";display roomid", which governs only where Lich's own id is placed, not whether the game's RealID is shown. So a ShowRoomID-on room shows the RealID in the window title under every placement, matching the game's own behavior and the RealID the game already leaves on the room-name line for the "line"/nil placements. The RealID is synthesized from the authoritative nav UID (XMLData.room_id) rather than copied from the inbound string, because the subtitle is rebuilt from the (UID-free) XMLData.room_title; for a complete arrival nav and the room-name literal agree, so the two surfaces read identically. The inline room-name injection for the "title"/"both" placements is handled separately in #modify_room_display.

Parameters:

  • alt_string (String) —

    the server string being rewritten

Returns:

  • (String) —

    the rewritten server string



2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
# File 'documented/games.rb', line 2108

def process_room_display(alt_string)
  alt_string = prepend_room_lines(alt_string, room_stringproc_entries, room_exit_entries)

  room_number = room_number_display
  unless room_number.empty?
    if room_id_in_line?
      alt_string = "#{room_styled("Room Number: #{room_number}")}\r\n#{alt_string}"
    end
    if Frontend.supports_room_window?
      subtitle = " - [#{XMLData.room_title[2..-3]} - #{room_number}]#{synthesized_realid_suffix}"
      alt_string = "<streamWindow id='main' title='Story' subtitle=\"#{subtitle}\" location='center' target='drop'/>\r\n#{alt_string}"
      alt_string = "<streamWindow id='room' title='Room' subtitle=\"#{subtitle}\" location='center' target='drop' ifClosed='' resident='true'/>#{alt_string}"
    end
  end

  alt_string
end