Improve comments in gamecallback/controller

Move public functions to top of class
Use parameter property instead of hard coded string inside healthTreatment()
This commit is contained in:
Dev 2023-07-14 12:55:32 +01:00
parent 455bde264c
commit 162709a5b0
3 changed files with 109 additions and 81 deletions

View File

@ -76,22 +76,30 @@ class GameCallbacks
return this.httpResponse.getBody(this.gameController.getGameConfig(sessionID)); return this.httpResponse.getBody(this.gameController.getGameConfig(sessionID));
} }
/**
* Handle client/server/list
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
public getServer(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<IServerDetails[]> public getServer(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<IServerDetails[]>
{ {
return this.httpResponse.getBody(this.gameController.getServer()); return this.httpResponse.getBody(this.gameController.getServer(sessionID));
} }
// Handle client/match/group/current /**
* Handle client/match/group/current
*/
public getCurrentGroup(url: string, info: IEmptyRequestData, sessionID: string): any public getCurrentGroup(url: string, info: IEmptyRequestData, sessionID: string): any
{ {
return this.httpResponse.getBody(this.gameController.getCurrentGroup(sessionID)); return this.httpResponse.getBody(this.gameController.getCurrentGroup(sessionID));
} }
/**
* Handle client/checkVersion
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars // eslint-disable-next-line @typescript-eslint/no-unused-vars
public validateGameVersion(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<ICheckVersionResponse> public validateGameVersion(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<ICheckVersionResponse>
{ {
return this.httpResponse.getBody(this.gameController.getValidGameVersion()); return this.httpResponse.getBody(this.gameController.getValidGameVersion(sessionID));
} }
/** /**

View File

@ -65,6 +65,9 @@ export class GameController
this.locationConfig = this.configServer.getConfig(ConfigTypes.LOCATION); this.locationConfig = this.configServer.getConfig(ConfigTypes.LOCATION);
} }
/**
* Handle client/game/start
*/
public gameStart(_url: string, _info: IEmptyRequestData, sessionID: string, startTimeStampMS: number): void public gameStart(_url: string, _info: IEmptyRequestData, sessionID: string, startTimeStampMS: number): void
{ {
// Store start time in app context // Store start time in app context
@ -152,36 +155,71 @@ export class GameController
} }
} }
} }
/** Check for any missing assorts inside each traders assort.json data, checking against traders qeustassort.json */ /**
protected validateQuestAssortUnlocksExist(): void * Handle client/game/config
*/
public getGameConfig(sessionID: string): IGameConfigResponse
{ {
const db = this.databaseServer.getTables(); const config: IGameConfigResponse = {
const traders = db.traders; languages: this.databaseServer.getTables().locales.languages,
const quests = db.templates.quests; ndaFree: false,
for (const traderId of Object.values(Traders)) reportAvailable: false,
{ twitchEventMember: false,
const traderData = traders[traderId]; lang: "en",
const traderAssorts = traderData?.assort; aid: sessionID,
if (!traderAssorts) taxonomy: 6,
{ activeProfileId: `pmc${sessionID}`,
continue; backend: {
} Lobby: this.httpServerHelper.getBackendUrl(),
Trading: this.httpServerHelper.getBackendUrl(),
Messaging: this.httpServerHelper.getBackendUrl(),
Main: this.httpServerHelper.getBackendUrl(),
RagFair: this.httpServerHelper.getBackendUrl()
},
// eslint-disable-next-line @typescript-eslint/naming-convention
utc_time: new Date().getTime() / 1000,
totalInGame: 1
};
// Merge started/success/fail quest assorts into one dictionary return config;
const mergedQuestAssorts = Object.assign({}, traderData.questassort["started"], traderData.questassort["success"], traderData.questassort["fail"]); }
// loop over all assorts for trader /**
for (const [assortKey, questKey] of Object.entries(mergedQuestAssorts)) * Handle client/server/list
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public getServer(sessionId: string): IServerDetails[]
{
return [
{ {
// Does assort key exist in trader assort file ip: this.httpConfig.ip,
if (!traderAssorts.loyal_level_items[assortKey]) port: this.httpConfig.port
{
// reverse lookup of enum key by value
this.logger.warning(this.localisationService.getText("assort-missing_quest_assort_unlock", {traderName: Object.keys(Traders)[Object.values(Traders).indexOf(traderId)], questName: quests[questKey].QuestName}));
}
} }
} ];
}
/**
* Handle client/match/group/current
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public getCurrentGroup(sessionId: string): ICurrentGroupResponse
{
return {
squad: []
};
}
/**
* Handle client/checkVersion
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public getValidGameVersion(sessionId: string): ICheckVersionResponse
{
return {
isvalid: true,
latestVersion: this.coreConfig.compatibleTarkovVersion
};
} }
/** /**
@ -446,6 +484,39 @@ export class GameController
} }
} }
/**
* Check for any missing assorts inside each traders assort.json data, checking against traders qeustassort.json
*/
protected validateQuestAssortUnlocksExist(): void
{
const db = this.databaseServer.getTables();
const traders = db.traders;
const quests = db.templates.quests;
for (const traderId of Object.values(Traders))
{
const traderData = traders[traderId];
const traderAssorts = traderData?.assort;
if (!traderAssorts)
{
continue;
}
// Merge started/success/fail quest assorts into one dictionary
const mergedQuestAssorts = Object.assign({}, traderData.questassort["started"], traderData.questassort["success"], traderData.questassort["fail"]);
// loop over all assorts for trader
for (const [assortKey, questKey] of Object.entries(mergedQuestAssorts))
{
// Does assort key exist in trader assort file
if (!traderAssorts.loyal_level_items[assortKey])
{
// reverse lookup of enum key by value
this.logger.warning(this.localisationService.getText("assort-missing_quest_assort_unlock", {traderName: Object.keys(Traders)[Object.values(Traders).indexOf(traderId)], questName: quests[questKey].QuestName}));
}
}
}
}
/** /**
* Add the logged in players name to PMC name pool * Add the logged in players name to PMC name pool
* @param pmcProfile * @param pmcProfile
@ -513,56 +584,4 @@ export class GameController
this.logger.debug(`PATH: ${this.encodingUtil.toBase64(process.argv[0])}`); this.logger.debug(`PATH: ${this.encodingUtil.toBase64(process.argv[0])}`);
this.logger.debug(`PATH: ${this.encodingUtil.toBase64(process.execPath)}`); this.logger.debug(`PATH: ${this.encodingUtil.toBase64(process.execPath)}`);
} }
public getGameConfig(sessionID: string): IGameConfigResponse
{
const config: IGameConfigResponse = {
languages: this.databaseServer.getTables().locales.languages,
ndaFree: false,
reportAvailable: false,
twitchEventMember: false,
lang: "en",
aid: sessionID,
taxonomy: 6,
activeProfileId: `pmc${sessionID}`,
backend: {
Lobby: this.httpServerHelper.getBackendUrl(),
Trading: this.httpServerHelper.getBackendUrl(),
Messaging: this.httpServerHelper.getBackendUrl(),
Main: this.httpServerHelper.getBackendUrl(),
RagFair: this.httpServerHelper.getBackendUrl()
},
// eslint-disable-next-line @typescript-eslint/naming-convention
utc_time: new Date().getTime() / 1000,
totalInGame: 1
};
return config;
}
public getServer(): IServerDetails[]
{
return [
{
ip: this.httpConfig.ip,
port: this.httpConfig.port
}
];
}
// eslint-disable-next-line @typescript-eslint/no-unused-vars
public getCurrentGroup(sessionId: string): ICurrentGroupResponse
{
return {
squad: []
};
}
public getValidGameVersion(): ICheckVersionResponse
{
return {
isvalid: true,
latestVersion: this.coreConfig.compatibleTarkovVersion
};
}
} }

View File

@ -140,6 +140,7 @@ export class HealthController
} }
/** /**
* Handle RestoreHealth event
* Occurs on post-raid healing page * Occurs on post-raid healing page
* @param pmcData player profile * @param pmcData player profile
* @param healthTreatmentRequest Request data from client * @param healthTreatmentRequest Request data from client
@ -150,7 +151,7 @@ export class HealthController
{ {
let output = this.eventOutputHolder.getOutput(sessionID); let output = this.eventOutputHolder.getOutput(sessionID);
const payMoneyRequest: IProcessBuyTradeRequestData = { const payMoneyRequest: IProcessBuyTradeRequestData = {
Action: "RestoreHealth", Action: healthTreatmentRequest.Action,
tid: Traders.THERAPIST, tid: Traders.THERAPIST,
// eslint-disable-next-line @typescript-eslint/naming-convention // eslint-disable-next-line @typescript-eslint/naming-convention
scheme_items: healthTreatmentRequest.items, scheme_items: healthTreatmentRequest.items,