Tibia 2 OT is a server for Tibia, an MMORPG from 1997 that still has a large player base, with its own client for PC, Android and the browser. This post is about the browser part: how the same C++ client that runs on Windows became a page that opens in Chrome, in Safari on iPhone and even in the Xbox browser, with nothing to install.
One codebase, four platforms
The client is a fork of OTClient: a C++ engine with the whole UI written in Lua and OTUI (a CSS-like layout language). The key decision was not to rewrite anything for the web. The same C++, the same Lua modules and the same build as the PC are compiled to WebAssembly with Emscripten. A bug fixed on PC is already fixed in the browser.
What differs per platform lives in a few thin layers: windowing and input (keyboard, touch, gamepad), audio and networking.
Networking: browsers can't open TCP sockets
The game protocol is plain TCP, and a web page only speaks HTTP and WebSocket. The fix is a WebSocket → TCP bridge in the login server (written in Go): the client opens a WebSocket, the bridge opens the TCP connection to the game world and relays bytes both ways. To the game server, a player coming through the bridge is just a regular client, with the same protocol and encryption.
The real problem: 137 MB before the game opens
The first version bundled every game file with the engine. It worked, but a first visit downloaded 137 MB (164 MB uncompressed) before showing the login screen, and Chrome refused to store a 277 MB file in its cache, so every visit downloaded everything again.
What fixed it:
-
Engine separate from data. The
.wasmcarries no game files. The page reads a manifest, downloads the packages (a simple format: a list of path + bytes), writes them to the engine's in-memory filesystem and only then starts the game. - Packages split by what changes together. Lua/OTUI code changes every update; UI images sometimes; sprite sheets only when the game version changes. Each group is a package with a hash in its name, stored in the browser's Cache API. After a regular update a player downloads about 7 MB, not 160.
- Sprite sheets stream in while the game is already open. They are half of the weight. The login screen opens without them, and the engine only needs a sheet when it draws a sprite from it. If the sheet hasn't arrived, the sprite stays "loading" for a frame and the engine asks the page for that sheet, which fetches just that slice of the package with an HTTP Range request. The package's first record is an index, so the page knows where each sheet starts as soon as the download begins.
- Recompression for the web. Sheets are recompressed with maximum LZMA (the engine reads the parameters from each sheet's header), and the browser package leaves out what the engine never reads.
Result: 48 MB to open the game on a first visit (down from 137 MB) and about 7 MB after an update.
Mobile
A mobile browser tab has far less memory. Non-essential packages (house images, for example) just aren't downloaded there, and the UI got touch controls. On Android there's also a native app built from the same code.
Takeaways
- Reusing the whole engine is what made this feasible for a small team.
- In the browser the bottleneck isn't CPU, it's how many bytes arrive before the first screen.
- Cache API + hashed file names + Range requests solve most of it without a complicated service worker.
You can try it at tibia2ot.com/play: it runs in desktop browsers, on Android and on iPhone.



Top comments (0)