nanoMMO

Building an MMO from scratch, 88 episodes in | nanoMMO Devlog

The story of nanoMMO so far, from the games before it to the world it's meant to become.

Watch on YouTube

The story of nanoMMO so far, an MMORPG I'm building from scratch in C++, eighty-eight episodes in. No code this time: the games and engines that came before it, why it's a tutorial about the engineering around a game as much as the game, and a living product at the same time. Then the game as it is today, with its weather, a world boss, duels, trading and guilds, the servers around it, and what went wrong on the way, from saves that fell behind to item dupes. And where I want to take it: a world that adapts on its own, a bit like the one in Sword Art Online, with quests and items an AI agent makes for each player. If you're new, episode one is the place to start, and you can play the game in your browser on the website.

Transcript

Intro

0:00 I'm building an MMO from scratch in C++, eighty-eight episodes in, and I'd like it to grow into a world that changes on its own, a bit like the one in Sword Art Online. Here, it's raining fire over the lava of the Ashlands, one of the game's lands.

0:15 Hello and welcome to a video that's a bit different from the others, as there's no code in it. Instead, I want to tell you the story of nanoMMO so far, and where I want to take it from here. If you're new here, I hope it's a good place to start, and if you've been following along, thank you so much for sticking with it!

Before nanoMMO

0:35 I've always been passionate about game development and complex systems. I started out with Borland Pascal as a teenager, then C++ and competitive programming, and on the side, websites, games and mobile apps in PHP and C#. One of those games is Secret Republic, a hacker role-playing game in the browser, where you break into simulated servers, crack passwords and run SQL against live databases. I first launched it in 2012, and it's open source, on its fourth version by now. In 2017, I tried an MMO in Swift, as a research experiment into how MMO servers and clients work. It had a login server and a world server, talking in packets I laid out byte by byte, and nanoMMO splits its servers that way too. In 2021, I wrote Omen, a backend in Scala for old-school browser games, the likes of Travian and Tribal Wars, where you describe a game in YAML. And in 2023, I started Hades, a 3D game engine in C++ with an editor. By now, it has a Vulkan renderer, and it can train reinforcement learning agents too. nanoMMO picks up from all of these, down to its monsters and items written as data, the way Omen describes a game in YAML. And this time, each step of building it is on video.

Why nanoMMO

1:54 First of all, nanoMMO is a tutorial, and a long one, I hope. Your average game devlog tends to focus on the flashy graphics, or a new kind of gameplay mechanic, in order to hook people in. Instead, I want to focus a lot on the software engineering and DevOps side of a game like this, from the database choices and Docker to tests, monitoring and deploys. I've come across a lot of this in very large companies, though not in game companies, and with C++ code bases too. So the purpose is to help you learn what comes into play in a production-like setup, especially if you're at the start of your career. That way, when a problem occurs, you understand what actually happens behind the scenes, and you can debug it, whether or not an AI writes a lot of the code for you. And it also lets me build a living product, the MMO I'd like to see exist, which keeps growing from one episode to the next, and which you can play.

So far

2:47 The grid has all eighty-eight, from the plan and a C++ server in episode one, to chaos testing the servers in the latest. Nearly all of them add something to the game, or around it, with its code typed out on screen.

The game today

3:00 Let's start with the game as it is today. Each land is an island of its own, and you travel between them through gates. The Meadows sit in the sea, the Ashlands in a sea of lava, and the Crypt is a dungeon where each player who goes in gets a copy of their own.

3:16 Behind the scenes, the server works out each land's time of day and weather from the wall clock, so all of the game's servers agree on it, and there's nothing to save. And the client draws the sunsets, the rain and the stars at night.

3:29 The skeletons of the Ashlands and the Crypt show their attacks as shapes on the ground before they land. The client fills each shape in as the blow gets closer, so you have a moment to step out of the way.

