Skip to content

Commit

Permalink
Fix RegionTimestampsPacket issue
Browse files Browse the repository at this point in the history
Let this be a warning against using "any"! :P
  • Loading branch information
Protonull authored and Gjum committed Aug 15, 2023
1 parent 17c5cd2 commit 6d32783
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
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)
}
}
}

0 comments on commit 6d32783

Please sign in to comment.