Overview
Lich 5 operates as a transparent proxy between the game server and your front-end client. This architecture enables powerful scripting capabilities while maintaining compatibility with multiple game clients.Game Server ↔ Lich Proxy ↔ Front-End Client
Proxy Architecture
The proxy architecture provides several key benefits:- Data interception: Parse XML streams from the game server before they reach your client
- Command injection: Send automated commands to the game server
- State management: Track game state without modifying the client
- Script isolation: Run multiple scripts independently with separate contexts
Connection Flow
- Your front-end client connects to Lich instead of directly to the game server
- Lich establishes a connection to the game server
- All traffic flows through Lich, allowing for inspection and modification
- Scripts can read game data and inject commands into the stream
Core Components
Game Module (lib/games.rb)
The Game module provides the foundation for game-specific functionality:
XMLParser (lib/common/xmlparser.rb)
Parses the XML stream from the game server and populates XMLData with current game state:
The XMLParser uses Ruby’s REXML stream listener for efficient processing of the continuous XML stream from the game server.
GameObj (lib/common/gameobj.rb)
Tracks all in-game objects (NPCs, loot, inventory, etc.) with efficient deduplication:
Script (lib/common/script.rb)
Manages script execution with proper isolation and lifecycle:
Settings (lib/common/settings.rb)
Provides persistent storage for script configuration:
Data Flow
Downstream (Server → Client)
- Game server sends XML data
- XMLParser processes tags and updates
XMLData - GameObj registries are updated (NPCs, loot, etc.)
- Scripts can read from
XMLDataandGameObj - Data is passed to the front-end client
Upstream (Client → Server)
- User types command in client OR script calls
put - Command is sent to game server
- Scripts can intercept with
UpstreamHook - Server processes command and sends response
Component Interaction
Thread Safety
Lich uses Ruby threads extensively:- Each script runs in its own thread with isolated bindings
- Shared data structures (XMLData, GameObj) are accessed from multiple threads
- Synchronization is handled internally for critical operations
Database Layer
Lich uses SQLite3 for persistent storage:lich.db3.
Next Steps
Scripting Engine
Learn how scripts are executed and isolated
XML Parsing
Understand how game data is parsed
Game Objects
Explore the GameObj tracking system
Settings
Manage persistent script configuration
