diff --git a/src/idz/db/timeAttack.ts b/src/idz/db/timeAttack.ts index ef124c2..6a8a35f 100644 --- a/src/idz/db/timeAttack.ts +++ b/src/idz/db/timeAttack.ts @@ -11,12 +11,16 @@ import { generateId } from "../../db"; export class SqlTimeAttackRepository implements TimeAttackRepository { constructor(private readonly _conn: ClientBase) {} - async loadTopTen(routeNo: RouteNo): Promise { + async loadTopTen( + routeNo: RouteNo, + minTimestamp: Date + ): Promise { const loadSql = sql .select("p.name", "ta.*") .from("idz.ta_best ta") .join("idz.profile p", { "ta.profile_id": "p.id" }) .where("ta.route_no", routeNo) + .where(sql.gt("ta.timestamp", minTimestamp)) .orderBy(["ta.total_time asc", "ta.timestamp asc"]) .limit(10) .toParams(); diff --git a/src/idz/decoder/loadTopTen1.ts b/src/idz/decoder/loadTopTen1.ts index 0f9dd83..cfe9e5c 100644 --- a/src/idz/decoder/loadTopTen1.ts +++ b/src/idz/decoder/loadTopTen1.ts @@ -16,7 +16,7 @@ export function loadTopTen1(buf: Buffer): LoadTopTenRequest { for (let i = 0; i < 32; i++) { selectors.push({ routeNo: (buf.readUInt16LE(0x0004 + 2 * i) >> 1) as RouteNo, - field_44: buf.readUInt32LE(0x0044 + 4 * i), + minTimestamp: new Date(buf.readUInt32LE(0x0044 + 4 * i) * 1000 + 1000), }); } diff --git a/src/idz/decoder/loadTopTen2.ts b/src/idz/decoder/loadTopTen2.ts index 53fe059..79e9341 100644 --- a/src/idz/decoder/loadTopTen2.ts +++ b/src/idz/decoder/loadTopTen2.ts @@ -16,7 +16,7 @@ export function loadTopTen2(buf: Buffer): LoadTopTenRequest { for (let i = 0; i < 40; i++) { selectors.push({ routeNo: (buf.readUInt16LE(0x0004 + 2 * i) >> 1) as RouteNo, - field_44: buf.readUInt32LE(0x0054 + 4 * i), + minTimestamp: new Date(buf.readUInt32LE(0x0054 + 4 * i) * 1000 + 1000), }); } diff --git a/src/idz/handler/loadTopTen.ts b/src/idz/handler/loadTopTen.ts index 8405ce6..a0f65d2 100644 --- a/src/idz/handler/loadTopTen.ts +++ b/src/idz/handler/loadTopTen.ts @@ -4,7 +4,7 @@ import { LoadTopTenResponseCourse, LoadTopTenResponseRow, } from "../response/loadTopTen"; -import { Repositories } from "../repo"; +import { Repositories, TopTenResult } from "../repo"; export async function loadTopTen( w: Repositories, @@ -17,12 +17,19 @@ export async function loadTopTen( break; } - if (selector.field_44 === 0) { + const { routeNo, minTimestamp } = selector; + let src: TopTenResult[]; + + if (req.teamId !== undefined) { + src = []; // TODO + } else { + src = await w.timeAttack().loadTopTen(routeNo, minTimestamp); + } + + if (src.length === 0) { continue; } - const { routeNo } = selector; - const src = await w.timeAttack().loadTopTen(routeNo); const dest = new Array(); for (const srcItem of src) { diff --git a/src/idz/repo.ts b/src/idz/repo.ts index 87197c8..dcf6b8c 100644 --- a/src/idz/repo.ts +++ b/src/idz/repo.ts @@ -72,7 +72,10 @@ export interface TopTenResult { } export interface TimeAttackRepository { - loadTopTen(routeNo: Model.RouteNo): Promise; + loadTopTen( + routeNo: Model.RouteNo, + minTimestamp: Date + ): Promise; loadAll( profileId: Model.ExtId diff --git a/src/idz/request/loadTopTen.ts b/src/idz/request/loadTopTen.ts index cda9abd..29a2fde 100644 --- a/src/idz/request/loadTopTen.ts +++ b/src/idz/request/loadTopTen.ts @@ -4,7 +4,7 @@ import { Team } from "../model/team"; export interface LoadTopTenRequestSelector { routeNo: RouteNo; - field_44: number; + minTimestamp: Date; } export interface LoadTopTenRequest {