Server/project/src/callbacks/GameCallbacks.ts

163 lines
5.6 KiB
TypeScript
Raw Normal View History

2023-03-03 15:23:46 +00:00
import { inject, injectable } from "tsyringe";
import { GameController } from "@spt-aki/controllers/GameController";
import { OnLoad } from "@spt-aki/di/OnLoad";
import { IEmptyRequestData } from "@spt-aki/models/eft/common/IEmptyRequestData";
import { ICheckVersionResponse } from "@spt-aki/models/eft/game/ICheckVersionResponse";
import { ICurrentGroupResponse } from "@spt-aki/models/eft/game/ICurrentGroupResponse";
import { IGameConfigResponse } from "@spt-aki/models/eft/game/IGameConfigResponse";
import { IGameEmptyCrcRequestData } from "@spt-aki/models/eft/game/IGameEmptyCrcRequestData";
import { IGameKeepAliveResponse } from "@spt-aki/models/eft/game/IGameKeepAliveResponse";
import { IGameLogoutResponseData } from "@spt-aki/models/eft/game/IGameLogoutResponseData";
import { IGameStartResponse } from "@spt-aki/models/eft/game/IGameStartResponse";
import { IGetRaidTimeRequest } from "@spt-aki/models/eft/game/IGetRaidTimeRequest";
2023-12-20 00:27:27 +00:00
import { IGetRaidTimeResponse } from "@spt-aki/models/eft/game/IGetRaidTimeResponse";
import { IReportNicknameRequestData } from "@spt-aki/models/eft/game/IReportNicknameRequestData";
import { IServerDetails } from "@spt-aki/models/eft/game/IServerDetails";
import { IVersionValidateRequestData } from "@spt-aki/models/eft/game/IVersionValidateRequestData";
import { IGetBodyResponseData } from "@spt-aki/models/eft/httpResponse/IGetBodyResponseData";
import { INullResponseData } from "@spt-aki/models/eft/httpResponse/INullResponseData";
import { SaveServer } from "@spt-aki/servers/SaveServer";
import { HttpResponseUtil } from "@spt-aki/utils/HttpResponseUtil";
import { Watermark } from "@spt-aki/utils/Watermark";
2023-03-03 15:23:46 +00:00
@injectable()
2023-11-10 15:19:56 -05:00
export class GameCallbacks implements OnLoad
2023-03-03 15:23:46 +00:00
{
constructor(
@inject("HttpResponseUtil") protected httpResponse: HttpResponseUtil,
@inject("Watermark") protected watermark: Watermark,
@inject("SaveServer") protected saveServer: SaveServer,
2023-11-10 15:19:56 -05:00
@inject("GameController") protected gameController: GameController,
2023-03-03 15:23:46 +00:00
)
{}
public async onLoad(): Promise<void>
{
this.gameController.load();
}
public getRoute(): string
{
return "aki-game";
}
2023-03-03 15:23:46 +00:00
/**
* Handle client/game/version/validate
* @returns INullResponseData
*/
public versionValidate(url: string, info: IVersionValidateRequestData, sessionID: string): INullResponseData
{
return this.httpResponse.nullResponse();
}
/**
* Handle client/game/start
* @returns IGameStartResponse
*/
public gameStart(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<IGameStartResponse>
{
const today = new Date().toUTCString();
const startTimeStampMS = Date.parse(today);
this.gameController.gameStart(url, info, sessionID, startTimeStampMS);
return this.httpResponse.getBody({ utc_time: startTimeStampMS / 1000 });
2023-03-03 15:23:46 +00:00
}
/**
* Handle client/game/logout
* Save profiles on game close
2023-03-03 15:23:46 +00:00
* @returns IGameLogoutResponseData
*/
2023-11-10 15:19:56 -05:00
public gameLogout(
url: string,
info: IEmptyRequestData,
sessionID: string,
): IGetBodyResponseData<IGameLogoutResponseData>
2023-03-03 15:23:46 +00:00
{
this.saveServer.save();
return this.httpResponse.getBody({ status: "ok" });
2023-03-03 15:23:46 +00:00
}
/**
* Handle client/game/config
* @returns IGameConfigResponse
*/
2023-11-10 15:19:56 -05:00
public getGameConfig(
url: string,
info: IGameEmptyCrcRequestData,
sessionID: string,
): IGetBodyResponseData<IGameConfigResponse>
2023-03-03 15:23:46 +00:00
{
return this.httpResponse.getBody(this.gameController.getGameConfig(sessionID));
}
/**
* Handle client/server/list
*/
2023-03-03 15:23:46 +00:00
public getServer(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<IServerDetails[]>
{
return this.httpResponse.getBody(this.gameController.getServer(sessionID));
2023-03-03 15:23:46 +00:00
}
/**
* Handle client/match/group/current
*/
2023-11-10 15:19:56 -05:00
public getCurrentGroup(
url: string,
info: IEmptyRequestData,
sessionID: string,
): IGetBodyResponseData<ICurrentGroupResponse>
2023-03-03 15:23:46 +00:00
{
return this.httpResponse.getBody(this.gameController.getCurrentGroup(sessionID));
}
/**
* Handle client/checkVersion
*/
2023-11-10 15:19:56 -05:00
public validateGameVersion(
url: string,
info: IEmptyRequestData,
sessionID: string,
): IGetBodyResponseData<ICheckVersionResponse>
2023-03-03 15:23:46 +00:00
{
return this.httpResponse.getBody(this.gameController.getValidGameVersion(sessionID));
2023-03-03 15:23:46 +00:00
}
/**
* Handle client/game/keepalive
* @returns IGameKeepAliveResponse
*/
2023-11-10 15:19:56 -05:00
public gameKeepalive(
url: string,
info: IEmptyRequestData,
sessionID: string,
): IGetBodyResponseData<IGameKeepAliveResponse>
2023-03-03 15:23:46 +00:00
{
return this.httpResponse.getBody(this.gameController.getKeepAlive(sessionID));
2023-03-03 15:23:46 +00:00
}
/**
* Handle singleplayer/settings/version
* @returns string
*/
public getVersion(url: string, info: IEmptyRequestData, sessionID: string): string
{
return this.httpResponse.noBody({ Version: this.watermark.getInGameVersionLabel() });
2023-03-03 15:23:46 +00:00
}
public reportNickname(url: string, info: IReportNicknameRequestData, sessionID: string): INullResponseData
{
return this.httpResponse.nullResponse();
}
/**
* Handle singleplayer/settings/getRaidTime
* @returns string
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
2023-12-20 00:27:27 +00:00
public getRaidTime(url: string, request: IGetRaidTimeRequest, sessionID: string): IGetRaidTimeResponse
{
return this.httpResponse.noBody(this.gameController.getRaidTime(sessionID, request));
}
2023-03-03 15:23:46 +00:00
}