5.1.4 • Published 2 months ago

gamedig v5.1.4

Weekly downloads
5,832
License
MIT
Repository
github
Last release
2 months ago

node-GameDig - Game Server Query Library

npmjs.com Node deno compatibility Bun

node-GameDig is a game server query Node.js module (as well as a command line executable), capable of querying for the status of nearly any game or voice server.

If a server makes its status publicly available, GameDig can fetch it for you.

Support is available on the Discord for questions, or GitHub for bugs.

Are you updating from v4 to v5? Many game ids have changed.
Make sure to check if your game's ID is in the id migration document and don't forget to check the changelog file.

Games List

node-GameDig can query over 320 games + a few services!
See the GAMES_LIST.md file for the currently supported titles, not yet supported titles and notes about some of them.

Usage from Node.js

Install using your favorite package manager: npm install gamedig, then use!
Tip: Do you want to try and use the latest features? Install GameDig from this repository via npm i git+https://github.com/gamedig/node-gamedig!

import { GameDig } from 'gamedig';
// Or if you're using CommonJS:
// const { GameDig } = require('gamedig'); 

GameDig.query({
    type: 'minecraft',
    host: 'mc.hypixel.net'
}).then((state) => {
    console.log(state);
}).catch((error) => {
    console.log(`Server is offline, error: ${error}`);
});

Confused on how this works, or you want to see more? Checkout the examples folder!

Required Fields

FieldTypeDescription
typestringOne of the game type IDs listed in the games list. Or you can use protocol-[name] to select a specific protocol. Protocols are listed here.
hoststringHostname or IP of the game server.

Optional Fields

FieldTypeDefaultDescription
addressstringundefinedOverride the IP address of the server skipping DNS resolution. When set, host will not be resolved, instead address will be connected to. However, some protocols still use host for other reasons e.g. as part of the query.
portnumberGame portConnection port or query port for the game server. Some games utilize a separate "query" port. If specifying the game port does not seem to work as expected, passing in this query port may work instead.
maxRetriesnumber1Number of retries to query server in case of failure. Note that this amount multiplies with the number of attempts.
socketTimeoutnumber2000Milliseconds to wait for a single packet. Beware that increasing this will cause many queries to take longer even if the server is online.
attemptTimeoutnumber10000Milliseconds allowed for an entire query attempt (including socketTimeout, beware that if this value is smaller (or even equal) to the socket one, the query will always fail).
givenPortOnlybooleanfalseOnly attempt to query server on given port. It will ignore the game's default port.
ipFamilynumber0IP family/version returned when looking up hostnames via DNS, can be 0 (IPv4 and IPv6), 4 (IPv4 only) or 6 (IPv6 only).
debugbooleanfalseEnables massive amounts of debug logging to stdout.
requestRulesbooleanfalseValve games only. Additional 'rules' may be fetched into the raw key.
requestPlayersbooleantrueValve games only. Disable this if you don't want to fetch players data.
requestRulesRequiredbooleanfalseValve games only. requestRules is always required to have a response or the query will timeout.
requestPlayersRequiredbooleanfalseValve games only. Querying players is always required to have a response or the query will timeout. Some games may not provide a players response.
stripColorsbooleantrueEnables stripping colors for protocols: unreal2, savage2, quake3, nadeo, gamespy2, doom3, armagetron.
portCachebooleantrueAfter you queried a server, the second time you query that exact server (identified by specified ip and port), first add an attempt to query with the last successful port.
noBreadthOrderbooleanfalseEnable the behaviour of retrying an attempt X times followed by the next attempt X times, otherwise try attempt A, then B, then A, then B until reaching the X retry count of each.
checkOldIDsbooleanfalseAlso checks the old ids amongst the current ones.

Query Response

The returned state object will contain the following keys:

KeyTypeDefaultDescription
namestringAn empty stringServer name.
mapstringAn empty stringServer map.
passwordbooleanfalseIf a password is required.
numplayersnumber0Number of players connected.
maxplayersnumber0Maximum number of connected players.
playersarray of objects[]Note that this could be of a different length compared to numplayers.
players.namestringAn empty stringIf the player's name is unknown, the string will be empty.
players.rawobject{}Additional information about the player if available.
botsarray of objects[]Same schema as players.
connectstring'${ip}:${port}'This will typically include the game's IP:PORT. The port will reflect the server's game port, even if your request specified the game's query port in the request. For some entries, this may be a server ID or connection URL if the previous isn't applicable.
pingnumber0Round trip time to the server (in milliseconds). Note that this is not the RTT of an ICMP echo, as ICMP packets are often blocked by NATs and node has poor support for raw sockets. This value is derived from the RTT of one of the query packets, which is usually quite accurate, but may add a bit due to server lag.
queryPortnumber0Indicates on which port the query was done on, if this is not applicable its the default value.
versionstringAn empty stringGame version that is running on the server.
rawobject{}Contains all information received from the server in a disorganized format.

Note that raw (or unstable) objects contents MAY change on a per-protocol basis between GameDig patch releases (although not typical).

Usage from Command Line

Want to integrate server queries from a batch script or other programming language? You'll still need npm to install gamedig:

npm install gamedig -g

After installing gamedig globally, you can call gamedig via the command line:

gamedig --type minecraft mc.example.com:11234
# Alternatively, if you don't want to install gamedig globally, you can run it with npx:
npx gamedig --type minecraft mc.example.com:11234

