From 34466735ef0eca56049154a6cb329790a0095075 Mon Sep 17 00:00:00 2001 From: Dev Date: Sat, 20 Apr 2024 09:58:47 +0100 Subject: [PATCH] Added nullguards insode `addPlayer()` to prevent server errors when profile not found or `inraid` object not found --- project/src/controllers/InraidController.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/project/src/controllers/InraidController.ts b/project/src/controllers/InraidController.ts index 71225ed6..b38cf227 100644 --- a/project/src/controllers/InraidController.ts +++ b/project/src/controllers/InraidController.ts @@ -96,7 +96,21 @@ export class InraidController public addPlayer(sessionID: string, info: IRegisterPlayerRequestData): void { this.applicationContext.addValue(ContextVariableType.REGISTER_PLAYER_REQUEST, info); - this.saveServer.getProfile(sessionID).inraid.location = info.locationId; + const profile = this.saveServer.getProfile(sessionID); + if (!profile) + { + this.logger.error(`No profile found with Id of: ${sessionID}`); + + return; + } + if (!profile.inraid) + { + profile.inraid = { character: sessionID, location: info.locationId }; + } + else + { + profile.inraid.location; + } } /**