Module: Lich::Common::RoomDescriptionFilter
- Defined in:
- documented/common/room_description_filter.rb
Overview
Works around a DragonRealms game bug for the client: the Saga-identity stream ignores FLAG DESCRIPTION OFF.
With the flag off, the legacy stream sends the room view without its
description (the line after the room name starts with the two spaces
before the objects, and has no roomDesc preset). The Saga-identity
stream (Frontend::CLIENT_STRING since #1700) fills the
The filter follows the game's replies to the flag,
You will no longer see room descriptions.
You will now see room descriptions.
and the Description row of the bare FLAG listing, which the
Saga-identity stream links (the first row of the table leads with
<d cmd="flag Description off">Description</d> ON Display room descriptions.
The state is the Status column; the link's cmd is the toggle, the opposite of it. A front end that clicks the link sends FLAG DESCRIPTION and gets the same reply as a typed command.
While the flag is off, the filter empties the description of each block
for the character's own room (RoomBlock.without_description). The legacy
rewrite then sends the legacy stream's line, and a front end that
renders
Opt-in (Lich.follow_description_flag, ";display descflag"), and only on the way to the client: scripts, XMLParser and the downstream hooks keep the description. Until the game has answered the flag or listed it in this session its state is unknown, and descriptions are shown.
Constant Summary collapse
- REPLY =
Pattern matching the game's reply to a FLAG DESCRIPTION command.
Captures the server's confirmation when the flag state changes. The reply starts a new line and includes the reason in the named group
:reply. /^You will (?<reply>no longer|now) see room descriptions\.\r?$/.freeze
- REPLY_TEXT =
' see room descriptions.'- LISTING_ROW =
The listing's Description row, linked or bare, read up to the Status column; the text after it is not read.
%r{^(?:<popBold/>)? (?:<d cmd="[^"]*">Description</d>|Description) +(?<status>ON|OFF)(?: |\r?$)}.freeze
- LISTING_TEXT =
'Description'- STATE =
Union pattern matching either the FLAG DESCRIPTION reply or the listing row.
Used by
.observeto capture state changes from either a direct command reply or a full FLAG listing. Later matches in a string take precedence. Regexp.union(REPLY, LISTING_ROW).freeze
Class Method Summary collapse
-
.apply(server_string, room_id:, room_exits:) ⇒ String
The string with the description of the character's room emptied while the flag is off; otherwise the same object.
-
.descriptions_off? ⇒ Boolean
Whether the game last said descriptions are off.
-
.observe(server_string) ⇒ void
Follows the game's reply to FLAG DESCRIPTION, or the Description row of the FLAG listing, in a server string; the later one wins.
-
.reset ⇒ void
Back to the unknown state (descriptions shown).
Class Method Details
.apply(server_string, room_id:, room_exits:) ⇒ String
Returns the string with the description of the character's room emptied while the flag is off; otherwise the same object.
106 107 108 109 110 |
# File 'documented/common/room_description_filter.rb', line 106 def apply(server_string, room_id:, room_exits:) return server_string unless @descriptions_off RoomBlock.without_description(server_string, room_id: room_id, room_exits: room_exits) end |
.descriptions_off? ⇒ Boolean
Returns whether the game last said descriptions are off.
91 92 93 |
# File 'documented/common/room_description_filter.rb', line 91 def descriptions_off? @descriptions_off end |
.observe(server_string) ⇒ void
This method returns an undefined value.
Follows the game's reply to FLAG DESCRIPTION, or the Description row of the FLAG listing, in a server string; the later one wins. Each must start a line, so one quoted inside another line (speech) does not count.
81 82 83 84 85 86 87 88 |
# File 'documented/common/room_description_filter.rb', line 81 def observe(server_string) return unless server_string.include?(REPLY_TEXT) || server_string.include?(LISTING_TEXT) server_string.scan(STATE) do match = Regexp.last_match @descriptions_off = match[:reply] ? match[:reply] == 'no longer' : match[:status] == 'OFF' end end |
.reset ⇒ void
This method returns an undefined value.
Back to the unknown state (descriptions shown).
97 98 99 |
# File 'documented/common/room_description_filter.rb', line 97 def reset @descriptions_off = false end |