{"_id":"@bsnext/mta-ase-query","_rev":"4-710795687f489da8ffef0077e2666702","name":"@bsnext/mta-ase-query","dist-tags":{"latest":"1.2.1"},"versions":{"1.0.0":{"name":"@bsnext/mta-ase-query","version":"1.0.0","keywords":["nodejs","typescript","mta","mtasa","ase","multitheftauto","server","query"],"author":{"name":"SalwadoR"},"license":"MIT","_id":"@bsnext/mta-ase-query@1.0.0","maintainers":[{"name":"bsnext","email":"beststudiomta@gmail.com"}],"homepage":"https://github.com/bsnext/MTA-ASE-Query#readme","bugs":{"url":"https://github.com/bsnext/MTA-ASE-Query/issues"},"dist":{"shasum":"89978b6fa1fe704f603a7f073a82811f54b1b076","tarball":"https://registry.npmjs.org/@bsnext/mta-ase-query/-/mta-ase-query-1.0.0.tgz","fileCount":6,"integrity":"sha512-nW/UJl34aZlSCq9tJ3Y4jIziGxEr60rVJbEomzBlBc9vk5l7R1P5Vq0oQeQmu34OuQ1hr5ggGSZ5oFTWmaFTNg==","signatures":[{"sig":"MEYCIQCVvzYkt72qkm8ivGoVT+mXFSKnMEt5hnBy2J65T5DVoAIhAJxjgappuKEfag1Fd0am0zkzyXXzthf8XDhwxE2CPbZ1","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":10187},"main":"dist/index.js","type":"commonjs","types":"dist/index.d.ts","gitHead":"b1d9446d7c960bfcfea70dc76acf35d28d370c89","scripts":{"build":"tsc --project tsconfig.json","start":"node dist/index.js","watch":"tsc --watch","example":"node dist/example/index.js"},"_npmUser":{"name":"bsnext","email":"beststudiomta@gmail.com"},"repository":{"url":"git+https://github.com/bsnext/MTA-ASE-Query.git","type":"git"},"_npmVersion":"10.8.1","description":"Node.JS library for send requests to MTA:SA servers and get basic info.","directories":{},"_nodeVersion":"22.3.0","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^4.9.3","@types/node":"^18.11.18"},"_npmOperationalInternal":{"tmp":"tmp/mta-ase-query_1.0.0_1719980506724_0.028734840161508624","host":"s3://npm-registry-packages"}},"1.1.0":{"name":"@bsnext/mta-ase-query","version":"1.1.0","keywords":["nodejs","typescript","mta","mtasa","ase","multitheftauto","server","query"],"author":{"name":"SalwadoR"},"license":"MIT","_id":"@bsnext/mta-ase-query@1.1.0","maintainers":[{"name":"bsnext","email":"beststudiomta@gmail.com"}],"homepage":"https://github.com/bsnext/MTA-ASE-Query#readme","bugs":{"url":"https://github.com/bsnext/MTA-ASE-Query/issues"},"dist":{"shasum":"7f2ff80a0a34a6ff0770f82e640bf9e2f90524ad","tarball":"https://registry.npmjs.org/@bsnext/mta-ase-query/-/mta-ase-query-1.1.0.tgz","fileCount":6,"integrity":"sha512-mP6BJDAg3Vr6WUAgUUuNaDke5UCYVhfgyJF9TQ3wVrUzybZ/R49r+voufUd2elzs5m5jbkhAWU7lTJvr2taY1A==","signatures":[{"sig":"MEYCIQDDMZpIz4owpIyq4in6n4GZGtX6UwTlRo7GGbQ0LLnDEAIhAPUls6JWED5tYVvtIqrb4xiY7cA0M0YlX/nhL6KJYxhB","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":15818},"main":"dist/index.js","type":"commonjs","types":"dist/index.d.ts","gitHead":"ec0339603917e98654303ca2eac8afb5c2acb1c4","scripts":{"build":"tsc --project tsconfig.json","start":"node dist/index.js","watch":"tsc --watch","example":"node dist/example/index.js"},"_npmUser":{"name":"bsnext","email":"beststudiomta@gmail.com"},"repository":{"url":"git+https://github.com/bsnext/MTA-ASE-Query.git","type":"git"},"_npmVersion":"10.8.1","description":"Node.JS library for send requests to MTA:SA servers and get basic info.","directories":{},"_nodeVersion":"22.3.0","dependencies":{},"_hasShrinkwrap":false,"devDependencies":{"typescript":"^4.9.3","@types/node":"^18.11.18"},"_npmOperationalInternal":{"tmp":"tmp/mta-ase-query_1.1.0_1720005698533_0.14096679650929356","host":"s3://npm-registry-packages"}},"1.2.1":{"name":"@bsnext/mta-ase-query","version":"1.2.1","description":"Node.JS library for send requests to MTA:SA servers and get basic info.","main":"dist/index.js","types":"dist/index.d.ts","scripts":{"start":"node dist/index.js","build":"tsc --project tsconfig.json","watch":"tsc --watch"},"repository":{"type":"git","url":"git+https://github.com/bsnext/MTA-ASE-Query.git"},"keywords":["nodejs","typescript","mta","mtasa","ase","multitheftauto","server","query"],"bugs":{"url":"https://github.com/bsnext/MTA-ASE-Query/issues"},"homepage":"https://github.com/bsnext/MTA-ASE-Query#readme","author":{"name":"SalwadoR"},"type":"commonjs","license":"MIT","dependencies":{},"devDependencies":{"@types/node":"^18.11.18","typescript":"^4.9.3"},"_id":"@bsnext/mta-ase-query@1.2.1","gitHead":"b8b4cd3d1e515ac26f0232709f68981936e04d83","_nodeVersion":"22.3.0","_npmVersion":"10.8.1","dist":{"integrity":"sha512-v4zJg3XYPf7N4u4G5MkX4ozM9Ghmhp6++/Z0XH/L19rBT3q1yPNJJA353qEahZvKIZJx1lIRMEW8oY+7ANmOrA==","shasum":"47a873d040c197834ac32715052f8f932e6d8966","tarball":"https://registry.npmjs.org/@bsnext/mta-ase-query/-/mta-ase-query-1.2.1.tgz","fileCount":6,"unpackedSize":20639,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQChLi1hk2sFV1lpx/DsYQgaPgjOXNcnLYMcCfgyfpwTDgIgWd3UX+3BOv8m4i0wnToLZuQRf5E+YbpQCwCz7pIz6lg="}]},"_npmUser":{"name":"bsnext","email":"beststudiomta@gmail.com"},"directories":{},"maintainers":[{"name":"bsnext","email":"beststudiomta@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mta-ase-query_1.2.1_1720716687601_0.7955744437541754"},"_hasShrinkwrap":false}},"time":{"created":"2024-07-03T04:21:46.631Z","modified":"2024-07-11T16:51:27.934Z","1.0.0":"2024-07-03T04:21:46.865Z","1.1.0":"2024-07-03T11:21:38.675Z","1.2.0":"2024-07-11T16:47:37.755Z","1.2.1":"2024-07-11T16:51:27.755Z"},"bugs":{"url":"https://github.com/bsnext/MTA-ASE-Query/issues"},"author":{"name":"SalwadoR"},"license":"MIT","homepage":"https://github.com/bsnext/MTA-ASE-Query#readme","keywords":["nodejs","typescript","mta","mtasa","ase","multitheftauto","server","query"],"repository":{"type":"git","url":"git+https://github.com/bsnext/MTA-ASE-Query.git"},"description":"Node.JS library for send requests to MTA:SA servers and get basic info.","maintainers":[{"name":"bsnext","email":"beststudiomta@gmail.com"}],"readme":"# MTA-ASE-Query\r\n\r\nLibrary for send requests to [Multi Theft Auto: San Andreas](https://mtasa.com) servers and get basic info.<br>\r\nWorking around ASE protocol ([EYE1](https://github.com/multitheftauto/mtasa-blue/blob/615b9b67c89fb3448f1e7c284146ee0800a3215e/Server/mods/deathmatch/logic/ASE.cpp#L236)).\r\n\r\nAlso, possible request all servers info with \"partially\" fields from [those API](https://mtasa.com/api).\r\n\r\n```ts\r\n// These objects is returned by getServerInfo()\r\ninterface MTAServerResponse {\r\n    name: string;\r\n    ip: string;\r\n    port: number;\r\n    gamemode: string;\r\n    map: string;\r\n    version: string;\r\n    private: boolean;\r\n    players: number;\r\n    max_players: number;\r\n    rules: {\r\n        name: string;\r\n        value: string;\r\n    }[],\r\n    players_list: {\r\n        name: string;\r\n        ping: number;\r\n        score: number;\r\n    }[]\r\n}\r\n\r\n// These objects is returned by getServers()\r\ninterface MTAServerResponseLite {\r\n    name: string;\r\n    ip: string;\r\n    port: number;\r\n    version: string;\r\n    private: boolean;\r\n    players: number;\r\n    max_players: number;\r\n}\r\n```\r\n\r\n**[What is a \"Rules\"?](https://wiki.multitheftauto.com/wiki/SetRuleValue)** (MTA:SA Wiki)<br>\r\n**[What is a \"Score\"?](https://wiki.multitheftauto.com/wiki/SetPlayerAnnounceValue)** (MTA:SA Wiki)\r\n\r\n## Installing:\r\n```bash\r\nnpm install @bsnext/mta-ase-query\r\n```\r\n\r\n## API:\r\n```ts\r\ngetServerInfo(\r\n    serverAdress: string, serverPort: number = 22003, requestTimeout: number = 7500\r\n): Promise<MTAServerResponse>;\r\n\r\n// serverAdress - Server adress, can be IP or Domain.\r\n// serverPort - Server port, 22003 by default.\r\n// requestTimeout - Timeout for close long-time requests.\r\n```\r\n\r\n```ts\r\ngetServers(): Promise<MTAServerResponseLite>;\r\n```\r\n\r\n## Usage:\r\n```ts\r\nimport { getServerInfo } from \"@bsnext/mta-ase-query\";\r\nconst serverInfo = await getServerInfo(`lime.dayzmta.ru`, 22003);\r\n\r\n/*\r\nserverInfo = {\r\n    name: '██ #3 | RU █ [BS] DAYZ ULTIMATE: LIME █ PVP, EASY, LOOT X3',\r\n    gamemode: 'RU ██ DayZ Ultimate 1.5',\r\n    map: 'None',\r\n    version: '1.6',\r\n    private: false,\r\n    players: 1,\r\n    max_players: 80,\r\n    rules: [],\r\n    players_list: [ \r\n        { name: 'WildDove83', ping: 7, score: 0 } \r\n    ]\r\n}\r\n*/\r\n```\r\n\r\n```ts\r\nimport { getServers } from \"@bsnext/mta-ase-query\";\r\nconst allServersInfo = await getServers();\r\n\r\n/*\r\nallServersInfo = [\r\n    ...,\r\n    {\r\n        name: '██ #3 | RU █ [BS] DAYZ ULTIMATE: LIME █ PVP, EASY, LOOT X3',\r\n        version: '1.6',\r\n        private: false,\r\n        players: 4,\r\n        max_players: 80,\r\n    },\r\n    {\r\n        name: '██ #4 | EU █ [BS] DAYZ ULTIMATE: MINT █ PVP, EASY, LOOT X3',\r\n        version: '1.6',\r\n        private: false,\r\n        players: 16,\r\n        max_players: 80,\r\n    },\r\n    ...\r\n]\r\n*/\r\n```\r\n\r\n## Example:\r\n**Basic example of request.**\r\n```ts\r\nconst result: MTAServerResponse = await getServerInfo(`lime.dayzmta.ru`, 22003);\r\n\r\nconsole.log(`Server Name: ${result.name}`);\r\nconsole.log(`Gamemode: ${result.gamemode}`);\r\nconsole.log(`Map: ${result.map}`);\r\nconsole.log(`Version: ${result.version}`);\r\nconsole.log(`Is Passworded: ${result.private ? `Yes` : `No`}`);\r\nconsole.log(`Players: ${result.players}/${result.max_players}`);\r\n\r\nif (result.rules.length > 0) {\r\n    console.log(`Rules:`);\r\n    for (const rule of result.rules) {\r\n        console.log(`- ${rule.name}: ${rule.value}`);\r\n    }\r\n}\r\n\r\nif (result.players_list.length > 0) {\r\n    console.log(`Players List:`);\r\n    for (const player of result.players_list) {\r\n        console.log(`- ${player.name}: ${player.score} (${player.ping} ms)`);\r\n    }\r\n}\r\n```\r\n\r\n**Catch the request error.**\r\n```ts\r\ntry {\r\n    const result: MTAServerResponse = await getServerInfo(`not-existed-server.dayzmta.ru`, 22003);\r\n    console.log(`Server Name: ${result.name}`);\r\n} catch(e) {\r\n    console.error(e);\r\n}\r\n```\r\n\r\n**Request all servers info, and filter by name.**\r\n```ts\r\nconst result: MTAServerResponseLite[] = await getServers();\r\n\r\nconst filteredResult = result.filter(\r\n    function (value) {\r\n        return value.name.search(`DAYZ ULTIMATE`) > -1;\r\n    }\r\n);\r\n\r\nfor (const serverInfo of filteredResult) {\r\n    console.log(`----------------`);\r\n    console.log(`Server Name: ${serverInfo.name}`);\r\n    console.log(`Version: ${serverInfo.version}`);\r\n    console.log(`Is Passworded: ${serverInfo.private ? `Yes` : `No`}`);\r\n    console.log(`Players: ${serverInfo.players}/${serverInfo.max_players}`);\r\n}\r\n```","readmeFilename":"README.md"}