Coder Social home page Coder Social logo

giyomoon / steam-server-query Goto Github PK

View Code? Open in Web Editor NEW
25.0 3.0 2.0 47 KB

Module which implements the Master Server Query Protocol and Game Server Queries.

Home Page: https://npmjs.com/package/steam-server-query

License: MIT License

TypeScript 100.00%
steam game-server-query master-server-query

steam-server-query's Introduction

Steam Server Query

npm version npm downloads license

Module which implements the Master Server Query Protocol and Game Server Queries. It is working with promises.

Install

npm install steam-server-query

API

Master Server Query

queryMasterServer(masterServer: string, region: REGIONS, filter?: Filter, timeout?: number, maxHosts?: number): Promise<string[]>

Fetch a Steam master server to retrieve a list of game server hosts.

  • masterServer: Host and port of the master server to call.
  • region: The region of the world where you wish to find servers in. Use REGIONS.ALL for all regions.
  • filter: Optional. Object which contains filters to be sent with the query. Default is { }.
  • timeout: Optional. Time in milliseconds after the socket request should fail. Default is 1 second.
  • maxHosts: Optional. Return a limited amount of hosts. Stops calling the master server after this limit is reached. Can be used to prevent getting rate limited.
  • Returns: A promise including an array of game server hosts.

Game Server Query

queryGameServerInfo(gameServer: string, attempts?: number, timeout?: number | number[]): Promise<InfoResponse>

Send a A2S_INFO request to a game server. Retrieves information like its name, the current map, the number of players and so on. Read more here.


queryGameServerPlayer(gameServer: string, attempts?: number, timeout?: number | number[]): Promise<PlayerResponse>

Send a A2S_PLAYER request to a game server. Retrieves the current playercount and for every player their name, score and duration. Read more here.


queryGameServerRules(gameServer: string, attempts?: number, timeout?: number | number[]): Promise<RulesResponse>

Send a A2S_RULES request to a game server. Retrieves the rule count and for every rule its name and value. Read more here.


Parameters for every Game Server Query function

  • gameServer: Host and port of the game server to call.
  • attempts: Optional. Number of call attempts to make. Default is 1 attempt.
  • timeout: Optional. Time in milliseconds after the socket request should fail. Default is 1000. Specify an array of timeouts if they should be different for every attempt. (Example for 3 attempts: [1000, 1000, 2000])
  • Returns: A promise including an object (Either type InfoResponse, PlayerResponse or RulesResponse)

Types

Master Server Query

REGIONS

enum REGIONS {
  'US_EAST_COAST' = 0x00,
  'US_WEST_COAST' = 0x01,
  'SOUTH_AMERICA' = 0x02,
  'EUROPE' = 0x03,
  'ASIA' = 0x04,
  'AUSTRALIA' = 0x05,
  'MIDDLE_EAST' = 0x06,
  'AFRICA' = 0x07,
  'ALL' = 0xFF
}

Filter

interface Filter extends BasicFilter {
  nor?: BasicFilter;
  nand?: BasicFilter;
}

interface BasicFilter {
  dedicated?: 1;
  secure?: 1;
  gamedir?: string;
  map?: string;
  linux?: 1;
  password?: 0;
  empty?: 1;
  full?: 1;
  proxy?: 1;
  appid?: number;
  napp?: number;
  noplayers?: 1;
  white?: 1;
  gametype?: string[];
  gamedata?: string[];
  gamedataor?: string[];
  name_match?: string;
  version_match?: string;
  collapse_addr_hash?: 1;
  gameaddr?: string;
}

Game Server Query

InfoResponse

interface InfoResponse {
  protocol: number;
  name: string;
  map: string;
  folder: string;
  game: string;
  appId: number;
  players: number;
  maxPlayers: number;
  bots: number;
  serverType: string;
  environment: string;
  visibility: number;
  vac: number;
  version: string;
  port?: number;
  serverId?: BigInt;
  spectatorPort?: number;
  spectatorName?: string;
  keywords?: string;
  gameId?: BigInt;
}

PlayerResponse

interface PlayerResponse {
  playerCount: number;
  players: Player[];
}

interface Player {
  index: number;
  name: string;
  score: number;
  duration: number;
}

RulesResponse

interface RulesResponse {
  ruleCount: number;
  rules: Rule[];
}

interface Rule {
  name: string;
  value: string;
}

