Skip to content

Commit

Permalink
chore: Convert all files to LF endings (#400)
Browse files Browse the repository at this point in the history
* Convert to LF?

* Modify gitattributes

* Force LF

* Git --renormalize

* Update .gitattributes to enforce eol=lf

* Redo CRLF -> LF on remaining files
  • Loading branch information
CosminPerRam authored Nov 12, 2023
1 parent a8bc752 commit cee42e7
Show file tree
Hide file tree
Showing 65 changed files with 5,697 additions and 5,697 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1 +1 @@
text=auto
* text=auto eol=lf
596 changes: 298 additions & 298 deletions CHANGELOG.md

Large diffs are not rendered by default.

890 changes: 445 additions & 445 deletions GAMES_LIST.md

Large diffs are not rendered by default.

138 changes: 69 additions & 69 deletions bin/gamedig.js
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
#!/usr/bin/env node

import * as process from "node:process";

import Minimist from 'minimist'
import GameDig from './../lib/index.js'

const argv = Minimist(process.argv.slice(2), {
boolean: ['pretty', 'debug', 'givenPortOnly', 'requestRules'],
string: ['guildId', 'listenUdpPort', 'ipFamily']
})

const debug = argv.debug
delete argv.debug
const pretty = !!argv.pretty || debug
delete argv.pretty
const givenPortOnly = argv.givenPortOnly
delete argv.givenPortOnly

const options = {}
for (const key of Object.keys(argv)) {
const value = argv[key]

if (key === '_' || key.charAt(0) === '$') { continue }

options[key] = value
}

if (argv._.length >= 1) {
const target = argv._[0]
const split = target.split(':')
options.host = split[0]
if (split.length >= 2) {
options.port = split[1]
}
}
if (debug) {
options.debug = true
}
if (givenPortOnly) {
options.givenPortOnly = true
}

const printOnPretty = (object) => {
if (pretty) {
console.log(JSON.stringify(object, null, ' '))
} else {
console.log(JSON.stringify(object))
}
}

const gamedig = new GameDig(options)
gamedig.query(options)
.then(printOnPretty)
.catch((error) => {
if (debug) {
if (error instanceof Error) {
console.log(error.stack)
} else {
console.log(error)
}
} else {
if (error instanceof Error) {
error = error.message
}

printOnPretty({ error })
}
})
#!/usr/bin/env node

import * as process from "node:process";

import Minimist from 'minimist'
import GameDig from './../lib/index.js'

const argv = Minimist(process.argv.slice(2), {
boolean: ['pretty', 'debug', 'givenPortOnly', 'requestRules'],
string: ['guildId', 'listenUdpPort', 'ipFamily']
})

const debug = argv.debug
delete argv.debug
const pretty = !!argv.pretty || debug
delete argv.pretty
const givenPortOnly = argv.givenPortOnly
delete argv.givenPortOnly

const options = {}
for (const key of Object.keys(argv)) {
const value = argv[key]

if (key === '_' || key.charAt(0) === '$') { continue }

options[key] = value
}

if (argv._.length >= 1) {
const target = argv._[0]
const split = target.split(':')
options.host = split[0]
if (split.length >= 2) {
options.port = split[1]
}
}
if (debug) {
options.debug = true
}
if (givenPortOnly) {
options.givenPortOnly = true
}

const printOnPretty = (object) => {
if (pretty) {
console.log(JSON.stringify(object, null, ' '))
} else {
console.log(JSON.stringify(object))
}
}

const gamedig = new GameDig(options)
gamedig.query(options)
.then(printOnPretty)
.catch((error) => {
if (debug) {
if (error instanceof Error) {
console.log(error.stack)
} else {
console.log(error)
}
} else {
if (error instanceof Error) {
error = error.message
}

printOnPretty({ error })
}
})
148 changes: 74 additions & 74 deletions lib/DnsResolver.js
Original file line number Diff line number Diff line change
@@ -1,74 +1,74 @@
import dns from 'node:dns'
import punycode from 'punycode/punycode.js'

export default class DnsResolver {
/**
* @param {Logger} logger
*/
constructor (logger) {
this.logger = logger
}

isIp (host) {
return !!host.match(/\d+\.\d+\.\d+\.\d+/)
}

/**
* Response port will only be present if srv record was involved.
* @param {string} host
* @param {number} ipFamily
* @param {string=} srvRecordPrefix
* @returns {Promise<{address:string, port:number=}>}
*/
async resolve (host, ipFamily, srvRecordPrefix) {
this.logger.debug('DNS Lookup: ' + host)

if (this.isIp(host)) {
this.logger.debug('Raw IP Address: ' + host)
return { address: host }
}

const asciiForm = punycode.toASCII(host)
if (asciiForm !== host) {
this.logger.debug('Encoded punycode: ' + host + ' -> ' + asciiForm)
host = asciiForm
}

if (srvRecordPrefix) {
this.logger.debug('SRV Resolve: ' + srvRecordPrefix + '.' + host)
let records
try {
records = await dns.promises.resolve(srvRecordPrefix + '.' + host, 'SRV')
if (records.length >= 1) {
this.logger.debug('Found SRV Records: ', records)
const record = records[0]
const srvPort = record.port
const srvHost = record.name
if (srvHost === host) {
throw new Error('Loop in DNS SRV records')
}
return {
port: srvPort,
...await this.resolve(srvHost, ipFamily, srvRecordPrefix)
}
}
this.logger.debug('No SRV Record')
} catch (e) {
this.logger.debug(e)
}
}

this.logger.debug('Standard Resolve: ' + host)
const dnsResult = await dns.promises.lookup(host, ipFamily)
// For some reason, this sometimes returns a string address rather than an object.
// I haven't been able to reproduce, but it's been reported on the issue tracker.
let address
if (typeof dnsResult === 'string') {
address = dnsResult
} else {
address = dnsResult.address
}
this.logger.debug('Found address: ' + address)
return { address }
}
}
import dns from 'node:dns'
import punycode from 'punycode/punycode.js'

export default class DnsResolver {
/**
* @param {Logger} logger
*/
constructor (logger) {
this.logger = logger
}

isIp (host) {
return !!host.match(/\d+\.\d+\.\d+\.\d+/)
}

/**
* Response port will only be present if srv record was involved.
* @param {string} host
* @param {number} ipFamily
* @param {string=} srvRecordPrefix
* @returns {Promise<{address:string, port:number=}>}
*/
async resolve (host, ipFamily, srvRecordPrefix) {
this.logger.debug('DNS Lookup: ' + host)

if (this.isIp(host)) {
this.logger.debug('Raw IP Address: ' + host)
return { address: host }
}

const asciiForm = punycode.toASCII(host)
if (asciiForm !== host) {
this.logger.debug('Encoded punycode: ' + host + ' -> ' + asciiForm)
host = asciiForm
}

if (srvRecordPrefix) {
this.logger.debug('SRV Resolve: ' + srvRecordPrefix + '.' + host)
let records
try {
records = await dns.promises.resolve(srvRecordPrefix + '.' + host, 'SRV')
if (records.length >= 1) {
this.logger.debug('Found SRV Records: ', records)
const record = records[0]
const srvPort = record.port
const srvHost = record.name
if (srvHost === host) {
throw new Error('Loop in DNS SRV records')
}
return {
port: srvPort,
...await this.resolve(srvHost, ipFamily, srvRecordPrefix)
}
}
this.logger.debug('No SRV Record')
} catch (e) {
this.logger.debug(e)
}
}

this.logger.debug('Standard Resolve: ' + host)
const dnsResult = await dns.promises.lookup(host, ipFamily)
// For some reason, this sometimes returns a string address rather than an object.
// I haven't been able to reproduce, but it's been reported on the issue tracker.
let address
if (typeof dnsResult === 'string') {
address = dnsResult
} else {
address = dnsResult.address
}
this.logger.debug('Found address: ' + address)
return { address }
}
}
Loading

0 comments on commit cee42e7

Please sign in to comment.