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

@bsnext/mta-ase-query

v1.2.1

Published

Node.JS library for send requests to MTA:SA servers and get basic info.

Downloads

66

Readme

MTA-ASE-Query

Library for send requests to Multi Theft Auto: San Andreas servers and get basic info. Working around ASE protocol (EYE1).

Also, possible request all servers info with "partially" fields from those API.

// These objects is returned by getServerInfo()
interface MTAServerResponse {
    name: string;
    ip: string;
    port: number;
    gamemode: string;
    map: string;
    version: string;
    private: boolean;
    players: number;
    max_players: number;
    rules: {
        name: string;
        value: string;
    }[],
    players_list: {
        name: string;
        ping: number;
        score: number;
    }[]
}

// These objects is returned by getServers()
interface MTAServerResponseLite {
    name: string;
    ip: string;
    port: number;
    version: string;
    private: boolean;
    players: number;
    max_players: number;
}

What is a "Rules"? (MTA:SA Wiki) What is a "Score"? (MTA:SA Wiki)

Installing:

npm install @bsnext/mta-ase-query

API:

getServerInfo(
    serverAdress: string, serverPort: number = 22003, requestTimeout: number = 7500
): Promise<MTAServerResponse>;

// serverAdress - Server adress, can be IP or Domain.
// serverPort - Server port, 22003 by default.
// requestTimeout - Timeout for close long-time requests.
getServers(): Promise<MTAServerResponseLite>;

Usage:

import { getServerInfo } from "@bsnext/mta-ase-query";
const serverInfo = await getServerInfo(`lime.dayzmta.ru`, 22003);

/*
serverInfo = {
    name: '██ #3 | RU █ [BS] DAYZ ULTIMATE: LIME █ PVP, EASY, LOOT X3',
    gamemode: 'RU ██ DayZ Ultimate 1.5',
    map: 'None',
    version: '1.6',
    private: false,
    players: 1,
    max_players: 80,
    rules: [],
    players_list: [ 
        { name: 'WildDove83', ping: 7, score: 0 } 
    ]
}
*/
import { getServers } from "@bsnext/mta-ase-query";
const allServersInfo = await getServers();

/*
allServersInfo = [
    ...,
    {
        name: '██ #3 | RU █ [BS] DAYZ ULTIMATE: LIME █ PVP, EASY, LOOT X3',
        version: '1.6',
        private: false,
        players: 4,
        max_players: 80,
    },
    {
        name: '██ #4 | EU █ [BS] DAYZ ULTIMATE: MINT █ PVP, EASY, LOOT X3',
        version: '1.6',
        private: false,
        players: 16,
        max_players: 80,
    },
    ...
]
*/

Example:

Basic example of request.

const result: MTAServerResponse = await getServerInfo(`lime.dayzmta.ru`, 22003);

console.log(`Server Name: ${result.name}`);
console.log(`Gamemode: ${result.gamemode}`);
console.log(`Map: ${result.map}`);
console.log(`Version: ${result.version}`);
console.log(`Is Passworded: ${result.private ? `Yes` : `No`}`);
console.log(`Players: ${result.players}/${result.max_players}`);

if (result.rules.length > 0) {
    console.log(`Rules:`);
    for (const rule of result.rules) {
        console.log(`- ${rule.name}: ${rule.value}`);
    }
}

if (result.players_list.length > 0) {
    console.log(`Players List:`);
    for (const player of result.players_list) {
        console.log(`- ${player.name}: ${player.score} (${player.ping} ms)`);
    }
}

Catch the request error.

try {
    const result: MTAServerResponse = await getServerInfo(`not-existed-server.dayzmta.ru`, 22003);
    console.log(`Server Name: ${result.name}`);
} catch(e) {
    console.error(e);
}

Request all servers info, and filter by name.

const result: MTAServerResponseLite[] = await getServers();

const filteredResult = result.filter(
    function (value) {
        return value.name.search(`DAYZ ULTIMATE`) > -1;
    }
);

for (const serverInfo of filteredResult) {
    console.log(`----------------`);
    console.log(`Server Name: ${serverInfo.name}`);
    console.log(`Version: ${serverInfo.version}`);
    console.log(`Is Passworded: ${serverInfo.private ? `Yes` : `No`}`);
    console.log(`Players: ${serverInfo.players}/${serverInfo.max_players}`);
}