Examples

Master Server Protocol

To retrieve all servers from the game Witch It with players on it:

import { queryMasterServer, REGIONS } from 'steam-server-query';

queryMasterServer('hl2master.steampowered.com:27011', REGIONS.ALL, { empty: 1, appid: 559650 }).then(servers => {
  console.log(servers);
}).catch((err) => {
  console.error(err);
});

Response (shortened):

[
  "176.57.181.178:27003"
  "176.57.181.178:27008"
  "176.57.171.49:27005"
  "176.57.181.178:27005"
]

Game Server Protocol

A2S_INFO

To retrieve information about the game server with the address 176.57.181.178:27003:

import { queryGameServerInfo } from 'steam-server-query';

queryGameServerInfo('176.57.181.178:27003').then(infoResponse => {
  console.log(infoResponse);
}).catch((err) => {
  console.error(err);
});

Response:

{
  "protocol": 17,
  "name": "EU04",
  "map": "RandomMapCycle",
  "folder": "WitchIt",
  "game": "Witch Hunt",
  "appId": 0,
  "players": 10,
  "maxPlayers": 16,
  "bots": 0,
  "serverType": "d",
  "environment": "l",
  "visibility": 0,
  "vac": 1,
  "version": "1.0.0.0",
  "port": 7780,
  "keywords": "BUILDID:0,OWNINGID:90154510593238022,OWNINGNAME:EU04,SESSIONFLAGS:683,GameMode_s:Hide and Seek,PlayerCount_i:10,MatchTime_i:265",
  "gameId": 559650
}

A2S_PLAYER

To retrieve players playing on the game server with the address 176.57.181.178:27003:

import { queryGameServerPlayer } from 'steam-server-query';

queryGameServerPlayer('176.57.181.178:27003').then(playerResponse => {
  console.log(playerResponse);
}).catch((err) => {
  console.error(err);
});

Response (shortened):

{
  "playerCount": 10,
  "players": [
    {
      "index": 0,
      "name": "Player_1",
      "score": 0,
      "duration": 1969.7518310546875
    },
    {
      "index": 0,
      "name": "Player_2",
      "score": 0,
      "duration": 1958.9234619140625
    },
    {
      "index": 0,
      "name": "Player_3",
      "score": 0,
      "duration": 1509.9417724609375
    }
  ]
}

A2S_RULES

To retrieve rules of the game server with the address 176.57.181.178:27003:

import { queryGameServerRules } from 'steam-server-query';

queryGameServerRules('176.57.181.178:27003').then(rulesResponse => {
  console.log(rulesResponse);
}).catch((err) => {
  console.error(err);
});

Response:

{
  "ruleCount": 14,
  "rules": [
    { "name": "CONMETHOD", "value": "P2P" },
    { "name": "GameMode_s", "value": "Hide and Seek" },
    { "name": "MatchStarted_b", "value": "true" },
    { "name": "MatchTime_i", "value": "265" },
    { "name": "OWNINGID", "value": "90154510593238022" },
    { "name": "OWNINGNAME", "value": "EU04" },
    { "name": "P2PADDR", "value": "90154510593238022" },
    { "name": "P2PPORT", "value": "7780" },
    { "name": "PlayerCount_i", "value": "10" },
    { "name": "SESSIONFLAGS", "value": "683" },
    { "name": "SessionName_s", "value": "EU04" },
    { "name": "StartTime_s", "value": "2021.12.29-00.47.20" },
    { "name": "Tournament_b", "value": "false" },
    { "name": "VersionNumber_s", "value": "1.2.3" }
  ]
}

Notes

  • The master servers are rate limited. Requests with large outputs (6000+ servers) will probably reach this limit and a timeout error will be thrown.

Links

License

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

steam-server-query's People

Contributors

giyomoon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

steam-server-query's Issues

Server rules are hashed

