Skip to content

Loomie/codebreaker-game

Repository files navigation

codebreaker-game

Decrypto-like multiplayer online browser game

It uses Vue.js for reactive pages.

The current page can be seen here: https://loomie.github.io/codebreaker-game/

Here is a screenshot how it might look: screenshot of the ui

Glossary

Code : Three numbers that denote the position of a keyword for which a hint must be given. For example 312 means the first hint must relate to the third keyword, second hint is for the first keyword and last hint is for the second keyword.

Encoder : The player who gives hints in the current round.

Guess : One number of the code. One guess is given for each hint to reconstruct the code used by the encoder.

Hint : A related word for a specific keyword. It describes/encodes one keyword so the own team can guess it but hopefully the other team can not.

Keyword : One of the four fixed words for which hints must be given to guess them.

Round : The game is played in multiple rounds. Each round consists of multiple steps that are went through: A code is generated for each team, Encoder gives hints for that code to her team, each team guesses the code based on the hints for both teams, the original code is revealed and compared to the guesses and finally the result is checked if the game ends or continues with the next round.

Configuration

Language of keywords

To determine which language will be used for the keywords, the environment variable LANG must be set when starting the server. The first two letters are used for choosing a word list.

# Linux/macOS
export LANG="de_DE.UTF-8"
; Windows PowerShell
$env:LANG="de_DE.UTF-8"

The following languages are currently available:

  • de
  • en (default)

To customize the wordlist look at the files server/wordlist_*.mjs.

Installation

To run the game a central server is needed. It hosts the web pages and connects the players.

Requirements

For the server part node.js must be installed. For the development version git is recommended. But the files can be downloaded directly form GitHub.

As an alternate the server can be run with Docker. You need docker to be installed in this case. See below for instructions to run the game server.

Setup

To setup the server just clone the git repository. Change to the folder server and initialize the project:

npm install

You need a TLS (SSL) certificate for HTTP/2 (HTTPS). Put a link to your certificate chain and key file as cert.pem and key.pem in the folder server/.

You can configure on which port the server runs with the environment variable CODEBREAKER_PORT (default: 12034).

Start

The server runs on port 12034 by default. So point your browser to https://<yourserver>:12034/. You can change the port by setting the environment variable CODEBREAKER_PORT.

Background service (daemon)

It is recommended to manage the service with systemd. A template service file is included. You need to create a copy and modify the path and maybe user name.

cd codebreaker-game/server
cp codebreaker.service.template codebreaker.service
nano codebreaker.service
sudo ln -s codebreaker.service /etc/systemd/system/
sudo systemctl daemon-reload
# autostart on boot
sudo systemctl enable codebreaker

Afterwards you can start and stop the service with

sudo systemctl start codebreaker
sudo systemctl stop codebreaker

Foreground

To run the process in the foreground:

cd codebreaker-game/server
npm start

Background one shot (Linux)

To run the process in the background just append an ampersand. To read the output redirect it into a log file:

node server.mjs >server.log &

Stop

To stop the service run sudo systemctl stop codebreaker. To stop the foreground server press CTRL + C.

Recommendation

Use a separate user to run the process. For linux create a system user without a login (needs root privileges). You need to start the server with a privileged user who changes to the dedicated system user. That is what systemd does for you.

# create system user
adduser --system --group codebreakeruser
# download game
su -s /bin/sh -c 'git clone https://github.com/Loomie/codebreaker-game.git' - codebreakeruser
# setup service as described above with the created user
# start the server in background (one shot)
systemctl start codebreaker

Instead of calling su for each step you can get an interactive shell with su -s /bin/bash - codebreakeruser

Use a free HTTPS certificate from Let's Encrypt by using certbot on your server. Because the game runs as a separate user you have to give it access to the private key. You have to change the group of the key file to your codebreakeruser (primary) group.

# change group of private key and certificate files if your domain is 'example.com'
chgrp -R codebreakeruser /etc/letsencrypt/archive/example.com
# allow the group to read the private key
chmod g+r /etc/letsencrypt/archive/example.com/privkey1.pem
# tell codebreaker to use the letsencrypt files
su -s /bin/sh -c 'cd codebreaker-game/server && ln -s /etc/letsencrypt/live/example.com/cert.pem cert.pem' - codebreakeruser
su -s /bin/sh -c 'cd codebreaker-game/server && ln -s /etc/letsencrypt/live/outstare.de/privkey.pem privkey.pem' - codebreakeruser

Docker

All the setup is done in a Docker container. It needs a certificate and private key for secure connections (HTTPS) as stated in the section "Setup".

To build the docker image locally run the following after your setup is done (in main folder of this project):

docker build --rm -t codebreakergame:latest .

To run the docker image in a container you need to provide the certificate and key file. Also set a local port where the game is reachable, like 4321 below:

docker run --init -d -v <your/path/to/privkey.pem>:/usr/games/codebreaker/server/privkey.pem -v <your/path/to/cert.pem>:/usr/games/codebreaker/server/cert.pem -p 4321:12034 --name codebreakergame codebreakergame:latest

Access the game on your machine like https://localhost:4321

To stop the so started container run

docker stop codebreakergame

To start again:

docker start codebreakergame