Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix RegionTimestampsPacket issue #76

Merged
merged 1 commit into from
Aug 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions server/src/database.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,15 @@ export function getRegionTimestamps(dimension: string) {
return get()
.selectFrom('player_chunk')
.select([
(eb) => kysely.sql<number>`floor(${eb.ref('chunk_x')} / 32.0)`.as('x'),
(eb) => kysely.sql<number>`floor(${eb.ref('chunk_z')} / 32.0)`.as('z'),
(eb) =>
kysely.sql<number>`floor(${eb.ref('chunk_x')} / 32.0)`.as('regionX'),
(eb) =>
kysely.sql<number>`floor(${eb.ref('chunk_z')} / 32.0)`.as('regionZ'),
(eb) => eb.fn.max('ts').as('timestamp'),
])
.where('world', '=', dimension)
.groupBy(['x', 'z'])
.orderBy('x', 'desc')
.groupBy(['regionX', 'regionZ'])
.orderBy('regionX', 'desc')
.execute()
}

Expand Down
6 changes: 6 additions & 0 deletions server/src/model.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
export interface CatchupRegion {
readonly regionX: number
readonly regionZ: number
readonly timestamp: number
}

export interface CatchupChunk {
world: string
chunk_x: number
Expand Down
10 changes: 5 additions & 5 deletions server/src/protocol/RegionTimestampsPacket.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { BufWriter } from './BufWriter'
import { CatchupRegion } from '../model'

export interface RegionTimestampsPacket {
type: 'RegionTimestamps'
world: string
regions: any[]
regions: Array<CatchupRegion>
}

export namespace RegionTimestampsPacket {
Expand All @@ -13,10 +14,9 @@ export namespace RegionTimestampsPacket {
console.log('Sending regions ' + JSON.stringify(pkt.regions))
for (let i = 0; i < pkt.regions.length; i++) {
let region = pkt.regions[i]
writer.writeInt16(region.region_x)
writer.writeInt16(region.region_z)

writer.writeInt64(pkt.regions[i].ts)
writer.writeInt16(region.regionX)
writer.writeInt16(region.regionZ)
writer.writeInt64(region.timestamp)
}
}
}