Server/project/src/callbacks/DataCallbacks.ts

182 lines
7.6 KiB
TypeScript
Raw Normal View History

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