nanoMMO

nanoMMO

The MMO I'd like to see exist, built from scratch in C++, with the engineering and the hard parts out in the open.

nanoMMO is a devlog where I build an MMO from scratch in C++, with features I'd like to see exist, even if some might be impractical for most games, such as players creating their own skills. It's a learning journey, with the software engineering and the hard parts out in the open, and not always about the gameplay.

The name is a working title. It takes after nanochat, a repository by Andrej Karpathy, with code that's kept minimal and easy to hack on. That's what I'm going for here as well: a codebase that covers an MMO from one end to the other, which you can read, run yourself, and play with.

The episodes are on YouTube. The game's code is on GitHub, tagged at each step of each episode, so you can follow along. Its API docs are here, and the reasons it's built the way it is are in its decision records.

LinuxWindowsclang-tidyASan + UBSanTSanfuzzingcoverageGitHub stars

Watch the seriesTry it in your browser

Architecture

  1. ClientsDesktop clientC++ and raylibBotsthe load testBrowser clientWebAssembly, WebGL 2
  2. Way inGatewayWebSocket, port 8090WebsiteLaravel, port 8080
  3. ServersLogin serveraccounts, port 7778Embera world, port 7777Frosta world, port 7787Next instancetakes over at a deploy
  4. Shared stateRedistokens, saves, eventsConsulthe worlds that are up
  5. WorkersSaverRedis to MySQLRecorderevents to ClickHouse
  6. StorageMySQLthe source of truthClickHouseanalytics
  7. PrometheusmetricsAlloygathers logs, tracesPyroscopeprofilesAlertmanageremails the alertsLokilogsTempotracesGrafanadashboards

Dev log

  1. Adding factions to an MMORPG

    Three factions in the content, each with a herald who swears players to it for good, checked by the world, saved once through Redis into MySQL, and shown as a diamond in its colour before each sworn player's name.

    YouTubeEpisode pageCode
  2. Checking game content as a graph for an indie MMO

    Our MMO's content as a graph in smollerGraph, the graph database from the other series, and a test that fails when a new player can't reach a quest, a monster, an item or a skill, run in CI.

    YouTubeEpisode pageCode
  3. Chaos testing and site reliability engineering for an indie MMO

    We freeze Redis, MySQL and the login server, and kill the saver, while bots play our indie MMO, and find a sword that existed twice and players dropped while our numbers said all was well, with Google's SRE book as the guide.

    YouTubeEpisode pageCode
  4. Distributed tracing with OpenTelemetry in a work-in-progress MMO

    Our work-in-progress MMO follows a player's way in, a trade and a deploy through its servers as traces, with a tracer of our own that speaks OpenTelemetry, and the first traces show each MySQL read taking two round trips.

    YouTubeEpisode pageCode
  5. Weather effects and ambient sound in a C++ MMORPG

    Our C++ MMORPG's film tool shoots the weather over a player's shoulder, while fire falls on the lava, fireflies come out after dusk and the rain, the thunder and the crickets get their sound, first made from numbers and then, for the rain and the fire, recorded.

    YouTubeEpisode pageCode
  6. MMORPG PvP duels in C++ that end at one health

    Two players in our C++ MMORPG agree to a duel, count down from three, pick each other as they would a monster, and fight until one is left with one health, with the server deciding each step.

    YouTubeEpisode pageCode
  7. Playing my C++ MMORPG offline in a browser, without a server

    Our C++ MMORPG's client runs the world's own rules on its own, natively and in a browser tab, after a raylib bug turns each person's hand into a spindle in WebGL.

    YouTubeEpisode pageCode
  8. Sharing my MMORPG's game rules between C++ server and client

    Our C++ MMORPG's world, and what each player is shown of it and what their inputs do, move out of the server into a library the client can run too.

    YouTubeEpisode pageCode
  9. Running my C++ MMORPG in a web browser with WebAssembly

    Our C++ MMORPG's client builds to WebAssembly with Emscripten and draws its login screen in a browser tab, after three things a browser does differently.

    YouTubeEpisode pageCode
  10. How MMO item dupes happen

    Our C++ MMORPG's red-team client learns to trade, and twice keeps the sword it gives away, until the server holds what's offered where it is, checks it before it gives anything, and saves both bags of a trade as one.

    YouTubeEpisode pageCode
  11. MMORPG gold and player trading in C++

    Monsters in our C++ MMORPG drop gold, kept in the bag's message and saved with it, and two players trade items and gold in a window, in a simple version the server swaps all or nothing.

    YouTubeEpisode pageCode
  12. Moving my C++ MMORPG to C++23, with CMake presets

    Each way our C++ MMORPG is built gets a CMake preset, and the code moves to C++23, where deducing this and a two-index subscript tidy it up, after the compilers trip us up three times.

    YouTubeEpisode pageCode
