Class: Lich::Common::UpstreamHook
- Inherits:
-
Object
- Object
- Lich::Common::UpstreamHook
- Extended by:
- HookRegistry
- Defined in:
- documented/common/upstreamhook.rb
Overview
Registry for hooks that process game server output before scripts receive it.
UpstreamHook allows scripts to intercept and transform the raw XML stream from the game server. Hooks are executed in priority order and receive the server string; each hook can modify it before passing to the next. If a hook raises an exception, it is removed and an error is logged, but processing continues.
Hooks registered with UpstreamHook are removed when their owning script dies, unless registered with persist: true.
Class Method Summary collapse
-
._hook_owners ⇒ Hash
private
Returns the per-class storage hash mapping hook keys to their owning scripts.
-
._hook_persist ⇒ Hash
private
Returns the per-class storage hash tracking which hooks should survive script death.
-
._hook_priorities ⇒ Hash
private
Returns the per-class storage hash mapping hook keys to their execution priorities.
-
._hook_sources ⇒ Hash
private
Returns the per-class storage hash mapping hook keys to their source scripts.
-
._hooks ⇒ Object
Per-class storage for the shared HookRegistry methods.
-
.run(client_string) ⇒ String?
Processes game server output through all registered upstream hooks in priority order.
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 per-class storage hash mapping hook keys to their owning scripts.
49 50 51 |
# File 'documented/common/upstreamhook.rb', line 49 def self._hook_owners @@upstream_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 hash tracking which hooks should survive script death.
57 58 59 |
# File 'documented/common/upstreamhook.rb', line 57 def self._hook_persist @@upstream_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 per-class storage hash mapping hook keys to their execution priorities.
65 66 67 |
# File 'documented/common/upstreamhook.rb', line 65 def self._hook_priorities @@upstream_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 per-class storage hash mapping hook keys to their source scripts.
41 42 43 |
# File 'documented/common/upstreamhook.rb', line 41 def self._hook_sources @@upstream_hook_sources end |
._hooks ⇒ Object
Per-class storage for the shared HookRegistry methods.
33 34 35 |
# File 'documented/common/upstreamhook.rb', line 33 def self._hooks @@upstream_hooks end |
.run(client_string) ⇒ String?
Processes game server output through all registered upstream hooks in priority order.
Executes each registered hook in priority order, passing the server output through them sequentially. If a hook raises an exception, it is automatically removed and an error is logged to the game window, but processing of remaining hooks continues. If any hook returns nil, processing stops and nil is returned.
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'documented/common/upstreamhook.rb', line 82 def self.run(client_string) for key in ordered_hook_names return nil if client_string.nil? begin action = hook_action(key) next unless action client_string = action.call(client_string) rescue remove(key) respond "--- Lich: UpstreamHook: #{$!}" respond $!.backtrace.first end end return client_string end |