Building a Multiplayer Server

Building a game for for multiplayer online use can be a challenge. A couple of months ago I started using Nakama, and it is a brilliant system for mp gaming and chats, etc. Its very well thought out and provides a very large array of features.

I want to be extremely clear about my use-case, Nakama wasnt really the right “fit” for the game I was making, and I really only found out that while building the game and using Nakama. The type of game I am building is a group discussion game where the webapp allows people to control the game flow and outcomes. In this manner I wanted a system that was extremely simple to join and create a game without all the login/handshaking/user management that alot of server systems have - Nakama has this. These systems are very important for things like realtime fps or high frequency controlled data sharing - but it isnt really suitable for the game I was making.

To explain, what I was looking for were the key following features:

  • No login or signup process - the app handles the device login, and handshakes for the auth.
  • Can easily generate a game from a name - the internal systems allow direct name lookup for the game.
  • Players can drop/in out of game lobby easily (backend handles all of it)
  • Modular game executions on backend (Ideally a luajit vm running it)
  • Admin panels and control to monitor and modify modules, games, and user profiles.
  • Wanted it to be properly open source(MIT)
  • A nice Defold client API.
    Its not an exhaustive list, but some of these things proved difficult to do in Nakama without spending alot of time building an RPC system to create the results I needed.

Additionally I wanted a simple SQLite based backend DB that allows me to snapshot state of the server if needed. I had built a number of luajit + Sqlite systems before so it seemed like a reasonable choice for the system type.

SWAMPY was born. Dont ask about the name, it was a tag I used and now its stuck :slight_smile:
The aim of SWAMPY is to meet the above features using a luajit based environment entirely written in lua. Yes, this is going to get a bit weird from here on in. The entire server is written in lua using a great toolkit and framework I have used in the past called luvit (www.luvit.io). It should run on pretty much any platform - technically you could run a server on your phone, which would be a bit odd.

The only real dependency is the libsqlite library used. I may compile that into the exe at some stage if I get the urge to. The whole thing, website + admin + luvit + luascripts = 17MB. Yes. 17MB. And this is a debug build, so expect the release to be < 8MB. This is another reason why I am a big fan of luajit based systems - cross platform, extremely tiny, and extremely fast with low resource overheads ( Mem use < 48MB with debug ).

SWAMPY is in its early stages of alpha testing. Most of the features are good to use and I am building my game to use them and trial it. Once I have deemed it stable enough to use, I’ll put it up on github for people to do whatever they want with it (along with the Defold Client).

SWAMPY still needs many things done to be properly user friendly too (especially on the admin side):

  • A decent UI theme. I need to spend some time on this and make it look nice.
  • Remove the placeholder data and put the proper data in (I have it, but not a priority atm).
  • Add a couple of nice admin login features - Google, Insta and FB auth as well 2FA would be good.
  • Data editing for the Sqlite db - this is high on my list of todos. It will probably be done sooner than later.
  • Many module and user related features…

I made this dev diary so that I can update here, and give some general idea about what I have been building to be used in this forum article at a later date: Peer 2 Peer Networking and State Buffers
(No I hadnt forgotten - life has gotten in the way).

My aim is to have this and the forum post all sorted over the next month (eta end of August) all things going well. I hope to have SWAMPY ready for consumption in the next two weeks along with my game Soul Survivor :slight_smile: … that may be a little optimistic, but it should be doable.

For the time being, here are some screenshots of SWAMPY in the web admin, and a couple of screenshots from Soul Survivor. Thanks for reading this far! :slight_smile:
SWAMPY Dash - ignore the stats, they are just placeholders

SWAMPY Profiles - users connected that are joining a module (game type).

SWAMPY Games - list of running games

Screenshots of Soul Survivor (wip)


Oh. Another interesting note. Soul Survivor is entirely written in Defold + imgui. There are no Defold ui elements used in this system. And its quite ui intensive - the game elements. I might write a whole dev diary on Soul Survivor and imgui - thats been a pretty interesting process, and its alot more powerful than I thought it would be.

26 Likes

Sounds fascinating. I’m assuming this game is designed for an app on the phone? I think it’s a cool idea, and has given me an idea for another game. Thanks for posting this!

What inspired you to this game? How do players start a game/invite others? What other kinds of games do you think would work for SWAMPY?

Hi Spencer. The game is designed for a phone and web. I’ll be adding voice chat so people can play remotely too (thats further down the track though).

