From 5b17317f73937b907cae1379891cd04b628f7cd2 Mon Sep 17 00:00:00 2001 From: tabarra Date: Mon, 5 Dec 2022 15:28:50 -0300 Subject: [PATCH] feat(core): resolve online player by license search if possible --- core/components/PlayerlistManager/index.ts | 8 ++++++++ core/playerLogic/playerResolver.ts | 7 ++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/core/components/PlayerlistManager/index.ts b/core/components/PlayerlistManager/index.ts index 24acc146b..0bc2ebacd 100644 --- a/core/components/PlayerlistManager/index.ts +++ b/core/components/PlayerlistManager/index.ts @@ -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 diff --git a/core/playerLogic/playerResolver.ts b/core/playerLogic/playerResolver.ts index 1c9931366..5ec1ae3d7 100644 --- a/core/playerLogic/playerResolver.ts +++ b/core/playerLogic/playerResolver.ts @@ -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