gen_game

Distributed game server, written in Elixir

Downloads
110
Stars
4

GenGame

Read website documentation

GenGame is realtime and distributed game server, runs on Erlang VM.

Whether you're building a social network game, MMORPG, or TCG, GenGame helps you create a robust backend game server, offering clients for popular game platforms. It's also extensible with Elixir/Erlang or any HTTP server.

Features

  • Users - Register/login new users.
  • Relay Multiplayer - Sending a message or event in the match.
  • Server Authoritative - Execute custom logic using Elixir/Erlang or any programming language via HTTP server.
  • Matchmaker - Let players finding fair match with expressive query.

Getting Started

Let's discover GenGame in less than 5 minutes.

There are two ways to get GenGame up and running: using Docker or building it from source. We recommend using Docker, as it's easier to manage. Building from source is intended for those who want to develop GenGame further or are interested in understanding how it works under the hood.

Using Docker (Recommended)

First, create a file docker-compose.yml.

services:
  gen_game:
    container_name: gen_game
    image: f4th4n/gen_game:latest
    environment:
      DATABASE_URL: ecto://postgres:postgres@postgres/gen_game_prod
    depends_on:
      - postgres
    ports:
      - 4000:4000

  postgres:
    container_name: postgres
    image: postgres:14-alpine
    healthcheck:
      test: "pg_isready -U postgres"
    volumes:
      - postgres:/var/lib/postgresql/data
    environment:
      PSQL_HISTFILE: /root/log/.psql_history
      POSTGRES_PASSWORD: postgres
      POSTGRES_DB: gen_game_prod
    ports:
      - 5433:5432

volumes:
  postgres:

Then run the command:

docker compose up

Test by visiting http://localhost:4000/, if you see response below then congratulation, it works:

{
  "status": "ok",
  "app": "gen_game"
}

Build Yourself

Requirements

  1. Elixir
  2. Erlang
  3. Postgres

Steps

  1. Clone the repo
  2. Copy .env.example to .env
  3. Update .env, fill DATABASE_URL
  4. Run command below:
source .env
iex --sname gen_game --cookie g3ng4m3 -S mix phx.server

Test by visiting http://localhost:4000/, if you see:

{
  "status": "ok",
  "app": "gen_game"
}

then it works.

Upgrade

To update to the latest version of GenGame:

If you are using Docker, change the tag to the newer version. You can see the full list of tags at Docker Hub.

If you are building it yourself, pull the newer code from the repository and then rebuild.

Client Libraries

Unity

If you're using Unity or any C# application then you should use gen_game_unity to connect to GenGame server.

JavaScript

If you're using PhaserJS, Cocos2d-x, Construct3, Telegram Game, Facebook Instant Game, or any JavaScript application then you should use gen_game_js to connect to GenGame server.

Extend With Hooks

You can extend GenGame functionality beyond its capability with hooks. Hooks let you run your own function in between events, so you can achieve thing like server authoritative actions.

Server authoritative means server doing some calculation before sending it to the client. For example, your game need to spawn an enemy or calculating damage based on player's armor.

There are 2 ways to do this.

  1. Using Elixir
  2. Using any other programming language

See the documentation here.

Benchmark

Is GenGame really fast? The main strength of GenGame is not raw speed but concurrent connection. They can handle ~20k concurrent connection with 2 CPU 4 GB memory easily. You can read the whole article how we did this here.