Files
game-server-watcher/README.md
2022-04-19 20:09:15 +02:00

10 KiB

Game Server Watcher

A simple discord/telegram bot that can be hosted on a free service to monitor your game servers and players in style. 😎

Table of Contents

[SHOW / HIDE]
  1. About the Project
  2. Getting Started
    1. Requirements
    2. Getting the source
    3. Installation
    4. Usage
    5. Configuration
    6. Managing the service
  3. Deployment
  4. How to Get Help
  5. Further Reading
  6. Contributing
  7. License
  8. Authors
  9. Acknowledgments
    1. Similar projects

About the Project

The main goals of this repo:

  1. create a (simple, but capable) service/bot to monitor game servers
    1. get gamedig & steam api server info (eg.: server name, map, players, etc.)
    2. relay real time server information to various channels via APIs (eg.: discord, telegram, slack etc.)
  2. should be able to host on a free service (target atm. is cloudno.de (nodejs 12.20.1))
  3. graciously add more features based on community feedback (discord / github)

Screenshots

[SHOW / HIDE]

Discord

discord

Telegram

telegram

Back to top

Project Status

The code itself is stable and continuously tested/deployed from the cloud branch.

The project is in a very early stage. More detailed customization options and additional features will be added as requested.

Possible features and configuration options to add in the future

  • optional player list
    • with configurable fields. eg.: time,name,ping,score
    • configurable field & order to sort by
    • max length for player names & nr of players
  • custom embed fields for discord
  • configurable timezone for graph x-axis
  • refresh on reaction
  • watched players (notify when a watched player enters/leaves the server)
  • detect server restart, notify when player number crosses a threshold
  • bot commands (reinit message, cleanup, start/stop, configure)
  • more integrations: slack, ms teams, twillio (email, sms)
  • web ui to manage & configure the servers and bots
  • put custom information in the channel name (online status indicator, number of players, map)
  • github action workflows to deploy to other cloud providers (azure, aws, etc.)

Back to top

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Requirements

node.js (version 12.20.0 or later)

Getting the source

This project is hosted on github. You can clone this project directly using this command:

git clone git@github.com:a-sync/game-server-watcher.git

The latest source and build can also be downloaded as a zip archive.

Installation

Use npm or yarn to install/update all the dependencies:

npm i

If you don't need to build the source, you can skip development dependencies:

npm i --only=prod

Usage

Start the built artifacts directly:

node ./dist/server.js

Build the source and start the service in one command:

npm start

Build, start and auto restart on source changes:

npm run dev

Configuration

The watcher service can be configured via environmental variables. .env (dotenv) file is also supported, for avaialable values and defaults check the default.env file.

Refer to the wiki on how to get tokens for:

Config file schema

The game server and bot configurations are stored in JSON files.
The path of the config file used is defined by the GSW_CONFIG env var. (default: ./config/default.config.json)

The config file must be a valid JSON file that holds a list (array) of game server configuration objects.

[example config JSON]
[
    {
        "host": "localhost",
        "port": 1234,
        "type": "gamedigID",
        "appId": 0,
        "discord": {
            "channelIds": ["9876543210","9080706050"]
        },
        "telegram": {
            "chatIds": ["-100987654"]
        }
    },
    {
        "host": "127.0.0.1",
        "port": 54321,
        "type": "gamedigID",
        "appId": 0,
        "discord": {
            "channelIds": ["9008006007"]
        },
        "telegram": {
            "chatIds": []
        }
    }
]

More sample configs are available in the config folder.

Game server configuration options

Each configuration object describes a game server (host, port, gamedig id, steam app id) and all the bots options for that game server. (discord options, telegram options)

host

String. Can be a domain name or IP.

port

Number. The port used by the game server instance.

type

String. Gamedig ID from the supported games list.

appId

Number. Steam app ID from steamdb.
Only used if you have STEAM_WEB_API_KEY configured and only as backup.
Set it to 0 if you don't need it.

discord.channelIds

String array. List of discord channel IDs.
Only used if you have DISCORD_BOT_TOKEN configured.

telegram.chatIds

String array. List of telegram chat IDs.
Only used if you have TELEGRAM_BOT_TOKEN configured.

Managing the service

A few web endpoints are available to clear out service data.
Make sure to configure a proper SECRET env var to enable these!

Servers data

GET /flush/servers/SECRET
Removes population history data. (configured by PLAYERS_HISTORY_HOURS)

Discord data

GET /flush/discord/SECRET
If the original message created by the bot gets deleted, you might need to flush the bot data to reinitialize the message.
The bot has no cleanup functionality, left over messages must be removed manually.

Telegram data

GET /flush/telegram/SECRET
If the original message created by the bot gets deleted, you need to flush the bot data to reinitialize the message.
The bot has no cleanup functionality, left over messages must be removed manually.

Back to top

Deployment

Check the wiki page for detailed instructions on how to setup a self deploying free cloud instance at cloudno.de.

Hosting

Make sure all the requirements are met!
Protip: check the node.js version with node -v.

Build artifacts (optional)

npm i
npm run build

Minimum required files on host

Copy the ./package.json and index.html files and the ./dist/ folder to your deployment folder.

Install production dependencies on host

Navigate to the deployment folder and execute the following command:

npm i --only=prod

Configuration

Create a writeable folder for the data storage. (configured by DATA_PATH env var, default: ./data/)
Create a configuration file. (configured by GSW_CONFIG, default: ./config/default.config.json)

Running

Run the program from the deployment folder:

node ./dist/server.js

Back to top

How to Get Help

Back to top

Further Reading

Back to top

Contributing

Public contributions are welcome!
Create a new issue for bugs, or open a pull request for any and all your changes.

Back to top

License

This project is licensed under the AGPL License - see LICENSE file for details.

Back to top

Authors

Check the list of contributors who participated in this project.

Back to top

Acknowledgments

This project was inpired by (the sudden disappearance of) "Game Status#5371" bot and its creator Ramzi Saheb on discord.

The IP regex was stolen from the ip-regex package source.

Similar projects

Back to top