Server/project/src/callbacks/DataCallbacks.ts

213 lines
7.5 KiB
TypeScript
Raw Normal View History

import { HideoutController } from "@spt/controllers/HideoutController";
import { RagfairController } from "@spt/controllers/RagfairController";
import { TraderHelper } from "@spt/helpers/TraderHelper";
import { IEmptyRequestData } from "@spt/models/eft/common/IEmptyRequestData";
import { IGlobals } from "@spt/models/eft/common/IGlobals";
import { ICustomizationItem } from "@spt/models/eft/common/tables/ICustomizationItem";
import { IHandbookBase } from "@spt/models/eft/common/tables/IHandbookBase";
import { IGetItemPricesResponse } from "@spt/models/eft/game/IGetItemPricesResponse";
import { IHideoutArea } from "@spt/models/eft/hideout/IHideoutArea";
import { IHideoutProductionData } from "@spt/models/eft/hideout/IHideoutProduction";
import { IHideoutScavCase } from "@spt/models/eft/hideout/IHideoutScavCase";
import { IHideoutSettingsBase } from "@spt/models/eft/hideout/IHideoutSettingsBase";
import { IGetBodyResponseData } from "@spt/models/eft/httpResponse/IGetBodyResponseData";
import { Money } from "@spt/models/enums/Money";
import { ISettingsBase } from "@spt/models/spt/server/ISettingsBase";
import { DatabaseService } from "@spt/services/DatabaseService";
import { HttpResponseUtil } from "@spt/utils/HttpResponseUtil";
import { TimeUtil } from "@spt/utils/TimeUtil";
import { inject, injectable } from "tsyringe";
2023-03-03 15:23:46 +00:00
/**
* Handle client requests
*/
@injectable()
export class DataCallbacks {
2023-03-03 15:23:46 +00:00
constructor(
@inject("HttpResponseUtil") protected httpResponse: HttpResponseUtil,
@inject("TimeUtil") protected timeUtil: TimeUtil,
@inject("TraderHelper") protected traderHelper: TraderHelper,
@inject("DatabaseService") protected databaseService: DatabaseService,
2023-03-03 15:23:46 +00:00
@inject("RagfairController") protected ragfairController: RagfairController,
2023-11-10 15:19:56 -05:00
@inject("HideoutController") protected hideoutController: HideoutController,
) {}
2023-03-03 15:23:46 +00:00
/**
* Handle client/settings
2023-03-03 15:23:46 +00:00
* @returns ISettingsBase
*/
public getSettings(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<ISettingsBase> {
return this.httpResponse.getBody(this.databaseService.getSettings());
2023-03-03 15:23:46 +00:00
}
/**
* Handle client/globals
2023-03-03 15:23:46 +00:00
* @returns IGlobals
*/
public getGlobals(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<IGlobals> {
const globals = this.databaseService.getGlobals();
globals.time = Date.now() / 1000;
return this.httpResponse.getBody(this.databaseService.getGlobals());
2023-03-03 15:23:46 +00:00
}
/**
* Handle client/items
2023-03-03 15:23:46 +00:00
* @returns string
*/
public getTemplateItems(url: string, info: IEmptyRequestData, sessionID: string): string {
return this.httpResponse.getUnclearedBody(this.databaseService.getItems());
2023-03-03 15:23:46 +00:00
}
/**
* Handle client/handbook/templates
2023-03-03 15:23:46 +00:00
* @returns IHandbookBase
*/
2023-11-10 15:19:56 -05:00
public getTemplateHandbook(
url: string,
info: IEmptyRequestData,
sessionID: string,
): IGetBodyResponseData<IHandbookBase> {
return this.httpResponse.getBody(this.databaseService.getHandbook());
2023-03-03 15:23:46 +00:00
}
/**
* Handle client/customization
2023-03-03 15:23:46 +00:00
* @returns Record<string, ICustomizationItem
*/
2023-11-10 15:19:56 -05:00
public getTemplateSuits(
url: string,
info: IEmptyRequestData,
sessionID: string,
): IGetBodyResponseData<Record<string, ICustomizationItem>> {
return this.httpResponse.getBody(this.databaseService.getTemplates().customization);
2023-03-03 15:23:46 +00:00
}
/**
* Handle client/account/customization
2023-03-03 15:23:46 +00:00
* @returns string[]
*/
public getTemplateCharacter(
url: string,
info: IEmptyRequestData,
sessionID: string,
): IGetBodyResponseData<string[]> {
return this.httpResponse.getBody(this.databaseService.getTemplates().character);
2023-03-03 15:23:46 +00:00
}
/**
* Handle client/hideout/settings
* @returns IHideoutSettingsBase
*/
2023-11-10 15:19:56 -05:00
public getHideoutSettings(
url: string,
info: IEmptyRequestData,
sessionID: string,
): IGetBodyResponseData<IHideoutSettingsBase> {
return this.httpResponse.getBody(this.databaseService.getHideout().settings);
2023-03-03 15:23:46 +00:00
}
2023-11-10 15:19:56 -05:00
public getHideoutAreas(
url: string,
info: IEmptyRequestData,
sessionID: string,
): IGetBodyResponseData<IHideoutArea[]> {
return this.httpResponse.getBody(this.databaseService.getHideout().areas);
2023-03-03 15:23:46 +00:00
}
public getHideoutProduction(
2023-11-10 15:19:56 -05:00
url: string,
info: IEmptyRequestData,
sessionID: string,
): IGetBodyResponseData<IHideoutProductionData> {
return this.httpResponse.getBody(this.databaseService.getHideout().production);
2023-03-03 15:23:46 +00:00
}
2023-11-10 15:19:56 -05:00
public getHideoutScavcase(
url: string,
info: IEmptyRequestData,
sessionID: string,
): IGetBodyResponseData<IHideoutScavCase[]> {
return this.httpResponse.getBody(this.databaseService.getHideout().scavcase);
2023-03-03 15:23:46 +00:00
}
/**
* Handle client/languages
*/
2023-11-10 15:19:56 -05:00
public getLocalesLanguages(
url: string,
info: IEmptyRequestData,
sessionID: string,
): IGetBodyResponseData<Record<string, string>> {
return this.httpResponse.getBody(this.databaseService.getLocales().languages);
2023-03-03 15:23:46 +00:00
}
/**
* Handle client/menu/locale
*/
public getLocalesMenu(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<string> {
const localeId = url.replace("/client/menu/locale/", "");
const locales = this.databaseService.getLocales();
let result = locales.menu[localeId];
if (result === undefined) {
result = locales.menu.en;
}
if (result === undefined) throw new Error(`Unable to determine locale for request with '${localeId}'`);
return this.httpResponse.getBody(result);
2023-03-03 15:23:46 +00:00
}
/**
* Handle client/locale
*/
public getLocalesGlobal(url: string, info: IEmptyRequestData, sessionID: string): string {
const localeId = url.replace("/client/locale/", "");
const locales = this.databaseService.getLocales();
let result = locales.global[localeId];
if (result === undefined) {
2024-07-23 17:30:20 +01:00
result = locales.global.en;
}
return this.httpResponse.getUnclearedBody(result);
2023-03-03 15:23:46 +00:00
}
/**
* Handle client/hideout/qte/list
*/
public getQteList(url: string, info: IEmptyRequestData, sessionID: string): string {
2023-03-03 15:23:46 +00:00
return this.httpResponse.getUnclearedBody(this.hideoutController.getQteList(sessionID));
}
/**
* Handle client/items/prices/
* Called when viewing a traders assorts
* TODO - fully implement this
*/
2023-11-10 15:19:56 -05:00
public getItemPrices(
url: string,
info: IEmptyRequestData,
sessionID: string,
): IGetBodyResponseData<IGetItemPricesResponse> {
2024-05-25 10:40:32 +01:00
const traderId = url.replace("/client/items/prices/", "");
// All traders share same item prices, unknown how to tell what items are shown for each trader
// Shown items listed are likely linked to traders items_buy/category array
2023-03-03 15:23:46 +00:00
const handbookPrices = this.ragfairController.getStaticPrices();
const response: IGetItemPricesResponse = {
supplyNextTime: this.traderHelper.getNextUpdateTimestamp(traderId),
2023-03-03 15:23:46 +00:00
prices: handbookPrices,
currencyCourses: {
"5449016a4bdc2d6f028b456f": handbookPrices[Money.ROUBLES],
"569668774bdc2da2298b4568": handbookPrices[Money.EUROS],
2023-11-10 15:19:56 -05:00
"5696686a4bdc2da3298b456a": handbookPrices[Money.DOLLARS],
},
2023-03-03 15:23:46 +00:00
};
2024-05-25 10:40:32 +01:00
2023-03-03 15:23:46 +00:00
return this.httpResponse.getBody(response);
}
2023-11-10 15:19:56 -05:00
}