Persist the actual grant in the purchase log and open one native receipt per unread entry. Keep pending receipts during log trimming and resume them when the price table becomes available. Verified TypeScript types, GUI patch application, and Quirrel syntax.
32 lines
1.1 KiB
TypeScript
32 lines
1.1 KiB
TypeScript
/**
|
|
* Time as the char server and the client count it: Windows FILETIME,
|
|
* 100-nanosecond ticks since 1601-01-01 UTC. The profile's serverTime:i64 sets the client's
|
|
* clock (set_charserver_time, aces.exe 2.61.0.37 0x904400; get_charserver_time_sec 0x15533a0
|
|
* turns it back into Unix seconds), and item expiry times (items/<uid>/expiredTimeH) are
|
|
* absolute times in the same unit.
|
|
*/
|
|
|
|
export type ServerTime = bigint;
|
|
|
|
const TICKS_PER_MILLISECOND = 10_000n;
|
|
const UNIX_EPOCH = 116_444_736_000_000_000n;
|
|
|
|
export const TICKS_PER_HOUR = 36_000_000_000n;
|
|
|
|
export function serverTimeFromUnixMs(milliseconds: number): ServerTime {
|
|
return BigInt(Math.trunc(milliseconds)) * TICKS_PER_MILLISECOND + UNIX_EPOCH;
|
|
}
|
|
|
|
export function serverTimeNow(): ServerTime {
|
|
return serverTimeFromUnixMs(Date.now());
|
|
}
|
|
|
|
export function serverTimeToUnixSeconds(time: ServerTime): number {
|
|
return Number((time - UNIX_EPOCH) / (1000n * TICKS_PER_MILLISECOND));
|
|
}
|
|
|
|
/** A whole or fractional number of hours as ticks. */
|
|
export function hoursToTicks(hours: number): bigint {
|
|
return BigInt(Math.round(hours * 3_600_000)) * TICKS_PER_MILLISECOND;
|
|
}
|