Class: Lich::Common::DownstreamHook
- Inherits:
-
Object
- Object
- Lich::Common::DownstreamHook
- 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
-
._hook_owners ⇒ Hash
private
Returns the storage hash mapping downstream hook identifiers to the script object IDs that registered them.
-
._hook_persist ⇒ Hash
private
Returns the storage hash tracking which downstream hooks should survive script death (persist across unload).
-
._hook_priorities ⇒ Hash
private
Returns the storage hash mapping downstream hook identifiers to their numeric execution priority (lower number = earlier execution).
-
._hook_sources ⇒ Hash
private
Returns the storage hash mapping downstream hook identifiers to their source file and line number.
-
._hooks ⇒ Object
Per-class storage for the shared HookRegistry methods.
-
.run(server_string) ⇒ String?
Executes all registered downstream hooks in priority order against the given server string.
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.
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).
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).
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.
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?
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.
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 |