update connect version based on ping response & fix typings (#101)
* update connect ver based on ping resp& add typings * Fixed and added extremeheat suggestion * Update API.md * Update createClient.js
This commit is contained in:
parent
e16e8381e5
commit
d02eb6c041
3 changed files with 6 additions and 6 deletions
|
|
@ -10,7 +10,7 @@ Returns a `Client` instance and connects to the server.
|
|||
| ----------- | ----------- |-|
|
||||
| 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. <br/>(Future feature, see [#69][1]) If not specified, should automatically match server version. <br/>(Current feature) Defaults to latest version. |
|
||||
| version | *optional* | Version to connect as. If not specified, automatically match server version. |
|
||||
| offline | *optional* | default to **false**. Set this to true to disable Microsoft/Xbox auth. |
|
||||
| username | Conditional | Required if `offline` set to true : Username to connect to server as. |
|
||||
| authTitle | *optional* | The title ID to connect as, see the README for usage. |
|
||||
|
|
@ -160,5 +160,3 @@ relay.on('connect', player => {
|
|||
```
|
||||
|
||||
'Relay' emits 'clientbound' and 'serverbound' events, along with the data for the outgoing packet that can be modified. You can send a packet to the client with `player.queue()` or to the backend server with `player.upstream.queue()`.
|
||||
|
||||
[1]: https://github.com/PrismarineJS/bedrock-protocol/issues/69
|
||||
|
|
|
|||
4
index.d.ts
vendored
4
index.d.ts
vendored
|
|
@ -22,7 +22,9 @@ declare module "bedrock-protocol" {
|
|||
// The view distance in chunks
|
||||
viewDistance?: number,
|
||||
// Specifies which game edition to sign in as. Optional, but some servers verify this.
|
||||
authTitle?: title | string
|
||||
authTitle?: title | string,
|
||||
// whether to skip initial ping and immediately connect
|
||||
skipPing?: boolean
|
||||
}
|
||||
|
||||
export interface ServerOptions extends Options {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ const assert = require('assert')
|
|||
const advertisement = require('./server/advertisement')
|
||||
const { sleep } = require('./datatypes/util')
|
||||
|
||||
/** @param {{ version?: number, host: string, port?: number, connectTimeout?: number }} options */
|
||||
/** @param {{ version?: number, host: string, port?: number, connectTimeout?: number, skipPing?: boolean }} options */
|
||||
function createClient (options) {
|
||||
assert(options)
|
||||
const client = new Client({ port: 19132, ...options })
|
||||
|
|
@ -15,7 +15,7 @@ function createClient (options) {
|
|||
client.ping().then(data => {
|
||||
const advert = advertisement.fromServerName(data)
|
||||
console.log(`Connecting to server ${advert.motd} (${advert.name}), version ${advert.version}`)
|
||||
// TODO: update connect version based on ping response
|
||||
client.version = options.version ?? advert.version
|
||||
connect(client)
|
||||
}, client)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue