Skip to content

Commit

Permalink
fix(server/player): add char id key member instance on join
Browse files Browse the repository at this point in the history
  • Loading branch information
LukeWasTakenn committed Aug 30, 2024
1 parent 8755553 commit ff40c02
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 6 additions & 3 deletions server/classInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ export class ClassInterface {

if (!member) return console.error(`cannot call method ${method} on ${name}<${id}> (invalid id)`);

if (!member[method]) return console.error(`cannot call method ${method} on ${name}<${id}> (method does not exist)`);
if (!member[method])
return console.error(`cannot call method ${method} on ${name}<${id}> (method does not exist)`);

if (!this.callableMethods[method])
return console.error(`cannot call method ${method} on ${name}<${id}> (method is not exported)`);
Expand All @@ -44,7 +45,7 @@ export class ClassInterface {

return this;
}

call(method: string, ...args: any) {
return (this as any)[method](...args);
}
Expand All @@ -67,7 +68,9 @@ export class ClassInterface {

if (this.keys) {
Object.entries(this.keys).forEach(([key, obj]) => {
obj[member[key]] = member;
if (member[key]) {
obj[member[key]] = member;
}
});
}

Expand Down
3 changes: 3 additions & 0 deletions server/player/class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,7 @@ export class OxPlayer extends ClassInterface {

if (dropped) return;

delete OxPlayer.keys.charId[this.charId];
delete this.charId;

this.emit('ox:startCharacterSelect', this.userId, await this.#getCharacters());
Expand Down Expand Up @@ -616,6 +617,8 @@ export class OxPlayer extends ClassInterface {
this.set('phoneNumber', phoneNumber, true);
this.set('activeGroup', groups.find((group) => group.isActive)?.name, true);

OxPlayer.keys.charId[character.charId] = this;

/**
* @todo Player metadata can ideally be handled with statebags, but requires security features.
* Rejection of client-set values is a must-have.
Expand Down

0 comments on commit ff40c02

Please sign in to comment.