Skip to content

Commit

Permalink
feat(core): resolve online player by license search if possible
Browse files Browse the repository at this point in the history
  • Loading branch information
tabarra committed Dec 5, 2022
1 parent 36c2c8e commit 5b17317
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
8 changes: 8 additions & 0 deletions core/components/PlayerlistManager/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,14 @@ export default class PlayerlistManager {
return this.#playerlist[netid];
}

/**
* Returns a specifc ServerPlayer or undefined.
* NOTE: this returns the actual object and not a deep clone!
*/
getOnlinePlayersByLicense(searchLicense: string) {
return this.#playerlist.filter(p => p && p.license === searchLicense && p.isConnected) as ServerPlayer[];
}


/**
* Handler for all txAdminPlayerlistEvent structured trace events
Expand Down
7 changes: 6 additions & 1 deletion core/playerLogic/playerResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,12 @@ export default (mutex: any, netid: any, license: any) => {

//If license provided or resolved through licenseCache, search in the database
if (typeof searchLicense === 'string' && searchLicense.length) {
return new DatabasePlayer(searchLicense, playerDatabase);
const onlineMatches = playerlistManager.getOnlinePlayersByLicense(searchLicense);
if(onlineMatches.length){
return onlineMatches.at(-1);
}else{
return new DatabasePlayer(searchLicense, playerDatabase);
}
}

//Player not found
Expand Down

0 comments on commit 5b17317

Please sign in to comment.