Skip to content
This repository has been archived by the owner on Dec 1, 2023. It is now read-only.

Commit

Permalink
Support for new server config options
Browse files Browse the repository at this point in the history
`server.query_port` Set if your game's server requires a specific query port.

`server.max_players` Set if your game's server response has issues with max players.
  • Loading branch information
fasko-web committed Feb 26, 2021
1 parent b81ae4b commit 96d4901
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 5 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,8 @@ Config Name | Information
`game` | The game your server is running on. Must be supported by [GameDig](https://github.com/gamedig/node-gamedig#games-list). Default: `'garrysmod'`
`ip` | Your game server's IP address.
`port` | Your game server's port. Set to false if unused. Default: `27015`

`query_port` | Your game server's separate query port. Expects an integer if set. Default `false`
`max_players` | Your game server's max players. Only necessary if the query is having trouble detecting accurate count. Default: `false`

##### Bot Settings - `server.bot`
Config Name | Information
Expand Down
4 changes: 4 additions & 0 deletions config/default.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@
ip = '00.00.000.000'
port = 27015 # Set to false or remove if not needed

# Extra optional settings for game servers with weird queries
query_port = false # Set if the game's server requires querying a specific port, expects an integer
max_players = false # Set if the game's server query has trouble detecting max players, expects an integer

# Discord Bot Settings
[server.bot]
token = '' # Discord bot token for this game server
Expand Down
5 changes: 4 additions & 1 deletion jobs/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,15 @@ module.exports = async function query(client_id, server) {
break;
default: // Queries Game Server
if (!serverQueryTime || serverQueryTime < new Date((new Date) - humanInterval(intervals.server))) {
response = await queryServer(server.ip, server.port, server.game);
response = await queryServer(server.ip, server.port, server.game, server.query_port);
serverQueryTime = new Date;
console.log('[EVENT]', `(${server.name}) Server queried.`);
}
}
state = response.state;
response.maxPlayers = (server.max_players > 0 && response.maxPlayers !== server.max_players)
? server.max_players
: response.maxPlayers;

// Queries Pterodactyl
if (server.pterodactyl && server.pterodactyl.enabled) {
Expand Down
7 changes: 4 additions & 3 deletions jobs/server.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const GameDig = require('gamedig');

module.exports = (ip, port = false, game = 'garrysmod') => {
module.exports = (ip, port = false, game = 'garrysmod', queryPort = false) => {
qp = queryPort || port;
const response = GameDig.query({
type: game,
host: ip,
...(port && { port : port.toString() }),
...(port && { givenPortOnly: true })
...(qp && { port : qp.toString() }),
...(qp && { givenPortOnly: true })
}).then((state) => {
return {
state: 'on',
Expand Down

0 comments on commit 96d4901

Please sign in to comment.