3:41 The Bone Colossus, our first world boss, is a skeleton four and a half metres tall. It fights in three phases, and goes for whoever's hurt it the most, from a threat table that each monster keeps now.

3:53 Two players can agree to a duel, which counts down from three, and ends once one of them is down to one health.

4:02 They can trade items and gold, in a window where both of them have to say they're ready. Keep the trading in mind, as it turned out to be one of the trickiest parts of the game, and we're going to come back to it.

4:15 And players can start guilds, with a roster, ranks and officers, kept in MySQL a transaction at a time.

4:24 Most of the players you see here are bots. They play the game over the network as a client would, which is how we put the servers under load, with as many as two thousand of them at once.

Around the game

4:35 Around the game, there's a lot more than a game server, and this is where most of the series goes. The client draws the world with raylib and sends what the player does, while the servers decide what happens. It logs in through our login server, over TLS, against the accounts in MySQL. A browser comes in through a WebSocket gateway, which we wrote from the RFC. Each world, Ember and Frost, registers with Consul, keeps its players in Redis, and a saver writes them behind to MySQL. The bots play against the worlds, what the players do goes into ClickHouse, and Prometheus, Grafana, Loki and Pyroscope keep an eye on all of it.

What went wrong

5:13 A lot of what we built came from something going wrong first. In episode thirteen, saving to MySQL after each tick fell behind at fifty players, which is why Redis went in between. Deploys used to throw the players out, so now a world hands its players over to the next version before it stops. And with two thousand bots, a world fell from twenty ticks a second to about eight, and a flame graph showed where the time went, from the broadcast to the kernel's UDP stack.

5:43 On a network slowed down to a 150 millisecond round trip, our player started and stopped walking late. So now, the client walks you the moment a key goes down. When packets got lost, everyone else lurched, so the client draws them a tenth of a second in the past, between two updates it already has. And in a duel, a blow that looked as if it landed could miss. So the server checks it against where the attacker's screen showed the opponent, up to 200 milliseconds back.

6:12 The client runs on the player's machine, so anything it sends can be made up, which is why I keep the game's logic on the server. When a red-team client of ours tried to cheat, the server already stopped most of its tricks. Trading was another story, as the red-team client found two ways to turn two swords into three, and a third, by playing one character on two servers at once, during a deploy. Each of them got fixed on the server, with both sides of a trade saved in a single Redis transaction, and a lease for each character. And Prometheus now alerts us when an item is held twice. If you'd like to pick a few episodes to watch, I'd go for these three, as I think dupes like these come up in most other games too.

6:54 And lately, the client builds to WebAssembly, so the game plays in a web browser, offline, with the world's rules in the page, or online, through that gateway. On the way, raylib sent WebGL its bone matrices untransposed, which stood a tall spindle by each person until a patch fixed it.

Where it's going

7:12 Now, let's talk about the world I'd like nanoMMO to become one day. A disclaimer first: what I'm about to describe might not scale in the end, for one reason or another. My interest is in dynamic intelligence, and in a world that evolves. I'd like to end up with something like Sword Art Online, in the sense of a world that can adapt of its own volition. Along the way, I want to build features that interest me, even if some of them might be impractical for most games, such as a system for the players to create skills of their own. Further down the line, an AI agent could even generate quests on the fly, made for a specific player, and do that for items and such, too. We've taken a small first step already, in episode twenty-five, with a storyteller NPC that writes you a story from a few words, using mvGPT, the small GPT from my other series.

Where to start

8:03 If you'd like to dig in, the website of the series has more information about the project, and a page for each episode.

8:10 On its Play page, you can play the game in your browser, with the world running in the page, and without a server.

8:27 The code is open source on GitHub, tagged at each step of each episode, so you can follow along from the first commit. And if you're new, your best bet is episode one, which sets out the plan, and then the rest of the playlist in order.

Playing it

9:03 Let me know in the comments what you'd like the world to do next, and if you want to follow along, subscribe to the channel. I hope you find this useful, and thanks for watching.