Update types, add authTitle option to relay, client renderDistance -> viewDistance

This commit is contained in:
extremeheat 2021-05-29 21:09:51 -04:00
commit 5af828bcb7
6 changed files with 73 additions and 15 deletions

View file

@ -4,4 +4,8 @@ __*
src/**/*.json
# Runtime generated data
data/**/sample
tools/bds*
tools/bds*
# Extra data
examples
test
.github

View file

@ -1014,6 +1014,16 @@ packet_container_set_data:
window_id: WindowID
# Key is the key of the property. It is one of the constants that can be found above. Multiple properties
# share the same key, but the functionality depends on the type of the container that the data is set to.
# IF FURNACE:
# 0: furnace_tick_count
# 1: furnace_lit_time
# 2: furnace_lit_duration
# 3: furnace_stored_xp
# 4: furnace_fuel_aux
# IF BREWING STAND:
# 0: brew_time
# 1: brew_fuel_amount
# 2: brew_fuel_total
property: zigzag32
# Value is the value of the property. Its use differs per property.
value: zigzag32
@ -1329,14 +1339,24 @@ packet_map_info_request:
!bound: both
map_id: zigzag64
# RequestChunkRadius is sent by the client to the server to update the server on the chunk view radius that
# it has set in the settings. The server may respond with a ChunkRadiusUpdated packet with either the chunk
# radius requested, or a different chunk radius if the server chooses so.
packet_request_chunk_radius:
!id: 0x45
!bound: both
# ChunkRadius is the requested chunk radius. This value is always the value set in the settings of the
# player.
chunk_radius: zigzag32
# ChunkRadiusUpdated is sent by the server in response to a RequestChunkRadius packet. It defines the chunk
# radius that the server allows the client to have. This may be lower than the chunk radius requested by the
# client in the RequestChunkRadius packet.
packet_chunk_radius_update:
!id: 0x46
!bound: client
# ChunkRadius is the final chunk radius that the client will adapt when it receives the packet. It does
# not have to be the same as the requested chunk radius.
chunk_radius: zigzag32
packet_item_frame_drop_item:
@ -1994,11 +2014,19 @@ packet_update_soft_enum:
!id: 0x72
!bound: client
# NetworkStackLatency is sent by the server (and the client, on development builds) to measure the latency
# over the entire Minecraft stack, rather than the RakNet latency. It has other usages too, such as the
# ability to be used as some kind of acknowledgement packet, to know when the client has received a certain
# other packet.
packet_network_stack_latency:
!id: 0x73
!bound: both
# Timestamp is the timestamp of the network stack latency packet. The client will, if NeedsResponse is
# set to true, send a NetworkStackLatency packet with this same timestamp packet in response.
timestamp: lu64
unknown_flag: u8
# NeedsResponse specifies if the sending side of this packet wants a response to the packet, meaning that
# the other side should send a NetworkStackLatency packet back.
needs_response: u8
packet_script_custom_event:
!id: 0x75

View file

@ -1,4 +1,4 @@
const { Relay } = require('../src/relay')
const { Relay, title } = require('bedrock-protocol')
function createRelay () {
console.log('Creating relay')
@ -7,10 +7,13 @@ function createRelay () {
/* host and port for clients to listen to */
host: '0.0.0.0',
port: 19130,
offline: false,
authTitle: title.MinecraftNintendoSwitch,
/* Where to send upstream packets to */
destination: {
host: '127.0.0.1',
port: 19132
port: 19132,
offline: false
}
})
relay.conLog = console.debug

35
index.d.ts vendored
View file

@ -7,15 +7,27 @@ declare module "bedrock-protocol" {
export interface Options {
// The string version to start the client or server as
version: number,
version: string
// 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,
host: string
// The port to connect or bind to, default: 19132
port: number,
// The maximum number of players allowed on the server at any time.
maxPlayers: number,
port: number
// For the client, if we should login with Microsoft/Xbox Live.
// For the server, if we should verify client's authentication with Xbox Live.
offline: boolean
}
export interface ClientOptions extends Options {
// The view distance in chunks
viewDistance: number,
// Specifies which game edition to sign in as. Optional, but some servers verify this.
authTitle: title | string
}
export interface ServerOptions extends Options {
// The maximum number of players allowed on the server at any time.
maxPlayers: number
motd: {
// The header for the MOTD shown in the server list.
motd: string,
@ -109,12 +121,19 @@ declare module "bedrock-protocol" {
port: number,
// Toggle packet logging.
logging: boolean,
// Skip authentication for connecting clients?
offline: false,
// Specifies which game edition to sign in as to the destination server. Optional, but some servers verify this.
authTitle: title | string
// Where to proxy requests to.
destination: {
host: string,
port: number
port: number,
// Skip authentication connecting to the remote server?
offline: false,
}
}
export class Relay extends Server {
constructor(options: RelayOptions)
}
@ -132,8 +151,8 @@ declare module "bedrock-protocol" {
serverId: string
}
export function createClient(options: Options): Client
export function createServer(options: Options): Server
export function createClient(options: ClientOptions): Client
export function createServer(options: ServerOptions): Server
export function ping({ host, port }) : ServerAdvertisement
}

View file

@ -2,6 +2,7 @@ const { Client } = require('./client')
const { RakClient } = require('./rak')
const assert = require('assert')
const advertisement = require('./server/advertisement')
const { sleep } = require('./datatypes/util')
/** @param {{ version?: number, host: string, port?: number, connectTimeout?: number }} options */
function createClient (options) {
@ -37,11 +38,13 @@ function connect (client) {
response_status: 'completed',
resourcepackids: []
})
client.queue('request_chunk_radius', { chunk_radius: client.renderDistance || 10 })
})
client.queue('client_cache_status', { enabled: false })
client.queue('tick_sync', { request_time: BigInt(Date.now()), response_time: 0n })
if (client.viewDistance) {
sleep(500).then(() => client.queue('request_chunk_radius', { chunk_radius: client.viewDistance }))
}
})
const KEEPALIVE_INTERVAL = 10 // Send tick sync packets every 10 ticks

View file

@ -3,7 +3,7 @@ const { Server } = require('./server')
const { Player } = require('./serverPlayer')
const debug = globalThis.isElectron ? console.debug : require('debug')('minecraft-protocol')
const debugging = true // Do re-encoding tests
const debugging = false // Do re-encoding tests
class RelayPlayer extends Player {
constructor (server, conn) {
@ -154,7 +154,8 @@ class Relay extends Server {
openUpstreamConnection (ds, clientAddr) {
const client = new Client({
offline: this.options.offline,
authTitle: this.options.authTitle,
offline: this.options.destination.offline ?? this.options.offline,
username: this.options.offline ? ds.profile.name : null,
version: this.options.version,
host: this.options.destination.host,