npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eimspyr

v0.6.1

Published

Query information from a running Source Dedicated Server (SRCDS) using UDP/IP packets.

Downloads

21

Readme

Eimspyr

npm GitHub npm type definitions node-current size repository size minified size minzip Continuous integration CodeQL

Eimspyr is a Node.js library written in TypeScript. It queries information from a running Source Dedicated Server (SRCDS) using UDP/IP packets.

Installation

npm i eimspyr

Usage

Example values for properties address & port must be replaced with the remote server to be queried.

JavaScript

import { infoQuery } from 'eimspyr'

const response = await infoQuery({
  address: '127.0.0.1',
  port: 12345,
})

TypeScript

import type { InfoQuery, InfoQueryOptions } from 'eimspyr'
import { infoQuery } from 'eimspyr'

const destination: InfoQueryOptions = {
  address: '127.0.0.1',
  port: 12345,
}

const response: InfoQuery = await infoQuery(destination)

Types reference

Built-in type definitions are available for supported IDEs and editors, including for non-TypeScript users.

Importing types with TypeScript is optional and suggested for type safety and readability.

Imports

import type { InfoQuery, InfoQueryOptions } from 'eimspyr'

Request

InfoQueryOptions is the input parameter for infoQuery.

type InfoQueryOptions = {
  address: string
  port: number
  portTolerance?: number
  timeout?: number
}

Port error tolerance

Queries that are inaccurate by up to 1 port number are allowed by default. This is useful for situations where interchangeable RCON and query ports are desired for convenience. Regardless of the inaccuracy of the provided port number, the true port of the request is included in the InfoQuery response at request.port.

For example, Valheim's joinable in-game port (RCON) is 1 less than the query port number (i.e.: rcon: 999 and query: 1000). It is usually not possible to query RCON ports without manually incrementing to find the query port number, but this incrementing is solved automatically by default, allowing all ports seen in-game and in the Steam server browser to be "queried" as-is.

Provide a number to the optional portTolerance property to change the port offset, which should equal the known distance commonly found between a game's RCON and query ports (usually 1).

Set to 0 for best performance.

Timeout

Queries time out at 3000 milliseconds (3 seconds) by default. This duration can be shortened or extended by providing a replacement number in milliseconds to the optional timeout property.

If the timeout occurs before the query completes, a RangeError is thrown.

Learn more about async error handling.

Response

Specification: SRCDS server queries

The InfoQuery response object is JSON-serializable. Multiple fields are conditional to the value of extraDataFlag.

type InfoQuery = {
  antiCheat: boolean
  appID?: string
  bots: number
  extraDataFlag: number
  folder: string
  game: string
  keywords?: string
  map: string
  operatingSystem: 'Linux' | 'macOS' | 'Windows'
  passwordRequired: boolean
  platformID?: string
  players: number
  playersMax: number
  port?: number
  protocolVersion: number
  request: {
    address: string
    port: number
    timeout: number
  }
  response: {
    address: string
    challenge?: number
    family: string
    latency: {
      maximum: number
      median: number
      minimum: number
      total: number
    }
    messages: [
      {
        latency: number
        message: Buffer
        size: number
      }
    ]
    packetSplit: boolean
    port: number
    reflectionHardened: boolean
    type: 'A2S_INFO'
  }
  serverName: string
  serverType: 'dedicated' | 'local' | 'proxy'
  serverVersion: string
  spectatorName?: number
  spectatorPort?: number
}

Compatibility

A2S_INFO single-packet query responses are supported. Multi-packet responses are not supported.

Responses are supported from servers both hardened and vulnerable against reflection attacks (est. Dec. 2020). This status can be read from response.reflectionHardened.

Environment

node:buffer and node:dgram are Node.js dependencies that are incompatible with a browser environment, unless integrated with an API (see also: Next.js API route handler).

Games tested

Other games are likely compatible but have yet to be tested. For querying unsupported games in Node.js, try node-GameDig (est. 2013).

Use cases

Next.js API route handler

import { infoQuery } from 'eimspyr'

export default async function handler(req, res) {
  res.status(200).json(
    await infoQuery({
      address: '127.0.0.1',
      port: 12345,
    })
  )
}