Class: Lich::Common::UpstreamHook Private

Inherits:
Object
  • Object
show all
Extended by:
HookRegistry
Defined in:
documented/common/upstreamhook.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 for hooks that intercept and transform text flowing from the game server to the client.

Upstream hooks receive each line of unprocessed server output and may modify or suppress it. Script-scoped hooks are automatically removed when a script dies; persistent hooks remain active.

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 registry of script owners for upstream hooks.

Returns:

  • (Hash) —

    maps hook keys to their owning script object IDs



42
43
44
# File 'documented/common/upstreamhook.rb', line 42

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 registry of persistence flags for upstream hooks.

Returns:

  • (Hash) —

    maps hook keys to boolean persistence flags



50
51
52
# File 'documented/common/upstreamhook.rb', line 50

def self._hook_persist
  @@upstream_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 registry of script sources for upstream hooks.

Returns:

  • (Hash) —

    maps hook keys to their defining scripts



34
35
36
# File 'documented/common/upstreamhook.rb', line 34

def self._hook_sources
  @@upstream_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.



26
27
28
# File 'documented/common/upstreamhook.rb', line 26

def self._hooks
  @@upstream_hooks
end

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

Invokes all registered upstream hooks in sequence to transform server output.

Each hook receives the client string and may modify or return nil to suppress it. If a hook raises an error, it is removed from the registry, an error message is sent, and processing stops.

Parameters:

  • client_string (String) —

    the text flowing from the game server to the client

Returns:

  • (String, nil) —

    the transformed text, or nil if any hook suppressed it



63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'documented/common/upstreamhook.rb', line 63

def self.run(client_string)
  for key in @@upstream_hooks.keys
    begin
      client_string = @@upstream_hooks[key].call(client_string)
    rescue
      @@upstream_hooks.delete(key)
      respond "--- Lich: UpstreamHook: #{$!}"
      respond $!.backtrace.first
    end
    return nil if client_string.nil?
  end
  return client_string
end