Fix empty chunks on proxy spawn (#89)

* Fix empty chunks on proxy spawn

Hack to fix issue with chunks not loading when client joins the proxy
* Queue chunk, respawn packets and only send them after player spawn

* fix lint
This commit is contained in:
extremeheat 2021-05-24 12:07:03 -04:00 committed by GitHub
commit 9cb4a888f4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 4 deletions

View file

@ -923,7 +923,15 @@ packet_set_spawn_position:
packet_animate:
!id: 0x2c
!bound: both
action_id: zigzag32
action_id: zigzag32 =>
0: none
1: swing_arm
2: unknown
3: wake_up
4: critical_hit
5: magic_critical_hit
6: row_right
7: row_left
runtime_entity_id: varint64
packet_respawn:

View file

@ -31,6 +31,7 @@ class RelayPlayer extends Player {
this.outLog = this.downOutLog
this.inLog = this.downInLog
this.chunkSendCache = []
this.respawnPacket = []
}
// Called when we get a packet from backend server (Backend -> PROXY -> Client)
@ -54,14 +55,21 @@ class RelayPlayer extends Player {
// If we're sending a chunk, but player isn't yet initialized, wait until it is.
// This is wrong and should not be an issue to send chunks before the client
// is in the world; need to investigate further, but for now it's fine.
if (name === 'level_chunk' && this.status !== 3) {
this.chunkSendCache.push([name, params])
return
if (this.status !== 3) {
if (name === 'level_chunk') {
this.chunkSendCache.push([name, params])
return
}
if (name === 'respawn') this.respawnPacket.push([name, params])
} else if (this.status === 3 && this.chunkSendCache.length) {
for (const chunk of this.chunkSendCache) {
this.queue(...chunk)
}
for (const rp of this.respawnPacket) {
this.queue(...rp)
}
this.chunkSendCache = []
this.respawnPacket = []
}
this.queue(name, params)
}