When i query a V rising server for server rules i get a hashed version of the rules
{ name: 'game-settings-hash', value: '77832daa06691342fdb31bdfe990d359880d156d8ccd287314cc2bfe8d449134' }, { name: 'settings0', value: 'AgAAAAAAAAAAAAAAAAAAAAAAAACgQAEDAgUAAAAAAAAAAAIAAAAAAwMAAAAABAQAAAAABQUAAAAABv4FAAAAAAAAAAAUAAAAABUyAAAAADNQAAAAAFGgAAAAAKH+' }, { name: 'settings1', value: 'BAAAAAEtAQJaAgOWBAT6BgQAAAABAQIBAwEEAaBpZjIJABAAChIAPM08MztmPAA8ADzNPAA8zTwAPAA8AEUAPAA8ADwAPAA8ADwAPABAZjoAQGY6ZjoAPEBOAEUA' }, { name: 'settings2', value: 'RTBfgFMAPAA8ADwAPAA8ZjoAPGYuADyaOZo5ADwAPAA8ADwAQABAAEABAgAAAgMAAAAAFwAAABcAFAAVABQAFgAAAgGbAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' }, { name: 'settings3', value: 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA' }
can you point me in the right direction of decoding those?

Error: Timeout reached. Possible reasons: You are being rate limited; Timeout too short; Wrong server host configured;

          > The two main reasons this error happens is because the server is either completely down, or your network/server isn't fast enough to complete the request in the default 1000 milliseconds. In this case, you can increase the timeout like this:
queryGameServerInfo('136.54.17.250:27016', 1, 2000)

This increases the timeout to 2000 milliseconds. The second parameter is the amount of attempts, which is the default 1. Try around with these two parameters, you should get it working with it.

@GiyoMoon

I changed to your package and tried again. I'm still getting the same error. Even with changing the retry attempts and timeout period. Example:

const steamServerQuery = require("steam-server-query")

steamServerQuery.queryGameServerInfo('136.54.17.250:27016', 5, 3000).then((result) => {
  console.log(result);
}).catch((error) => {
  console.log(error);
});

I get this back:

Error: Timeout reached. Possible reasons: You are being rate limited; Timeout too short; Wrong server host configured;
at GameServerQuery.info — line 73
        catch (err) {
            this._promiseSocket.closeSocket();
            throw new Error(err);
        }
at Object.queryGameServerInfo — line 19

Originally posted by @Andrew1175 in #7 (comment)

Enable Goldsrc Servers support

This package only supports response for Source servers, I have made changes to make it compatible with Goldsrc servers (Counter Strike 1.6, Half-Life, Team Fortress Classic, etc)

Steam documentation taught me how to validate this.
For more information: https://developer.valvesoftware.com/wiki/Server_queries

It must be discriminated in the _parseInfoBuffer function in position [4] of the buffer and determine if it is "m" or "I"

I have changes ready to propose, I hope you can give me access to contribute to the project

Querying an Arma 3 server for players results in a buffer error

Awesome package! I'm having issues querying Arma 3 servers. Do you know why this is?

const { queryGameServerPlayer } = require("steam-server-query");

queryGameServerPlayer("51.195.209.188:2303")
  .then((playerResponse) => {
    console.log(playerResponse);
  })
  .catch((err) => {
    console.error(err);
  });
RangeError [ERR_BUFFER_OUT_OF_BOUNDS]: Attempt to access memory outside buffer bounds
    at new NodeError (node:internal/errors:371:5)
    at boundsError (node:internal/buffer:84:11)
    at Buffer.readInt32LE (node:internal/buffer:390:5)
    at GameServerQuery._readPlayer (node_modules\steam-server-query\lib\gameServer\gameServer.js:252:31)
    at GameServerQuery._parsePlayerBuffer (node_modules\steam-server-query\lib\gameServer\gameServer.js:219:37)      
    at GameServerQuery.player (node_modules\steam-server-query\lib\gameServer\gameServer.js:110:41)
    at async queryGameServerPlayer (node_modules\steam-server-query\lib\gameServer\gameServer.js:37:20) {
  code: 'ERR_BUFFER_OUT_OF_BOUNDS'
}

i have some questions

first ,this libriary is very nice.i made a library like this by Java.but ,i have two questions or suggestions
1、i crash one error like this
TypeError: buffer.readBigInt64LE is not a function
from infoResponse.gameId
2、this library has a2s_info、a2s_players、a2s_rule,and can u add rcon protocol?

`Timeout reached` error

Hello. I am following the API examples and I keep getting this error

Error: Timeout reached. Possible reasons: You are being rate limited; Timeout too short; Wrong server host configured;
    at GameServerQuery.info (/home/runner/steam-server-query-test/node_modules/steam-server-query/lib/gameServer/gameServer.js:73:19)

I tried it with the example server address and also with other public servers and I still get the same error.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.