image library changes, bit flags changes

This commit is contained in:
2025-09-16 18:01:55 -04:00
parent 5934f1a91c
commit c4f32b1940
16 changed files with 119 additions and 284 deletions

View File

@@ -26,7 +26,7 @@ export class PlatformsManager extends ServerContentBase {
async getToken(prof: Profile, type: TokenType) {
const secret = env["SECRET"];
if (!secret) throw new Error("No SECRET in env. Did you forget to set it?");
const exp = type == TokenType.Access ? Math.round(Date.now() / 1000) + 21_600 : Math.round(Date.now() / 1000) + 31_556_952;
const exp = type == TokenType.Access ? Math.round(Date.now() / 1000) + 21_600 : Math.round(Date.now() / 1000) + 21_600;
const token: TokenFormat = {
typ: type,

View File

@@ -2,10 +2,8 @@ export enum TokenType {
Access,
Refresh
}
export interface TokenFormatBase {
export interface TokenFormat {
typ: TokenType
}
export interface TokenFormat extends TokenFormatBase {
iss: string,
exp: number,
iat: number,

View File

@@ -13,7 +13,7 @@ export class ProfileMatchmakingManager extends ProfileContentManager {
#loginLockKey = this.profile.constructProfilePropertyKey('loginlock');
async setLoginLock(lock: string) {
await this.kv.getKv().set(this.#deviceClassKey, lock);
await this.kv.getKv().set(this.#loginLockKey, lock);
}
async getLoginLock(): Promise<string | null> {
return (await this.kv.getKv().get<string>(this.#loginLockKey)).value;

View File

@@ -4,8 +4,9 @@ import Profile from "./profile.ts";
import { SelfAccount, type RecNetAccount } from "./types/profile.ts";
import Command from "./../commands/command.ts";
import z from "zod";
import { PlatformMask, ProfileRole, TokenType } from "../platforms/types.ts";
import { PlatformMask, PlatformType, ProfileRole, TokenType } from "../platforms/types.ts";
import Logging from "@proxnet/undead-logging";
import { BitFlags } from "../../util/flags.ts";
const profiles: Map<number, Profile> = new Map();
@@ -45,7 +46,7 @@ class ProfileManagerBase extends ServerContentBase {
else return await this.#getUnusedUsername();
}
async create(platform: number, platformId: string, username?: string, id?: number) {
async create(platform: PlatformType, mask: BitFlags<PlatformMask>, platformId: string, username?: string, id?: number) {
if (typeof id == 'number') {
const prof = await this.get(id);
if (prof) throw new Error("ID is in use");
@@ -60,14 +61,14 @@ class ProfileManagerBase extends ServerContentBase {
accountId: newId,
username: newUsername,
displayName: newUsername,
platforms: PlatformMask.None,
platforms: mask.getValue(),
profileImage: "DefaultProfileImage.png",
createdAt: new Date()
}
await this.kv.getKv().set([ ProfileManagerBase.profilesKey, newId ], newProfile);
await this.kv.getKv().set([ ProfileManagerBase.profilesKey, newUsername ], newId);
await this.server.Platforms.addCachedLogin(platform, platformId, newId);
if (platformId !== "") await this.server.Platforms.addCachedLogin(platform, platformId, newId);
return this.get(newId);
}

View File

@@ -39,6 +39,16 @@ export class ServerRoomsBase extends ServerContentBase {
if (agrooms.value !== null) this.#agroomIds = agrooms.value;
this.#log.i(`${this.#agroomIds.size} AG rooms exist`);
if (this.getAgRoomIds().size === 0) {
try {
const config = await this.tryGetAgRoomRuntimeConfig();
this.#log.i(`Starting AG room initialization`);
this.initBuiltinRooms(config.Rooms, config.Locations);
} catch (err) {
this.#log.e(`Could not run AG room initialization: ${(err as Error).stack}`);
}
}
const baserooms = await this.kv.getKv().get<Set<number>>([ServerRoomsBase.baseRoomIdsKey]);
if (baserooms.value !== null) this.#baseroomIds = baserooms.value;
@@ -52,6 +62,8 @@ export class ServerRoomsBase extends ServerContentBase {
key: ["initag", "initagrooms", "initagroom", "iag"],
zod: z.tuple([]).rest(z.string()),
exec: async (...arrayPath: string[]) => {
if (this.#agroomIds.size !== 0) return new Error("AG rooms already initialized");
const path = arrayPath.join(' ');
try {
const config = JSON.parse((await Deno.readTextFile(path)).toString()) as AGRoomRuntimeConfig;
@@ -105,6 +117,9 @@ export class ServerRoomsBase extends ServerContentBase {
return this.#agRoomRuntimeConfig;
}
async tryGetAgRoomRuntimeConfig() {
return JSON.parse(await Deno.readTextFile(`${RootPath}/res/rooms.json`)) as AGRoomRuntimeConfig;
}
async initBuiltinRooms(rooms: AGRoom[], locations: AGRoomLocation[]) {
await Promise.all(rooms.map(async room => {
if (room.Accessibility == RoomDataTypes.RoomAccessibility.Private) return;
@@ -115,10 +130,7 @@ export class ServerRoomsBase extends ServerContentBase {
"ARRoom",
"Registration",
"DormRoom"
].includes(room.Name)) {
this.#log.w(`Room '${room.Name}' is not eligible for builtin room generation`);
return;
}
].includes(room.Name)) return;
const roomFactory = await this.write();
if (roomFactory == null) {
@@ -185,9 +197,9 @@ export class ServerRoomsBase extends ServerContentBase {
if (builtinScene) return builtinScene.SupportsJoinInProgress;
else {
if (!this.#joinInProgressLookup) throw new Error("JoinInProgress lookup table is not yet initialized");
const lookup = this.#joinInProgressLookup[subroomFactory.RoomSceneLocationId];
if (lookup) return lookup;
else return false;
const lookup = this.#joinInProgressLookup[subroomFactory.RoomSceneLocationId];
if (lookup) return lookup;
else return false;
}
}