changed network log format, player settings

This commit is contained in:
2025-07-26 00:17:14 -04:00
parent e604c7a437
commit 2302290d34
8 changed files with 126 additions and 27 deletions

View File

@@ -2,6 +2,7 @@ import KV from "../persistence/kv.ts";
import { ProfileRole } from "../platforms/base.ts";
import { type ServerBase } from "../server.ts";
import { type SignalRSocketHandler } from "../socket/signalr/socket.ts";
import { ProfileSettingsManager } from "./content/Settings.ts";
import ProfileManagerBase from "./manager.ts";
import { recNetAccountSchema, SelfAccount, type RecNetAccount } from "./types/profile.ts";
@@ -15,19 +16,23 @@ class Profile {
#selfAcc: SelfAccount;
Settings: ProfileSettingsManager;
constructor(acc: SelfAccount, kv: KV, server: ServerBase) {
this.#id = acc.accountId;
this.#selfAcc = acc;
this.#kv = kv;
this.#server = server;
this.Settings = new ProfileSettingsManager(this, this.#kv);
}
async #saveSelfAcc() {
await this.#kv.getKv().set(this.#constructProfilePropertyKey(), this.#selfAcc);
await this.#kv.getKv().set(this.constructProfilePropertyKey(), this.#selfAcc);
this.#server.emit('profile.update', { profile: this });
}
#constructProfilePropertyKey(...keys: (string | undefined)[]) {
constructProfilePropertyKey(...keys: (string | undefined)[]) {
return [ ProfileManagerBase.profilesKey, this.#id, ...keys.filter(val => typeof val == 'string') ];
}
@@ -51,24 +56,24 @@ class Profile {
}
async getBio(){
const key = this.#constructProfilePropertyKey('bio');
const key = this.constructProfilePropertyKey('bio');
const val = await this.#kv.getKv().get<string>(key);
if (!val.value) return null;
else return val.value;
}
async setBio(bio: string) {
const key = this.#constructProfilePropertyKey('bio');
const key = this.constructProfilePropertyKey('bio');
await this.#kv.getKv().set(key, bio);
}
async getRole(): Promise<ProfileRole> {
const val = (await this.#kv.getKv().get<ProfileRole>(this.#constructProfilePropertyKey('role'))).value;
const val = (await this.#kv.getKv().get<ProfileRole>(this.constructProfilePropertyKey('role'))).value;
if (!val) return ProfileRole.User;
else return val;
}
async setRole(role: ProfileRole) {
await this.#kv.getKv().set(this.#constructProfilePropertyKey('role'), role);
await this.#kv.getKv().set(this.constructProfilePropertyKey('role'), role);
this.#server.emit('profile.roleupdate', { profile: this, newRole: role });
}