Prerequisites
- Install Visual Studio Code to use with WSL: https://code.visualstudio.com/
a. Install the Remote WSL extension: https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-wsl
b. Probably Golang extension wouldn’t hurt too: https://marketplace.visualstudio.com/items?itemName=ms-vscode.Go - Install WSL: https://docs.microsoft.com/en-us/windows/wsl/install-win10
- Install a distro for WSL from Microsoft Store, e.g. Ubuntu
- Install the correct version of Go into WSL: https://golang.org/doc/install#install
- Install CockroachDB: https://www.cockroachlabs.com/docs/stable/install-cockroachdb-linux.html
Setting up Nakama & Cockroach
- Make a directory for the local Nakama server
mkdir nakama-server
cd nakama-server
- Download and extract Nakama binary
wget https://github.com/heroiclabs/nakama/releases/download/v2.12.0/nakama-2.12.0-linux-amd64.tar.gz
tar -xzvf nakama-2.12.0-linux-amd64.tar.gz
# here you might want to remove everything except for the binary itself
- Create a directory for the local database & start it there
mkdir db
cd db
cockroach start-single-node --insecure
# now go for another terminal, leave the db working here
- Start Nakama and make sure everything is fine
./nakama migrate up
./nakama
# if you see that everything went well, shut it down for now
Setting up the project
- Create your go.mod file. This is what it would look like if MODULENAME is the name of your server module
module MODULENAME
go 1.14
require (
github.com/golang/protobuf v1.3.5
github.com/heroiclabs/nakama-common v1.5.1
)
Now, it’s worth mentioning that vscode would probably try to suggest you to upgrade the version of protobuf. Don’t, or if you did, get it back to 1.3.5 (at this point).
- Optionally, write a shell script for automatic module building and launching Nakama with it. This is super useful, because you’re gonna rebuild hundreds of times during the development and this is an easy and super quick way to do it, instead of manually copying and pasting your .so module.
export NAKAMA_RUNTIME_PATH=<path-to-where-you-want-you-data-stored>
export NAKAMA_PATH=<path-to-directory-with-nakama-executable>
export MY_NAKAMA_MODULE_NAME=<nakama-module-name>
# e.g. in my case it is
# export NAKAMA_RUNTIME_PATH=/home/beluc/nakama-server/
# export NAKAMA_PATH=/home/beluc/nakama-server/
# export MY_NAKAMA_MODULE_NAME=spacebattle
if (go build -buildmode=plugin -trimpath -o $NAKAMA_RUNTIME_PATH/data/modules/$MY_NAKAMA_MODULE_NAME.so) ; then
$NAKAMA_PATH/nakama migrate up
$NAKAMA_PATH/nakama -runtime.path $NAKAMA_RUNTIME_PATH
fi
Finally
Try it out on Heroic Labs’ sample Nakama module: https://github.com/heroiclabs/nakama/tree/master/sample_go_module