mirror of
https://github.com/gamedig/node-gamedig.git
synced 2024-11-18 01:30:39 +01:00
Add support for running using deno (#362)
* Add missing CRLF line ending * Add support for running using deno Prefix node imports with "node:" and gate a socket API that is not implemented in [deno](https://deno.land) so that the library can be used there. This should not break node and doesn't in my brief testing.
This commit is contained in:
parent
150fa0035f
commit
01794f6339
11 changed files with 32 additions and 14 deletions
|
@ -36,6 +36,8 @@
|
||||||
* Operation: Harsh Doorstop (2023) - Added support.
|
* Operation: Harsh Doorstop (2023) - Added support.
|
||||||
* Insurgency: Modern Infantry Combat (2007) - Added support.
|
* Insurgency: Modern Infantry Combat (2007) - Added support.
|
||||||
* Capatilzed Unturned in game.txt
|
* Capatilzed Unturned in game.txt
|
||||||
|
* Added Deno support: the library and CLI can now be experimentally used with the [Deno runtime](https://deno.com)
|
||||||
|
* `deno run --allow-net --allow-read=. bin/gamedig.js --type tf2 127.0.0.1`
|
||||||
|
|
||||||
### 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.
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
|
import * as process from "node:process";
|
||||||
|
|
||||||
import Minimist from 'minimist'
|
import Minimist from 'minimist'
|
||||||
import GameDig from './../lib/index.js'
|
import GameDig from './../lib/index.js'
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
|
|
||||||
import * as fs from 'fs'
|
import * as fs from 'node:fs'
|
||||||
import GameResolver from '../lib/GameResolver'
|
import GameResolver from '../lib/GameResolver'
|
||||||
|
|
||||||
const gameResolver = new GameResolver()
|
const gameResolver = new GameResolver()
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import * as dns from 'dns'
|
import * as dns from 'node:dns'
|
||||||
import punycode from 'punycode/punycode.js'
|
import punycode from 'punycode/punycode.js'
|
||||||
import { promisify } from 'util'
|
import { promisify } from 'node:util'
|
||||||
|
|
||||||
const dnsLookupAsync = promisify(dns.lookup)
|
const dnsLookupAsync = promisify(dns.lookup)
|
||||||
const dnsResolveAsync = promisify(dns.resolve)
|
const dnsResolveAsync = promisify(dns.resolve)
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import * as path from 'path'
|
import * as path from 'node:path'
|
||||||
import { fileURLToPath } from 'url'
|
import { fileURLToPath } from 'node:url'
|
||||||
import * as fs from 'fs'
|
import * as fs from 'node:fs'
|
||||||
|
|
||||||
export default class GameResolver {
|
export default class GameResolver {
|
||||||
constructor () {
|
constructor () {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { createSocket } from 'dgram'
|
import { createSocket } from 'node:dgram'
|
||||||
import { debugDump } from './HexUtil.js'
|
import { debugDump } from './HexUtil.js'
|
||||||
import { promisify } from 'util'
|
import { promisify } from 'node:util'
|
||||||
import Logger from './Logger.js'
|
import Logger from './Logger.js'
|
||||||
|
|
||||||
export default class GlobalUdpSocket {
|
export default class GlobalUdpSocket {
|
||||||
|
@ -18,7 +18,10 @@ export default class GlobalUdpSocket {
|
||||||
type: 'udp4',
|
type: 'udp4',
|
||||||
reuseAddr: true
|
reuseAddr: true
|
||||||
})
|
})
|
||||||
udpSocket.unref()
|
// https://github.com/denoland/deno/issues/20138
|
||||||
|
if (typeof Deno === "undefined") {
|
||||||
|
udpSocket.unref();
|
||||||
|
}
|
||||||
udpSocket.on('message', (buffer, rinfo) => {
|
udpSocket.on('message', (buffer, rinfo) => {
|
||||||
const fromAddress = rinfo.address
|
const fromAddress = rinfo.address
|
||||||
const fromPort = rinfo.port
|
const fromPort = rinfo.port
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { debugDump } from './HexUtil.js'
|
import { debugDump } from './HexUtil.js'
|
||||||
|
import { Buffer} from 'node:buffer'
|
||||||
|
|
||||||
export default class Logger {
|
export default class Logger {
|
||||||
constructor () {
|
constructor () {
|
||||||
|
|
|
@ -69,13 +69,22 @@ export default class QueryRunner {
|
||||||
for (const attempt of attempts) {
|
for (const attempt of attempts) {
|
||||||
for (let retry = 0; retry < numRetries; retry++) {
|
for (let retry = 0; retry < numRetries; retry++) {
|
||||||
attemptNum++
|
attemptNum++
|
||||||
|
let result
|
||||||
try {
|
try {
|
||||||
return await this._attempt(attempt)
|
result = await this._attempt(attempt)
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
e.stack = 'Attempt #' + attemptNum + ' - Port=' + attempt.port + ' Retry=' + (retry) + ':\n' + e.stack
|
e.stack = 'Attempt #' + attemptNum + ' - Port=' + attempt.port + ' Retry=' + (retry) + ':\n' + e.stack
|
||||||
errors.push(e)
|
errors.push(e)
|
||||||
|
} finally {
|
||||||
|
// Deno doesn't support unref, so we must close the socket after every connection
|
||||||
|
// https://github.com/denoland/deno/issues/20138
|
||||||
|
if (typeof Deno !== "undefined") {
|
||||||
|
this.udpSocket?.socket?.close()
|
||||||
|
delete this.udpSocket
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (result) return result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const err = new Error('Failed all ' + errors.length + ' attempts')
|
const err = new Error('Failed all ' + errors.length + ' attempts')
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import Iconv from 'iconv-lite'
|
import Iconv from 'iconv-lite'
|
||||||
import Long from 'long'
|
import Long from 'long'
|
||||||
import { Buffer } from 'buffer'
|
import { Buffer } from 'node:buffer'
|
||||||
import Varint from 'varint'
|
import Varint from 'varint'
|
||||||
|
|
||||||
function readUInt64BE (buffer, offset) {
|
function readUInt64BE (buffer, offset) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { EventEmitter } from 'events'
|
import { EventEmitter } from 'node:events'
|
||||||
import * as net from 'net'
|
import * as net from 'node:net'
|
||||||
import Reader from '../lib/reader.js'
|
import Reader from '../lib/reader.js'
|
||||||
import { debugDump } from '../lib/HexUtil.js'
|
import { debugDump } from '../lib/HexUtil.js'
|
||||||
import Logger from '../lib/Logger.js'
|
import Logger from '../lib/Logger.js'
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
import Bzip2 from 'seek-bzip'
|
import Bzip2 from 'seek-bzip'
|
||||||
import Core from './core.js'
|
import Core from './core.js'
|
||||||
|
import { Buffer } from 'node:buffer'
|
||||||
|
|
||||||
const AppId = {
|
const AppId = {
|
||||||
Squad: 393380,
|
Squad: 393380,
|
||||||
|
|
Loading…
Reference in a new issue