An example project template on how to set up and write custom logic in Nakama server.
The codebase shows a few simple gameplay features written in all three of the runtime framework languages supported by the server: Go, Lua, and TypeScript. The code shows how to read/write storage objects, send in-app notifications, parse JSON, update player wallets, and handle errors.
For more documentation have a look at:
- https://heroiclabs.com/docs/nakama/server-framework/introduction/index.html
- https://heroiclabs.com/docs/nakama/concepts/storage/
- https://heroiclabs.com/docs/nakama/concepts/user-accounts/#virtual-wallet
- https://heroiclabs.com/docs/nakama/concepts/notifications/
- https://heroiclabs.com/docs/nakama/concepts/multiplayer/authoritative/
For a detailed guide on setting up TypeScript check out the Setup page.
NOTE You can remove the Go, Lua or TypeScript code within this project to develop with just the single language you prefer.
The codebase requires these development tools:
- Docker Engine: 19.0.0 or greater.
- Node v14 (active LTS) or greater.
- Basic UNIX tools or knowledge on the Windows equivalents.
The project uses NPM to manage dependencies which can be installed as normal:
npm install
Before you start the server you can transpile the TypeScript code to JavaScript code with the TypeScript compiler:
npx tsc
The bundled JavaScript code output can be found in "build/index.js".
The recommended workflow is to use Docker and the compose file to build and run the game server, database resources and tensorflow-serving (AI model server).
docker-compose up --build nakama
When the containers have been started as shown above you can replace just the game server custom code and recompile it with the -d
option.
docker-compose up -d --build nakama
To stop all running containers you can use the Docker compose sub-command.
docker-compose down
You can wipe the database and workspace with docker-compose down -v
to remove the disk volumes.
Take the session token in the response and use it to execute the RPC function as the user:
curl "127.0.0.1:7350/v2/rpc/rewards" -H 'Authorization: Bearer $TOKEN' --data '""'
This will generate an RPC response on the initial response in that day and grant no more until the rollover.
{"payload":"{\"coins_received\":500}"}
or
{"payload":"{\"coins_received\":0}"}
You can also skip the cURL steps and use the Nakama Console's API Explorer to execute the RPCs.
The authoritative multiplayer example includes a match handler that defines game logic, and an RPC function players should call to find a match they can join or have the server create one for them if none are available.
Running the match finder RPC function registered as RPC ID "find_match" returns one or more match IDs that fit the user's criteria:
curl "127.0.0.1:7350/v2/rpc/find_match" -H 'Authorization: Bearer $TOKEN' --data '"{}"'
This will return one or more match IDs:
{"payload":"{\"match_ids\":[\"match ID 1\","match ID 2\",\"...\"]}"}
To join one of these matches check our matchmaker documentation.
The development roadmap is managed as GitHub issues and pull requests are welcome. If you're interested to add a gameplay feature as a new example; which is not mentioned on the issue tracker please open one to create a discussion or drop in and discuss it in the community forum.