2023-03-03 15:23:46 +00:00
|
|
|
import { inject, injectable } from "tsyringe";
|
2024-05-21 17:59:04 +00:00
|
|
|
import { HideoutController } from "@spt/controllers/HideoutController";
|
|
|
|
import { RagfairController } from "@spt/controllers/RagfairController";
|
|
|
|
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";
|
2023-03-03 15:23:46 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle client requests
|
|
|
|
*/
|
|
|
|
@injectable()
|
|
|
|
export class DataCallbacks
|
|
|
|
{
|
|
|
|
constructor(
|
|
|
|
@inject("HttpResponseUtil") protected httpResponse: HttpResponseUtil,
|
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,
|
2023-03-03 15:23:46 +00:00
|
|
|
)
|
2023-11-10 15:19:56 -05: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
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
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,
|
|
|
|
): IGetBodyResponseData<IHandbookBase>
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
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,
|
|
|
|
): IGetBodyResponseData<Record<string, ICustomizationItem>>
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
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,
|
|
|
|
): IGetBodyResponseData<string[]>
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
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,
|
|
|
|
): IGetBodyResponseData<IHideoutSettingsBase>
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
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,
|
|
|
|
): IGetBodyResponseData<IHideoutArea[]>
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
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,
|
|
|
|
): IGetBodyResponseData<IHideoutProduction[]>
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
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,
|
|
|
|
): IGetBodyResponseData<IHideoutScavCase[]>
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
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,
|
|
|
|
): IGetBodyResponseData<Record<string, string>>
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
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
|
|
|
|
*/
|
2023-03-03 15:23:46 +00: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
|
|
|
|
|
|
|
if (result === undefined)
|
|
|
|
{
|
2024-05-28 13:59:19 +01:00
|
|
|
result = locales.menu.en;
|
2024-01-15 12:45:24 +00:00
|
|
|
}
|
|
|
|
|
2024-05-27 16:05:16 +00:00
|
|
|
if (result === undefined)
|
|
|
|
throw new Error(`Unable to determine locale for request with '${localeId}'`);
|
|
|
|
|
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
|
|
|
|
*/
|
2023-03-03 15:23:46 +00: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
|
|
|
|
|
|
|
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
|
|
|
|
*/
|
|
|
|
public getQteList(url: string, info: IEmptyRequestData, sessionID: string): string
|
|
|
|
{
|
|
|
|
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>
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
2024-05-25 10:40:32 +01:00
|
|
|
const traderId = url.replace("/client/items/prices/", "");
|
2023-03-03 15:23:46 +00:00
|
|
|
const handbookPrices = this.ragfairController.getStaticPrices();
|
|
|
|
const response: IGetItemPricesResponse = {
|
|
|
|
supplyNextTime: 1672236024, // todo: get trader refresh time?
|
|
|
|
prices: handbookPrices,
|
|
|
|
currencyCourses: {
|
2023-11-10 15:19:56 -05:00
|
|
|
/* eslint-disable @typescript-eslint/naming-convention */
|
2023-03-03 15:23:46 +00:00
|
|
|
"5449016a4bdc2d6f028b456f": handbookPrices[Money.ROUBLES],
|
|
|
|
"569668774bdc2da2298b4568": handbookPrices[Money.EUROS],
|
2023-11-10 15:19:56 -05:00
|
|
|
"5696686a4bdc2da3298b456a": handbookPrices[Money.DOLLARS],
|
|
|
|
/* eslint-enable @typescript-eslint/naming-convention */
|
|
|
|
},
|
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
|
|
|
}
|