2024-05-21 17:59:04 +00:00
|
|
|
import { HideoutController } from "@spt/controllers/HideoutController";
|
|
|
|
import { RagfairController } from "@spt/controllers/RagfairController";
|
2024-06-04 15:17:46 +01:00
|
|
|
import { TraderHelper } from "@spt/helpers/TraderHelper";
|
2024-05-21 17:59:04 +00:00
|
|
|
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 { IHideoutProduction } 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";
|
2024-05-28 13:59:19 +01:00
|
|
|
import { DatabaseService } from "@spt/services/DatabaseService";
|
2024-05-21 17:59:04 +00:00
|
|
|
import { HttpResponseUtil } from "@spt/utils/HttpResponseUtil";
|
2024-05-31 16:16:10 +01:00
|
|
|
import { TimeUtil } from "@spt/utils/TimeUtil";
|
2024-07-23 11:12:53 -04:00
|
|
|
import { inject, injectable } from "tsyringe";
|
2023-03-03 15:23:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle client requests
|
|
|
|
*/
|
|
|
|
@injectable()
|
2024-07-23 11:12:53 -04:00
|
|
|
export class DataCallbacks {
|
2023-03-03 15:23:46 +00:00
|
|
|
constructor(
|
|
|
|
@inject("HttpResponseUtil") protected httpResponse: HttpResponseUtil,
|
2024-05-31 16:16:10 +01:00
|
|
|
@inject("TimeUtil") protected timeUtil: TimeUtil,
|
2024-06-04 15:17:46 +01:00
|
|
|
@inject("TraderHelper") protected traderHelper: TraderHelper,
|
2024-05-28 22:24:52 +01:00
|
|
|
@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,
|
2024-07-23 11:12:53 -04:00
|
|
|
) {}
|
2023-03-03 15:23:46 +00:00
|
|
|
|
|
|
|
/**
|
2023-07-15 10:56:00 +01:00
|
|
|
* Handle client/settings
|
2023-03-03 15:23:46 +00:00
|
|
|
* @returns ISettingsBase
|
|
|
|
*/
|
2024-07-23 11:12:53 -04:00
|
|
|
public getSettings(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<ISettingsBase> {
|
2024-05-28 22:24:52 +01:00
|
|
|
return this.httpResponse.getBody(this.databaseService.getSettings());
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-07-15 10:56:00 +01:00
|
|
|
* Handle client/globals
|
2023-03-03 15:23:46 +00:00
|
|
|
* @returns IGlobals
|
|
|
|
*/
|
2024-07-23 11:12:53 -04:00
|
|
|
public getGlobals(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<IGlobals> {
|
2024-05-28 22:24:52 +01:00
|
|
|
const globals = this.databaseService.getGlobals();
|
2024-05-28 13:59:19 +01:00
|
|
|
globals.time = Date.now() / 1000;
|
|
|
|
|
2024-05-28 22:24:52 +01:00
|
|
|
return this.httpResponse.getBody(this.databaseService.getGlobals());
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-07-15 10:56:00 +01:00
|
|
|
* Handle client/items
|
2023-03-03 15:23:46 +00:00
|
|
|
* @returns string
|
|
|
|
*/
|
2024-07-23 11:12:53 -04:00
|
|
|
public getTemplateItems(url: string, info: IEmptyRequestData, sessionID: string): string {
|
2024-05-28 22:24:52 +01:00
|
|
|
return this.httpResponse.getUnclearedBody(this.databaseService.getItems());
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-07-15 10:56:00 +01: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,
|
2024-07-23 11:12:53 -04:00
|
|
|
): IGetBodyResponseData<IHandbookBase> {
|
2024-05-28 22:24:52 +01:00
|
|
|
return this.httpResponse.getBody(this.databaseService.getHandbook());
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-07-15 10:56:00 +01: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,
|
2024-07-23 11:12:53 -04:00
|
|
|
): IGetBodyResponseData<Record<string, ICustomizationItem>> {
|
2024-05-28 22:24:52 +01:00
|
|
|
return this.httpResponse.getBody(this.databaseService.getTemplates().customization);
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-07-15 10:56:00 +01:00
|
|
|
* Handle client/account/customization
|
2023-03-03 15:23:46 +00:00
|
|
|
* @returns string[]
|
|
|
|
*/
|
2024-05-17 15:32:41 -04:00
|
|
|
public getTemplateCharacter(
|
|
|
|
url: string,
|
|
|
|
info: IEmptyRequestData,
|
|
|
|
sessionID: string,
|
2024-07-23 11:12:53 -04:00
|
|
|
): IGetBodyResponseData<string[]> {
|
2024-05-28 22:24:52 +01:00
|
|
|
return this.httpResponse.getBody(this.databaseService.getTemplates().character);
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-15 10:56:00 +01:00
|
|
|
/**
|
|
|
|
* Handle client/hideout/settings
|
|
|
|
* @returns IHideoutSettingsBase
|
|
|
|
*/
|
2023-11-10 15:19:56 -05:00
|
|
|
public getHideoutSettings(
|
|
|
|
url: string,
|
|
|
|
info: IEmptyRequestData,
|
|
|
|
sessionID: string,
|
2024-07-23 11:12:53 -04:00
|
|
|
): IGetBodyResponseData<IHideoutSettingsBase> {
|
2024-05-28 22:24:52 +01:00
|
|
|
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,
|
2024-07-23 11:12:53 -04:00
|
|
|
): IGetBodyResponseData<IHideoutArea[]> {
|
2024-05-28 22:24:52 +01:00
|
|
|
return this.httpResponse.getBody(this.databaseService.getHideout().areas);
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
2023-11-10 15:19:56 -05:00
|
|
|
public gethideoutProduction(
|
|
|
|
url: string,
|
|
|
|
info: IEmptyRequestData,
|
|
|
|
sessionID: string,
|
2024-07-23 11:12:53 -04:00
|
|
|
): IGetBodyResponseData<IHideoutProduction[]> {
|
2024-05-28 22:24:52 +01:00
|
|
|
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,
|
2024-07-23 11:12:53 -04:00
|
|
|
): IGetBodyResponseData<IHideoutScavCase[]> {
|
2024-05-28 22:24:52 +01:00
|
|
|
return this.httpResponse.getBody(this.databaseService.getHideout().scavcase);
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-15 10:56:00 +01:00
|
|
|
/**
|
|
|
|
* Handle client/languages
|
|
|
|
*/
|
2023-11-10 15:19:56 -05:00
|
|
|
public getLocalesLanguages(
|
|
|
|
url: string,
|
|
|
|
info: IEmptyRequestData,
|
|
|
|
sessionID: string,
|
2024-07-23 11:12:53 -04:00
|
|
|
): IGetBodyResponseData<Record<string, string>> {
|
2024-05-28 22:24:52 +01:00
|
|
|
return this.httpResponse.getBody(this.databaseService.getLocales().languages);
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-15 10:56:00 +01:00
|
|
|
/**
|
|
|
|
* Handle client/menu/locale
|
|
|
|
*/
|
2024-07-23 11:12:53 -04:00
|
|
|
public getLocalesMenu(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<string> {
|
2024-01-15 12:45:24 +00:00
|
|
|
const localeId = url.replace("/client/menu/locale/", "");
|
2024-05-28 22:24:52 +01:00
|
|
|
const locales = this.databaseService.getLocales();
|
2024-05-28 13:59:19 +01:00
|
|
|
let result = locales.menu[localeId];
|
2024-01-15 12:45:24 +00:00
|
|
|
|
2024-07-23 11:12:53 -04:00
|
|
|
if (result === undefined) {
|
2024-05-28 13:59:19 +01:00
|
|
|
result = locales.menu.en;
|
2024-01-15 12:45:24 +00:00
|
|
|
}
|
|
|
|
|
2024-07-23 11:12:53 -04:00
|
|
|
if (result === undefined) throw new Error(`Unable to determine locale for request with '${localeId}'`);
|
2024-05-27 16:05:16 +00:00
|
|
|
|
2024-01-15 12:45:24 +00:00
|
|
|
return this.httpResponse.getBody(result);
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-15 10:56:00 +01:00
|
|
|
/**
|
|
|
|
* Handle client/locale
|
|
|
|
*/
|
2024-07-23 11:12:53 -04:00
|
|
|
public getLocalesGlobal(url: string, info: IEmptyRequestData, sessionID: string): string {
|
2024-01-15 12:45:24 +00:00
|
|
|
const localeId = url.replace("/client/locale/", "");
|
2024-05-28 22:24:52 +01:00
|
|
|
const locales = this.databaseService.getLocales();
|
2024-05-28 13:59:19 +01:00
|
|
|
let result = locales.global[localeId];
|
2024-01-15 12:45:24 +00:00
|
|
|
|
2024-07-23 11:12:53 -04:00
|
|
|
if (result === undefined) {
|
2024-05-28 13:59:19 +01:00
|
|
|
result = locales.global["en"];
|
2024-01-15 12:45:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.httpResponse.getUnclearedBody(result);
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle client/hideout/qte/list
|
|
|
|
*/
|
2024-07-23 11:12:53 -04:00
|
|
|
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,
|
2024-07-23 11:12:53 -04:00
|
|
|
): IGetBodyResponseData<IGetItemPricesResponse> {
|
2024-05-25 10:40:32 +01:00
|
|
|
const traderId = url.replace("/client/items/prices/", "");
|
2024-05-31 16:16:10 +01:00
|
|
|
|
2024-06-04 15:17:46 +01:00
|
|
|
// All traders share same item prices, unknown how to tell what items are shown for each trader
|
2024-05-31 16:16:10 +01:00
|
|
|
// 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();
|
2024-05-31 16:16:10 +01:00
|
|
|
|
2024-07-23 11:12:53 -04:00
|
|
|
const response: IGetItemPricesResponse = {
|
2024-06-04 15:17:46 +01:00
|
|
|
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
|
|
|
}
|