So, you want to build an MMORPG Server

Published by

on

Even researching how to build an MMORPG server is a large undertaking. There are so many different architectures and designs, components and considerations to take, even before you start coding. It helps to have a high level understanding of what and why it is so complicated. Please keep in mind I’ve Never Done This and this is all new to me, but I have been researching different designs over the years just kind of in passing, as I seek out knowledge on the subject matter.

For a really nice break down on what the server actually needs to do, I highly recommend reading through The Server Loop. Done? Good. So now you know the time and complexity constraints here. Just like a game engine, we have a pretty strict time frame in which to execute a large number of actions:

  • Handle client input (including decrypting messages)
  • Perform movement (player and AI)
  • Perform actions (player and AI)
  • Tick timers
  • Update physics
  • Serialize world/state changes (hopefully creating just a delta)
  • Encrypt and send state back to all clients

All of these actions must be done in the loop, and it’s usually time boxed to certain rates, usually in terms of Hz (sometimes called ticks, this is actually the same as FPS, but we ain’t got no renderer, so we ain’t got no frames). My understanding is that there’s a few common tick rates:

  • 20
  • 30
  • 60 (usually First Person Shooters/Fighter games)

Some MMORPGs, such as albion online state they have no tick (See slide 23). I would absolutely love to see that code base by the way. I think they have probably the best architecture (or at least, the best documented one!), that I’d like to mimic.

But for now, let’s assume we have a game loop with a tick rate. I’ll probably shoot for 30hz, but assume I’ll hit 20hz due to my significant lack of C++ experience. Why C++? Because that’s what I want to write it in. Although I mostly program in Go, the client is UE5 (C++) so it just makes sense to keep everything in C++.

Why even make your own server?

Some of you may ask, why a custom server at all? Why not use UE5 engine? With everything that needs to be calculated for more than 64 clients, there’s just no way a single UE5 instance could handle the load. Hence, you really need a headless/non-rendered engine. Also, you don’t need all the full complexity of a true Game Engine. You can "cheat" in a lot of ways.

OK so with that out of the way, what kind of architectures are we looking at?

Architectures

  • Map-Centric – Splits the World and Areas into separate servers, this is how Albion Online does it with some additional smarts around Areas of Interest
  • Responsibility-Oriented – Splits the servers into their responsible domains (AI, Gameplay, Visibility)
  • Seamless World – Probably the most complicated, but takes the Map-Centric approach and splits the areas even further, but also allowing some overlap for seamless travel for users across servers. Ever notice a lag spike in an open world game while transitioning between areas? That’s it unloading/loading all the state.

I think I’ll start with Big Ass Monolith, with components built via interfaces so it could be built into a Map Centric architecture when needed, (or if ever I get to that point :fingerscrossed:).

OK. So architecture is a bit set, what kind of components will I need here?

Required Components (Just the game server, not supporting services!!!)

These are just the high level ones. We also need database servers for like auction houses and user items and long term storage, login servers, load balancers and everything else!

  • Reliable UDP server/client code
  • Encryption/Decryption routines (hello cha cha poly!)
  • Server-side prediction
  • Serialization/Deserialization
  • Area of Interest System
  • Timers
  • World persistence (Custom Data structures or…)
    • All objects, possibly using Entity Component System (ECS) framework
  • Mesh loaders (FBX?)
  • World / Landscape Meshes
    • Navigation Mesh (NavMesh) System
    • Collision Meshes
  • Simple physics engine (falling, possibly jumping)
    • Collision Detection (AABB)
    • Player collision (Good fun for body blocking)
  • AI for NPCs/mobs
  • Pathfinding (A*)
  • Ability System (think attack abilities, DoTs, Buffs etc.)
  • Weather System
  • Quest System
  • Group/Guild/Clan/Alliance System
  • Chat System
  • World Event System
  • Outpost/Castle/Housing System
  • Sieging System
  • Calendar System for Sieging (If allowed)
  • Reputation System (Griefers… shadow banning, or kill counting/titles like EQ2)
  • Anti-Cheat/Bot Detection Systems

A lot of the above strongly depends on how I’m going to structure my data. I have been researching Entity Component Systems (ECS) a lot the past two days and it seems almost too good to be true for an MMO RPG server.

Entity Component System (ECS)

If you’re not familiar with ECS, you should read the Entity component system wikipedia page. Basically, it’s an alternate design for working with lots of objects that doesn’t really care about inheritance, but cares more about composition. Meaning you can add new re-usable components to your entities relatively easy. It’s also amazing for performance because it’s extremely easy to cache objects that are in arrays. ECS seems really good for creating ability systems. If you’ve ever tried to write your own they are and can be EXTREMELY complex. I tried previously for my failed MOBA project.

The two major ECS frameworks for C/C++ are flecs and entt. While entt has a few bigger backers and users, I really like going with frameworks that have good tooling. And flecs’ tooling looks amazing. This is ESPECIALLY important for server side coding because we don’t have a rendered output to easily see what objects exist. With their built in tooling, the server debugging of entity related problems should be far easier to reckon with.

What about the game Client?

Are you kidding? Unreal Engine of course :>. There’s even flecs integration tutorials!

Wrap up

Phew ok that’s a lot, as you can see you absolutely should not write your own MMO RPG server unless you have lots of time and patience. (I have neither ha ha!) But it’s too interesting not to try anyways!

So to recap:

  • Server in C++
  • Clients over UDP (I didn’t discuss but there’s a reason for this, maybe the next post)
  • Going big monolith (Scale? Who needs scale when it’s just me!)
  • Flecs entity system
  • Unreal Engine 5 client

I think my next post will be getting my environment setup:

  • Linux
  • CMake
  • Boost Asio server? (Maybe)
  • ENet for reliable UDP? (Maybe)
  • Need to choose a testing framework
  • Need to choose a logging framework

Some Random links:

Netcode

  • ENet Reliable UDP network library, tried and tested
  • GPPO Network rollback library (mainly used in fighting games which have ridiculously high latency/perception constraints!)
  • yojimbo Reliable UDP network library, with encryption/authentication. Unfortunately best suited for FPSs, not MMORPG

Resources & Links