🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

A decent (ideally simple) C# MMO game server example?

Started by
10 comments, last by Armchair-Advisor 3 years, 2 months ago

Hi everyone,

This is my first post here, but hopefully not the last one (and hopefully I'll be able to provide support rather than asking for it shortly).

I'm a software engineer with a few years of experience, working predominantly with C# (but also other tech stacks).

I'm very keen to learn more about game dev and figured that the best way to do that in my case would be to look at some good examples.

And so here I am: I'd like to ask you guys if there are any example games (MMO) / game servers that you'd recommend me to take a look at in my pursuit of knowledge? What I'm interested in finding is the libraries and project structures most suitable for use in game dev (server side) and certain techniques specific to building real-time game server.

Ideally I'm looking for .NET Core / C# examples, but Java, Go or Rust would do too. The aspects I'm interested in the most are networking, communications (protocols, encryption, etc.) and state management.

While I have a pretty decent idea how I could approach it, I also value the lessons that come from people who've been there before me.

Thanks in advance!

Advertisement

MMOs are really hard to build. Not mainly because of technology (although that matters, too) but because of the massive amount of content you have to build to support a massive playerbase, and then the massive amount of marketing you have to do to actually reach a massive playerbase.

Because of this, they generally aren't “open source,” and thus, it's not that common to see publicly available code for a MMO.

In addition, MMOs vary a bit in what their requirements are. Planetside will have different requirements from Wizard 101, will have different requirements from Roblox, will have different requirements from WoW, will have different requirements from Eve. For example: A game like Planetside, having strong first-person-shooter elements, will likely use UDP for the gameplay networking bits, whereas a less action-oriented game can get away with TCP just fine, and thus simplify certain parts of the messaging stack. Similarly, whether you focus on building or combat or exploration or trading, and whether your game is naturally split into separate zones/systems/levels or just one big continent, matters to the technology.

The main, top-level, piece of advice I can give, is that business networking is mainly about robustness, de-coupling, and backwards compatibility. Game networking is mainly about performance (both latency and throughput,) and it generally makes vastly different trade-offs, especially in the “real-time gameplay state” area, from what you'd do in a business service environment. If you haven't done low-level game networking before, for some action game, you're unlikely to have enough exposure to recognize the right parameters for each use case, so maybe a good idea is to start by picking apart some existing networked action game – there are tons of Unity or Unreal Engine games that might be helpful (although some of those, are pretty bad, too… as is always the case with “free as in speech/beer” things; quality varies!)

enum Bool { True, False, FileNotFound };

hplus0603 said:

MMOs are really hard to build. Not mainly because of technology (although that matters, too) but because of the massive amount of content you have to build to support a massive playerbase, and then the massive amount of marketing you have to do to actually reach a massive playerbase.

Because of this, they generally aren't “open source,” and thus, it's not that common to see publicly available code for a MMO.

In addition, MMOs vary a bit in what their requirements are. Planetside will have different requirements from Wizard 101, will have different requirements from Roblox, will have different requirements from WoW, will have different requirements from Eve. For example: A game like Planetside, having strong first-person-shooter elements, will likely use UDP for the gameplay networking bits, whereas a less action-oriented game can get away with TCP just fine, and thus simplify certain parts of the messaging stack. Similarly, whether you focus on building or combat or exploration or trading, and whether your game is naturally split into separate zones/systems/levels or just one big continent, matters to the technology.

The main, top-level, piece of advice I can give, is that business networking is mainly about robustness, de-coupling, and backwards compatibility. Game networking is mainly about performance (both latency and throughput,) and it generally makes vastly different trade-offs, especially in the “real-time gameplay state” area, from what you'd do in a business service environment. If you haven't done low-level game networking before, for some action game, you're unlikely to have enough exposure to recognize the right parameters for each use case, so maybe a good idea is to start by picking apart some existing networked action game – there are tons of Unity or Unreal Engine games that might be helpful (although some of those, are pretty bad, too… as is always the case with “free as in speech/beer” things; quality varies!)

All good points and everything that I'm aware of. That's really why I asked for some decent examples, because if I were to pick apart existing games I'd also learn the “pretty bad” stuff too.

So I'm more than happy to take a look at these Unity / Unreal games, it would make it easier if I knew which one are worth looking at ;-)

And I should have been a bit more clear here, I'm not looking for a complete game that's been open-sourced, but something very basic - the rest of it I can figure out myself. Just on your point around business vs game networking, I'm well aware of these differences.

Also back in Lineage (1) ages I had a great interest in gamedev, so I had a chance to look at private servers / emulators code. Except I didn't think the code was any good and I doubt my opinion would change now.

But perhaps I'm naive to think that you can have code optimised for games and yet make it manageable. I'll learn the hard way soon enough I suppose.

I really appreciate your reply and if there are really no good examples are there at least some basic tutorials? It's not like I can't start without any of it and try to figure it out myself, but trying to re-invent the wheel (and probably failing number of times before nailing it down) is not something I'm particularly interested in ;-)

The closest I know about are the “MMO Starter Kit” type content packs on the Unity and Unreal asset stores.

The draw-back is that they're probably not built by people who built and shipped a successful MMO before, so it might be a bit of “learning together" to jump on those ;-) But if you want some code to read, that's code that's pretty cheap to buy. Read it, throw it away, and then build your own thing!

enum Bool { True, False, FileNotFound };

If you want to stick to C#, you will probably stick to unity or Godot as your game engine.
I would say, the next question then is: Do you want to write your dedicated server code, or will you use the game engine for your server application as well. Writing the server application with .NET will most likely result in better performance/scalability than using the game engine. However, if you need a lot of components of the engine (like physics) or want to develop in the same environment you might be better off with using the engine.

.NET

If you want to build a separate server application, ENet and LiteNetLib might be interesting networking libraries to take a look at. I built a benchmark that might help you in your decision process: https://github.com/JohannesDeml/NetworkBenchmarkDotNet​ It also includes links to simple examples. Note that this is quite low level, and you will need to build a lot of logic on top of the libraries.

Unity

If you want to stick to unity, there are multiple libraries out there you can use. Have a look at MLAPI (their official library) and Mirror. If you want to have an even simpler solution photon or normcore might be a fitting choice. For searching for fitting examples, I recommend using Unitylist for searching for examples for the tech of your choice.

Godot

Not a expert here, but I know that Godot is using ENet for their networking and saw a youtube tutorial for Multiplayer networking that might be interesting for you: https://www.youtube.com/playlist?list=PLZ-54sd-DMAKU8Neo5KsVmq8KtoDkfi4s

I hope this gives you a starting point ?

None

hplus0603 said:

The closest I know about are the “MMO Starter Kit” type content packs on the Unity and Unreal asset stores.

The draw-back is that they're probably not built by people who built and shipped a successful MMO before, so it might be a bit of “learning together" to jump on those ;-) But if you want some code to read, that's code that's pretty cheap to buy. Read it, throw it away, and then build your own thing!

Thanks a lot, appreciate it. Who knows, maybe it has been built by people who shipped a successful MMO ;-) Worth looking at them regardless!

