Server authoritative unity


So I’m having a hard time understanding the documentation regarding how to write functions server side that will dictate what clients can and must do at a given time.

I have more experience with other solutions like PUN but on a p2p level not a server authoritative like the one I’m working on right now.

The first mini game I’m trying to make is fairly simple, it’s a hyper casual 2 players game where one player has to select a number and second player has to guess if the first player has selected an odd or even number.

So basically I need to be able to do the following :

1)Server decides randomly which player starts and tells the client that they can play or wait for the other client to play

  1. Client 1 selects a number and send that information to the server

  2. Server tells client 2 they can play and client 1 they have to wait for client 2 to play

  3. Client 2 tells the server if they think client 1 number is odd or even

  4. Server compares the answer and determines if client 2 has won or not and tells it to both clients.

It adds score to client 2 if it has won or to client 1 if client 2 has lost

  1. Server starts a new round and this time client 2 starts and client 1 will bid on odd /even.

So fairly simple, but I don’t really know how to start with writing these functions server side.

Thank you for your inputs,

@atv The Nakama project template repo contains full examples in Lua, Go, and TypeScript for a server-authoritative multiplayer tic-tac-toe example. It will show you how to get players into matches, manage server-side state, control who needs to submit data next, decide winners, and even play multiple rounds in the same match.

I suggest you start there and experiment with that example. :+1:

Thank you for your time and your answer.

I took the time to review once again the template repo that I had already seen but it’s not helpful unfortunalty.

I guess most of the things I’m looking for are in the game handler script but it does not change the fact that I don’t understand the logic lying there and that I still don’t understand exactly how to connect it with the rest of the game in unity. It’s really confusing.

Previous stages were clearer, mainly due to the fact that they were back up by videos on your youtube channel which is not the case with the part I’m struggling with at the moment.

If i were you i would start by questioning whether you really need the server to decide which player goes first, because you can likely also achieve what you want without an authoritative server which means you could just follow the fishgame tutorial videos.

opcode 1 can be for determining who goes first.
2 could be that the first player has picked a number.
and 3 could be that the second player had guessed odd or even.

for example: Have each client generate a random number between 0 and 100 and send that to the match and compare those numbers to determine the first player.

if you however decide that it’s important to have the server decide it, start by building an authoritative server, these two have a video describing the process:
Typescript: TypeScript Setup - Heroic Labs Documentation
Golang: Go Setup - Heroic Labs Documentation
or Lua (without video): Lua Setup - Heroic Labs Documentation

And once you have that create the match upon matchmaking, and already decide the first player.


Yes, we need to have a server authoritative system for this game.
Now, the server is running locally using docker on a mac, but we can’t even manage to install typescript module on it despite following the documentation, all the folders and files are here as per the documentation but the server administration interface says that no javascript module is installed and it doesn’t show the “hello world” contained in the index.js in the console.

We only have that message : can’t find a suitable configuration file in this directory or any parent: not found

Are you using the dockerfile from the documentation, or made some changes to it?
And are you using Docker Compose?

because the docker compose has this line --config /nakama/data/local.yml but in the dockerfile it’s placed in . which points to /nakama/ if I’m not mistaken.
So changing that line to:

COPY local.yml /nakama/data/

might help you further.

Yes I’m using Docker Compose and the dockerfile from the documentation. BTW, what extension should the dockerfile be as it’s not indicated ?

I’ve made the change you asked in the dockerfile, but it doesn’t seem to solve the problem.

The docker compose logs shows this :
21T13:58:48.187Z","caller":"server/runtime_javascript.go:524","msg":"Initialising JavaScript runtime provider","path":"/nakama/data/modules","entrypoint":""}

{"level":"info","ts":"2021-11-21T13:58:48.188Z","caller":"server/runtime_javascript.go:1466","msg":"JavaScript runtime modules loaded"}

{"level":"info","ts":"2021-11-21T13:58:48.188Z","caller":"server/runtime_javascript.go:1469","msg":"Allocating minimum JavaScript runtime pool","count":16}

{"level":"info","ts":"2021-11-21T13:58:48.188Z","caller":"server/runtime_javascript.go:1477","msg":"Allocated minimum JavaScript runtime pool"}

{"level":"info","ts":"2021-11-21T13:58:48.188Z","caller":"server/runtime.go:610","msg":"Found runtime modules","count":0,"modules":[]}

{"level":"info","ts":"2021-11-21T13:58:48.188Z","caller":"server/leaderboard_scheduler.go:91","msg":"Leaderboard scheduler start"}


But no sign of the Hello World message and then when we check the Nakama console, it says there is no javascript module installed.

Yeah so that means it definitely can’t find the config yaml or it isn’t passed to the container correctly, because the config file has “runtime: path:” to tell where those modules are located.

I personally am using golang and got that working, i’ll be able to check what’s wrong with the typescript one tonight.

Did you get any errors when you tried to build the docker image?
Anyhow I got the basics working quite easily but maybe this helps you find the issue:

No, I don’t get any error messages.
Should the Dockerfile be a txt file or something else?

Dockerfile doesn’t have an extension, you can try with the repo I linked, that resulted in a working situation for me.
If you want to keep your own files instead i suggest going through the files to compare and adjust your files where needed.

Tried using the dockerfile from the repo, it still says no javascript modules were found in the Nakama console and no sign of the hello world message in the server logs

try checking out that repo, and see if that starts correctly (which it does on my machine :smirk: )
because the problem can be in any of the other files too, not just the Dockerfile :sweat_smile: