Class: Lich::Common::DownstreamHook

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

Overview

Registry and execution engine for downstream hooks.

Downstream hooks intercept and transform text received from the game server before it reaches the game client display. Hooks are registered by script and executed in priority order; each hook receives the server string, may modify it, and passes the result to the next hook. If a hook raises an exception, it is logged and removed; execution continues with remaining hooks.

Class Method Summary collapse

Methods included from HookRegistry

add, cleanup_on_death, extended, hook_sources, list, ordered_hook_names, 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 storage hash mapping downstream hook identifiers to the script object IDs that registered them.

Returns:

  • (Hash) —

    hook ID to script object ID



48
49
50
# File 'documented/common/downstreamhook.rb', line 48

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 storage hash tracking which downstream hooks should survive script death (persist across unload).

Returns:

  • (Hash) —

    hook ID to persistence flag



57
58
59
# File 'documented/common/downstreamhook.rb', line 57

def self._hook_persist
  @@downstream_hook_persist
end

._hook_priorities ⇒ 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 storage hash mapping downstream hook identifiers to their numeric execution priority (lower number = earlier execution).

Returns:

  • (Hash) —

    hook ID to priority value



66
67
68
# File 'documented/common/downstreamhook.rb', line 66

def self._hook_priorities
  @@downstream_hook_priorities
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 storage hash mapping downstream hook identifiers to their source file and line number.

Returns:

  • (Hash) —

    hook ID to source location metadata



39
40
41
# File 'documented/common/downstreamhook.rb', line 39

def self._hook_sources
  @@downstream_hook_sources
end

._hooks ⇒ Object

Per-class storage for the shared HookRegistry methods.



30
31
32
# File 'documented/common/downstreamhook.rb', line 30

def self._hooks
  @@downstream_hooks
end

.run(server_string) ⇒ String?

Note:

Hooks that return nil halt the chain; downstream hooks do not execute.

Executes all registered downstream hooks in priority order against the given server string.

Each hook is invoked with a duplicate of the string to prevent unwanted side effects. The transformed result flows to the next hook. If a hook raises an exception, it is logged and removed from the registry; remaining hooks continue executing.

Examples:

result = DownstreamHook.run("[Notice: Your spell is ready.]")  #=> processed string

Parameters:

  • server_string (String, nil) —

    the server output to process

Returns:

  • (String, nil) —

    the transformed server string, or nil if a hook returns nil



83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'documented/common/downstreamhook.rb', line 83

def self.run(server_string)
  for key in ordered_hook_names
    return nil if server_string.nil?
    begin
      action = hook_action(key)
      next unless action

      server_string = action.call(server_string.dup) if server_string.is_a?(String)
    rescue
      remove(key)
      respond "--- Lich: DownstreamHook: #{$!}"
      respond $!.backtrace.first
    end
  end
  return server_string
end