JohannesDeml said:

If you want to stick to C#, you will probably stick to unity or Godot as your game engine.
I would say, the next question then is: Do you want to write your dedicated server code, or will you use the game engine for your server application as well. Writing the server application with .NET will most likely result in better performance/scalability than using the game engine. However, if you need a lot of components of the engine (like physics) or want to develop in the same environment you might be better off with using the engine.

.NET

If you want to build a separate server application, ENet and LiteNetLib might be interesting networking libraries to take a look at. I built a benchmark that might help you in your decision process: https://github.com/JohannesDeml/NetworkBenchmarkDotNet​ It also includes links to simple examples. Note that this is quite low level, and you will need to build a lot of logic on top of the libraries.

Unity

If you want to stick to unity, there are multiple libraries out there you can use. Have a look at MLAPI (their official library) and Mirror. If you want to have an even simpler solution photon or normcore might be a fitting choice. For searching for fitting examples, I recommend using Unitylist for searching for examples for the tech of your choice.

Godot

Not a expert here, but I know that Godot is using ENet for their networking and saw a youtube tutorial for Multiplayer networking that might be interesting for you: https://www.youtube.com/playlist?list=PLZ-54sd-DMAKU8Neo5KsVmq8KtoDkfi4s

I hope this gives you a starting point ?

Really appreciate your input. After a lot of reading I'm considering C# or Rust (for the server side) and C# + Unity / Godot (I'm familiarising myself with both to make an informed decision) for the client.

This also implies that I intend to build a server application rather than using a game engine. My priority is not building a complete, complex game, but rather learn as much as I can by going as low-level as it usually takes.

I had a look at the benchmark briefly (checked the libraries and yet to look at the actual results). Is there a reason why your benchmark doesn't include https://github.com/GlaireDaggers/Netcode.IO.NET?This is the first library I found that does networking specifically for game se

rvers.This is the first library I found that does networking specifically for game servers.

I haven't touched netcode.io so far, since I have the feeling, that the .NET/Unity port is quite dead. There hasn't been a lot of development/traction in either the unity forum nor the github repo and the maintainer hasn't been active in the forum for over two years now. It might still be a valid choice, would love to hear your experience with it, if you go down that route. ?

None

You can find some open source examples of 2D MMO servers (for the game Open Tibia) here:

Main Open Tibia Server distro (C++/Lua, 200k lines of code, very stable and thorough server, developed over the past 20 years by hundreds of devs): https://github.com/otland/forgottenserver

C# distros (usually smaller in size and simpler, made by usually less than a handful of developers, often just a couple): https://github.com/search?l=C%23&q=open+tibia&type=Repositories

Worth noting: These are tile based servers that runs 100% of the game logic on the server side.
Anything that isn't tile based won't fit this (thorough) model, in which case you'll instead have to come up with sneakier models that just tries to catch cheaters when they're doing something fishy (walking through walls, walking too fast, teleporting, levitating, shooting through walls, etc).

JohannesDeml said:
If you want to build a separate server application

The best library I ever found for .Net is NetCoreLib. It is small and doesn't need/use any native code as you anyways have to implement package logic for your specific needs. It also comes with a lot of example server/client implementations

Shaarigan said:

The best library I ever found for .Net is NetCoreLib.

Interesting you mention that particular one. I thought, that NetCoreServer should have the best performance for simple unreliable non batched messages, but from the benchmark posted before (This benchmark is the fair comparison for NetCoreServer) it seems like ENet is a better choice on windows and especially linux. Additionally, for NetCoreServer I miss things like batching or support for reliable messages. Sure you can build that all yourself, but I'm not sure it is worth the additional effort instead of using ENet or LiteNetLib. Or am I missing any advantages you gain from NetCoreServer other than being fully managed and freely portable to all platforms?

None

This topic is closed to new replies.

Advertisement