From db296499e9ce50b727d4473cfd893ddb9768f89d Mon Sep 17 00:00:00 2001 From: Dev Date: Wed, 27 Dec 2023 22:01:30 +0000 Subject: [PATCH] Fix profile ids being prepended with pmc/scav killing game load --- .../src/callbacks/CustomizationCallbacks.ts | 2 +- project/src/callbacks/ProfileCallbacks.ts | 19 +----------- project/src/controllers/GameController.ts | 2 +- project/src/controllers/LauncherController.ts | 31 ++++++++++++++++--- project/src/controllers/ProfileController.ts | 31 +++++++++++++++++-- project/src/models/eft/profile/IAkiProfile.ts | 2 ++ project/src/routers/HttpRouter.ts | 2 +- project/src/services/MatchLocationService.ts | 14 ++++++--- 8 files changed, 71 insertions(+), 32 deletions(-) diff --git a/project/src/callbacks/CustomizationCallbacks.ts b/project/src/callbacks/CustomizationCallbacks.ts index 35c85210..7c6f5a2b 100644 --- a/project/src/callbacks/CustomizationCallbacks.ts +++ b/project/src/callbacks/CustomizationCallbacks.ts @@ -29,7 +29,7 @@ export class CustomizationCallbacks public getSuits(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData { const result: IGetSuitsResponse = { - _id: `pmc${sessionID}`, + _id: sessionID, suites: this.saveServer.getProfile(sessionID).suits, }; return this.httpResponse.getBody(result); diff --git a/project/src/callbacks/ProfileCallbacks.ts b/project/src/callbacks/ProfileCallbacks.ts index ca399f12..3da09fd0 100644 --- a/project/src/callbacks/ProfileCallbacks.ts +++ b/project/src/callbacks/ProfileCallbacks.ts @@ -138,24 +138,7 @@ export class ProfileCallbacks sessionID: string, ): IGetBodyResponseData { - const response: GetProfileStatusResponseData = { - maxPveCountExceeded: false, - profiles: [{ - profileid: `scav${sessionID}`, - profileToken: null, - status: "Free", - sid: "", - ip: "", - port: 0, - version: "live", - location: "bigmap", - raidMode: "Online", - mode: "deathmatch", - shortId: "xxx1x1", - }, { profileid: `pmc${sessionID}`, profileToken: null, status: "Free", sid: "", ip: "", port: 0 }], - }; - - return this.httpResponse.getBody(response); + return this.httpResponse.getBody(this.profileController.getProfileStatus(sessionID)); } /** diff --git a/project/src/controllers/GameController.ts b/project/src/controllers/GameController.ts index 85d1558f..ef97988b 100644 --- a/project/src/controllers/GameController.ts +++ b/project/src/controllers/GameController.ts @@ -434,7 +434,7 @@ export class GameController lang: "en", aid: profile.aid, taxonomy: 6, - activeProfileId: `pmc${sessionID}`, + activeProfileId: sessionID, backend: { Lobby: this.httpServerHelper.getBackendUrl(), Trading: this.httpServerHelper.getBackendUrl(), diff --git a/project/src/controllers/LauncherController.ts b/project/src/controllers/LauncherController.ts index 16797698..55adeeac 100644 --- a/project/src/controllers/LauncherController.ts +++ b/project/src/controllers/LauncherController.ts @@ -17,6 +17,8 @@ import { DatabaseServer } from "@spt-aki/servers/DatabaseServer"; import { SaveServer } from "@spt-aki/servers/SaveServer"; import { LocalisationService } from "@spt-aki/services/LocalisationService"; import { HashUtil } from "@spt-aki/utils/HashUtil"; +import { RandomUtil } from "@spt-aki/utils/RandomUtil"; +import { TimeUtil } from "@spt-aki/utils/TimeUtil"; @injectable() export class LauncherController @@ -26,6 +28,8 @@ export class LauncherController constructor( @inject("WinstonLogger") protected logger: ILogger, @inject("HashUtil") protected hashUtil: HashUtil, + @inject("TimeUtil") protected timeUtil: TimeUtil, + @inject("RandomUtil") protected randomUtil: RandomUtil, @inject("SaveServer") protected saveServer: SaveServer, @inject("HttpServerHelper") protected httpServerHelper: HttpServerHelper, @inject("ProfileHelper") protected profileHelper: ProfileHelper, @@ -110,9 +114,11 @@ export class LauncherController protected createAccount(info: IRegisterData): string { - const sessionID = this.hashUtil.generate(); + const profileId = this.generateProfileId(); + const scavId = this.generateProfileId(); const newProfileDetails: Info = { - id: sessionID, + id: profileId, + scavId: scavId, aid: this.hashUtil.generateAccountId(), username: info.username, password: info.password, @@ -121,10 +127,25 @@ export class LauncherController }; this.saveServer.createProfile(newProfileDetails); - this.saveServer.loadProfile(sessionID); - this.saveServer.saveProfile(sessionID); + this.saveServer.loadProfile(profileId); + this.saveServer.saveProfile(profileId); - return sessionID; + return profileId; + } + + protected generateProfileId(): string + { + const timestamp = this.timeUtil.getTimestamp(); + + return this.formatID(timestamp, timestamp * this.randomUtil.getInt(1, 1000000)); + } + + protected formatID(timeStamp: number, counter: number): string + { + const timeStampStr = timeStamp.toString(16).padStart(8, '0'); + const counterStr = counter.toString(16).padStart(16, '0'); + + return timeStampStr.toLowerCase() + counterStr.toLowerCase(); } public changeUsername(info: IChangeRequestData): string diff --git a/project/src/controllers/ProfileController.ts b/project/src/controllers/ProfileController.ts index ca39a36e..5318bf8d 100644 --- a/project/src/controllers/ProfileController.ts +++ b/project/src/controllers/ProfileController.ts @@ -10,6 +10,7 @@ import { IPmcData } from "@spt-aki/models/eft/common/IPmcData"; import { TemplateSide } from "@spt-aki/models/eft/common/tables/IProfileTemplate"; import { IItemEventRouterResponse } from "@spt-aki/models/eft/itemEvent/IItemEventRouterResponse"; import { IMiniProfile } from "@spt-aki/models/eft/launcher/IMiniProfile"; +import { GetProfileStatusResponseData } from "@spt-aki/models/eft/profile/GetProfileStatusResponseData"; import { IAkiProfile, Inraid, Vitality } from "@spt-aki/models/eft/profile/IAkiProfile"; import { IProfileChangeNicknameRequestData } from "@spt-aki/models/eft/profile/IProfileChangeNicknameRequestData"; import { IProfileChangeVoiceRequestData } from "@spt-aki/models/eft/profile/IProfileChangeVoiceRequestData"; @@ -133,9 +134,9 @@ export class ProfileController this.deleteProfileBySessionId(sessionID); // PMC - pmcData._id = `pmc${sessionID}`; + pmcData._id = account.id; pmcData.aid = account.aid; - pmcData.savage = `scav${sessionID}`; + pmcData.savage = account.scavId; pmcData.sessionId = sessionID; pmcData.Info.Nickname = info.nickname; pmcData.Info.LowerNickname = info.nickname.toLowerCase(); @@ -356,4 +357,30 @@ export class ProfileController { return [{ _id: this.hashUtil.generate(), Info: { Level: 1, Side: "Bear", Nickname: info.nickname } }]; } + + /** + * Handle client/profile/status + */ + public getProfileStatus(sessionId: string): GetProfileStatusResponseData + { + const account = this.saveServer.getProfile(sessionId).info; + const response: GetProfileStatusResponseData = { + maxPveCountExceeded: false, + profiles: [{ + profileid: account.scavId, + profileToken: null, + status: "Free", + sid: "", + ip: "", + port: 0, + version: "live", + location: "bigmap", + raidMode: "Online", + mode: "deathmatch", + shortId: "xxx1x1", + }, { profileid: account.id, profileToken: null, status: "Free", sid: "", ip: "", port: 0 }], + }; + + return response; + } } diff --git a/project/src/models/eft/profile/IAkiProfile.ts b/project/src/models/eft/profile/IAkiProfile.ts index fa2d4d72..cefa2c5d 100644 --- a/project/src/models/eft/profile/IAkiProfile.ts +++ b/project/src/models/eft/profile/IAkiProfile.ts @@ -29,7 +29,9 @@ export class TraderPurchaseData export interface Info { + /** main profile id */ id: string; + scavId: string; aid: number; username: string; password: string; diff --git a/project/src/routers/HttpRouter.ts b/project/src/routers/HttpRouter.ts index a507f3c8..108982e7 100644 --- a/project/src/routers/HttpRouter.ts +++ b/project/src/routers/HttpRouter.ts @@ -50,7 +50,7 @@ export class HttpRouter // TODO: Temporary hack to change ItemEventRouter response sessionID binding to what client expects if (wrapper.output?.includes("\"profileChanges\":{")) { - wrapper.output = wrapper.output.replace(sessionID, `pmc${sessionID}`); + wrapper.output = wrapper.output.replace(sessionID, sessionID); } return wrapper.output; diff --git a/project/src/services/MatchLocationService.ts b/project/src/services/MatchLocationService.ts index d81b1817..f077cdd0 100644 --- a/project/src/services/MatchLocationService.ts +++ b/project/src/services/MatchLocationService.ts @@ -1,6 +1,7 @@ import { inject, injectable } from "tsyringe"; import { ICreateGroupRequestData } from "@spt-aki/models/eft/match/ICreateGroupRequestData"; +import { SaveServer } from "@spt-aki/servers/SaveServer"; import { TimeUtil } from "@spt-aki/utils/TimeUtil"; @injectable() @@ -8,16 +9,21 @@ export class MatchLocationService { protected locations = {}; - constructor(@inject("TimeUtil") protected timeUtil: TimeUtil) + constructor( + @inject("TimeUtil") protected timeUtil: TimeUtil, + @inject("SaveServer") protected saveServer: SaveServer, + ) {} public createGroup(sessionID: string, info: ICreateGroupRequestData): any { + + const account = this.saveServer.getProfile(sessionID).info; const groupID = "test"; this.locations[info.location].groups[groupID] = { _id: groupID, - owner: `pmc${sessionID}`, + owner: account.id, location: info.location, gameVersion: "live", region: "EUR", @@ -26,10 +32,10 @@ export class MatchLocationService timeShift: "CURR", dt: this.timeUtil.getTimestamp(), players: [{ - _id: `pmc${sessionID}`, + _id: account.id, region: "EUR", ip: "127.0.0.1", - savageId: `scav${sessionID}`, + savageId: account.scavId, accessKeyId: "", }], customDataCenter: [],