Module: Lich::Common::ClientCapabilities
- Defined in:
- documented/common/client_capabilities.rb
Overview
Which of DragonRealms' rich-stream rewrites each attached front end gets.
Lich rewrites the Saga-identity stream for a front end that cannot take
it: the inline
- what the client declared with a
SET_FRONTEND_CAPSline (see docs/frontends/capability-declaration.md); - the session's
--frontend-caps=launch flag; - the frontend catalog's capabilities for
$frontend(what every client got before declarations existed).
Only these three rewrites follow the client. Everything else Lich does
to the stream for a front end (Wizard's GSL codes, the origin sentinel,
mono, the room-number display, the Genie and Frostbite subtitle edits)
still follows the session's $frontend. A Wizard/Avalon (GSL) session
ignores declarations: its GSL conversion keeps state across lines, so
every client there gets the session's set.
Constant Summary collapse
- DECLARABLE =
The capabilities a client can declare, in canonical order.
%i[room_element game_links double_bold].freeze
Class Attribute Summary collapse
-
.launch_capabilities ⇒ Array<Symbol>?
The session's set from --frontend-caps=, or nil when not given.
Class Method Summary collapse
-
.declaration?(line) ⇒ Boolean
Whether a line from a client is a capability declaration.
-
.declare(client, line) ⇒ Boolean
Applies a capability declaration to the client that sent it.
-
.group(clients) ⇒ Hash{Array<Symbol> => Array}
Groups clients by the capability set each one gets, so a server line is rewritten once per distinct set, not once per client.
-
.parse(names) ⇒ Array(Array<Symbol>, Array<String>)
Splits a list of capability names into the known set and the rest.
-
.session_default(frontend = $frontend) ⇒ Array<Symbol>
The set a client gets when it has not declared one: the launch flag's, else the catalog's for the session's front end.
Class Attribute Details
.launch_capabilities ⇒ Array<Symbol>?
The session's set from --frontend-caps=, or nil when not given.
91 92 93 |
# File 'documented/common/client_capabilities.rb', line 91 def launch_capabilities @launch_capabilities end |
Class Method Details
.declaration?(line) ⇒ Boolean
Whether a line from a client is a capability declaration.
51 52 53 |
# File 'documented/common/client_capabilities.rb', line 51 def declaration?(line) line.is_a?(String) && DECLARATION.match?(line) end |
.declare(client, line) ⇒ Boolean
Applies a capability declaration to the client that sent it.
The declared set replaces any earlier declaration from that client. Names Lich does not know are ignored, so a newer client can declare capabilities an older Lich lacks; a declaration with no known name (or none at all) declares the empty set, the full legacy rewrite.
66 67 68 69 70 71 72 73 74 75 |
# File 'documented/common/client_capabilities.rb', line 66 def declare(client, line) match = line.is_a?(String) && DECLARATION.match(line) return false unless match capabilities, unknown = parse(match[:names]) client.declared_capabilities = capabilities if client.respond_to?(:declared_capabilities=) log("info: client declared capabilities [#{capabilities.join(' ')}]" \ "#{" (ignored unknown: #{unknown.join(' ')})" unless unknown.empty?}") true end |
.group(clients) ⇒ Hash{Array<Symbol> => Array}
Groups clients by the capability set each one gets, so a server line is rewritten once per distinct set, not once per client.
116 117 118 119 120 121 |
# File 'documented/common/client_capabilities.rb', line 116 def group(clients) session = session_default return { session => clients.dup } if clients.empty? || Frontend.supports_gsl? clients.group_by { |client| declared(client) || session } end |
.parse(names) ⇒ Array(Array<Symbol>, Array<String>)
Splits a list of capability names into the known set and the rest.
82 83 84 85 86 87 |
# File 'documented/common/client_capabilities.rb', line 82 def parse(names) tokens = names.to_s.split(SEPARATOR).reject(&:empty?) known, unknown = tokens.partition { |token| DECLARABLE.include?(token.downcase.to_sym) } wanted = known.map { |token| token.downcase.to_sym } [DECLARABLE.select { |capability| wanted.include?(capability) }.freeze, unknown] end |
.session_default(frontend = $frontend) ⇒ Array<Symbol>
The set a client gets when it has not declared one: the launch flag's, else the catalog's for the session's front end.
105 106 107 |
# File 'documented/common/client_capabilities.rb', line 105 def session_default(frontend = $frontend) launch_capabilities || DECLARABLE.select { |capability| Frontend.has_capability?(frontend, capability) }.freeze end |