The 72 before theseOnly the newest 12
  1. Trying to cheat in my own C++ MMORPG

    A red-team client for our C++ MMORPG breaks the client's rules one at a time, finds that the server already stops most of them, finds one that hits about twice as often, and the server gets its fix in this episode.

    YouTubeEpisode pageCode
  2. Documenting architecture decisions in a C++ MMORPG

    Twenty-four architecture decision records for our C++ MMORPG, from C++ and an authoritative server in episode one to last time's delta worlds, each with what forced the choice, what lost to it and what it costs us.

    YouTubeEpisode pageCode
  3. Sending only what changed in a C++ MMORPG

    Our C++ MMORPG's server remembers a second of what it sent each client and leaves out of each world whoever hasn't changed since a world the client has whole, which roughly halves what forty bots receive.

    YouTubeEpisode pageCode
  4. Smooth movement for other players in a C++ MMORPG

    Our C++ MMORPG draws the other players and the monsters a tenth of a second in the past, between two worlds it already has, so they walk smoothly on a network that loses packets, and carry on for a moment when worlds go missing.

    YouTubeEpisode pageCode
  5. Client-side prediction in a C++ MMORPG, on a slow network

    Our C++ MMORPG numbers each input, walks you the moment a key goes down with the server's own walking code, and lets the server's answer correct you, on a network netem slows to a 150 ms round trip.

    YouTubeEpisode pageCode
  6. MMORPG guild ranks in C++ with a roster, officers and kicks

    Our C++ MMORPG's guilds get a roster with who's playing, officers the leader makes, removing a player by rank and disbanding, each change locking the guild's row in MySQL first.

    YouTubeEpisode pageCode
  7. MMORPG guilds in C++, from MySQL to the nameplate

    Our C++ MMORPG gets guilds, kept in MySQL a transaction at a time, with invitations in Redis, a window to found one, the name over your head, a chat for the guild, and a leader who hands it on.

    YouTubeEpisode pageCode
  8. From git clone to playing a C++ MMORPG

    Our C++ MMORPG on a brand-new Ubuntu machine, from git clone to a laptop playing on it, with each thing that got in the way fixed in the code.

    YouTubeEpisode pageCode
  9. MMORPG drag and drop in C++ for the inventory and the hotbar

    Our C++ MMORPG's hotbar, chat, bag and login screens get the new look, and items and skills drag for real, checked by the server's own rules.

    YouTubeEpisode pageCode
  10. MMORPG game UI in C++ with a compass and a round minimap

    Our C++ MMORPG's interface gets a look of its own, which scales with the screen, a menu on Escape, a portrait, a compass along the top and a round minimap.

    YouTubeEpisode pageCode
  11. MMORPG sword skills in C++ that dash, launch and juggle

    Five sword skills for our C++ MMORPG, with dashes the server walks the player along, blows that throw monsters into the air and keep them there, copies left behind, a flash, and a camera that goes in.

    YouTubeEpisode pageCode
  12. MMORPG combat feel in C++ with hit-stop, knockback and a sword combo

    Blows that push monsters back, a moment's hold as each one lands, monsters that flash and rock back, a lit blade and cuts in the air, and a chain of three swings on Space, in our C++ MMORPG.

    YouTubeEpisode pageCode
  13. Procedural walk and run cycles with two-bone IK in a C++ MMORPG

    Our C++ MMORPG's people get a skeleton of their own, in its content, and the client works out their idle, walk, run and death from it, so a fresh clone needs nothing from Mixamo.

    YouTubeEpisode pageCode
  14. Versioning a C++ MMO and updating its libraries

    Our C++ MMORPG gets a version, which the client shows and the login server checks, and its libraries get pinned by hash and updated each week.

    YouTubeEpisode pageCode
  15. MMO character selection in C++ with a 3D preview

    An account gets up to four characters in each world, with names of their own, picked on a screen that draws each one in 3D, after a login that comes first, in our C++ MMORPG.

    YouTubeEpisode pageCode
  16. MMORPG trailer from code in C++ with slow motion, a sky and clouds

    Our C++ MMORPG films its own trailer, frame by frame, in slow motion, under a new sky with clouds.

    YouTubeEpisode pageCode
  17. MMORPG skill and gate sounds made from code in C++

    Each skill in our C++ MMORPG gets a sound made from the fx it already lists, from a whoosh of the blade to thunder, and each land a chord for when we arrive.

    YouTubeEpisode pageCode
  18. MMORPG footstep sounds made from code in C++

    Footsteps for our C++ MMORPG, which the client makes from numbers with a small synthesizer of our own, for each kind of ground, timed to the frames where the walk puts each foot down.

    YouTubeEpisode pageCode
  19. MMORPG skill effects in C++ for stone, ice, lightning and fire

    Four new skills in our C++ MMORPG, with shards and spikes that are lit like the world, lightning that strikes again and again, a crescent of fire, and a slice in front of the player for the server to hit.

    YouTubeEpisode pageCode
  20. MMORPG skill animation and VFX in C++ with keyframes, trails and sparks

    Skill animations of our own, as keyframes of joint turns in a text file, with sword trails, glows, shockwaves, sparks and a camera shake, in the raylib client of our C++ MMORPG, and the swing on Space as a skill too.

    YouTubeEpisode pageCode
  21. MMORPG pathfinding in C++ with A*, a map and a minimap

    A* pathfinding over the island's walkable squares on the C++ server, click to walk there, a map and a minimap drawn from the land, and monster camps spread over it, in our MMORPG.

    YouTubeEpisode pageCode
  22. MMORPG click targeting in C++ to pick a monster, run up and attack

    Swings and skills that go for the monster you clicked, with a ring at its feet and a frame of its own, a run up to it when it's out of reach, and cursors over what a click would do, in our C++ MMORPG.

    YouTubeEpisode pageCode
  23. MMORPG loading screen and death screen in C++

    A loading screen that covers the world until its land is built, with the fog lifting off it, a death screen that counts down to a Respawn button, and round gates, in the C++ client and server of our MMORPG.

    YouTubeEpisode pageCode
  24. MMORPG game events with an event queue in C++

    An event queue for what happens in the world, from the C++ server's tick through the interest management to each player near it, over TCP, shown in the raylib client as combat text.

    YouTubeEpisode pageCode
  25. Recap and what's next

    A check-in after forty-seven episodes, on what we've built, the practices around it, and where the game goes next.

    YouTubeEpisode page
  26. MMORPG game analytics with ClickHouse and Grafana

    What players do, as events, from the C++ server through a Redis stream into ClickHouse, a column-oriented database, and onto a Grafana dashboard of the game.

    YouTubeEpisode pageCode
  27. MMORPG server load test, with flame graphs from Pyroscope

    Bots that take quests, hunt for them and turn them in, two thousand of them against our server, with its CPU profiled all the time by Pyroscope, through eBPF, in Grafana.

    YouTubeEpisode pageCode
  28. MMORPG quest system in C++, with NPCs that give quests

    Quests in the content, given by NPCs that are people now, which ask you to kill a number of monsters, counted on the server, turned in for experience and prizes, and saved.

    YouTubeEpisode pageCode
  29. Low poly characters for an MMORPG in C++

    The players become low poly people, made of parts the content describes and posed by the bots' bones, each with their own skin and hair, a hull for the outline, and clothes that are items.

    YouTubeEpisode pageCode
  30. Low poly water shader for an MMORPG in C++

    Three ways to make the sea move, ripples in the light, smooth waves and flat triangles, the facets picked to match the world, then a shore with foam and a liquid for each land, with lava that glows at the tops of its waves.

    YouTubeEpisode pageCode
  31. MMORPG loot tables and drops on a C++ server

    Monsters drop loot from tables in the content, each item with its chance, into the killer's bag, the chat says what dropped, and the bots drink and dress.

    YouTubeEpisode pageCode
  32. Drag and drop MMORPG inventory with Dear ImGui

    The server sends each player their bag and takes what they do with it, and the client draws it, with icons, tooltips, drag and drop, and the slots that are worn.

    YouTubeEpisode pageCode
  33. Saving MMO inventories with Redis and MySQL

    Each player carries a bag and fights with what they wear, drinks potions with a cooldown, and has their bag saved, through Redis to MySQL, when it changes.

    YouTubeEpisode pageCode
  34. A data-driven item system for an MMO game server

    Items made of parts instead of types, with stacks, equipment slots, stats, potions and rolls, and a bag to carry them in, which a property test plays with twenty thousand times.

    YouTubeEpisode pageCode
  35. Instanced dungeons for an MMORPG game server

    The Crypt, a dungeon that gives each player who goes in a copy of it of their own, with copies that go once they're empty, and players saved outside it.

    YouTubeEpisode pageCode
  36. Deploy on push with a self-hosted GitHub Actions runner

    A GitHub Actions runner on our server, in Docker, deploys each push to main once CI passes, with the worlds handing their players over, and refuses any other job.

    YouTubeEpisode pageCode
  37. Zero downtime deploys for an MMORPG game server

    A world that hands its players over to its next instance before it stops, through Consul, with a token for each move, so a deploy no longer throws anyone out.

    YouTubeEpisode pageCode
  38. Game server logs with Grafana Loki and Alloy

    The servers' logs in Loki, collected by Alloy from Docker, labelled by service and stream, on the dashboard next to the metrics, and an alert from the logs.

    YouTubeEpisode pageCode
  39. MMORPG skill trainer NPC with MySQL and Redis

    A trainer that teaches the skills, from their levels on, checked on the server, asked for in a window of its own, and saved through Redis to a table in MySQL.

    YouTubeEpisode pageCode
  40. Bloom and cel shading in C++ with raylib

    Bloom from raylib's post-processing example, done the way games do it, with a frame of floats and lava that gives off light, then cel shading from raylib's example, FXAA, and settings for them.

    YouTubeEpisode pageCode
  41. Game music in C++ with raylib audio

    Music in the world with raylib's audio, streamed and refilled each frame, faded in and out by a jukebox, with volume sliders in decibels and settings that the client keeps.

    YouTubeEpisode pageCode
  42. MMORPG skills, cooldowns and a hotbar in C++

    Four skills as content, used on the server with a level and a cooldown each, a hotbar on the number keys, animations from Mixamo, and a camera that tilts.

    YouTubeEpisode pageCode
  43. Prometheus Alertmanager alert rules and email

    Prometheus alerts when a world falls behind or goes down, Alertmanager emails each alert to a mail server in Docker, and promtool tests the rules.

    YouTubeEpisode pageCode
  44. Integration testing a C++ game server

    A test starts the world server on port zero and plays it over TLS, UBSan catches the test's own bug, and the coverage report sees the game loop run.

    YouTubeEpisode pageCode
  45. C++ sanitizers, fuzzing and coverage in Docker

    Sanitizers under the bots, fuzzing, clang-tidy and a coverage report find what the tests don't, and we fix it.

    YouTubeEpisode pageCode
  46. Data-driven MMO content in C++ with protobuf

    Monsters and NPCs join the items as data both sides read, go out by kind, and a content hash keeps clients and worlds in step.

    YouTubeEpisode pageCode
  47. MMO items in C++ with protobuf text format

    Our sword moves out of code into one items file, in protobuf's text format, which both the server and the client read, each taking the part it needs.

    YouTubeEpisode pageCode
  48. An LLM-powered NPC in a C++ MMO server

    A storyteller NPC writes players a story from a few words, with a small language model served next to the game, asked from threads off the tick.

    YouTubeEpisode pageCode
  49. Data-driven MMO NPCs in C++ on low bandwidth

    Our first NPCs, as tables of kinds and spawns, sent once a second and drawn as coloured balls until they have models.

    YouTubeEpisode pageCode
  50. MMO chat in C++ with TCP, ImGui and rate limits

    Players talk to everyone in their world, over TCP, with each line cleaned on the server and a token bucket against floods.

    YouTubeEpisode pageCode
  51. MMO zones and portals in C++ with raylib

    Each world gets a second land, the Ashlands, with a gate from the Meadows, and each land a look of its own, as data.

    YouTubeEpisode pageCode
  52. Consul service discovery for a C++ game server

    Each game server is a world that registers with Consul, the client lists the worlds through the login server, and each world keeps its own players.

    YouTubeEpisode pageCode
  53. MMO interest management to send each player less

    Each player gets the players near them, in cells of the island, and names and levels once a second, measured change by change, on my machine and on the VPS.

    YouTubeEpisode pageCode
  54. Deploy a C++ game server to a VPS with Docker

    Our game goes onto a VPS, deployed over SSH with Docker Compose, with the database kept private and certificates for the server's address.

    YouTubeEpisode pageCode
  55. MySQL schema migrations with Flyway in Docker

    Flyway keeps our MySQL tables in versions, so a change to them keeps the players' accounts, starting with saving their health.

    YouTubeEpisode pageCode
  56. Game character screen in C++ with raylib, ImGui

    A character screen with our player's details next to an idle 3D preview, which a camera of its own draws into a render texture for Dear ImGui to show.

    YouTubeEpisode pageCode
  57. Trees and frustum culling in C++ with raylib

    Trees grow on the island where the seed says, the server makes their trunks solid, and chunks with culling make the client a lot faster.

    YouTubeEpisode pageCode
  58. Procedural terrain in C++ with noise and raylib

    Our board of tiles becomes an island 512 metres across, from noise and a seed that the server and the client share, with a camera that follows you.

    YouTubeEpisode pageCode
  59. TLS for a C++ game server with OpenSSL and Asio

    Our client sends the password, and gets its token back, as plain bytes, so we put TLS 1.3 on all our TCP connections, with OpenSSL, Asio and a certificate authority of our own.

    YouTubeEpisode pageCode
  60. Redis cache in C++ with write-behind to MySQL

    Saving each change to MySQL slows our server down with a few dozen players, so we put Redis in between, with a pipeline, an append-only file and a saver that writes to MySQL in batches.

    YouTubeEpisode pageCode
  61. Laravel game website in Docker, with login and rankings

    A Laravel website next to the game, in Docker, with rankings, and accounts that log into the game, on the game's own MySQL tables, with no CSS of our own.

    YouTubeEpisode pageCode
  62. C++ MMO combat with swords, hits and respawns

    A public-domain sword in each hand, swings the server decides, and monsters that fight back, with a death animation for both.

    YouTubeEpisode pageCode
  63. C++ MMO monsters with AI, health and levels

    A public-domain skeleton, monsters with an AI on the server, and health, levels and experience for everyone.

    YouTubeEpisode pageCode
  64. TCP vs UDP for a game server, under packet loss

    We make the network drop packets, measure how old the world on a player's screen gets over TCP and then over UDP, and let the numbers decide.

    YouTubeEpisode pageCode
  65. Profiling a C++ game server with perf and Tracy

    We step the bots up until the server falls behind, find out where its time goes with perf, flame graphs and Tracy, fix the broadcast, and measure it again.

    YouTubeEpisode pageCode
  66. raylib 3D animation in C++ with Mixamo and glTF

    Mixamo characters converted to glTF, merged into files raylib can load, synced through the server and skinned on the GPU.

    YouTubeEpisode pageCode
  67. C++ login server with Redis tokens

    A login server checks passwords away from the game server's tick, and hands each login over through Redis as a one-time token.

    YouTubeEpisode pageCode
  68. C++ game accounts with MySQL and Argon2id

    Players get accounts, kept in MySQL through its C API, with their passwords hashed with Argon2id.

    YouTubeEpisode pageCode
  69. Prometheus and Grafana for a C++ game server

    Our server reports metrics, Prometheus collects them, Grafana draws them, Docker Compose starts it all, and three hundred bots give it something to show.

    YouTubeEpisode pageCode
  70. C++ multiplayer with protobuf and Asio

    A C++ server keeps several clients in sync, over TCP, with a protobuf contract between them.

    YouTubeEpisode pageCode
  71. C++ game client with raylib, ImGui and shaders

    The client's first window, drawn with raylib, with Dear ImGui on top, tests that run in Docker without a screen or a GPU, and a cube that the keyboard moves.

    YouTubeEpisode pageCode
  72. How to build an MMORPG from scratch in C++

    Where the series is going, and a C++ project that is built, tested and documented on each push.

    YouTubeEpisode pageCode

