<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tibia 2 OT</title>
    <description>The latest articles on DEV Community by Tibia 2 OT (@tibia2ot).</description>
    <link>https://dev.to/tibia2ot</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4261030%2F99325eab-cf63-4eac-8ec6-0da4392ed541.png</url>
      <title>DEV Community: Tibia 2 OT</title>
      <link>https://dev.to/tibia2ot</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tibia2ot"/>
    <language>en</language>
    <item>
      <title>Running a C++ MMORPG client in the browser (and on iPhone) with WebAssembly</title>
      <dc:creator>Tibia 2 OT</dc:creator>
      <pubDate>Mon, 23 Nov 2026 16:43:49 +0000</pubDate>
      <link>https://dev.to/tibia2ot/running-a-c-mmorpg-client-in-the-browser-and-on-iphone-with-webassembly-3knk</link>
      <guid>https://dev.to/tibia2ot/running-a-c-mmorpg-client-in-the-browser-and-on-iphone-with-webassembly-3knk</guid>
      <description>&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftyzqguuya9qqhdl6m150.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ftyzqguuya9qqhdl6m150.webp" alt="The same client running in a phone browser" width="799" height="369"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  One codebase, four platforms
&lt;/h3&gt;

&lt;p&gt;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 &lt;strong&gt;not to rewrite anything for the web&lt;/strong&gt;. 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.&lt;/p&gt;

&lt;p&gt;What differs per platform lives in a few thin layers: windowing and input (keyboard, touch, gamepad), audio and networking.&lt;/p&gt;

&lt;h3&gt;
  
  
  Networking: browsers can't open TCP sockets
&lt;/h3&gt;

&lt;p&gt;The game protocol is plain TCP, and a web page only speaks HTTP and WebSocket. The fix is a &lt;strong&gt;WebSocket → TCP bridge&lt;/strong&gt; 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.&lt;/p&gt;

&lt;h3&gt;
  
  
  The real problem: 137 MB before the game opens
&lt;/h3&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;What fixed it:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Engine separate from data.&lt;/strong&gt; The &lt;code&gt;.wasm&lt;/code&gt; carries 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.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Packages split by what changes together.&lt;/strong&gt; 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.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Sprite sheets stream in while the game is already open.&lt;/strong&gt; 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 &lt;strong&gt;Range&lt;/strong&gt; request. The package's first record is an index, so the page knows where each sheet starts as soon as the download begins.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Recompression for the web.&lt;/strong&gt; 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.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Result: &lt;strong&gt;48 MB to open the game&lt;/strong&gt; on a first visit (down from 137 MB) and about 7 MB after an update.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2ozmfsxq5l9ijv6n00l0.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F2ozmfsxq5l9ijv6n00l0.webp" alt="In-game screen: choosing an instanced hunting room" width="800" height="475"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Mobile
&lt;/h3&gt;

&lt;p&gt;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.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbwz7d1ib0szx5kfuhpq8.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fbwz7d1ib0szx5kfuhpq8.webp" alt="The in-game encyclopedia map, part of the same Lua UI on every platform" width="800" height="475"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Takeaways
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Reusing the whole engine is what made this feasible for a small team.&lt;/li&gt;
&lt;li&gt;In the browser the bottleneck isn't CPU, it's &lt;strong&gt;how many bytes arrive before the first screen&lt;/strong&gt;.&lt;/li&gt;
&lt;li&gt;Cache API + hashed file names + Range requests solve most of it without a complicated service worker.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;You can try it at &lt;a href="https://tibia2ot.com/play" rel="noopener noreferrer"&gt;tibia2ot.com/play&lt;/a&gt;: it runs in desktop browsers, on Android and on iPhone.&lt;/p&gt;

</description>
      <category>webassembly</category>
      <category>gamedev</category>
      <category>cpp</category>
      <category>emscripten</category>
    </item>
  </channel>
</rss>
