From 39659cf48b5c64f4a2383bde1b4eb7ada45a6e2b Mon Sep 17 00:00:00 2001 From: u9g <43508353+u9g@users.noreply.github.com> Date: Fri, 23 Apr 2021 03:23:43 -0400 Subject: [PATCH] rename hostname to host (#74) --- README.md | 2 +- docs/API.md | 14 +++++++------- examples/clientTest.js | 2 +- examples/createClientExample.js | 2 +- examples/createRelay.js | 6 +++--- examples/relay.js | 6 +++--- examples/serverTest.js | 2 +- examples/viewer/client/ClientProvider.js | 2 +- examples/viewer/client/ProxyProvider.js | 4 ++-- index.d.ts | 8 ++++---- src/auth/login.js | 2 +- src/client.js | 12 ++++++------ src/createClient.js | 5 ++--- src/createServer.js | 1 - src/rak.js | 16 ++++++++-------- src/rakWorker.js | 10 +++++----- src/relay.js | 4 ++-- src/server.js | 10 +++++----- test/internal.js | 4 ++-- test/proxy.js | 8 ++++---- test/vanilla.js | 2 +- tools/dumpPackets.js | 2 +- tools/genPacketDumps.js | 2 +- 23 files changed, 62 insertions(+), 64 deletions(-) diff --git a/README.md b/README.md index 5b17a18..a8307aa 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ client.on('text', (packet) => { // Listen for chat messages and echo them back. ```js const bedrock = require('bedrock-protocol') const server = new bedrock.createServer({ - host: '0.0.0.0', // optional. Hostname to bind as. + host: '0.0.0.0', // optional. host to bind as. port: 19132, // optional version: '1.16.220' // optional. The server version, latest if not specified. }) diff --git a/docs/API.md b/docs/API.md index 0b64c8e..071cb6b 100644 --- a/docs/API.md +++ b/docs/API.md @@ -8,7 +8,7 @@ Returns a `Client` instance and connects to the server. | Parameter | Optionality | Description | | ----------- | ----------- |-| -| host | **Required** | Hostname to connect to, for example `127.0.0.1`. | +| host | **Required** | host to connect to, for example `127.0.0.1`. | | port | *optional* | port to connect to, default to **19132** | | version | *optional* | Version to connect as.
(Future feature, see [#69][1]) If not specified, should automatically match server version.
(Current feature) Defaults to latest version. | | offline | *optional* | default to **false**. Set this to true to disable Microsoft/Xbox auth. | @@ -28,7 +28,7 @@ authenticated unless offline is set to true. | Parameter | Optionality | Description | | ----------- | ----------- |-| -| host | **Required** | The hostname to bind to. use `0.0.0.0` to bind all IPv4 addresses. | +| host | **Required** | The host to bind to. use `0.0.0.0` to bind all IPv4 addresses. | | port | *optional* | the port to bind to, default **19132** | | version | *optional* | Version to run server as. Clients below this version will be kicked, clients above will still be permitted. | | offline | *optional* | default to **false**. Set this to true to disable Microsoft/Xbox auth enforcement. | @@ -55,7 +55,7 @@ You can create a server as such: ```js const bedrock = require('bedrock-protocol') const server = bedrock.createServer({ - host: '0.0.0.0', // the hostname to bind to, use '0.0.0.0' to bind all hostnames + host: '0.0.0.0', // the host to bind to, use '0.0.0.0' to bind all hosts port: 19132, // optional, port to bind to, default 19132 offline: false, // default false. verify connections with XBL motd: { @@ -90,7 +90,7 @@ You can create a server as such: ```js const bedrock = require('bedrock-protocol') const client = bedrock.createClient({ - host: '127.0.0.1', // the hostname to bind to, use '0.0.0.0' to bind all hostnames + host: '127.0.0.1', // the host to bind to, use '0.0.0.0' to bind all hosts port: 19132, // optional, port to bind to, default 19132 username: 'Notch' // Any profile name, only used internally for account caching when in online mode. In offline mode, the username to connect with. }) @@ -129,12 +129,12 @@ You can create a proxy ("Relay") to create a machine-in-the-middle (MITM) connec const { Relay } = require('bedrock-protocol') const relay = new Relay({ version: '1.16.220', // The version - /* Hostname and port to listen for clients on */ - hostname: '0.0.0.0', + /* host and port to listen for clients on */ + host: '0.0.0.0', port: 19132, /* Where to send upstream packets to */ destination: { - hostname: '127.0.0.1', + host: '127.0.0.1', port: 19131 } }) diff --git a/examples/clientTest.js b/examples/clientTest.js index 717a428..a6996eb 100644 --- a/examples/clientTest.js +++ b/examples/clientTest.js @@ -4,7 +4,7 @@ const { ChunkColumn, Version } = require('bedrock-provider') async function test () { const client = new Client({ - hostname: '127.0.0.1', + host: '127.0.0.1', port: 19132 // You can specify version by adding : // version: '1.16.210' diff --git a/examples/createClientExample.js b/examples/createClientExample.js index 6de4b9b..f05a0b5 100644 --- a/examples/createClientExample.js +++ b/examples/createClientExample.js @@ -1,6 +1,6 @@ const { createClient } = require('bedrock-protocol') -const client = createClient({ hostname: '127.0.0.1' }) +const client = createClient({ host: '127.0.0.1' }) let ix = 0 client.on('packet', (args) => { diff --git a/examples/createRelay.js b/examples/createRelay.js index 78eb4d3..7209904 100644 --- a/examples/createRelay.js +++ b/examples/createRelay.js @@ -4,12 +4,12 @@ function createRelay () { console.log('Creating relay') /* Example to create a non-transparent proxy (or 'Relay') connection to destination server */ const relay = new Relay({ - /* Hostname and port for clients to listen to */ - hostname: '0.0.0.0', + /* host and port for clients to listen to */ + host: '0.0.0.0', port: 19130, /* Where to send upstream packets to */ destination: { - hostname: '127.0.0.1', + host: '127.0.0.1', port: 19132 } }) diff --git a/examples/relay.js b/examples/relay.js index f8e5791..7fce986 100644 --- a/examples/relay.js +++ b/examples/relay.js @@ -5,12 +5,12 @@ const { Relay } = require('bedrock-protocol') // Start the proxy server const relay = new Relay({ version: '1.16.220', // The version - /* Hostname and port to listen for clients on */ - hostname: '0.0.0.0', + /* host and port to listen for clients on */ + host: '0.0.0.0', port: 19132, /* Where to send upstream packets to */ destination: { - hostname: '127.0.0.1', + host: '127.0.0.1', port: 19131 } }) diff --git a/examples/serverTest.js b/examples/serverTest.js index 6cae966..e299b62 100644 --- a/examples/serverTest.js +++ b/examples/serverTest.js @@ -23,7 +23,7 @@ async function startServer (version = '1.16.220', ok) { const Item = require('../types/Item')(version) const port = 19132 - const server = new Server({ hostname: '0.0.0.0', port, version }) + const server = new Server({ host: '0.0.0.0', port, version }) let loop const getPath = (packetPath) => DataProvider(server.options.protocolVersion).getPath(packetPath) diff --git a/examples/viewer/client/ClientProvider.js b/examples/viewer/client/ClientProvider.js index e8f3ada..73d7b8f 100644 --- a/examples/viewer/client/ClientProvider.js +++ b/examples/viewer/client/ClientProvider.js @@ -14,7 +14,7 @@ class ClientProvider extends BotProvider { downKeys = new Set() connect () { - const client = new Client({ hostname: '127.0.0.1', version: '1.16.210', username: 'notch', offline: true, port: 19132, connectTimeout: 100000 }) + const client = new Client({ host: '127.0.0.1', version: '1.16.210', username: 'notch', offline: true, port: 19132, connectTimeout: 100000 }) client.once('resource_packs_info', (packet) => { client.write('resource_pack_client_response', { diff --git a/examples/viewer/client/ProxyProvider.js b/examples/viewer/client/ProxyProvider.js index de97ee6..29f74c7 100644 --- a/examples/viewer/client/ProxyProvider.js +++ b/examples/viewer/client/ProxyProvider.js @@ -7,11 +7,11 @@ class ProxyProvider extends BotProvider { connect () { const proxy = new Relay({ - hostname: '0.0.0.0', + host: '0.0.0.0', port: 19130, // logging: true, destination: { - hostname: '127.0.0.1', + host: '127.0.0.1', port: 19132 } }) diff --git a/index.d.ts b/index.d.ts index bb64b6c..26b764a 100644 --- a/index.d.ts +++ b/index.d.ts @@ -6,8 +6,8 @@ declare module "bedrock-protocol" { export interface Options { // The string version to start the client or server as version: number, - // For the client, the hostname of the server to connect to (default: 127.0.0.1) - // For the server, the hostname to bind to (default: 0.0.0.0) + // For the client, the host of the server to connect to (default: 127.0.0.1) + // For the server, the host to bind to (default: 0.0.0.0) host: string, // The port to connect or bind to, default: 19132 port: number, @@ -103,13 +103,13 @@ declare module "bedrock-protocol" { } type RelayOptions = Options & { - hostname: string, + host: string, port: number, // Toggle packet logging. logging: boolean, // Where to proxy requests to. destination: { - hostname: string, + host: string, port: number } } diff --git a/src/auth/login.js b/src/auth/login.js index c2d56bb..afa74fb 100644 --- a/src/auth/login.js +++ b/src/auth/login.js @@ -66,7 +66,7 @@ module.exports = (client, server, options) => { PlayFabId: '5eb65f73-af11-448e-82aa-1b7b165316ad.persona-e199672a8c1a87e0-0', // 1.16.210 PremiumSkin: false, SelfSignedId: nextUUID(), - ServerAddress: `${options.hostname}:${options.port}`, + ServerAddress: `${options.host}:${options.port}`, SkinAnimationData: '', SkinColor: '#ffffcd96', SkinData: 'AAAAAA==', diff --git a/src/client.js b/src/client.js index 8bdce58..049dda0 100644 --- a/src/client.js +++ b/src/client.js @@ -17,7 +17,7 @@ class Client extends Connection { // The RakNet connection connection - /** @param {{ version: number, hostname: string, port: number }} options */ + /** @param {{ version: number, host: string, port: number }} options */ constructor (options) { super() this.options = { ...Options.defaultOptions, ...options } @@ -29,9 +29,9 @@ class Client extends Connection { Login(this, null, this.options) LoginVerify(this, null, this.options) - const hostname = this.options.hostname + const host = this.options.host const port = this.options.port - this.connection = new RakClient({ useWorkers: true, hostname, port }) + this.connection = new RakClient({ useWorkers: true, host, port }) this.startGameData = {} this.clientRuntimeId = null @@ -54,7 +54,7 @@ class Client extends Connection { } validateOptions () { - if (!this.options.hostname || this.options.port == null) throw Error('Invalid hostname/port') + if (!this.options.host || this.options.port == null) throw Error('Invalid host/port') if (!Options.Versions[this.options.version]) { console.warn('Supported versions: ', Options.Versions) @@ -79,13 +79,13 @@ class Client extends Connection { try { return await this.connection.ping(this.options.connectTimeout) } catch (e) { - console.warn(`Unable to connect to [${this.options.hostname}]/${this.options.port}. Is the server running?`) + console.warn(`Unable to connect to [${this.options.host}]/${this.options.port}. Is the server running?`) throw e } } _connect = async (sessionData) => { - debug('[client] connecting to', this.options.hostname, this.options.port, sessionData, this.connection) + debug('[client] connecting to', this.options.host, this.options.port, sessionData, this.connection) this.connection.onConnected = () => this.sendLogin() this.connection.onCloseConnection = () => this.close() this.connection.onEncapsulated = this.onEncapsulated diff --git a/src/createClient.js b/src/createClient.js index e357627..85856f9 100644 --- a/src/createClient.js +++ b/src/createClient.js @@ -3,10 +3,9 @@ const { RakClient } = require('./rak') const assert = require('assert') const advertisement = require('./server/advertisement') -/** @param {{ version?: number, hostname: string, port?: number, connectTimeout?: number }} options */ +/** @param {{ version?: number, host: string, port?: number, connectTimeout?: number }} options */ function createClient (options) { assert(options) - if (options.host) options.hostname = options.host const client = new Client({ port: 19132, ...options }) if (options.skipPing) { @@ -67,7 +66,7 @@ function connect (client) { } async function ping ({ host, port }) { - const con = new RakClient({ hostname: host, port }) + const con = new RakClient({ host, port }) const ret = await con.ping() con.close() return advertisement.fromServerName(ret) diff --git a/src/createServer.js b/src/createServer.js index 3c6762c..88b362d 100644 --- a/src/createServer.js +++ b/src/createServer.js @@ -1,7 +1,6 @@ const { Server } = require('./server') function createServer (options) { - if (options.host) options.hostname = options.host if (!options.port) options.port = 19132 const server = new Server(options) server.listen() diff --git a/src/rak.js b/src/rak.js index 930bc8a..05cacc0 100644 --- a/src/rak.js +++ b/src/rak.js @@ -19,7 +19,7 @@ class RakNativeClient extends EventEmitter { this.onCloseConnection = () => { } this.onEncapsulated = () => { } - this.raknet = new Client(options.hostname, options.port, { protocolVersion: 10 }) + this.raknet = new Client(options.host, options.port, { protocolVersion: 10 }) this.raknet.on('encapsulated', ({ buffer, address }) => { this.onEncapsulated(buffer, address) }) @@ -70,7 +70,7 @@ class RakNativeServer extends EventEmitter { this.onOpenConnection = () => { } this.onCloseConnection = () => { } this.onEncapsulated = () => { } - this.raknet = new Server(options.hostname, options.port, { + this.raknet = new Server(options.host, options.port, { maxConnections: options.maxPlayers || 3, protocolVersion: 10, message: server.getAdvertisement().toBuffer() @@ -120,8 +120,8 @@ class RakJsClient extends EventEmitter { } } - workerConnect (hostname = this.options.hostname, port = this.options.port) { - this.worker = ConnWorker.connect(hostname, port) + workerConnect (host = this.options.host, port = this.options.port) { + this.worker = ConnWorker.connect(host, port) this.worker.on('message', (evt) => { switch (evt.type) { @@ -138,12 +138,12 @@ class RakJsClient extends EventEmitter { }) } - async plainConnect (hostname = this.options.hostname, port = this.options.port) { - this.raknet = new RakClient(hostname, port) + async plainConnect (host = this.options.host, port = this.options.port) { + this.raknet = new RakClient(host, port) await this.raknet.connect() this.raknet.on('connecting', () => { - console.log(`[client] connecting to ${hostname}/${port}`) + console.log(`[client] connecting to ${host}/${port}`) }) this.raknet.on('connected', this.onConnected) @@ -180,7 +180,7 @@ class RakJsServer extends EventEmitter { async plainListen () { this.raknet = new Listener() - await this.raknet.listen(this.options.hostname, this.options.port) + await this.raknet.listen(this.options.host, this.options.port) this.raknet.on('openConnection', (conn) => { conn.sendReliable = function (buffer, immediate) { const sendPacket = new EncapsulatedPacket() diff --git a/src/rakWorker.js b/src/rakWorker.js index d9a4bc5..97643a9 100644 --- a/src/rakWorker.js +++ b/src/rakWorker.js @@ -3,10 +3,10 @@ const { Worker, isMainThread, parentPort } = require('worker_threads') const EncapsulatedPacket = require('jsp-raknet/protocol/encapsulated_packet') const Reliability = require('jsp-raknet/protocol/reliability') -function connect (hostname, port) { +function connect (host, port) { if (isMainThread) { const worker = new Worker(__filename) - worker.postMessage({ type: 'connect', hostname, port }) + worker.postMessage({ type: 'connect', host, port }) return worker } } @@ -16,15 +16,15 @@ let raknet function main () { parentPort.on('message', (evt) => { if (evt.type === 'connect') { - const { hostname, port } = evt - raknet = new RakClient(hostname, port) + const { host, port } = evt + raknet = new RakClient(host, port) raknet.connect().then(() => { console.log('Raknet Connected!') }) raknet.on('connecting', () => { - console.log(`[client] connecting to ${hostname}/${port}`) + console.log(`[client] connecting to ${host}/${port}`) parentPort.postMessage('message', { type: 'connecting' }) console.log('Raknet', raknet) }) diff --git a/src/relay.js b/src/relay.js index 492ca9e..9e7992a 100644 --- a/src/relay.js +++ b/src/relay.js @@ -138,14 +138,14 @@ class Relay extends Server { offline: this.options.offline, username: this.options.offline ? ds.profile.name : null, version: this.options.version, - hostname: this.options.destination.hostname, + host: this.options.destination.host, port: this.options.destination.port, autoInitPlayer: false }) // Set the login payload unless `noLoginForward` option if (!client.noLoginForward) client.skinData = ds.skinData client.connect() - this.conLog('Connecting to', this.options.destination.hostname, this.options.destination.port) + this.conLog('Connecting to', this.options.destination.host, this.options.destination.port) client.outLog = ds.upOutLog client.inLog = ds.upInLog client.once('join', () => { // Intercept once handshaking done diff --git a/src/server.js b/src/server.js index a953c39..b10abd8 100644 --- a/src/server.js +++ b/src/server.js @@ -68,15 +68,15 @@ class Server extends EventEmitter { return this.advertisement } - async listen (hostname = this.options.hostname, port = this.options.port) { - this.raknet = new RakServer({ hostname, port }, this) + async listen (host = this.options.host, port = this.options.port) { + this.raknet = new RakServer({ host, port }, this) try { await this.raknet.listen() } catch (e) { - console.warn(`Failed to bind server on [${this.options.hostname}]/${this.options.port}, is the port free?`) + console.warn(`Failed to bind server on [${this.options.host}]/${this.options.port}, is the port free?`) throw e } - this.conLog('Listening on', hostname, port, this.options.version) + this.conLog('Listening on', host, port, this.options.version) this.raknet.onOpenConnection = this.onOpenConnection this.raknet.onCloseConnection = this.onCloseConnection this.raknet.onEncapsulated = this.onEncapsulated @@ -85,7 +85,7 @@ class Server extends EventEmitter { this.raknet.updateAdvertisement() }, 1000) - return { hostname, port } + return { host, port } } async close (disconnectReason) { diff --git a/test/internal.js b/test/internal.js index 449df62..9cdc76c 100644 --- a/test/internal.js +++ b/test/internal.js @@ -14,7 +14,7 @@ async function startTest (version = '1.16.220', ok) { await prepare(version) const Item = require('../types/Item')(version) const port = 19130 - const server = new Server({ hostname: '0.0.0.0', port, version, offline: true }) + const server = new Server({ host: '0.0.0.0', port, version, offline: true }) function getPath (packetPath) { return DataProvider(server.options.protocolVersion).getPath(packetPath) @@ -108,7 +108,7 @@ async function startTest (version = '1.16.220', ok) { // client logic const client = new Client({ - hostname: '127.0.0.1', + host: '127.0.0.1', port, username: 'Notch', version, diff --git a/test/proxy.js b/test/proxy.js index 280efbf..ad5d3ab 100644 --- a/test/proxy.js +++ b/test/proxy.js @@ -23,12 +23,12 @@ function proxyTest (version, timeout = 1000 * 20) { const relay = new Relay({ version, offline: true, - /* Hostname and port for clients to listen to */ - hostname: '0.0.0.0', + /* host and port for clients to listen to */ + host: '0.0.0.0', port: 19132, /* Where to send upstream packets to */ destination: { - hostname: '127.0.0.1', + host: '127.0.0.1', port: 19131 } }) @@ -37,7 +37,7 @@ function proxyTest (version, timeout = 1000 * 20) { console.debug('Proxy started', server.options.version) - const client = createClient({ hostname: '127.0.0.1', version, username: 'Boat', offline: true }) + const client = createClient({ host: '127.0.0.1', version, username: 'Boat', offline: true }) console.debug('Client started') diff --git a/test/vanilla.js b/test/vanilla.js index 6970a6c..13c6069 100644 --- a/test/vanilla.js +++ b/test/vanilla.js @@ -11,7 +11,7 @@ async function test (version) { console.log('Started server') const client = new Client({ - hostname: '127.0.0.1', + host: '127.0.0.1', port: 19130, username: 'Notch', version, diff --git a/tools/dumpPackets.js b/tools/dumpPackets.js index 8ef569a..47cc30b 100644 --- a/tools/dumpPackets.js +++ b/tools/dumpPackets.js @@ -20,7 +20,7 @@ async function dump (version) { console.log('Started server') const client = new Client({ - hostname: '127.0.0.1', + host: '127.0.0.1', port, username: 'dumpBot', offline: true diff --git a/tools/genPacketDumps.js b/tools/genPacketDumps.js index 94a718b..a5b63b7 100644 --- a/tools/genPacketDumps.js +++ b/tools/genPacketDumps.js @@ -25,7 +25,7 @@ async function dump (version, force) { console.log('Started server') const client = new Client({ - hostname: '127.0.0.1', + host: '127.0.0.1', port, version, username: 'Boat' + random,