server

command module
v0.0.0-...-56dc94b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2020 License: MIT Imports: 9 Imported by: 0

README

Idlemon

Idlemon is a networked tower defense game. This is the server side of the game.

Architecture

Idlemon includes an API, a WebSocket server, and a client made with Unity.

  • The API exposes HTTP routes for user authentication.
  • The client acts as the "frontend" of the game and is kept in a separate repository.
  • The WebSocket server runs the game and handles the connected players.

Dependencies

Environment Variables

Idlemon uses several environment variables with default values. You can make a copy of .env.default and name it .env, this file will be loaded instead of .env.default if it is present. Note that environment variables will not be overwritten by the .env file if they are already set. Also note that .env files will not be loaded if ENV is set to production, you will need to set the env variables manually when deploying to a production environment.

  • ENV=development set this to production when deploying.
  • API_PORT=3000 this is the port that the API will bind to.
  • SERVER_PORT=8080 this is the port that the WebSocket server will bind to.
  • DB_HOST=127.0.0.1 this is the IP address of the PostgreSQL database.
  • DB_NAME=postgres this is the name of the database to connect to.
  • DB_USER=postgres this is the username used to connect to PostgreSQL.
  • DB_PASS=password this is the password used to connect to PostgreSQL.
  • REDIS_HOST=127.0.0.1 this is the IP address of the Redis server.

Docker

Idlemon includes a docker-compose.yml file and Dockerfiles, you can build and deploy the binaries manually or use Docker.

Dockerfile

Docker files are included to build Alpine images of the API and WebSocket server. You should provide your PostgreSQL password through the DB_PASS environment variable. Both the API and Server need to access the same PostgreSQL and Redis server. Note that the ENV variable is set to production by default.

Build and run the API

docker build -t idlemon-api -f api.Dockerfile .
docker run -itd -e DB_PASS=password --restart=always --network=host --name idlemon-api idlemon-api

Build and run the WebSocket server

docker build -t server .
docker run -itd --env-file .env --restart=always --network=host --name server server

Authentication process

  1. User logs in through the API.
  2. API generates an authentication token and stores it in Redis using the user ID as the key. The token is set to expire after a certain time.
  3. The user ID and auth token are returned to the client.
  4. The client sends the user ID and auth token to the server through HTTP headers requesting to upgrade to a WebSocket connection.
  5. The server verifies that the user ID and auth token are in redis.
  6. Once verified the user is considered authenticated and the connection is upgraded to a WebSocket connection

VS Code

If you are using VS Code and have Go installed, you can press "ctrl + shift + b" to show the build tasks. They can help with running the binaries during development.

Documentation

Documentation

The Go Gopher

There is no documentation for this package.

Directories

Path Synopsis
pkg
ws

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL