2023-03-03 16:23:46 +01:00
|
|
|
import { inject, injectable } from "tsyringe";
|
|
|
|
|
2023-10-19 19:21:17 +02:00
|
|
|
import { HideoutController } from "@spt-aki/controllers/HideoutController";
|
|
|
|
import { RagfairController } from "@spt-aki/controllers/RagfairController";
|
|
|
|
import { IEmptyRequestData } from "@spt-aki/models/eft/common/IEmptyRequestData";
|
|
|
|
import { IGlobals } from "@spt-aki/models/eft/common/IGlobals";
|
|
|
|
import { ICustomizationItem } from "@spt-aki/models/eft/common/tables/ICustomizationItem";
|
|
|
|
import { IHandbookBase } from "@spt-aki/models/eft/common/tables/IHandbookBase";
|
|
|
|
import { IGetItemPricesResponse } from "@spt-aki/models/eft/game/IGetItemPricesResponse";
|
|
|
|
import { IHideoutArea } from "@spt-aki/models/eft/hideout/IHideoutArea";
|
|
|
|
import { IHideoutProduction } from "@spt-aki/models/eft/hideout/IHideoutProduction";
|
|
|
|
import { IHideoutScavCase } from "@spt-aki/models/eft/hideout/IHideoutScavCase";
|
|
|
|
import { IHideoutSettingsBase } from "@spt-aki/models/eft/hideout/IHideoutSettingsBase";
|
|
|
|
import { IGetBodyResponseData } from "@spt-aki/models/eft/httpResponse/IGetBodyResponseData";
|
|
|
|
import { Money } from "@spt-aki/models/enums/Money";
|
|
|
|
import { ISettingsBase } from "@spt-aki/models/spt/server/ISettingsBase";
|
|
|
|
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
|
|
|
import { HttpResponseUtil } from "@spt-aki/utils/HttpResponseUtil";
|
2023-03-03 16:23:46 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle client requests
|
|
|
|
*/
|
|
|
|
@injectable()
|
|
|
|
export class DataCallbacks
|
|
|
|
{
|
|
|
|
constructor(
|
|
|
|
@inject("HttpResponseUtil") protected httpResponse: HttpResponseUtil,
|
|
|
|
@inject("DatabaseServer") protected databaseServer: DatabaseServer,
|
|
|
|
@inject("RagfairController") protected ragfairController: RagfairController,
|
2023-11-10 21:19:56 +01:00
|
|
|
@inject("HideoutController") protected hideoutController: HideoutController,
|
2023-03-03 16:23:46 +01:00
|
|
|
)
|
2023-11-10 21:19:56 +01:00
|
|
|
{}
|
2023-03-03 16:23:46 +01:00
|
|
|
|
|
|
|
/**
|
2023-07-15 11:56:00 +02:00
|
|
|
* Handle client/settings
|
2023-03-03 16:23:46 +01:00
|
|
|
* @returns ISettingsBase
|
|
|
|
*/
|
|
|
|
public getSettings(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<ISettingsBase>
|
|
|
|
{
|
|
|
|
return this.httpResponse.getBody(this.databaseServer.getTables().settings);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-07-15 11:56:00 +02:00
|
|
|
* Handle client/globals
|
2023-03-03 16:23:46 +01:00
|
|
|
* @returns IGlobals
|
|
|
|
*/
|
|
|
|
public getGlobals(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<IGlobals>
|
|
|
|
{
|
|
|
|
this.databaseServer.getTables().globals.time = Date.now() / 1000;
|
|
|
|
return this.httpResponse.getBody(this.databaseServer.getTables().globals);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-07-15 11:56:00 +02:00
|
|
|
* Handle client/items
|
2023-03-03 16:23:46 +01:00
|
|
|
* @returns string
|
|
|
|
*/
|
|
|
|
public getTemplateItems(url: string, info: IEmptyRequestData, sessionID: string): string
|
|
|
|
{
|
|
|
|
return this.httpResponse.getUnclearedBody(this.databaseServer.getTables().templates.items);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-07-15 11:56:00 +02:00
|
|
|
* Handle client/handbook/templates
|
2023-03-03 16:23:46 +01:00
|
|
|
* @returns IHandbookBase
|
|
|
|
*/
|
2023-11-10 21:19:56 +01:00
|
|
|
public getTemplateHandbook(
|
|
|
|
url: string,
|
|
|
|
info: IEmptyRequestData,
|
|
|
|
sessionID: string,
|
|
|
|
): IGetBodyResponseData<IHandbookBase>
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
return this.httpResponse.getBody(this.databaseServer.getTables().templates.handbook);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-07-15 11:56:00 +02:00
|
|
|
* Handle client/customization
|
2023-03-03 16:23:46 +01:00
|
|
|
* @returns Record<string, ICustomizationItem
|
|
|
|
*/
|
2023-11-10 21:19:56 +01:00
|
|
|
public getTemplateSuits(
|
|
|
|
url: string,
|
|
|
|
info: IEmptyRequestData,
|
|
|
|
sessionID: string,
|
|
|
|
): IGetBodyResponseData<Record<string, ICustomizationItem>>
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
return this.httpResponse.getBody(this.databaseServer.getTables().templates.customization);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-07-15 11:56:00 +02:00
|
|
|
* Handle client/account/customization
|
2023-03-03 16:23:46 +01:00
|
|
|
* @returns string[]
|
|
|
|
*/
|
|
|
|
public getTemplateCharacter(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<string[]>
|
|
|
|
{
|
|
|
|
return this.httpResponse.getBody(this.databaseServer.getTables().templates.character);
|
|
|
|
}
|
|
|
|
|
2023-07-15 11:56:00 +02:00
|
|
|
/**
|
|
|
|
* Handle client/hideout/settings
|
|
|
|
* @returns IHideoutSettingsBase
|
|
|
|
*/
|
2023-11-10 21:19:56 +01:00
|
|
|
public getHideoutSettings(
|
|
|
|
url: string,
|
|
|
|
info: IEmptyRequestData,
|
|
|
|
sessionID: string,
|
|
|
|
): IGetBodyResponseData<IHideoutSettingsBase>
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
return this.httpResponse.getBody(this.databaseServer.getTables().hideout.settings);
|
|
|
|
}
|
|
|
|
|
2023-11-10 21:19:56 +01:00
|
|
|
public getHideoutAreas(
|
|
|
|
url: string,
|
|
|
|
info: IEmptyRequestData,
|
|
|
|
sessionID: string,
|
|
|
|
): IGetBodyResponseData<IHideoutArea[]>
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
return this.httpResponse.getBody(this.databaseServer.getTables().hideout.areas);
|
|
|
|
}
|
|
|
|
|
2023-11-10 21:19:56 +01:00
|
|
|
public gethideoutProduction(
|
|
|
|
url: string,
|
|
|
|
info: IEmptyRequestData,
|
|
|
|
sessionID: string,
|
|
|
|
): IGetBodyResponseData<IHideoutProduction[]>
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
return this.httpResponse.getBody(this.databaseServer.getTables().hideout.production);
|
|
|
|
}
|
|
|
|
|
2023-11-10 21:19:56 +01:00
|
|
|
public getHideoutScavcase(
|
|
|
|
url: string,
|
|
|
|
info: IEmptyRequestData,
|
|
|
|
sessionID: string,
|
|
|
|
): IGetBodyResponseData<IHideoutScavCase[]>
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
return this.httpResponse.getBody(this.databaseServer.getTables().hideout.scavcase);
|
|
|
|
}
|
|
|
|
|
2023-07-15 11:56:00 +02:00
|
|
|
/**
|
|
|
|
* Handle client/languages
|
|
|
|
*/
|
2023-11-10 21:19:56 +01:00
|
|
|
public getLocalesLanguages(
|
|
|
|
url: string,
|
|
|
|
info: IEmptyRequestData,
|
|
|
|
sessionID: string,
|
|
|
|
): IGetBodyResponseData<Record<string, string>>
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
return this.httpResponse.getBody(this.databaseServer.getTables().locales.languages);
|
|
|
|
}
|
|
|
|
|
2023-07-15 11:56:00 +02:00
|
|
|
/**
|
|
|
|
* Handle client/menu/locale
|
|
|
|
*/
|
2023-03-03 16:23:46 +01:00
|
|
|
public getLocalesMenu(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<string>
|
|
|
|
{
|
2024-01-15 13:45:24 +01:00
|
|
|
const localeId = url.replace("/client/menu/locale/", "");
|
|
|
|
const tables = this.databaseServer.getTables();
|
|
|
|
let result = tables.locales.menu[localeId];
|
|
|
|
|
|
|
|
if (result === undefined)
|
|
|
|
{
|
2024-02-02 21:00:12 +01:00
|
|
|
result = tables.locales.menu.en;
|
2024-01-15 13:45:24 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return this.httpResponse.getBody(result);
|
2023-03-03 16:23:46 +01:00
|
|
|
}
|
|
|
|
|
2023-07-15 11:56:00 +02:00
|
|
|
/**
|
|
|
|
* Handle client/locale
|
|
|
|
*/
|
2023-03-03 16:23:46 +01:00
|
|
|
public getLocalesGlobal(url: string, info: IEmptyRequestData, sessionID: string): string
|
|
|
|
{
|
2024-01-15 13:45:24 +01:00
|
|
|
const localeId = url.replace("/client/locale/", "");
|
|
|
|
const tables = this.databaseServer.getTables();
|
|
|
|
let result = tables.locales.global[localeId];
|
|
|
|
|
|
|
|
if (result === undefined)
|
|
|
|
{
|
|
|
|
result = tables.locales.global[localeId];
|
|
|
|
}
|
|
|
|
|
|
|
|
return this.httpResponse.getUnclearedBody(result);
|
2023-03-03 16:23:46 +01: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 21:19:56 +01:00
|
|
|
public getItemPrices(
|
|
|
|
url: string,
|
|
|
|
info: IEmptyRequestData,
|
|
|
|
sessionID: string,
|
|
|
|
): IGetBodyResponseData<IGetItemPricesResponse>
|
2023-03-03 16:23:46 +01:00
|
|
|
{
|
|
|
|
const handbookPrices = this.ragfairController.getStaticPrices();
|
|
|
|
const response: IGetItemPricesResponse = {
|
|
|
|
supplyNextTime: 1672236024, // todo: get trader refresh time?
|
|
|
|
prices: handbookPrices,
|
|
|
|
currencyCourses: {
|
2023-11-10 21:19:56 +01:00
|
|
|
/* eslint-disable @typescript-eslint/naming-convention */
|
2023-03-03 16:23:46 +01:00
|
|
|
"5449016a4bdc2d6f028b456f": handbookPrices[Money.ROUBLES],
|
|
|
|
"569668774bdc2da2298b4568": handbookPrices[Money.EUROS],
|
2023-11-10 21:19:56 +01:00
|
|
|
"5696686a4bdc2da3298b456a": handbookPrices[Money.DOLLARS],
|
|
|
|
/* eslint-enable @typescript-eslint/naming-convention */
|
|
|
|
},
|
2023-03-03 16:23:46 +01:00
|
|
|
};
|
|
|
|
return this.httpResponse.getBody(response);
|
|
|
|
}
|
2023-11-10 21:19:56 +01:00
|
|
|
}
|