Move to ES6 module (#357)

* Redo imports and exports for lib

* Redo imports and exports for bim

* Redo imports and exports for games

* Remove remaining module.exports

* Use export default in lib

* Use export default in protocols

* Fix import in genreadme.js

* Make package module and solve __dirname

* Fix minecraft protocol imports

* Fix imports on games and make binary runnable

* Renamed protocol class exports to lowercase

* Export promises class as default

* Update README.md to use imports instead of require

* Update CHANGELOG to mention the changes.

* Remove Valve unused imports

* Fix iconv import
This commit is contained in:
CosminPerRam 2023-09-14 23:28:31 +03:00 committed by GitHub
parent b4f6e7fab6
commit ad9adff06c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
64 changed files with 249 additions and 323 deletions

View File

@ -1,6 +1,8 @@
### To Be Released... ### To Be Released...
* Replaced usage of deprecated `substr` with `substring`. * Replaced usage of deprecated `substr` with `substring`.
* Moved the library a `module`.
* CLI: Resolved incorrect error message when querying with a non-existent protocol name.
### 4.1.0 ### 4.1.0
* Replace `compressjs` dependency by `seek-bzip` to solve some possible import issues. * Replace `compressjs` dependency by `seek-bzip` to solve some possible import issues.

View File

@ -11,13 +11,14 @@ Support is available on the [GameDig Discord](https://discord.gg/NVCMn3tnxH) (fo
See the [GAMES_LIST.md](GAMES_LIST.md) file for the currently supported titles, not yet supported ones and notes about some of them. See the [GAMES_LIST.md](GAMES_LIST.md) file for the currently supported titles, not yet supported ones and notes about some of them.
## Usage from Node.js ## Usage from Node.js
Install...
```shell ```shell
npm install gamedig npm install gamedig
``` ```
... then use!
```js
import GameDig from 'gamedig';
```javascript
const GameDig = require('gamedig');
GameDig.query({ GameDig.query({
type: 'minecraft', type: 'minecraft',
host: 'mc.example.com' host: 'mc.example.com'

View File

@ -1,7 +1,7 @@
#!/usr/bin/env node #!/usr/bin/env node
const Minimist = require('minimist'); import Minimist from 'minimist';
const GameDig = require('..'); import GameDig from './../lib/index.js';
const argv = Minimist(process.argv.slice(2), { const argv = Minimist(process.argv.slice(2), {
boolean: ['pretty','debug','givenPortOnly','requestRules'], boolean: ['pretty','debug','givenPortOnly','requestRules'],

View File

@ -1,8 +1,9 @@
#!/usr/bin/env node #!/usr/bin/env node
const fs = require('fs'), import * as fs from 'fs';
GameResolver = require('../lib/GameResolver'), import GameResolver from "../lib/GameResolver";
gameResolver = new GameResolver();
const gameResolver = new GameResolver();
const generated = gameResolver.printReadme(); const generated = gameResolver.printReadme();

View File

@ -1,11 +1,11 @@
const dns = require('dns'), import * as dns from 'dns';
Logger = require('./Logger'), import * as punycode from "punycode";
util = require('util'), import { promisify } from "util";
dnsLookupAsync = util.promisify(dns.lookup),
dnsResolveAsync = util.promisify(dns.resolve),
punycode = require('punycode');
class DnsResolver { const dnsLookupAsync = promisify(dns.lookup);
const dnsResolveAsync = promisify(dns.resolve);
export default class DnsResolver {
/** /**
* @param {Logger} logger * @param {Logger} logger
*/ */
@ -76,5 +76,3 @@ class DnsResolver {
return {address: address}; return {address: address};
} }
} }
module.exports = DnsResolver;

View File

@ -1,7 +1,8 @@
const Path = require('path'), import * as path from 'path';
fs = require('fs'); import { fileURLToPath } from "url";
import * as fs from 'fs';
class GameResolver { export default class GameResolver {
constructor() { constructor() {
const loaded = this._readGames(); const loaded = this._readGames();
this.gamesByKey = loaded.gamesByKey; this.gamesByKey = loaded.gamesByKey;
@ -56,7 +57,9 @@ class GameResolver {
} }
_readGames() { _readGames() {
const gamesFile = Path.normalize(__dirname+'/../games.txt'); const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const gamesFile = path.normalize(__dirname+'/../games.txt');
const lines = fs.readFileSync(gamesFile,'utf8').split('\n'); const lines = fs.readFileSync(gamesFile,'utf8').split('\n');
const gamesByKey = new Map(); const gamesByKey = new Map();
@ -117,5 +120,3 @@ class GameResolver {
return out; return out;
} }
} }
module.exports = GameResolver;

View File

@ -1,9 +1,10 @@
const dgram = require('dgram');
const HexUtil = require('./HexUtil');
const Logger = require('./Logger');
const util = require('util');
class GlobalUdpSocket { import { createSocket } from "dgram";
import { debugDump } from "./HexUtil.js";
import { promisify } from "util";
import Logger from "./Logger.js";
export default class GlobalUdpSocket {
constructor({port}) { constructor({port}) {
this.socket = null; this.socket = null;
this.callbacks = new Set(); this.callbacks = new Set();
@ -14,7 +15,7 @@ class GlobalUdpSocket {
async _getSocket() { async _getSocket() {
if (!this.socket) { if (!this.socket) {
const udpSocket = dgram.createSocket({ const udpSocket = createSocket({
type: 'udp4', type: 'udp4',
reuseAddr: true reuseAddr: true
}); });
@ -24,7 +25,7 @@ class GlobalUdpSocket {
const fromPort = rinfo.port; const fromPort = rinfo.port;
this.logger.debug(log => { this.logger.debug(log => {
log(fromAddress + ':' + fromPort + " <--UDP(" + this.port + ")"); log(fromAddress + ':' + fromPort + " <--UDP(" + this.port + ")");
log(HexUtil.debugDump(buffer)); log(debugDump(buffer));
}); });
for (const callback of this.callbacks) { for (const callback of this.callbacks) {
callback(fromAddress, fromPort, buffer); callback(fromAddress, fromPort, buffer);
@ -33,7 +34,7 @@ class GlobalUdpSocket {
udpSocket.on('error', e => { udpSocket.on('error', e => {
this.logger.debug("UDP ERROR:", e); this.logger.debug("UDP ERROR:", e);
}); });
await util.promisify(udpSocket.bind).bind(udpSocket)(this.port); await promisify(udpSocket.bind).bind(udpSocket)(this.port);
this.port = udpSocket.address().port; this.port = udpSocket.address().port;
this.socket = udpSocket; this.socket = udpSocket;
} }
@ -46,11 +47,11 @@ class GlobalUdpSocket {
if (debug) { if (debug) {
this.logger._print(log => { this.logger._print(log => {
log(address + ':' + port + " UDP(" + this.port + ")-->"); log(address + ':' + port + " UDP(" + this.port + ")-->");
log(HexUtil.debugDump(buffer)); log(debugDump(buffer));
}); });
} }
await util.promisify(socket.send).bind(socket)(buffer,0,buffer.length,port,address); await promisify(socket.send).bind(socket)(buffer,0,buffer.length,port,address);
} }
addCallback(callback, debug) { addCallback(callback, debug) {
@ -66,5 +67,3 @@ class GlobalUdpSocket {
this.logger.debugEnabled = this.debuggingCallbacks.size > 0; this.logger.debugEnabled = this.debuggingCallbacks.size > 0;
} }
} }
module.exports = GlobalUdpSocket;

View File

@ -1,24 +1,21 @@
class HexUtil {
/** @param {Buffer} buffer */
static debugDump(buffer) {
let hexLine = '';
let chrLine = '';
let out = '';
out += "Buffer length: " + buffer.length + " bytes\n";
for(let i = 0; i < buffer.length; i++) {
const sliced = buffer.slice(i,i+1);
hexLine += sliced.toString('hex')+' ';
let chr = sliced.toString();
if(chr < ' ' || chr > '~') chr = ' ';
chrLine += chr+' ';
if(hexLine.length > 60 || i === buffer.length - 1) {
out += hexLine + '\n';
out += chrLine + '\n';
hexLine = chrLine = '';
}
}
return out;
}
}
module.exports = HexUtil; /** @param {Buffer} buffer */
export const debugDump = (buffer) => {
let hexLine = '';
let chrLine = '';
let out = '';
out += "Buffer length: " + buffer.length + " bytes\n";
for(let i = 0; i < buffer.length; i++) {
const sliced = buffer.slice(i,i+1);
hexLine += sliced.toString('hex')+' ';
let chr = sliced.toString();
if(chr < ' ' || chr > '~') chr = ' ';
chrLine += chr+' ';
if(hexLine.length > 60 || i === buffer.length - 1) {
out += hexLine + '\n';
out += chrLine + '\n';
hexLine = chrLine = '';
}
}
return out;
}

View File

@ -1,6 +1,6 @@
const HexUtil = require('./HexUtil'); import {debugDump} from './HexUtil.js';
class Logger { export default class Logger {
constructor() { constructor() {
this.debugEnabled = false; this.debugEnabled = false;
this.prefix = ''; this.prefix = '';
@ -31,7 +31,7 @@ class Logger {
if (arg instanceof Error) { if (arg instanceof Error) {
out.push(arg.stack); out.push(arg.stack);
} else if (arg instanceof Buffer) { } else if (arg instanceof Buffer) {
out.push(HexUtil.debugDump(arg)); out.push(debugDump(arg));
} else if (typeof arg == 'function') { } else if (typeof arg == 'function') {
const result = arg.call(undefined, (...args) => this._print(...args)); const result = arg.call(undefined, (...args) => this._print(...args));
if (result !== undefined) out.push(...this._convertArgsToStrings(result)); if (result !== undefined) out.push(...this._convertArgsToStrings(result));
@ -42,5 +42,3 @@ class Logger {
return out; return out;
} }
} }
module.exports = Logger;

View File

@ -1,4 +1,4 @@
class Promises { export default class Promises {
static createTimeout(timeoutMs, timeoutMsg) { static createTimeout(timeoutMs, timeoutMsg) {
let cancel = null; let cancel = null;
const wrapped = new Promise((res, rej) => { const wrapped = new Promise((res, rej) => {
@ -16,5 +16,3 @@ class Promises {
return wrapped; return wrapped;
} }
} }
module.exports = Promises;

View File

@ -1,22 +1,8 @@
const Path = require('path'), import * as Protocols from '../protocols/index.js'
fs = require('fs'),
Core = require('../protocols/core');
class ProtocolResolver { export const getProtocol = (protocolId) => {
constructor() { if(!(protocolId in Protocols))
this.protocolDir = Path.normalize(__dirname+'/../protocols'); throw Error('Protocol definition file missing: ' + protocolId);
}
/** return new Protocols[protocolId];
* @returns Core
*/
create(protocolId) {
protocolId = Path.basename(protocolId);
const path = this.protocolDir+'/'+protocolId;
if(!fs.existsSync(path+'.js')) throw Error('Protocol definition file missing: '+type);
const protocol = require(path);
return new protocol();
}
} }
module.exports = ProtocolResolver;

View File

@ -1,6 +1,6 @@
const GameResolver = require('./GameResolver'), import GameResolver from "./GameResolver.js";
ProtocolResolver = require('./ProtocolResolver'), import {getProtocol} from './ProtocolResolver.js';
GlobalUdpSocket = require('./GlobalUdpSocket'); import GlobalUdpSocket from "./GlobalUdpSocket.js";
const defaultOptions = { const defaultOptions = {
socketTimeout: 2000, socketTimeout: 2000,
@ -9,13 +9,12 @@ const defaultOptions = {
ipFamily: 0 ipFamily: 0
}; };
class QueryRunner { export default class QueryRunner {
constructor(runnerOpts = {}) { constructor(runnerOpts = {}) {
this.udpSocket = new GlobalUdpSocket({ this.udpSocket = new GlobalUdpSocket({
port: runnerOpts.listenUdpPort port: runnerOpts.listenUdpPort
}); });
this.gameResolver = new GameResolver(); this.gameResolver = new GameResolver();
this.protocolResolver = new ProtocolResolver();
} }
async run(userOptions) { async run(userOptions) {
@ -90,11 +89,9 @@ class QueryRunner {
} }
async _attempt(options) { async _attempt(options) {
const core = this.protocolResolver.create(options.protocol); const core = getProtocol(options.protocol);
core.options = options; core.options = options;
core.udpSocket = this.udpSocket; core.udpSocket = this.udpSocket;
return await core.runOnceSafe(); return await core.runOnceSafe();
} }
} }
module.exports = QueryRunner;

View File

@ -1,4 +1,5 @@
class Player {
export class Player {
name = ''; name = '';
raw = {}; raw = {};
@ -13,7 +14,7 @@ class Player {
} }
} }
class Players extends Array { export class Players extends Array {
setNum(num) { setNum(num) {
// If the server specified some ridiculous number of players (billions), we don't want to // If the server specified some ridiculous number of players (billions), we don't want to
// run out of ram allocating these objects. // run out of ram allocating these objects.
@ -29,7 +30,7 @@ class Players extends Array {
} }
} }
class Results { export class Results {
name = ''; name = '';
map = ''; map = '';
password = false; password = false;
@ -40,5 +41,3 @@ class Results {
players = new Players(); players = new Players();
bots = new Players(); bots = new Players();
} }
module.exports = Results;

View File

@ -1,8 +1,8 @@
const QueryRunner = require('./QueryRunner'); import QueryRunner from './QueryRunner.js';
let singleton = null; let singleton = null;
class Gamedig { export default class Gamedig {
constructor(runnerOpts) { constructor(runnerOpts) {
this.queryRunner = new QueryRunner(runnerOpts); this.queryRunner = new QueryRunner(runnerOpts);
} }
@ -22,5 +22,3 @@ class Gamedig {
return await Gamedig.getInstance().query(...args); return await Gamedig.getInstance().query(...args);
} }
} }
module.exports = Gamedig;

View File

@ -1,8 +1,7 @@
const Iconv = require('iconv-lite'), import Iconv from "iconv-lite";
Long = require('long'), import Long from 'long';
Core = require('../protocols/core'), import {Buffer} from "buffer";
Buffer = require('buffer'), import Varint from 'varint';
Varint = require('varint');
function readUInt64BE(buffer,offset) { function readUInt64BE(buffer,offset) {
const high = buffer.readUInt32BE(offset); const high = buffer.readUInt32BE(offset);
@ -15,7 +14,7 @@ function readUInt64LE(buffer,offset) {
return new Long(low,high,true); return new Long(low,high,true);
} }
class Reader { export default class Reader {
/** /**
* @param {Core} query * @param {Core} query
* @param {Buffer} buffer * @param {Buffer} buffer
@ -171,5 +170,3 @@ class Reader {
return this.i >= this.buffer.length; return this.i >= this.buffer.length;
} }
} }
module.exports = Reader;

View File

@ -20,6 +20,7 @@
"csgo", "csgo",
"minecraft" "minecraft"
], ],
"type": "module",
"main": "lib/index.js", "main": "lib/index.js",
"author": "GameDig Contributors", "author": "GameDig Contributors",
"version": "4.1.0", "version": "4.1.0",

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class Armagetron extends Core { export default class armagetron extends Core {
constructor() { constructor() {
super(); super();
this.encoding = 'latin1'; this.encoding = 'latin1';
@ -61,5 +61,3 @@ class Armagetron extends Core {
return str.replace(/0x[0-9a-f]{6}/g,''); return str.replace(/0x[0-9a-f]{6}/g,'');
} }
} }
module.exports = Armagetron;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class Ase extends Core { export default class ase extends Core {
async run(state) { async run(state) {
const buffer = await this.udpSend('s',(buffer) => { const buffer = await this.udpSend('s',(buffer) => {
const reader = this.reader(buffer); const reader = this.reader(buffer);
@ -43,5 +43,3 @@ class Ase extends Core {
return reader.pascalString(1, -1); return reader.pascalString(1, -1);
} }
} }
module.exports = Ase;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class AssettoCorsa extends Core { export default class assettocorsa extends Core {
async run(state) { async run(state) {
const serverInfo = await this.request({ const serverInfo = await this.request({
url: `http://${this.options.address}:${this.options.port}/INFO`, url: `http://${this.options.address}:${this.options.port}/INFO`,
@ -14,7 +14,7 @@ class AssettoCorsa extends Core {
if (!serverInfo || !carInfo || !carInfo.Cars) { if (!serverInfo || !carInfo || !carInfo.Cars) {
throw new Error('Query not successful'); throw new Error('Query not successful');
} }
state.maxplayers = serverInfo.maxclients; state.maxplayers = serverInfo.maxclients;
state.name = serverInfo.name; state.name = serverInfo.name;
state.map = serverInfo.track; state.map = serverInfo.track;
@ -36,5 +36,3 @@ class AssettoCorsa extends Core {
} }
} }
} }
module.exports = AssettoCorsa;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class Battlefield extends Core { export default class battlefield extends Core {
constructor() { constructor() {
super(); super();
this.encoding = 'latin1'; this.encoding = 'latin1';
@ -159,5 +159,3 @@ class Battlefield extends Core {
return params; return params;
} }
} }
module.exports = Battlefield;

View File

@ -1,7 +1,7 @@
const Core = require('./core'), import Core from './core.js';
cheerio = require('cheerio'); import * as cheerio from "cheerio";
class BuildAndShoot extends Core { export default class buildandshoot extends Core {
async run(state) { async run(state) {
const body = await this.request({ const body = await this.request({
url: 'http://'+this.options.address+':'+this.options.port+'/', url: 'http://'+this.options.address+':'+this.options.port+'/',
@ -53,5 +53,3 @@ class BuildAndShoot extends Core {
*/ */
} }
} }
module.exports = BuildAndShoot;

View File

@ -1,15 +1,15 @@
const EventEmitter = require('events').EventEmitter; import {EventEmitter} from "events";
const net = require('net'); import * as net from "net";
const Reader = require('../lib/reader'); import Reader from "../lib/reader.js";
const HexUtil = require('../lib/HexUtil'); import {debugDump} from '../lib/HexUtil.js';
const Promises = require('../lib/Promises'); import Logger from "../lib/Logger.js";
const Logger = require('../lib/Logger'); import DnsResolver from "../lib/DnsResolver.js";
const DnsResolver = require('../lib/DnsResolver'); import {Results} from "../lib/Results.js";
const Results = require('../lib/Results'); import Promises from "../lib/Promises.js";
let uid = 0; let uid = 0;
class Core extends EventEmitter { export default class Core extends EventEmitter {
constructor() { constructor() {
super(); super();
this.encoding = 'utf8'; this.encoding = 'utf8';
@ -178,7 +178,7 @@ class Core extends EventEmitter {
const writeHook = socket.write; const writeHook = socket.write;
socket.write = (...args) => { socket.write = (...args) => {
log(address+':'+port+" TCP-->"); log(address+':'+port+" TCP-->");
log(HexUtil.debugDump(args[0])); log(debugDump(args[0]));
writeHook.apply(socket,args); writeHook.apply(socket,args);
}; };
socket.on('error', e => log('TCP Error:', e)); socket.on('error', e => log('TCP Error:', e));
@ -352,5 +352,3 @@ class Core extends EventEmitter {
this.logger.debug(...args); this.logger.debug(...args);
} }
} }
module.exports = Core;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class Cs2d extends Core { export default class cs2d extends Core {
async run(state) { async run(state) {
{ {
const reader = await this.sendQuery( const reader = await this.sendQuery(
@ -69,5 +69,3 @@ class Cs2d extends Core {
return reader.pascalString(1); return reader.pascalString(1);
} }
} }
module.exports = Cs2d;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class Discord extends Core { export default class discord extends Core {
async run(state) { async run(state) {
const guildId = this.options.guildId; const guildId = this.options.guildId;
if (typeof guildId !== 'string') { if (typeof guildId !== 'string') {
@ -27,5 +27,3 @@ class Discord extends Core {
state.raw = json; state.raw = json;
} }
} }
module.exports = Discord;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class Doom3 extends Core { export default class doom3 extends Core {
constructor() { constructor() {
super(); super();
this.encoding = 'latin1'; this.encoding = 'latin1';
@ -147,5 +147,3 @@ class Doom3 extends Core {
return str.replace(/\^(X.{6}|.)/g,''); return str.replace(/\^(X.{6}|.)/g,'');
} }
} }
module.exports = Doom3;

View File

@ -1,6 +1,6 @@
const Valve = require('./valve'); import valve from './valve.js';
class Ffow extends Valve { export default class ffow extends valve {
constructor() { constructor() {
super(); super();
this.byteorder = 'be'; this.byteorder = 'be';
@ -35,5 +35,3 @@ class Ffow extends Valve {
state.raw.timeleft = reader.uint(2); state.raw.timeleft = reader.uint(2);
} }
} }
module.exports = Ffow;

View File

@ -1,6 +1,6 @@
const Quake2 = require('./quake2'); import quake2 from './quake2.js';
class FiveM extends Quake2 { export default class fivem extends quake2 {
constructor() { constructor() {
super(); super();
this.sendHeader = 'getinfo xxx'; this.sendHeader = 'getinfo xxx';
@ -31,5 +31,3 @@ class FiveM extends Quake2 {
} }
} }
} }
module.exports = FiveM;

View File

@ -1,4 +1,4 @@
const Core = require('./core'); import Core from './core.js';
const stringKeys = new Set([ const stringKeys = new Set([
'website', 'website',
@ -29,7 +29,7 @@ function normalizeEntry([key,value]) {
return [key,value]; return [key,value];
} }
class Gamespy1 extends Core { export default class gamespy1 extends Core {
constructor() { constructor() {
super(); super();
this.encoding = 'latin1'; this.encoding = 'latin1';
@ -177,5 +177,3 @@ class Gamespy1 extends Core {
}); });
} }
} }
module.exports = Gamespy1;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class Gamespy2 extends Core { export default class gamespy2 extends Core {
constructor() { constructor() {
super(); super();
this.encoding = 'latin1'; this.encoding = 'latin1';
@ -138,5 +138,3 @@ class Gamespy2 extends Core {
return units; return units;
} }
} }
module.exports = Gamespy2;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class Gamespy3 extends Core { export default class gamespy3 extends Core {
constructor() { constructor() {
super(); super();
this.sessionId = 1; this.sessionId = 1;
@ -194,5 +194,3 @@ class Gamespy3 extends Core {
}); });
} }
} }
module.exports = Gamespy3;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class GeneShift extends Core { export default class geneshift extends Core {
async run(state) { async run(state) {
await this.tcpPing(); await this.tcpPing();
@ -44,5 +44,3 @@ class GeneShift extends Core {
state.raw.version = found[19]; state.raw.version = found[19];
} }
} }
module.exports = GeneShift;

View File

@ -1,10 +1,8 @@
const Valve = require('./valve'); import valve from './valve.js';
class GoldSrc extends Valve { export default class goldsrc extends valve {
constructor() { constructor() {
super(); super();
this.goldsrcInfo = true; this.goldsrcInfo = true;
} }
} }
module.exports = GoldSrc;

View File

@ -1,6 +1,6 @@
const Quake1 = require('./quake1'); import quake1 from './quake1.js';
class Hexen2 extends Quake1 { export default class hexen2 extends quake1 {
constructor() { constructor() {
super(); super();
this.sendHeader = '\xFFstatus\x0a'; this.sendHeader = '\xFFstatus\x0a';
@ -11,5 +11,3 @@ class Hexen2 extends Quake1 {
state.gamePort = this.options.port - 50; state.gamePort = this.options.port - 50;
} }
} }
module.exports = Hexen2;

52
protocols/index.js Normal file
View File

@ -0,0 +1,52 @@
import armagetron from "./armagetron.js";
import ase from "./ase.js";
import assettocorsa from "./assettocorsa.js";
import battlefield from "./battlefield.js";
import buildandshoot from "./buildandshoot.js";
import cs2d from "./cs2d.js";
import discord from "./discord.js";
import doom3 from "./doom3.js";
import ffow from "./ffow.js";
import fivem from "./fivem.js";
import gamespy1 from "./gamespy1.js";
import gamespy2 from "./gamespy2.js";
import gamespy3 from "./gamespy3.js";
import geneshift from "./geneshift.js";
import goldsrc from "./goldsrc.js";
import hexen2 from "./hexen2.js";
import jc2mp from "./jc2mp.js";
import kspdmp from "./kspdmp.js";
import mafia2mp from "./mafia2mp.js";
import mafia2online from "./mafia2online.js";
import minecraft from "./minecraft.js";
import minecraftbedrock from "./minecraftbedrock.js";
import minecraftvanilla from "./minecraftvanilla.js";
import mumble from "./mumble.js";
import mumbleping from "./mumbleping.js";
import nadeo from "./nadeo.js";
import openttd from "./openttd.js";
import quake1 from "./quake1.js";
import quake2 from "./quake2.js";
import quake3 from "./quake3.js";
import rfactor from "./rfactor.js";
import samp from "./samp.js";
import savage2 from "./savage2.js";
import starmade from "./starmade.js";
import starsiege from "./starsiege.js";
import teamspeak2 from "./teamspeak2.js";
import teamspeak3 from "./teamspeak3.js";
import terraria from "./terraria.js";
import tribes1 from "./tribes1.js";
import tribes1master from "./tribes1master.js";
import unreal2 from "./unreal2.js";
import ut3 from "./ut3.js";
import valve from "./valve.js";
import vcmp from "./vcmp.js";
import ventrilo from "./ventrilo.js";
import warsow from "./warsow.js";
export { armagetron, ase, assettocorsa, battlefield, buildandshoot, cs2d, discord, doom3, ffow, fivem, gamespy1,
gamespy2, gamespy3, geneshift, goldsrc, hexen2, jc2mp, kspdmp, mafia2mp, mafia2online, minecraft,
minecraftbedrock, minecraftvanilla, mumble, mumbleping, nadeo, openttd, quake1, quake2, quake3, rfactor, samp,
savage2, starmade, starsiege, teamspeak2, teamspeak3, terraria, tribes1, tribes1master, unreal2, ut3, valve,
vcmp, ventrilo, warsow }

View File

@ -1,8 +1,8 @@
const Gamespy3 = require('./gamespy3'); import gamespy3 from './gamespy3.js';
// supposedly, gamespy3 is the "official" query protocol for jcmp, // supposedly, gamespy3 is the "official" query protocol for jcmp,
// but it's broken (requires useOnlySingleSplit), and may not include some player names // but it's broken (requires useOnlySingleSplit), and may not include some player names
class Jc2mp extends Gamespy3 { export default class jc2mp extends gamespy3 {
constructor() { constructor() {
super(); super();
this.useOnlySingleSplit = true; this.useOnlySingleSplit = true;
@ -16,5 +16,3 @@ class Jc2mp extends Gamespy3 {
} }
} }
} }
module.exports = Jc2mp;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class Kspdmp extends Core { export default class kspdmp extends Core {
async run(state) { async run(state) {
const json = await this.request({ const json = await this.request({
url: 'http://'+this.options.address+':'+this.options.port, url: 'http://'+this.options.address+':'+this.options.port,
@ -25,5 +25,3 @@ class Kspdmp extends Core {
} }
} }
} }
module.exports = Kspdmp;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class Mafia2Multiplayer extends Core { export default class mafia2mp extends Core {
constructor() { constructor() {
super(); super();
this.encoding = 'latin1'; this.encoding = 'latin1';
@ -39,5 +39,3 @@ class Mafia2Multiplayer extends Core {
return reader.pascalString(1,-1); return reader.pascalString(1,-1);
} }
} }
module.exports = Mafia2Multiplayer;

View File

@ -1,11 +1,9 @@
const Mafia2Multiplayer = require('./mafia2mp'); import mafia2mp from './mafia2mp.js';
class Mafia2Online extends Mafia2Multiplayer { export default class mafia2online extends mafia2mp {
constructor() { constructor() {
super(); super();
this.header = 'M2Online'; this.header = 'M2Online';
this.isMafia2Online = true; this.isMafia2Online = true;
} }
} }
module.exports = Mafia2Online;

View File

@ -1,8 +1,8 @@
const Core = require('./core'); import Core from './core.js';
const MinecraftVanilla = require('./minecraftvanilla'); import minecraftbedrock from "./minecraftbedrock.js";
const MinecraftBedrock = require('./minecraftbedrock'); import minecraftvanilla from "./minecraftvanilla.js";
const Gamespy3 = require('./gamespy3'); import Gamespy3 from "./gamespy3.js";
const Results = require('../lib/Results'); import {Results} from "../lib/Results.js";
/* /*
Vanilla servers respond to minecraftvanilla only Vanilla servers respond to minecraftvanilla only
@ -12,7 +12,7 @@ Some bedrock servers respond to minecraftbedrock only
Unsure if any bedrock servers respond to gamespy3 and minecraftbedrock Unsure if any bedrock servers respond to gamespy3 and minecraftbedrock
*/ */
class Minecraft extends Core { export default class minecraft extends Core {
constructor() { constructor() {
super(); super();
this.srvRecord = "_minecraft._tcp"; this.srvRecord = "_minecraft._tcp";
@ -21,7 +21,7 @@ class Minecraft extends Core {
/** @type {Promise<Results>[]} */ /** @type {Promise<Results>[]} */
const promises = []; const promises = [];
const vanillaResolver = new MinecraftVanilla(); const vanillaResolver = new minecraftvanilla();
vanillaResolver.options = this.options; vanillaResolver.options = this.options;
vanillaResolver.udpSocket = this.udpSocket; vanillaResolver.udpSocket = this.udpSocket;
promises.push((async () => { promises.push((async () => {
@ -38,7 +38,7 @@ class Minecraft extends Core {
try { return await gamespyResolver.runOnceSafe(); } catch(e) {} try { return await gamespyResolver.runOnceSafe(); } catch(e) {}
})()); })());
const bedrockResolver = new MinecraftBedrock(); const bedrockResolver = new minecraftbedrock();
bedrockResolver.options = this.options; bedrockResolver.options = this.options;
bedrockResolver.udpSocket = this.udpSocket; bedrockResolver.udpSocket = this.udpSocket;
promises.push((async () => { promises.push((async () => {
@ -97,5 +97,3 @@ class Minecraft extends Core {
state.name = state.name.replace(/\u00A7./g, ''); state.name = state.name.replace(/\u00A7./g, '');
} }
} }
module.exports = Minecraft;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class MinecraftBedrock extends Core { export default class minecraftbedrock extends Core {
constructor() { constructor() {
super(); super();
this.byteorder = 'be'; this.byteorder = 'be';
@ -68,9 +68,5 @@ class MinecraftBedrock extends Core {
return true; return true;
}); });
} }
} }
module.exports = MinecraftBedrock;

View File

@ -1,7 +1,7 @@
const Core = require('./core'), import Core from './core.js';
Varint = require('varint'); import Varint from "varint";
class MinecraftVanilla extends Core { export default class minecraftvanilla extends Core {
async run(state) { async run(state) {
const portBuf = Buffer.alloc(2); const portBuf = Buffer.alloc(2);
portBuf.writeUInt16BE(this.options.port,0); portBuf.writeUInt16BE(this.options.port,0);
@ -78,5 +78,3 @@ class MinecraftVanilla extends Core {
]); ]);
} }
} }
module.exports = MinecraftVanilla;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class Mumble extends Core { export default class mumble extends Core {
async run(state) { async run(state) {
const json = await this.withTcp(async socket => { const json = await this.withTcp(async socket => {
return await this.tcpSend(socket, 'json', (buffer) => { return await this.tcpSend(socket, 'json', (buffer) => {
@ -37,5 +37,3 @@ class Mumble extends Core {
return str.replace(/<.*>/g,''); return str.replace(/<.*>/g,'');
} }
} }
module.exports = Mumble;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class MumblePing extends Core { export default class mumbleping extends Core {
constructor() { constructor() {
super(); super();
this.byteorder = 'be'; this.byteorder = 'be';
@ -22,5 +22,3 @@ class MumblePing extends Core {
state.raw.allowedbandwidth = reader.uint(4); state.raw.allowedbandwidth = reader.uint(4);
} }
} }
module.exports = MumblePing;

View File

@ -1,8 +1,8 @@
const gbxremote = require('gbxremote'), import Core from './core.js';
Core = require('./core'), import Promises from "../lib/Promises.js";
Promises = require('../lib/Promises'); import * as gbxremote from 'gbxremote';
class Nadeo extends Core { export default class nadeo extends Core {
async run(state) { async run(state) {
await this.withClient(async client => { await this.withClient(async client => {
const start = Date.now(); const start = Date.now();
@ -82,7 +82,4 @@ class Nadeo extends Core {
stripColors(str) { stripColors(str) {
return str.replace(/\$([0-9a-f]{3}|[a-z])/gi,''); return str.replace(/\$([0-9a-f]{3}|[a-z])/gi,'');
} }
} }
module.exports = Nadeo;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class OpenTtd extends Core { export default class openttd extends Core {
async run(state) { async run(state) {
{ {
const [reader, version] = await this.query(0, 1, 1, 4); const [reader, version] = await this.query(0, 1, 1, 4);
@ -125,5 +125,3 @@ class OpenTtd extends Core {
return arr[num]; return arr[num];
} }
} }
module.exports = OpenTtd;

View File

@ -1,11 +1,9 @@
const Quake2 = require('./quake2'); import quake2 from './quake2.js';
class Quake1 extends Quake2 { export default class quake1 extends quake2 {
constructor() { constructor() {
super(); super();
this.responseHeader = 'n'; this.responseHeader = 'n';
this.isQuake1 = true; this.isQuake1 = true;
} }
} }
module.exports = Quake1;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class Quake2 extends Core { export default class quake2 extends Core {
constructor() { constructor() {
super(); super();
this.encoding = 'latin1'; this.encoding = 'latin1';
@ -84,5 +84,3 @@ class Quake2 extends Core {
if('hostname' in state.raw) state.name = state.raw.hostname; if('hostname' in state.raw) state.name = state.raw.hostname;
} }
} }
module.exports = Quake2;

View File

@ -1,6 +1,6 @@
const Quake2 = require('./quake2'); import quake2 from './quake2.js';
class Quake3 extends Quake2 { export default class quake3 extends quake2 {
constructor() { constructor() {
super(); super();
this.sendHeader = 'getstatus'; this.sendHeader = 'getstatus';
@ -20,5 +20,3 @@ class Quake3 extends Quake2 {
return str.replace(/\^(X.{6}|.)/g,''); return str.replace(/\^(X.{6}|.)/g,'');
} }
} }
module.exports = Quake3;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class Rfactor extends Core { export default class rfactor extends Core {
constructor() { constructor() {
super(); super();
//this.byteorder = 'be'; //this.byteorder = 'be';
@ -72,5 +72,3 @@ class Rfactor extends Core {
return this.reader(consumed).string(); return this.reader(consumed).string();
} }
} }
module.exports = Rfactor;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class Samp extends Core { export default class samp extends Core {
constructor() { constructor() {
super(); super();
this.encoding = 'win1252'; this.encoding = 'win1252';
@ -105,5 +105,3 @@ class Samp extends Core {
); );
} }
} }
module.exports = Samp;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class Savage2 extends Core { export default class savage2 extends Core {
constructor() { constructor() {
super(); super();
} }
@ -27,5 +27,3 @@ class Savage2 extends Core {
return str.replace(/\^./g,''); return str.replace(/\^./g,'');
} }
} }
module.exports = Savage2;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class Starmade extends Core { export default class starmade extends Core {
constructor() { constructor() {
super(); super();
this.encoding = 'latin1'; this.encoding = 'latin1';
@ -65,5 +65,3 @@ class Starmade extends Core {
if(typeof data[6] === 'number') state.maxplayers = data[6]; if(typeof data[6] === 'number') state.maxplayers = data[6];
} }
} }
module.exports = Starmade;

View File

@ -1,6 +1,6 @@
const Tribes1 = require('./tribes1'); import tribes1 from "./tribes1.js";
class Starsiege extends Tribes1 { export default class starsiege extends tribes1 {
constructor() { constructor() {
super(); super();
this.encoding = 'latin1'; this.encoding = 'latin1';
@ -8,5 +8,3 @@ class Starsiege extends Tribes1 {
this.responseByte = 0x73; this.responseByte = 0x73;
} }
} }
module.exports = Starsiege;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class Teamspeak2 extends Core { export default class teamspeak2 extends Core {
async run(state) { async run(state) {
const queryPort = this.options.teamspeakQueryPort || 51234; const queryPort = this.options.teamspeakQueryPort || 51234;
@ -68,5 +68,3 @@ class Teamspeak2 extends Core {
}); });
} }
} }
module.exports = Teamspeak2;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class Teamspeak3 extends Core { export default class teamspeak3 extends Core {
async run(state) { async run(state) {
const queryPort = this.options.teamspeakQueryPort || 10011; const queryPort = this.options.teamspeakQueryPort || 10011;
@ -64,5 +64,3 @@ class Teamspeak3 extends Core {
} }
} }
} }
module.exports = Teamspeak3;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class Terraria extends Core { export default class terraria extends Core {
async run(state) { async run(state) {
const json = await this.request({ const json = await this.request({
url: 'http://'+this.options.address+':'+this.options.port+'/v2/server/status', url: 'http://'+this.options.address+':'+this.options.port+'/v2/server/status',
@ -22,5 +22,3 @@ class Terraria extends Core {
state.raw.numplayers = json.playercount; state.raw.numplayers = json.playercount;
} }
} }
module.exports = Terraria;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class Tribes1 extends Core { export default class tribes1 extends Core {
constructor() { constructor() {
super(); super();
this.encoding = 'latin1'; this.encoding = 'latin1';
@ -148,5 +148,3 @@ class Tribes1 extends Core {
return reader.pascalString(1); return reader.pascalString(1);
} }
} }
module.exports = Tribes1;

View File

@ -1,8 +1,8 @@
const Core = require('./core'); import Core from './core.js';
/** Unsupported -- use at your own risk!! */ /** Unsupported -- use at your own risk!! */
class Tribes1Master extends Core { export default class tribes1master extends Core {
constructor() { constructor() {
super(); super();
this.encoding = 'latin1'; this.encoding = 'latin1';
@ -77,5 +77,3 @@ class Tribes1Master extends Core {
return reader.pascalString(1); return reader.pascalString(1);
} }
} }
module.exports = Tribes1Master;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class Unreal2 extends Core { export default class unreal2 extends Core {
constructor() { constructor() {
super(); super();
this.encoding = 'latin1'; this.encoding = 'latin1';
@ -148,5 +148,3 @@ class Unreal2 extends Core {
}); });
} }
} }
module.exports = Unreal2;

View File

@ -1,6 +1,6 @@
const Gamespy3 = require('./gamespy3'); import gamespy3 from './gamespy3.js';
class Ut3 extends Gamespy3 { export default class ut3 extends gamespy3 {
async run(state) { async run(state) {
await super.run(state); await super.run(state);
@ -43,5 +43,3 @@ class Ut3 extends Gamespy3 {
if('map' in state.raw) state.map = state.raw.map; if('map' in state.raw) state.map = state.raw.map;
} }
} }
module.exports = Ut3;

View File

@ -1,7 +1,5 @@
const Bzip2 = require('seek-bzip'); import Bzip2 from 'seek-bzip';
const Core = require('./core'); import Core from './core.js';
const Results = require('../lib/Results');
const Reader = require('../lib/reader');
const AppId = { const AppId = {
Squad: 393380, Squad: 393380,
@ -16,7 +14,7 @@ const AppId = {
Source_SDK_Base_2006: 215 Source_SDK_Base_2006: 215
}; };
class Valve extends Core { export default class valve extends Core {
constructor() { constructor() {
super(); super();
@ -606,5 +604,3 @@ class Valve extends Core {
); );
} }
} }
module.exports = Valve;

View File

@ -1,6 +1,6 @@
const Samp = require('./samp'); import samp from './samp.js';
class Vcmp extends Samp { export default class vcmp extends samp {
constructor() { constructor() {
super(); super();
this.magicHeader = 'VCMP'; this.magicHeader = 'VCMP';
@ -8,5 +8,3 @@ class Vcmp extends Samp {
this.isVcmp = true; this.isVcmp = true;
} }
} }
module.exports = Vcmp;

View File

@ -1,6 +1,6 @@
const Core = require('./core'); import Core from './core.js';
class Ventrilo extends Core { export default class ventrilo extends Core {
constructor() { constructor() {
super(); super();
this.byteorder = 'be'; this.byteorder = 'be';
@ -233,5 +233,3 @@ const crc_table = [
0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8, 0xef1f, 0xff3e, 0xcf5d, 0xdf7c, 0xaf9b, 0xbfba, 0x8fd9, 0x9ff8,
0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0 0x6e17, 0x7e36, 0x4e55, 0x5e74, 0x2e93, 0x3eb2, 0x0ed1, 0x1ef0
]; ];
module.exports = Ventrilo;

View File

@ -1,6 +1,6 @@
const Quake3 = require('./quake3'); import quake3 from './quake3.js';
class Warsow extends Quake3 { export default class warsow extends quake3 {
async run(state) { async run(state) {
await super.run(state); await super.run(state);
if(state.players) { if(state.players) {
@ -11,5 +11,3 @@ class Warsow extends Quake3 {
} }
} }
} }
module.exports = Warsow;