0
0
mirror of https://github.com/sp-tarkov/server.git synced 2025-02-13 09:50:43 -05:00
server/project/src/callbacks/MatchCallbacks.ts
Refringe 0368a230fb
BunJS Runtime, Updated Build System, and... (#992)
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.
2024-12-21 22:46:39 +00:00

227 lines
9.2 KiB
TypeScript

import { MatchController } from "@spt/controllers/MatchController";
import type { IEmptyRequestData } from "@spt/models/eft/common/IEmptyRequestData";
import type { IMetrics } from "@spt/models/eft/common/tables/IMatch";
import type { IGetBodyResponseData } from "@spt/models/eft/httpResponse/IGetBodyResponseData";
import type { INullResponseData } from "@spt/models/eft/httpResponse/INullResponseData";
import type { IEndLocalRaidRequestData } from "@spt/models/eft/match/IEndLocalRaidRequestData";
import type { IGetRaidConfigurationRequestData } from "@spt/models/eft/match/IGetRaidConfigurationRequestData";
import type { IGroupCharacter } from "@spt/models/eft/match/IGroupCharacter";
import type { IMatchGroupCurrentResponse } from "@spt/models/eft/match/IMatchGroupCurrentResponse";
import type { IMatchGroupInviteSendRequest } from "@spt/models/eft/match/IMatchGroupInviteSendRequest";
import type { IMatchGroupPlayerRemoveRequest } from "@spt/models/eft/match/IMatchGroupPlayerRemoveRequest";
import type { IMatchGroupStartGameRequest } from "@spt/models/eft/match/IMatchGroupStartGameRequest";
import type { IMatchGroupStatusRequest } from "@spt/models/eft/match/IMatchGroupStatusRequest";
import type { IMatchGroupStatusResponse } from "@spt/models/eft/match/IMatchGroupStatusResponse";
import type { IMatchGroupTransferRequest } from "@spt/models/eft/match/IMatchGroupTransferRequest";
import type { IProfileStatusResponse } from "@spt/models/eft/match/IProfileStatusResponse";
import type { IPutMetricsRequestData } from "@spt/models/eft/match/IPutMetricsRequestData";
import type { IRequestIdRequest } from "@spt/models/eft/match/IRequestIdRequest";
import type { IStartLocalRaidRequestData } from "@spt/models/eft/match/IStartLocalRaidRequestData";
import type { IStartLocalRaidResponseData } from "@spt/models/eft/match/IStartLocalRaidResponseData";
import type { IUpdatePingRequestData } from "@spt/models/eft/match/IUpdatePingRequestData";
import { DatabaseService } from "@spt/services/DatabaseService";
import { HttpResponseUtil } from "@spt/utils/HttpResponseUtil";
import { JsonUtil } from "@spt/utils/JsonUtil";
import { inject, injectable } from "tsyringe";
@injectable()
export class MatchCallbacks {
constructor(
@inject("HttpResponseUtil") protected httpResponse: HttpResponseUtil,
@inject("JsonUtil") protected jsonUtil: JsonUtil,
@inject("MatchController") protected matchController: MatchController,
@inject("DatabaseService") protected databaseService: DatabaseService,
) {}
/** Handle client/match/updatePing */
public updatePing(url: string, info: IUpdatePingRequestData, sessionID: string): INullResponseData {
return this.httpResponse.nullResponse();
}
// Handle client/match/exit
public exitMatch(url: string, info: IEmptyRequestData, sessionID: string): INullResponseData {
return this.httpResponse.nullResponse();
}
/** Handle client/match/group/exit_from_menu */
public exitFromMenu(url: string, info: IEmptyRequestData, sessionID: string): INullResponseData {
return this.httpResponse.nullResponse();
}
/** Handle client/match/group/current */
public groupCurrent(
url: string,
info: IEmptyRequestData,
sessionID: string,
): IGetBodyResponseData<IMatchGroupCurrentResponse> {
return this.httpResponse.getBody({ squad: [] });
}
/** Handle client/match/group/looking/start */
public startGroupSearch(url: string, info: IEmptyRequestData, sessionID: string): INullResponseData {
return this.httpResponse.nullResponse();
}
/** Handle client/match/group/looking/stop */
public stopGroupSearch(url: string, info: IEmptyRequestData, sessionID: string): INullResponseData {
return this.httpResponse.nullResponse();
}
/** Handle client/match/group/invite/send */
public sendGroupInvite(
url: string,
info: IMatchGroupInviteSendRequest,
sessionID: string,
): IGetBodyResponseData<string> {
return this.httpResponse.getBody("2427943f23698ay9f2863735");
}
/** Handle client/match/group/invite/accept */
public acceptGroupInvite(
url: string,
info: IRequestIdRequest,
sessionId: string,
): IGetBodyResponseData<IGroupCharacter[]> {
const result = [];
result.push({});
return this.httpResponse.getBody(result);
}
/** Handle client/match/group/invite/decline */
public declineGroupInvite(url: string, info: IRequestIdRequest, sessionId: string): IGetBodyResponseData<boolean> {
return this.httpResponse.getBody(true);
}
/** Handle client/match/group/invite/cancel */
public cancelGroupInvite(url: string, info: IRequestIdRequest, sessionID: string): IGetBodyResponseData<boolean> {
return this.httpResponse.getBody(true);
}
/** Handle client/match/group/transfer */
public transferGroup(
url: string,
info: IMatchGroupTransferRequest,
sessionId: string,
): IGetBodyResponseData<boolean> {
return this.httpResponse.getBody(true);
}
/** Handle client/match/group/invite/cancel-all */
public cancelAllGroupInvite(
url: string,
info: IEmptyRequestData,
sessionId: string,
): IGetBodyResponseData<boolean> {
return this.httpResponse.getBody(true);
}
/** Handle client/putMetrics */
public putMetrics(url: string, request: IPutMetricsRequestData, sessionId: string): INullResponseData {
return this.httpResponse.nullResponse();
}
/** Handle client/analytics/event-disconnect */
public eventDisconnect(url: string, request: IPutMetricsRequestData, sessionId: string): INullResponseData {
return this.httpResponse.nullResponse();
}
// Handle client/match/available
public serverAvailable(url: string, info: IEmptyRequestData, sessionId: string): IGetBodyResponseData<boolean> {
const output = this.matchController.getEnabled();
return this.httpResponse.getBody(output);
}
/** Handle match/group/start_game */
public joinMatch(
url: string,
info: IMatchGroupStartGameRequest,
sessionID: string,
): IGetBodyResponseData<IProfileStatusResponse> {
return this.httpResponse.getBody(this.matchController.joinMatch(info, sessionID));
}
/** Handle client/getMetricsConfig */
public getMetrics(url: string, info: any, sessionID: string): IGetBodyResponseData<IMetrics> {
return this.httpResponse.getBody(this.databaseService.getMatch().metrics);
}
/**
* Called periodically while in a group
* Handle client/match/group/status
* @returns
*/
public getGroupStatus(
url: string,
info: IMatchGroupStatusRequest,
sessionID: string,
): IGetBodyResponseData<IMatchGroupStatusResponse> {
return this.httpResponse.getBody(this.matchController.getGroupStatus(info));
}
/** Handle client/match/group/delete */
public deleteGroup(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<boolean> {
this.matchController.deleteGroup(info);
return this.httpResponse.getBody(true);
}
// Handle client/match/group/leave
public leaveGroup(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<boolean> {
return this.httpResponse.getBody(true);
}
/** Handle client/match/group/player/remove */
public removePlayerFromGroup(
url: string,
info: IMatchGroupPlayerRemoveRequest,
sessionID: string,
): IGetBodyResponseData<boolean> {
return this.httpResponse.getBody(true);
}
/** Handle client/match/local/start */
public startLocalRaid(
url: string,
info: IStartLocalRaidRequestData,
sessionID: string,
): IGetBodyResponseData<IStartLocalRaidResponseData> {
return this.httpResponse.getBody(this.matchController.startLocalRaid(sessionID, info));
}
/** Handle client/match/local/end */
public endLocalRaid(url: string, info: IEndLocalRaidRequestData, sessionID: string): INullResponseData {
this.matchController.endLocalRaid(sessionID, info);
return this.httpResponse.nullResponse();
}
/** Handle client/raid/configuration */
public getRaidConfiguration(
url: string,
info: IGetRaidConfigurationRequestData,
sessionID: string,
): INullResponseData {
this.matchController.configureOfflineRaid(info, sessionID);
return this.httpResponse.nullResponse();
}
/** Handle client/raid/configuration-by-profile */
public getConfigurationByProfile(
url: string,
info: IGetRaidConfigurationRequestData,
sessionID: string,
): INullResponseData {
return this.httpResponse.nullResponse();
}
/** Handle client/match/group/raid/ready */
public raidReady(url: string, info: IEmptyRequestData, sessionId: string): IGetBodyResponseData<boolean> {
return this.httpResponse.getBody(true);
}
/** Handle client/match/group/raid/not-ready */
public notRaidReady(url: string, info: IEmptyRequestData, sessionId: string): IGetBodyResponseData<boolean> {
return this.httpResponse.getBody(true);
}
}