Understanding the different APIs for authoritative/realtime games

Hi there! I’m really liking Nakama so far, but I’m a bit confused about the methods available in realtime vs authoritative. Can the client only interact with an authoritative game through RPCs? Methods on the client like socket.SendMatchStateAsync are only available for realtime games or can you hook onto those events in your custom go/lua module?

Hi @au-re welcome :wave:

I can answer your questions and clear up the confusion.

Can the client only interact with an authoritative game through RPCs?

Different multiplayer solutions tend to refer to messages sent that form command messages as part of the netcode for the game as “RPCs” but in Nakama both client and socket-based RPCs are essentially cloud functions that can be written in Go, TypeScript/JavaScript, or Lua. These functions you can write are essentially RPCs in the original sense of the definition remote procedure calls invoked on the server.

https://heroiclabs.com/docs/runtime-code-basics/#rpc-hook

Methods on the client like socket.SendMatchStateAsync are only available for realtime games or can you hook onto those events in your custom go/lua module?

The multiplayer features in Nakama server fall into two categories:

  • Relayed multiplayer - The server tracks connected presences (peers in the match) but does not store any match state on the server (other than the match ID); and its up to the game to define its own netcode, define the master client (host), and handle host rotation. These are all easy to do but are very much game specific.

  • Authoritative multiplayer - A match is created via the matchmaker hook on the server or with the server side function called nk.MatchCreate. This will create the match handler which is named when registered. All multiplayer messages will flow from game clients to the server match handler and can be processed on a fixed tick rate. The match handler must implement a handful of lifecycle functions.

    You can see an example of an authoritative match handler and how game clients would interact with the server’s match loop in the TicTacToe example we’ve created:

Irrespective of which of the two multiplayer systems you use in the server the game client interacts with the server via the exact same client API. This is by design because it makes it impossible to know via game client code whether the match is authoritative or not.

Let me know if you’d like more information or have a specific multiplayer game design in mind to talk through.

Hi @novabyte thank you for the quick and clear answer! I think I have a good idea on how to proceed now. The guides (.NET/Unity client guide - Nakama server) are really useful, but is there an API reference in the documentation for the client as well? Something similar to: Function Reference - Nakama server but with all methods available in the client.