Its kinda inspired by a whole tun of board/card games me and my family play. Like Secret Hitler, the Werewolf one (forget the name), a game called Chameleon which can be harsh :slight_smile: … and some others. The goal was to make something that is fun in the creation stage, and then also in the discussion stage. Most discussion games have problems with arbitration, so we added a judge… and it works well.

We are making a prototype card game and will hopefully have a kickstarter in a month or so.

Starting a game is built a bit like some other phone games. The app finds a server (atm the only 1, but it will use geoip and find closest). A player then simply “joins” a game with a nominated name - I generate random ones if people want. Then other players join by simply providing the same name. At the moment theres no passwords so you may land in someone elses game if its in lobby mode :slight_smile: … thats easily fixed if you want a private game (passwords). Once the minimum amount have joined the original creator can start the game, and others can click “ready” to allow the creator to start it.
Some of the gameplay also occurs in the lobby… so while you are waiting you can not get too bored while waiting :slight_smile:

SWAMPY really was made for this type of game. However, its all REST / API based at the moment, so it would work well for simple event styled dropin games. Like board games and card games. It can do more complex ones, because you can write sockets in the modules and have clients join to them, so its not impossible to write a rts or fps in it if you really want, but I’d need to make sure the API has the features needed for it.

4 Likes

The server side solution sounds like something @88.josh could use for his digital version of Malas Decisiones. @88.josh: I can’t remember if you ever completed the digital version or not?

1 Like

Update: Have been running the server for two weeks now for dev testing and it seems quite stable. Going to put together a little sample for people to test with. Due to house issues, this has all taken far longer than Id like, but at least its working and the game soul survivor is looking fine too so I hope to wrap this all up in the coming couple of weeks.

7 Likes

Ok. The server is up. It is currently empty (I removed my IP from it). I will be adding a little test MP game using Defolds demos. Probably a little twist on the Tank demo :slight_smile:

If you have any questions raise an issue or msg me. It should be fairly simple to get working. Highly recommend using Docker-Compose or, if you want to dev you can run it directly. I’ll add some more docs tonight in the swampy folder on how to do that.

7 Likes

Really cool! Thank you for sharing!

1 Like

Ok. Theres now a simple sample module. Its not fully complete, but should be in a day or so.
Once thats done, there will be a little War Battles example added as well - probably a week away.

The warbattles is here (not complete).

This should be wrapped up in around two weeks. Then I’ll sort out the state buffered networking sample using this. Sorry its taken so long, work and life… you know.
Just to let you know our little dog died (of 18yrs), we renovated and sold our old house of 12 yrs, Started a new major project with fmad.io (exciting, but lotsa hours) and many family events in between… I know everyone has things going on, I just want people to know I am committed to Defold and will get these projects sorted as best I can.

And again… really love working with Defold and I am very appreciative of the hard work everyone has done to make such a nice system to work with. Kudos to you all!

10 Likes

Test example all working nicely. Sample module is able to be used as a basis for games.
Currently event/poll based and a few features yet to be added:

  • Module per Luajit env
  • Websocket sample for realtime games (FPS, RTS etc)
  • Data exchange example in the module

Some of these will be added over the coming weeks (for use with the War Battles MP demo).
Otherwise its in a fairly good condition. Feel free to hassle me if you need anything specific.

8 Likes

Added a bit more to the admin. Some tidy up and some gfx.
Fixed a number of issues with the example. And adding in a module for War Battles MP.
On track to have War Battles MP working by end of week - fingers crossed.

11 Likes

Ok. War Battles MP is starting to work.
I need to make sure everyone understands what this is and what it is.
What is isnt:

  • A useful RTS/FPS example
  • A high speed low latency game server and client
  • Hugely scalable network game system for realtime games

What it is:

  • An example of http (yes, you read right) only realtime game server
  • A starting example of how to do multiplayer state sharing (badly atm)
  • A demonstration of the module system for swampy to run a gaming session with a different style of game (non event based)

I’ll add in the tanks (driven from game module) tomorrow and that will probably be it for this example and setup for the time being. People are welcome to use and abuse the code/systems as they need :slight_smile:

Here’s a little sample of two players in a game. The lag is roughly a 300 ms round trip with interpolation. And the http req’s stack up a bit. I’ll improve this, it should end up reasonably snappy.
There are also a bucket load of bugs to iron out. Nothing too nasty though. Enjoy.

10 Likes