game-server-watcher
Requirements: node.js (version 12.20.0 or later)
Configuration
//TODO: env vars (dotenv files supported)
//TODO: config file schema description
Starting the service
Install dependencies: npm i
Build & start program: npm start
The goals of this repo
- create a (simple, but capable) service/bot to monitor game servers
- get gamedig & steam api server info (eg.: server name, map, players, etc.)
- relay real time server information to various channels via APIs (eg.: discord, telegram, slack etc.)
- should be able to host on a free service (target atm. is cloudno.de (nodejs 12.20.1))
- graciously add more features based on community feedback
Get support on discord or on github.
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)
Self host on cloudno.de
You can fork (copy) this repo on github, and automatically deploy your configuration or other changes as a cloud service.
Part 1: create and setup cloudno.de repo
- register account
- create app: https://cloudno.de/myapps?new //TODO: create app, make sure to set the latest node.js version and leave server.js as entry point;
- provision app
- copy https git URL from app
- go to profile copy your token
- add username and as authentication to the URL like
https://username:secrettoken@git.cloudno.de/git/username/xyz; save it for later (github) - go to application --> manage --> environment
- set
DATA_PATH=/mnt/in cloud app env
//go to https://cloudno.de/account --> API tokens // on github: goto settings --> secrets --> actions and setupCLOUDNODE_REPO_URLsecret with the full URL
Part 2 (optional): create and invite discord bot and get token
//TODO: create discord bot;
- create app
- create bot
- under the bots name you should seee a token or an option to reset token
- check message content intent
- oauth2 --> url generator --> check bot as scopes; create bot invite link with permissions: view channels, send messages, message history, embed links, add reaction (85056),
- invite bot to servers(guilds)
- create bot auth token, copy it
- setup
DISCORD_BOT_TOKENin cloud app env - //CONFIG: find and copy then setup channel ids in config
Part 3 (optional): create telegram bot and get token
//TODO: get token from botfather and setup as TELEGRAM_BOT_TOKEN in cloud app env; get chat id from getidsbot and setup chat ids in config
Part 4 (optional): create steam web api key
//TODO: request a web api key and setup as STEAM_WEB_API_KEY in cloud app env; set appId fields in config
Part 5: create and setup github repo
//TODO: fork this repo
- hit fork button
- repo settings page --> actions --> general: allow all actions (if no confirmation comes up, disable then re-enable all actions)
Part 6: create cloud branch, configure and deploy the service
- switch to the
cloudbranch of your fork; (git checkout -b cloud) - create a new config file (and setup
GSW_CONFIGin cloud app env to point to it) or edit config/default.config.json and save it - commit and push your changes (
git add . && git commit -m :shipit: && git push origin cloud)
You can also just use the github web editor to make changes to the default config file, just make sure to switch to the cloud branch to have it automatically deployed.
Commiting your changes and pushing your commits to github will trigger github actions to push your files to cloudno.de and restart the app
Manage
A few web endpoints are available to clear out service data.
Make sure to configure a proper SECRET env var to enable these!
Servers /flush/servers/SECRET
Removes all stored game server data:
- population history configured by
PLAYERS_HISTORY_HOURS
Telegram /flush/telegram/SECRET
The bot has no cleanup functionality, left over messages must be removed manually.
If the original message created by the bot gets deleted, you need to flush the bot data to reinitialize the message.
Discord /flush/discord/SECRET
The bot has no cleanup functionality, left over messages must be removed manually.
If the original message created by the bot gets deleted, you might need to flush the bot data to reinitialize the message.
Development
Running locally
npm i
npm run dev
Nodejs v12 dependency limitations
- discord.js v12 (discord API v8)
- got v11