Skip to content

HellaMadMax/gamedig-discord-status

Repository files navigation

Gamedig Discord Status

Library which uses gamedig and discord.js to show the player count and map of a game server as a discord message or bot activity status.
Can also report if the game server has gone down and send a discord message to report it.

Images

image image image

Installation & Usage

npm install gamedig-discord-status
const GameServer = require('gamedig-discord-status')
let hll1 = new GameServer({
	id: "Official Hell Let Loose Aus #1",
	type: "hll",
	host: "176.57.135.34",
	port: 28015,
	login: "token",
	updateActivity: true,
	updateMessage: true,
	channelID: "1234567890987654321",
	messageID: "0987654321234567890",
	reportDown: true,
	reportPrefixDown: "<@2345678909876543> Server has stopped responding",
	reportPrefixUp: "Server is now responding"
}).query()

GameServer options

Most of the options are gamedig query options (host and port are required) with a few different defaults:

  • type: "protocol-valve"
  • maxAttempts: 4
  • socketTimeout: 6000
  • givenPortOnly: true

Non-GameDig options:

  • id: string - Identifier for the server to show in logs and message title. Defaults to query IP:Port
  • interval: number - Milliseconds to wait between queries. Defaults to 30 * 1000 (30 seconds)
  • client: object - Directly pass a discord.js client object to be used instead of it being automatically created
  • token: string - Discord Bot login token. They can be created here
  • discordDebug: boolean - Enables debug logging for discord client
  • logDebug: boolean - console.log on updateActivity, updateMessage and sendMessage
  • logActivity: boolean - console.log on activity change
  • updateActivity: boolean - Update discord bot activity with player count
  • updateMessage: boolean - Update discord message with player count (requires both ChannelID and MessageID)
  • updateInterval: number - Milliseconds to wait before calling updateActivity even when activity text hasn't changed. Needed due to discord clearing activity after awhile of not reciving updates. Defaults to 30 * 60000 (30 minutes)
  • channelID: string - Discord channel ID
  • messageID: string - Discord message ID (MUST BE POSTED FROM DISCORD BOT ACCOUNT TO EDIT)
  • messageLinkIP: boolean - Add steam://connect/ to ip address field in discord message (if game uses valve protocol). Defaults to true
  • reportDown: boolean - Report when a server stops responding to queries, and when it starts doing so again
  • reportChannelID: string - Use this channel instead of channelID when sending down reports
  • reportPrefixDown: string - Prefix this message when reporting server not responding, useful for mentions
  • reportPrefixUp: string - Prefix this message when reporting server started responding, useful for mentions

Functions

  • setProp(name, value): Set any GameServer property/function (allows chaining)
  • addMap(map, name): Add name to be shown instead of the map name, useful for games with weird internal map names (allows chaining)

Example:

const GameServer = require('gamedig-discord-status')
let hll1 = new GameServer({id: "Official Hell Let Loose Aus #1", type: "hll", host: "176.57.135.34", port: 28015})
.addMap("CT", "Carentan")
.addMap("Hill400", "Hill 400")
.addMap("Hurtgen", "Hürtgen Forest")
.addMap("Omaha", "Omaha Beach")
.addMap("PHL", "Purple Heart Lane",)
.addMap("StMarie", "Sainte-Marie-du-Mont")
.addMap("SME", "Sainte-Mère-Église")
.addMap("Stalin", "Stalingrad")
.addMap("Utah", "Utah Beach")
.query()

Events

  • getMap (event.map) - used by getActivity/getMessage for map
  • getGame (event.game) - used by getMessage for game field
  • getActivity (activity) - used to format activity when updateActivity is enabled
  • getMessage (message) - used to format discord messages when sending or editing them (updateMessage/reportDown/reportUp)
  • updateActivity (activity) - when updateActivity is called
  • updatedActivity (activity, presence) - after updateActivity is called (presence is return value of client.setActivity)
  • updateMessage (newMessage) - when updateMessage is called
  • updatedMessage (newMessage, edit) - after updateMessage is called (edit is return value of message.edit)
  • sendMessage (message) - when sendMessage is called
  • sentMessage (message, sent) - after sendMessage is called (sent is return value of channel.send)
  • discordLogin (client) - after discord client has logged in
  • discordLoginError (error) - error while logging into discord
  • query (query) - after receiving a valid query response from gamedig
  • queryError (error) - error getting query from gamedig
  • activityChange (from, to) - when activity text has changed
  • messageChange (from, to) - when message text has changed
  • reportDown () - after queryError when previous response was valid
  • reportUp () - after query when previous response was error

Example:

.on("getMap", function(event) {
	if (event.map == "de_") {
		event.map = event.map.substr(3)
	}
})

Notes

Query port

The query port can be different from the connect port you use to join the game.
If you don't know what the query port and the game uses the valve protocol you can use the master server script to find out.

cd node_modules\gamedig-discord-status
npm run master 176.57.135.34

> [email protected] master
> node cmd_master.js "176.57.135.34"

[ '176.57.135.34', '28015' ]
 Results {
  name: 'HLL Official - Australia #01',
  map: 'PHL',
  password: false,
  raw: {
    protocol: 17,
    folder: 'hlldir',
    game: 'Hell Let Loose',
    appId: 686810,
    numplayers: 0,
    numbots: 0,
    listentype: 'd',
    environment: 'w',
    secure: 1,
    version: '0.1.1.0',
    steamid: '90158480733430790',
    tags: [
      'GS:ojF+bcTzWycBAAAG',
      'CONMETHOD:P2P',
      'P2PADDR:90158480733430790',
      'P2PPORT:28000',
      'SESSIONFLAGS:171',
      'VISIB_i:0'
    ]
  },
  maxplayers: 100,
  players: Players(0) [],
  bots: Players(0) [],
  connect: '176.57.135.34:28000',
  ping: 46
}
[ '176.57.135.34', '28215' ]
 Results {
  name: 'HLL Official - Australia #02',
  map: 'Stalin',
  password: false,
  raw: {
    protocol: 17,
    folder: 'hlldir',
    game: 'Hell Let Loose',
    appId: 686810,
    numplayers: 0,
    numbots: 0,
    listentype: 'd',
    environment: 'w',
    secure: 1,
    version: '0.1.1.0',
    steamid: '90158480733513734',
    tags: [
      'GS:ozFGbsTzWycBAACG',
      'CONMETHOD:P2P',
      'P2PADDR:90158480733513734',
      'P2PPORT:28200',
      'SESSIONFLAGS:171',
      'VISIB_i:0'
    ]
  },
  maxplayers: 100,
  players: Players(0) [],
  bots: Players(0) [],
  connect: '176.57.135.34:28200',
  ping: 48
}

In this example the query and connect ports are:
query 176.57.135.34:28015 => connect 176.57.135.34:28000
query 176.57.135.34:28215 => connect 176.57.135.34:28200

Discord message edit

When updating status via updateMessage the messageID MUST be one created by the bot, otherwise it will throw an error when attempting to edit it
You can easily make a placeholder message by running the createmsg script and using the returned message ID

npm run createmsg (login token) (channel ID)

> [email protected] createmsg
> node cmd_createmsg.js "(login token)" "(channel ID)"

26/04/2022, 10:50:19 pm - logged into discord (Bot Name#1234)
26/04/2022, 10:50:19 pm - found discord channel (channel name)
26/04/2022, 10:50:20 pm - created discord message (1234567890987654321)

License

This repository and the code inside it is licensed under the MIT License. Read LICENSE for more information.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published