forked from JJJ4n/node-samp-query
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
34 lines (31 loc) · 851 Bytes
/
utils.js
File metadata and controls
34 lines (31 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
const { resolve: dnsResolve } = require('dns');
const iconv = require('iconv-lite');
class SampError extends Error {};
exports.SampError = SampError;
/**
* @param {string} hostname Hostname to resolve
* @returns {Promise<string>} Resolved IP-address
*/
exports.resolveHostname = hostname => {
return new Promise((resolve, reject) => {
dnsResolve(hostname, (error, addresses) => {
if (error) {
reject(error);
} else if (addresses.length == 0) {
reject(new SampError('Hostname resolved to empty list'));
} else {
// For game servers there is usually one record
resolve(addresses[0]);
}
});
});
}
/**
* @param {Buffer} buffer
* @param {number} start
* @param {number} end
* @returns {string}
*/
exports.decodeWin1251 = (buffer, start, end) => {
return iconv.decode(buffer.subarray(start, end), 'win1251');
}