MMO Journey: Weeks 5-6 (network's hard yo)

OK, so I had decided I was making an MMORPG.  I'm not entirely sure how M of an MORPG I'll be able to make, but I'm going to keep using the term MMO regardless because MO or MORPG just sounds weird to me.

The first thing I did was set up a sandbox in Unity using free assets, where I could run around in first-person on some terrain.  From there, I needed to get the game talking to some sort of server, right?  I decided to use C++ for the server for a few reasons:

  1. Performance.  I honesty do want to attempt an MMO, and I know I won't come close with a run-time language like Ruby/Perl/Python.
  2. Linux compatibility.  I have access to Linux servers and am very comfortable working with Linux.  I don't like the idea of running a C# server on Linux, even though that would make life easier (I'm using C# for Unity scripting), and just the idea of trying to operate/manage a game server environment on Windows machines makes me want to cry.
  3. Relevance.  C++ has been used to make games since the beginning of time.  Chances are if I run into a problem it'll be easier to find an answer with C++ vs Rust, Go or some other compiled language that isn't commonly used for game development.
So, C++.  Having no idea what I was doing, I dived in and started hacking around with Boost.Asio, a C++ network library.  I decided to use TCP instead of UDP, because an MMORPG doesn't need real-time feedback.  Additionally, it's important that the game messages make it back and forth reliably, and if TCP is doing that I won't have to worry about in code. After a few days, I managed to piece together a very basic server that would reliably accept TCP connections and packets.  From here on out any time I mention game messages I'll be talking about the things that get sent between the client and server.

I decided that for performance I was going to create custom messages at the byte level, to cram as much information as possible into my packets.  In theory an MMO server will be sending and receiving thousands of packets each second, and the last thing I want is to have to do a bunch of string processing on each packet.

My first stab at a "PositionMessage" (a message that communicates position) just took the player's position (x, y, z) and turned those into bytes, popped on a header to identify it as a position message.  This got sent to the server, which decoded it, printed out the coordinates to the console, then inserted the message into a Boost.Signals queue that caused it to get echoed back to the client.

"Great! Now it'll be easy to have two people logged in and watching each other move around." I thought. Hahaha, NOPE!

The first thing I realized is that I had no way of even identifying two different people and logging them into the game.  I had a rough idea of how to get the messages back and forth once all that happened, but that meant nothing without more than one client connected.

Previous entry
Next entry


Popular posts from this blog

MMO Journey: Weeks 7-9 (logging in)

MMO Journey: Week 10 (binary message hell)