Learn-Nakama - An example project template on how to set up and write custom logic in Nakama server

Overview

Nakama Project Template

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:

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.

Prerequisites

The codebase requires these development tools:

  • Go compiler and runtime: 1.15.2 or greater.
  • Docker Engine: 19.0.0 or greater.
  • Node v14 (active LTS) or greater.
  • Basic UNIX tools or knowledge on the Windows equivalents.

Go Dependencies

The project uses Go modules which should be vendored as normal:

env GO111MODULE=on GOPRIVATE="github.com" go mod vendor

TypeScript Dependencies

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".

Start

The recommended workflow is to use Docker and the compose file to build and run the game server and database resources.

docker-compose up --build nakama

Recompile / Run

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

Stop

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.

Run RPC function

A bunch of RPC IDs are registered with the server logic. A couple of these are:

  • "rewards" in Go or as "reward" in Lua.
  • "refreshes" in Go or as "refresh" in Lua.

To execute the RPC function with cURL generated a session token:

curl "127.0.0.1:7350/v2/account/authenticate/device" --data "{\"id\": \""$(uuidgen)"\"}" --user 'defaultkey:'

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.

Authoritative Multiplayer

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 the documentation on individual client libraries here.

Contribute

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.

Finally, we love feedback and would love to hear from you. Please join our Forums and connect with us today!

You might also like...
Перевод книги «Learn Go with Tests» на русский язык.
Перевод книги «Learn Go with Tests» на русский язык.

Изучите Go через тестирование Обложка нарисована Denise Форматы для чтения Gitbook EPUB or PDF Доступные переводы English 中文 Português 日本語 한국어 Türkçe

A series of small code snipppets & exercises to learn Go.

Learning-Go A series of small code snipppets & exercises to learn Go. WARNING: During this excercise you will be learning along with me, I am not your

Learn the Go programming language (Golang) in this step-by-step tutorial course for beginners

Learn the Go programming language (Golang) in this step-by-step tutorial course for beginners. Go is an open source programming language designed at Google that makes it easy to build simple, reliable, and efficient software.

Rps-game-in-go - Learn Go for Beginners Crash Course (Golang)

rps-game-in-go This rock-paper-scissors game was based on the Udemy course "Lear

This is my first golang project. The main reason for its existence is the need for practice. I will be studying golang while writing this project

My first GoLang project Project Aim The goal of this project is to develop the most simple golang bot to learn how to work with this programming langu

Go-beginners-guide-project - golang beginners project from tutorialedge.net

Go Beginner's Project Running Locally If you want to run this application locally then run the following commands: $ go run cmd/cli/main.go Build Appl

Example skills and a cli utility written in Go for interacting with Webex Assistant Skills

Webex Assistant Skills - Go This repository holds example skills and a cli utility written in Go for interacting with Webex Assistant Skills. It is in

This is an example of a keep-it-simple directory layout for Go projects that was created using DDD principles, please copy and share if you like it.

DDD Go Template This project was created to illustrate a great architectural structure I developed together with @fabiorodrigues in the period I was w

Example repository for embedding Litestream in a Go application.

Litestream as Library This repository is an example of embedding Litestream as a library in a Go application. The Litestream API is not stable so you

Owner
Hartawan Bahari M.
Hartawan Bahari M.
Learn how to write webapps without a framework in Go.

This is an easy to understand example based tutorial aimed at those who know a little of Go and nothing of webdev and want to learn how to write a webserver in Go. You will create a to do list application as you advance the chapters.

Suraj Patil 3k Sep 25, 2022
The purpose of this project is to learn about go-swagger.

learn-go-swagger The purpose of this project is to learn about go-swagger. Requirements Go go-swagger Setup Run ./scripts/gen-swagger to generate swag

Henrik Christensen 0 Nov 20, 2021
Golang tutorials - a self-project to learn Go.

Golang Tutorials a self-project to learn Go. prod by blvnk. Tech With Tim Tutorials Intro to Go created a Hello World program. compiled a Hello World

adore_blvnk 0 Feb 21, 2022
Go.work-workspace-example - Go1.18 workspace example

Go.work-workspace-example - Go1.18 workspace example

Andrey Burov 0 Jan 20, 2022
A repository for showcasing my knowledge of the Google Go (2009) programming language, and continuing to learn the language.

Learning Google Golang (programming language) Not to be confused with the Go! programming language by Francis McCabe I don't know very much about the

Sean P. Myrick V19.1.7.2 1 Aug 26, 2022
A repository for showcasing my knowledge of the Go! (2003) programming language, and continuing to learn the language.

Learning Go! (programming language) Not to be confused with Google Golang (2009) I don't know too much about the Go! programming language, but I know

Sean P. Myrick V19.1.7.2 1 Aug 26, 2022
Learn Golang in-depth by solving 15 Quizzes, 10 Exercises and 4 Projects

Modern Go (Golang) - The Complete Beginners Guide 2021 Learn Go (Golang) in-dept

Classroooms 4 Aug 22, 2022
Questions and answers example project.

Question Answer Service REST Service for questions and answers Database modeling Directory tree pkg: Here is the main source code. sql: Here are all t

Ken Esparta Ccorahua 1 Dec 17, 2021
Introduction to beginners learn to go

For-learning-Go-Tutorial 准备写一本Go的书针对初学者快速入门开发和使用go! 学习Go语言需要去了解Go的特性,然后在深入的去实践,如果你想使用Go语言写出Go味道的程序,那么你就需要付出努力去实践了! 先来了解下Go语言为何创造出来的历史吧,Go 语言是由谷歌公司在 20

keke 560 Sep 26, 2022
Building a shoe store with golang to learn more about this language :)

shoestore-go Building a shoe store with golang to learn more about this language :) TODO Create a basic webpage with the pages: home : to show homepag

Bruno B. Melo 4 Jan 24, 2022