This commit is contained in:
2025-09-11 19:47:33 -04:00
parent 317da3aaf7
commit c2eb111291
14 changed files with 217 additions and 44 deletions

View File

@@ -8,6 +8,8 @@ import Command from "../commands/command.ts";
import z from "zod";
import { PushNotificationId } from "../socket/signalr/types.ts";
const log = new Logging("Presence");
export enum VRMovementMode {
TELEPORT,
WALK
@@ -87,6 +89,8 @@ export class Presence {
}
export() {
log.d(`profId ${this.#profile.getId()} presence exported. has instance: ${this.#profile.getInstance() !== null}`);
this.#lastExported = new Date();
const e: PresenceExport = {
playerId: this.#profile.getId(),
@@ -127,7 +131,6 @@ export class ServerPresenceBase extends ServerContentBase {
this.#intervalId = setInterval(() => {
if (this.#presenceMap.size === 0) return;
this.#log.i('Clearing dead presences');
this.#deleteDeadPresences();
}, 300_000);

View File

@@ -4,7 +4,7 @@ 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, PlatformType, ProfileRole, TokenType } from "../platforms/types.ts";
import { PlatformMask, ProfileRole, TokenType } from "../platforms/types.ts";
import Logging from "@proxnet/undead-logging";
const profiles: Map<number, Profile> = new Map();
@@ -36,29 +36,40 @@ class ProfileManagerBase extends ServerContentBase {
if (await this.getByUsername(username)) username = await this.#getUnusedUsername();
return username;
}
async #getUsernameDefault(username: string) {
async #getUsernameDefault(username?: string) {
if (!username) return await this.#getUnusedUsername();
const prof = await this.getByUsername(username);
if (!prof) return username;
else return await this.#getUnusedUsername();
}
async create(platform: PlatformType, platformId: string, username?: string) {
const id = await this.#getUnusedId();
const newUsername = username ? await this.#getUsernameDefault(username) : await this.#getUnusedUsername();
async create(platform: number, 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");
}
const newId = typeof id == 'number' ? id : await this.#getUnusedId();
const newUsername = await this.#getUsernameDefault(username);
this.#log.d(`Creating account "${newUsername}" (${newId})`);
const newProfile: RecNetAccount = {
accountId: id,
accountId: newId,
username: newUsername,
displayName: newUsername,
platforms: PlatformMask.None,
profileImage: "DefaultProfileImage.png",
createdAt: new Date()
}
await this.kv.getKv().set([ ProfileManagerBase.profilesKey, id ], newProfile);
await this.kv.getKv().set([ ProfileManagerBase.profilesKey, newUsername ], id);
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, id);
await this.server.Platforms.addCachedLogin(platform, platformId, newId);
return this.get(id);
return this.get(newId);
}
async get(id: number) {

View File

@@ -14,6 +14,7 @@ import { ProfileSettingsManager } from "./content/Settings.ts";
import { ProfileSubscriptionsManager } from "./content/Subscriptions.ts";
import ProfileManagerBase from "./manager.ts";
import { recNetAccountSchema, SelfAccount, type RecNetAccount } from "./types/profile.ts";
import { hash, verify } from "@felix/bcrypt";
class Profile {
@@ -95,7 +96,7 @@ class Profile {
async getRole(): Promise<ProfileRole> {
const val = (await this.#kv.getKv().get<ProfileRole>(this.constructProfilePropertyKey('role'))).value;
if (!val) return ProfileRole.Game;
if (!val) return "gameClient";
else return val;
}
@@ -146,8 +147,8 @@ class Profile {
if (this.#instance) this.#instance.removePlayer(this);
inst.addPlayer(this);
this.#server.emit('presence.update', { profile: this, presence: this.#server.Presence.getPresence(this) });
this.#instance = inst;
this.#server.emit('presence.update', { profile: this, presence: this.#server.Presence.getPresence(this) });
}
getId() {
@@ -176,6 +177,15 @@ class Profile {
return profile.getId() == this.getId();
}
async setPassword(pass: string) {
await this.#kv.getKv().set(this.constructProfilePropertyKey("password"), await hash(pass));
}
async verifyPassword(pass: string) {
const hash = await this.#kv.getKv().get<string>(this.constructProfilePropertyKey("password"));
if (hash.value == null) return false;
else return await verify(pass, hash.value);
}
}
export default Profile;