Design choices

  1. 0047A faction is sworn to once, at its herald, guilds have none, and it means nothing in a fight yetLv 97
  2. 0046The servers send their sentences as their English and args, which the client translates
  3. 0045The client translates with gettext's PO files, as it shows each string, and the content stays English
  4. 0044Looks are chosen once, as places in the content's lists, and names show over whoever's pointed at or picked
  5. 0043Craft from the bag, without a station, and a recipe needs all it takes
  6. 0042A war kill counts once, a victim scores once every five minutes, and nobody leaves a war
  7. 0041Guilds at war hurt each other anywhere, for half an hour, and count their kills
  8. 0040Check the content as a graph, with smollerGraph, in the testsLv 90
  9. 0039Objectives with error budgets, and chaos experiments in staging, never in production
  10. 0038Trace requests with a tracer of our own, which speaks OpenTelemetryLv 87
  11. 0037The server owns the sky
  12. 0036A boss fights whoever's hurt it most, and its death is everyone's who took 5% of its health
All 47 decision records

Start here

  1. Watch the first episode

    Where the series is going, and a C++ project that is built, tested and documented on each push.

    Watch episode 1 · 48 min
  2. Follow the code

    Each step of an episode is a tag in the game's repository, so you can check out the code as it was at that point in the video.

    git checkout ep001/step-1Browse the code
  3. Run it yourself

    From cloning the code to running it, step by step, with every command to copy.

    Get started

Latest episodes

All 87 episodes
  1. Adding factions to an MMORPG

    Three factions in the content, each with a herald who swears players to it for good, checked by the world, saved once through Redis into MySQL, and shown as a diamond in its colour before each sworn player's name.

    49 min

  2. Checking game content as a graph for an indie MMO

    Our MMO's content as a graph in smollerGraph, the graph database from the other series, and a test that fails when a new player can't reach a quest, a monster, an item or a skill, run in CI.

    21 min

  3. Chaos testing and site reliability engineering for an indie MMO

    We freeze Redis, MySQL and the login server, and kill the saver, while bots play our indie MMO, and find a sword that existed twice and players dropped while our numbers said all was well, with Google's SRE book as the guide.

    70 min

  4. Distributed tracing with OpenTelemetry in a work-in-progress MMO

    Our work-in-progress MMO follows a player's way in, a trade and a deploy through its servers as traces, with a tracer of our own that speaks OpenTelemetry, and the first traces show each MySQL read taking two round trips.

    70 min

Explore by topic