Module: Lich::Main::DetachableClientNotice Private

Defined in:
documented/main/detachable_client_notice.rb

Overview

This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.

Builds the human-facing notices Lich prints to $stdout for detachable client listener lifecycle events: when the listener starts accepting connections and when an attached client drops.

These notices share a controlling terminal with an exec'd frontend (for example ProfanityFE launched by a wrapper script), so they only become visible once that frontend releases the screen. Keeping the wording in one pure formatter ensures the connect and disconnect paths stay symmetric and can be unit tested without opening sockets.

Since:

  • 5.18.0

Constant Summary collapse

PREFIX =

This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.

Since:

  • 5.18.0

'--- Lich: detachable client'

Class Method Summary collapse

Class Method Details

.address(host, port) ⇒ 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.

Formats a "host:port" endpoint, bracketing IPv6 literals so the port is unambiguous (for example [::1]:8000). A host that is already bracketed is left as-is.

Parameters:

  • host (String, nil)

    bind host or address

  • port (Integer, String)

    listener port

Returns:

  • (String)

    "host:port" with IPv6 literals bracketed

Since:

  • 5.18.0



33
34
35
36
37
# File 'documented/main/detachable_client_notice.rb', line 33

def self.address(host, port)
  formatted_host = host.to_s
  formatted_host = "[#{formatted_host}]" if formatted_host.include?(':') && !formatted_host.start_with?('[')
  "#{formatted_host}:#{port}"
end

.disconnected(name:, host:, port:, attached:) ⇒ 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.

Notice emitted when an attached client disconnects. Includes the session name so an operator can tell which character's frontend dropped, the endpoint it was attached to, and how many clients remain attached.

Parameters:

  • name (String, nil)

    character/session name the client was attached to; when blank the name is omitted

  • host (String, nil)

    bind host or address

  • port (Integer, String)

    listener port

  • attached (Integer)

    detachable clients still attached after the drop

Returns:

Since:

  • 5.18.0



58
59
60
61
# File 'documented/main/detachable_client_notice.rb', line 58

def self.disconnected(name:, host:, port:, attached:)
  subject = name.to_s.empty? ? PREFIX : "#{PREFIX} #{name}"
  "#{subject} disconnected from #{address(host, port)} (#{attached} attached)"
end

.listening(host:, port:) ⇒ 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.

Notice emitted when the detachable listener is ready for connections.

Parameters:

  • host (String, nil)

    bind host or address

  • port (Integer, String)

    listener port

Returns:

Since:

  • 5.18.0



44
45
46
# File 'documented/main/detachable_client_notice.rb', line 44

def self.listening(host:, port:)
  "#{PREFIX} listening on #{address(host, port)}"
end