feat(saves): edit local save nicknames and premium days
Let the launcher update a save's account nickname and replace or clear its remaining premium time. Reuse registration validation and preserve the existing login and password hash.
This commit is contained in:
1 parent
1d3af395c2
commit
d20b7f4249
13 files changed
+127
-19
No files matched your search
@@ -45,6 +45,15 @@ export function extendPremiumAccount(profile: BlkBlock, days: number, nowFiletim
|
||||
setParam(entry, 'expiredTime', { type: 'int64', value: base + BigInt(days) * TICKS_PER_DAY });
|
||||
}
|
||||
|
||||
export function setPremiumDays(profile: BlkBlock, days: number, nowFiletime: bigint): void {
|
||||
if (!Number.isSafeInteger(days) || days < 0) throw new RangeError('Premium days must be a whole non-negative number.');
|
||||
const expires = nowFiletime + BigInt(days) * TICKS_PER_DAY;
|
||||
if (expires >= (1n << 63n)) throw new RangeError('Premium expiration exceeds the saved format.');
|
||||
const entry = ensureBlock(ensureBlock(profile, ENTITLEMENTS_INFO), PREMIUM_ACCOUNT_ENTITLEMENT);
|
||||
setParam(entry, 'count', { type: 'int', value: days > 0 ? Math.max(1, intField(entry, 'count')) : 0 });
|
||||
setParam(entry, 'expiredTime', { type: 'int64', value: expires });
|
||||
}
|
||||
|
||||
/** Remaining whole days (rounded up) of Premium Account, or 0 when inactive. */
|
||||
export function remainingPremiumDays(profile: BlkBlock, nowFiletime: bigint): number {
|
||||
const entry = findBlock(findBlock(profile, ENTITLEMENTS_INFO) ?? EMPTY_BLK, PREMIUM_ACCOUNT_ENTITLEMENT);
|
||||
|
||||
Reference in new issue
Block a user