2023-03-03 15:23:46 +00:00
|
|
|
import { inject, injectable } from "tsyringe";
|
|
|
|
|
2023-10-19 17:21:17 +00:00
|
|
|
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 { 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,
|
2023-03-23 14:48:10 +00:00
|
|
|
@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
|
|
|
)
|
|
|
|
{}
|
|
|
|
|
2023-10-10 11:03:20 +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);
|
2023-11-13 12:31:52 -05:00
|
|
|
return this.httpResponse.getBody({utc_time: startTimeStampMS / 1000});
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle client/game/logout
|
2023-03-23 14:48:10 +00:00
|
|
|
* 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
|
|
|
{
|
2023-03-23 14:48:10 +00:00
|
|
|
this.saveServer.save();
|
2023-11-13 12:31:52 -05:00
|
|
|
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));
|
|
|
|
}
|
|
|
|
|
2023-07-14 12:55:32 +01:00
|
|
|
/**
|
|
|
|
* Handle client/server/list
|
|
|
|
*/
|
2023-03-03 15:23:46 +00:00
|
|
|
public getServer(url: string, info: IEmptyRequestData, sessionID: string): IGetBodyResponseData<IServerDetails[]>
|
|
|
|
{
|
2023-07-14 12:55:32 +01:00
|
|
|
return this.httpResponse.getBody(this.gameController.getServer(sessionID));
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-14 12:55:32 +01: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));
|
|
|
|
}
|
|
|
|
|
2023-07-14 12:55:32 +01:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
{
|
2023-07-14 12:55:32 +01: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
|
|
|
{
|
2023-07-15 10:57:39 +01: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
|
|
|
|
{
|
2023-11-13 12:31:52 -05:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|