Warbattles MP - Nakama

After discussing some problems with users on Discord about Nakama and some of its uses, I wanted to convert my old warbattlesmp which works fine with my Swampy server, to work with the Nakama server.

I did try this about three years ago, but there were various problem trying to achieve certain capibilites for realtime mp networking.

I have currently converted a fair portion of the code across, and its taken alot longer than I originally thought it would, and mostly because I think Nakama is more suited to event styled networking and not really ideal for realtime mp (note: this is based on the free github server version).

Some of the key problems encountered:

  • Connecting to named matches directly (without matchmaker). This seems like a simple thing, but people have asked on the Nakama forums it, but it isnt implemented. So I made a rpc that does it.
  • The match_loop is heavy if you have too many ticks, and you will get issues (timing, sync etc) if you run it too hard (this is mentioned in the docs). This limits what you can do in this loop, but its really the only place you can do realtime updates on client input (I got around this too).
  • Modules are not really modules in Nakama. It looks like if you init a match which uses a module, that module cannot be loaded into another RPC and the state used. These are not the same env. I understand this, but it limits lua’s use heavily. However there are undocumented feature that can help (detail below)
  • Documentation. Is very inconsistent. And there are not enough sample to really show how to use the Server and Client side with something like a realtime game.

While the above are not completely disastrous, if you dont know how to get around them you will get frustrated.

Some helpers:
nk.localcache_put( "MyCacheObject", MyCacheObject, TTL or 0)
This can store a table in the local cache for a certain amount of time (0 is infinite)
local mycacheobj = nk.localcache_get( "MyCacheObject" )
This fetches the table from the local cache.

Use RPC where you need to get around things, in combo with the above methods. You can do quite alot with this. It is more management of your own state, but imho, thats kind of better anyway.

The current repo Im working on is here:

I will attempt to document things as much as time allows. Its extremely prototype atm, but it works in terms of client sending realtime data to the server and the server state updating and handling it.
I hope to have this working decently by this weekend, but I said that last week. I have gotten past the main problems with the modules (which was driving me nuts) and I really hope this will be able to work as a demo for future reference or just something to point and laugh at the code :slight_smile:

NOTE/WARNING: Make sure you remove the last line in main.lua which authenticates a fixed ID for a device - Im using this in a ‘hacky’ way to auth devices manually.

For those wanting to look at SWAMPY its here (currently going through some upgrades):

9 Likes

Oky dokes. Finally. Its working (base level).

This is a direct data update there are some missing bits (will add tonight):

  • Player init position for new players are off until they move.
  • There is no sync atm. Each player gets propagated state server does not check.
  • There is no score correction and collision validation from server. Fairly easy to add something.
  • Can be a bit flakey to connect to from same machine (the device_ids I dont think are great).

However… it works. Feel free to use and abuse as much as you want :slight_smile:

4 Likes

This looks awesome can’t wait to test it out!

No probs. Will update docs and be cleaning up over the next few hours. Should also have some basic working collision and some fun bits - like being able to explode your opponents across the map :slight_smile:

1 Like

Added some little bump phsyics when you shoot a rocket at someone.
Didnt end up adding much sync. Future additions…
Theres alot that can be done with this. Im shutting down my nakama server for this, so you will need to setup your own. I will add some more docs to the repo readme to describe this in more detail.

3 Likes