mirror of
https://github.com/sp-tarkov/server.git
synced 2025-02-13 09:50:43 -05:00
This is a big one. 🔥
**Changes:**
- Targets next major release (v4.0.0)
- Switch runtimes from NodeJS to BunJS (bun.sh)
- Typescript library support moved to `ESNext`
- Typescript compile option `verbatimModuleSyntax` enabled
- Updated all interfaces to be imported explicitly as types
- Strict mode enabled
- Reduces the number of tsconfig files
- Pins all dep packages to specific patch versions
- Includes Bun lock file in repo (doesn't cause issues like the
package-lock did)
- Replaces Gulp with a new Typescript based build system
- Adds `core-js` as a workaround for Bun not playing nice with
`reflect-metadata`
- Removes `pkg` and `swc` (Yay Bun!)
- Updated package scripts and entry point system to be more intuitive
- Updated VSCode workspace configurations
- Updated `.gitignore` to align with updated project structure
- Updated Biome configuration to align with updated project structure
- `Program.ts` - Removes call to set encoding on the process
- `global.d.ts` - Added underscores to build globals to match other
global names
- `JsonUtil.ts` - Replaced old `fixJson` package with newer `jsonrepair`
package
- `HashUtil.ts` - Replaced old `buffer-crc32` package with built-in
`node:zlib` package
- `DatabaseImporter.ts` - Updates database validation object to be flat,
where the keys are the relative path to the file
- `BunTimer.ts` - Adds an easy to use timer class that's compatible with
nanoseconds.
**TODO:**
- Look into mod loading. I think we use a TS transpiler for mods and I
believe that can be removed now.
- Bun includes a number of APIs that can be used in place of Node's
packages (built-in or otherwise); HTTP server, WebSocket server, File
IO, Hashing, File Globing, Testing... Each of these should be utilized
where ever possible.
- Update in-repo documentation to reference BunJS instead of NodeJS.
93 lines
3.6 KiB
TypeScript
93 lines
3.6 KiB
TypeScript
import { ApplicationContext } from "@spt/context/ApplicationContext";
|
|
import { ContextVariableType } from "@spt/context/ContextVariableType";
|
|
import { BotController } from "@spt/controllers/BotController";
|
|
import type { IGenerateBotsRequestData } from "@spt/models/eft/bot/IGenerateBotsRequestData";
|
|
import type { IEmptyRequestData } from "@spt/models/eft/common/IEmptyRequestData";
|
|
import type { IBotBase } from "@spt/models/eft/common/tables/IBotBase";
|
|
import type { IDifficulties } from "@spt/models/eft/common/tables/IBotType";
|
|
import type { IGetBodyResponseData } from "@spt/models/eft/httpResponse/IGetBodyResponseData";
|
|
import type { IGetRaidConfigurationRequestData } from "@spt/models/eft/match/IGetRaidConfigurationRequestData";
|
|
import { HttpResponseUtil } from "@spt/utils/HttpResponseUtil";
|
|
import { inject, injectable } from "tsyringe";
|
|
|
|
@injectable()
|
|
export class BotCallbacks {
|
|
constructor(
|
|
@inject("BotController") protected botController: BotController,
|
|
@inject("HttpResponseUtil") protected httpResponse: HttpResponseUtil,
|
|
@inject("ApplicationContext") protected applicationContext: ApplicationContext,
|
|
) {}
|
|
|
|
/**
|
|
* Handle singleplayer/settings/bot/limit
|
|
* Is called by client to define each bot roles wave limit
|
|
* @returns string
|
|
*/
|
|
public getBotLimit(url: string, info: IEmptyRequestData, sessionID: string): string {
|
|
const splittedUrl = url.split("/");
|
|
const type = splittedUrl[splittedUrl.length - 1];
|
|
return this.httpResponse.noBody(this.botController.getBotPresetGenerationLimit(type));
|
|
}
|
|
|
|
/**
|
|
* Handle singleplayer/settings/bot/difficulty
|
|
* @returns string
|
|
*/
|
|
public getBotDifficulty(url: string, info: IEmptyRequestData, sessionID: string): string {
|
|
const splittedUrl = url.split("/");
|
|
const type = splittedUrl[splittedUrl.length - 2].toLowerCase();
|
|
const difficulty = splittedUrl[splittedUrl.length - 1];
|
|
if (difficulty === "core") {
|
|
return this.httpResponse.noBody(this.botController.getBotCoreDifficulty());
|
|
}
|
|
|
|
const raidConfig = this.applicationContext
|
|
.getLatestValue(ContextVariableType.RAID_CONFIGURATION)
|
|
?.getValue<IGetRaidConfigurationRequestData>();
|
|
|
|
return this.httpResponse.noBody(this.botController.getBotDifficulty(type, difficulty, raidConfig));
|
|
}
|
|
|
|
/**
|
|
* Handle singleplayer/settings/bot/difficulties
|
|
* @returns dictionary of every bot and its diffiulty settings
|
|
*/
|
|
public getAllBotDifficulties(
|
|
url: string,
|
|
info: IEmptyRequestData,
|
|
sessionID: string,
|
|
): Record<string, IDifficulties> {
|
|
return this.httpResponse.noBody(this.botController.getAllBotDifficulties());
|
|
}
|
|
|
|
/**
|
|
* Handle client/game/bot/generate
|
|
* @returns IGetBodyResponseData
|
|
*/
|
|
public async generateBots(
|
|
url: string,
|
|
info: IGenerateBotsRequestData,
|
|
sessionID: string,
|
|
): Promise<IGetBodyResponseData<IBotBase[]>> {
|
|
return this.httpResponse.getBody(await this.botController.generate(sessionID, info));
|
|
}
|
|
|
|
/**
|
|
* Handle singleplayer/settings/bot/maxCap
|
|
* @returns string
|
|
*/
|
|
public getBotCap(url: string, info: IEmptyRequestData, sessionID: string): string {
|
|
const splitUrl = url.split("/");
|
|
const location = splitUrl[splitUrl.length - 1];
|
|
return this.httpResponse.noBody(this.botController.getBotCap(location));
|
|
}
|
|
|
|
/**
|
|
* Handle singleplayer/settings/bot/getBotBehaviours
|
|
* @returns string
|
|
*/
|
|
public getBotBehaviours(): string {
|
|
return this.httpResponse.noBody(this.botController.getAiBotBrainTypes());
|
|
}
|
|
}
|