Class: Lich::Common::DownstreamHook Private

Inherits:
Object
  • Object
show all
Extended by:
HookRegistry
Defined in:
documented/common/downstreamhook.rb

Overview

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

Registry of hooks that process server strings as they arrive from the game.

DownstreamHook instances intercept and transform strings received from the game server before they are delivered to scripts and the UI. Hooks are executed in registration order and may modify, filter, or pass through the server string unchanged. Script-scoped hooks are automatically removed when their owning script dies; persistent hooks remain.

Class Method Summary collapse

Methods included from HookRegistry

add, cleanup_on_death, hook_sources, list, remove, sources

Class Method Details

._hook_owners ⇒ Hash

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 per-class storage mapping hook IDs to their owning script object IDs.

Returns:

  • (Hash) —

    a hash keyed by hook ID



44
45
46
# File 'documented/common/downstreamhook.rb', line 44

def self._hook_owners
  @@downstream_hook_owners
end

._hook_persist ⇒ Hash

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 per-class storage mapping hook IDs to their persistence flags.

Returns:

  • (Hash) —

    a hash keyed by hook ID, with boolean values indicating whether each hook persists across script death



52
53
54
# File 'documented/common/downstreamhook.rb', line 52

def self._hook_persist
  @@downstream_hook_persist
end

._hook_sources ⇒ Hash

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 per-class storage mapping hook IDs to their source files.

Returns:

  • (Hash) —

    a hash keyed by hook ID



36
37
38
# File 'documented/common/downstreamhook.rb', line 36

def self._hook_sources
  @@downstream_hook_sources
end

._hooks ⇒ Object

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.

Per-class storage for the shared HookRegistry methods.



28
29
30
# File 'documented/common/downstreamhook.rb', line 28

def self._hooks
  @@downstream_hooks
end

.run(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.

Processes a server string through all registered downstream hooks in order.

Each hook is called with a duplicate of the string and may return a modified string, nil, or raise an exception. If a hook raises an exception, it is removed from the registry, the error is logged to the console, and execution continues with the next hook. If any hook returns nil, processing stops immediately and nil is returned.

Parameters:

  • server_string (String, nil) —

    the string received from the game server

Returns:

  • (String, nil) —

    the processed string after all hooks have run, or nil if any hook returned nil



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'documented/common/downstreamhook.rb', line 66

def self.run(server_string)
  for key in @@downstream_hooks.keys
    return nil if server_string.nil?
    begin
      server_string = @@downstream_hooks[key].call(server_string.dup) if server_string.is_a?(String)
    rescue
      @@downstream_hooks.delete(key)
      respond "--- Lich: DownstreamHook: #{$!}"
      respond $!.backtrace.first
    end
  end
  return server_string
end