The output of the command will be in JSON format.
Additional advanced parameters can be passed in as well:

  • --debug: Print debugging information, useful when stating an issue.
  • --pretty: Outputs the JSON format nicely.
  • --requestRules: Request Valve games rules.
  • --givenPortOnly: Run the query with the specified port only (if any).
  • --socketTimeout N: Specifies socket timeout (where N is a number, e.g. 5000).
  • ... and the rest in the same format.

Using with other runtimes

While we still expect to be some minor issues with these, the library works, if any problems arises please open an issue, and we'll look into it.

  • Deno: Minimum supported deno version is 1.39.2 and the --allow-net permission is required.
  • Bun: Minimum supported version is 1.1.21.

Common Issues

Firewalls block incoming UDP

(replit / docker / some VPS providers)

Most game query protocols require a UDP request and response. This means that in some environments, gamedig may not be able to receive the response required due to environmental restrictions.

Some examples include:

  • Docker containers
    • You may need to run the container in --network host mode so that gamedig can bind a UDP listen port.
    • Alternatively, you can forward a single UDP port to your container, and force gamedig to listen on that port using the instructions in the section down below.
  • replit
    • Most online IDEs run in an isolated container, which will never receive UDP responses from outside networks.
  • Various VPS / server providers
    • Even if your server provider doesn't explicitly block incoming UDP packets, some server hosts block other server hosts from connecting to them for DDOS-mitigation and anti-botting purposes.

Gamedig doesn't work in the browser

Gamedig cannot operate within a browser. This means you cannot package it as part of your webpack / browserify / rollup / parcel package.
Even if you were able to get it packaged into a bundle, unfortunately no browsers support the UDP protocols required to query server status from most game servers.
As an alternative, we'd recommend using gamedig on your server-side, then expose your own API to your webapp's frontend displaying the status information. If your application is thin (with no constant server component), you may wish to investigate a server-less lambda provider.

Specifying a listen UDP port override

In some very rare scenarios, you may need to bind / listen on a fixed local UDP port. The is usually not needed except behind some extremely strict firewalls, or within a docker container (where you only wish to forward a single UDP port).
To use a fixed listen udp port, construct a new Gamedig object like this:

const gamedig = new GameDig({
    listenUdpPort: 13337
});
gamedig.query(...)
5.1.4

2 months ago

5.1.3

4 months ago

5.1.2

4 months ago

4.3.2

4 months ago

5.1.1

4 months ago

5.1.0

5 months ago

5.0.1

6 months ago

5.0.0

7 months ago

5.0.0-beta.2

11 months ago

5.0.0-beta.1

11 months ago

5.0.0-beta.0

11 months ago

4.3.1

12 months ago

4.3.0

1 year ago

4.2.0

1 year ago

4.1.0

1 year ago

4.0.7

1 year ago

4.0.6

2 years ago

4.0.5

2 years ago

4.0.4

3 years ago

4.0.3

3 years ago

3.0.8

3 years ago

4.0.1

3 years ago

4.0.0

3 years ago

4.0.2

3 years ago

3.0.9

3 years ago

3.0.7

3 years ago

3.0.6

3 years ago

3.0.4

4 years ago

3.0.3

4 years ago

3.0.2

4 years ago

3.0.5

4 years ago

3.0.1

4 years ago

3.0.0

4 years ago

2.0.28

4 years ago

2.0.26

4 years ago

2.0.27

4 years ago

2.0.25

4 years ago

2.0.24

4 years ago

2.0.23

4 years ago

2.0.22

4 years ago

2.0.21

4 years ago

2.0.20

5 years ago

2.0.19

5 years ago

2.0.18

5 years ago

2.0.17

5 years ago

2.0.16

5 years ago

2.0.15

5 years ago

2.0.14

6 years ago

2.0.13

6 years ago

2.0.12

6 years ago

2.0.11

6 years ago

2.0.10

6 years ago

2.0.9

6 years ago

2.0.8

6 years ago

2.0.7

6 years ago

2.0.6

6 years ago

2.0.5

6 years ago

2.0.4

6 years ago

2.0.3

6 years ago

2.0.2

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.0.49

6 years ago

1.0.48

6 years ago

1.0.47

6 years ago

1.0.46

7 years ago

1.0.45

7 years ago

1.0.44

7 years ago

1.0.43

7 years ago

1.0.42

7 years ago

1.0.41

7 years ago

1.0.40

7 years ago

1.0.39

7 years ago

1.0.38

7 years ago

1.0.37

7 years ago

1.0.36

7 years ago

1.0.35

7 years ago

1.0.34

7 years ago

1.0.33

7 years ago

1.0.32

7 years ago

0.2.30

7 years ago

0.2.28

8 years ago

0.2.27

8 years ago

0.2.26

8 years ago

0.2.25

9 years ago

0.2.24

10 years ago

0.2.23

10 years ago

0.2.22

10 years ago

0.2.21

10 years ago

0.2.20

10 years ago

0.2.19

10 years ago

0.2.18

10 years ago

0.2.17

10 years ago

0.2.16

10 years ago

0.2.15

10 years ago

0.2.14

10 years ago

0.2.13

10 years ago

0.2.12

10 years ago

0.2.11

10 years ago

0.2.10

10 years ago

0.2.9

10 years ago

0.2.8

10 years ago

0.2.7

10 years ago

0.2.6

10 years ago

0.2.5

10 years ago

0.2.4

11 years ago

0.2.3

11 years ago

0.2.2

11 years ago

0.2.1

11 years ago

0.2.0

11 years ago

0.1.2

11 years ago

0.1.1

11 years ago

0.1.0

11 years ago