Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Groups #37

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/callbacks/FikaRaidCallbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,22 @@ export class FikaRaidCallbacks {
}

/** Handle /fika/raid/gethost */
public handleRaidGethost(_url: string, info: IFikaRaidServerIdRequestData, _sessionID: string): string {
return this.httpResponseUtil.noBody(this.fikaRaidController.handleRaidGethost(info));
public handleRaidGethost(_url: string, info: IFikaRaidServerIdRequestData, sessionID: string): string {
return this.httpResponseUtil.noBody(this.fikaRaidController.handleRaidGethost(info, sessionID));
}

/** Handle /fika/raid/spawnpoint */
public handleRaidSpawnpoint(_url: string, info: IFikaRaidServerIdRequestData, _sessionID: string): string {
return this.httpResponseUtil.noBody(this.fikaRaidController.handleRaidSpawnpoint(info));
public handleRaidSpawnpoint(_url: string, info: IFikaRaidServerIdRequestData, sessionID: string): string {
return this.httpResponseUtil.noBody(this.fikaRaidController.handleRaidSpawnpoint(info, sessionID));
}

/** Handle /fika/raid/getsettings */
public handleRaidGetSettings(_url: string, info: IFikaRaidServerIdRequestData, _sessionID: string): string {
return this.httpResponseUtil.noBody(this.fikaRaidController.handleRaidGetSettings(info));
}

/** Handle /fika/raid/group */
public handleGetGroupRaid(_url: string, sessionID: string): string {
return this.httpResponseUtil.noBody(this.fikaRaidController.handleGetGroupRaid(sessionID))
}
}
169 changes: 169 additions & 0 deletions src/controllers/FikaMatchController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import { inject, injectable } from "tsyringe";

import { ApplicationContext } from "@spt/context/ApplicationContext";
import { MatchController } from "@spt/controllers/MatchController";
import { LootGenerator } from "@spt/generators/LootGenerator";
import { ProfileHelper } from "@spt/helpers/ProfileHelper";
import { TraderHelper } from "@spt/helpers/TraderHelper";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { SaveServer } from "@spt/servers/SaveServer";
import { BotGenerationCacheService } from "@spt/services/BotGenerationCacheService";
import { BotLootCacheService } from "@spt/services/BotLootCacheService";
import { MailSendService } from "@spt/services/MailSendService";
import { MatchLocationService } from "@spt/services/MatchLocationService";
import { ProfileSnapshotService } from "@spt/services/ProfileSnapshotService";
import { HashUtil } from "@spt/utils/HashUtil";
import { RandomUtil } from "@spt/utils/RandomUtil";
import { TimeUtil } from "@spt/utils/TimeUtil";
import { NotificationSendHelper } from "@spt/helpers/NotificationSendHelper";
import { IMatchGroupInviteSendRequest } from "@spt/models/eft/match/IMatchGroupInviteSendRequest";
import { IEmptyRequestData } from "@spt/models/eft/common/IEmptyRequestData";
import { IMatchGroupCurrentResponse } from "@spt/models/eft/match/IMatchGroupCurrentResponse";
import { IRequestIdRequest } from "@spt/models/eft/match/IRequestIdRequest";
import { IGroupCharacter } from "@spt/models/eft/match/IGroupCharacter";
import { IMatchGroupTransferRequest } from "@spt/models/eft/match/IMatchGroupTransferRequest";
import { IMatchGroupPlayerRemoveRequest } from "@spt/models/eft/match/IMatchGroupPlayerRemoveRequest";
import { IGetRaidConfigurationRequestData } from "@spt/models/eft/match/IGetRaidConfigurationRequestData";

import { FikaGroupService } from "../services/FikaGroupService";

@injectable()
export class FikaMatchController extends MatchController {
constructor(
@inject("PrimaryLogger") protected logger: ILogger,
@inject("SaveServer") protected saveServer: SaveServer,
@inject("MailSendService") protected mailSendService: MailSendService,
@inject("TimeUtil") protected timeUtil: TimeUtil,
@inject("RandomUtil") protected randomUtil: RandomUtil,
@inject("HashUtil") protected hashUtil: HashUtil,
@inject("ProfileHelper") protected profileHelper: ProfileHelper,
@inject("MatchLocationService") protected matchLocationService: MatchLocationService,
@inject("TraderHelper") protected traderHelper: TraderHelper,
@inject("BotLootCacheService") protected botLootCacheService: BotLootCacheService,
@inject("ConfigServer") protected configServer: ConfigServer,
@inject("ProfileSnapshotService") protected profileSnapshotService: ProfileSnapshotService,
@inject("BotGenerationCacheService") protected botGenerationCacheService: BotGenerationCacheService,
@inject("LootGenerator") protected lootGenerator: LootGenerator,
@inject("ApplicationContext") protected applicationContext: ApplicationContext,
@inject("NotificationSendHelper") protected notifications: NotificationSendHelper,
@inject("FikaGroupService") protected groupService: FikaGroupService,
) {
super(logger, saveServer, mailSendService, timeUtil, randomUtil, hashUtil,
profileHelper, matchLocationService, traderHelper, botLootCacheService, configServer,
profileSnapshotService, botGenerationCacheService, lootGenerator, applicationContext
);
}

/**
* Handle client/match/group/invite/send
* @param info Sender & receipient info
* @param sessionID Player's session ID
* @returns {string} Invite's request ID
*/
public sendGroupInvite(info: IMatchGroupInviteSendRequest, sessionID: string): string {
const recipient = Object.values(this.saveServer.getProfiles()).find(p => p.info.aid.toString() === info.to.toString())
return this.groupService.sendInvite(recipient.info.id, sessionID, info.inLobby);
}

/**
* Handle client/match/group/invite/decline
* @param info Invite's request ID
* @param sessionID Player's session ID
* @returns
*/
public acceptGroupInvite(info: IRequestIdRequest, sessionID: string): IGroupCharacter[] {
return this.groupService.acceptInvite(info.requestId, sessionID);
}

/**
* Handle client/match/group/invite/decline
* @param info Invite's request ID
* @param sessionID Player's session ID
* @returns
*/
public declineGroupInvite(info: IRequestIdRequest, sessionID: string): boolean {
return this.groupService.declineInvite(info.requestId, sessionID);
}

/**
* Handle client/match/group/invite/cancel
* @param info Invite's request ID
* @param sessionID Player's session ID
* @returns
*/
public cancelGroupInvite(info: IRequestIdRequest, sessionID: string): boolean {
return this.groupService.cancelInvite(info.requestId);
}

/**
* Handle client/match/group/invite/cancel-all
* @param info ignored
* @param sessionID Player's session ID
* @returns
*/
public cancelAllGroupInvite(info: IEmptyRequestData, sessionID: string): boolean {
const groupId = this.groupService.getGroupIdByMember(sessionID);
return this.groupService.cancelAllInvites(groupId, sessionID);
}

/**
* Handle client/match/group/transfer
* @param info
* @param sessionID Player's session ID
* @returns {boolean}
*/
public transferGroup(info: IMatchGroupTransferRequest, sessionID: string): boolean {
const groupId = this.groupService.getGroupIdByMember(sessionID);
const profile = Object.values(this.saveServer.getProfiles()).find(p => String(p.info.aid) === info.aidToChange);
return this.groupService.transferGroup(groupId, sessionID, profile?.info?.id);
}

/**
* Handle client/match/group/player/remove
* @param info ignored
* @param sessionID Player's session ID
* @returns
*/
public leaveGroup(info: IEmptyRequestData, sessionID: string): boolean {
const groupId = this.groupService.getGroupIdByMember(sessionID);
return !!this.groupService.leaveGroup(groupId, sessionID);
}

/**
* Handle client/match/group/player/remove
* @param info
* @param sessionID Player's session ID
* @returns
*/
public removePlayerFromGroup(info: IMatchGroupPlayerRemoveRequest, sessionID: string): boolean {
const groupId = this.groupService.getGroupIdByMember(sessionID);
const profile = Object.values(this.saveServer.getProfiles()).find(p => String(p.info.aid) === info.aidToKick)
return !!this.groupService.kickPlayer(groupId, sessionID, profile?.info?.id);
}

/**
* Handle client/match/group/current
* @param info ignored
* @param sessionID Player's session ID
* @returns
*/
public groupCurrent(info: IEmptyRequestData, sessionID: string): IMatchGroupCurrentResponse {
const group = this.groupService.getGroupByMember(sessionID);
return { squad: group ?? [] }
}

/**
* Handle /client/raid/configuration
* @param request Raid config request
* @param sessionID Player's session ID
*/
public startOfflineRaid = (request: IGetRaidConfigurationRequestData, sessionID: string) => {
super.startOfflineRaid(request, sessionID);

const groupId = this.groupService.getGroupIdByMember(sessionID);
if (groupId) {
this.groupService.sendRaidSettings(groupId, request);
}
}
}
68 changes: 61 additions & 7 deletions src/controllers/FikaRaidController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,15 @@ import { IFikaRaidJoinResponse } from "../models/fika/routes/raid/join/IFikaRaid
import { IFikaRaidLeaveRequestData } from "../models/fika/routes/raid/leave/IFikaRaidLeaveRequestData";
import { IFikaRaidSpawnpointResponse } from "../models/fika/routes/raid/spawnpoint/IFikaRaidSpawnpointResponse";
import { FikaMatchService } from "../services/FikaMatchService";
import { FikaGroupService } from "../services/FikaGroupService";
import { IFikaGroupRaidResponse } from "../models/fika/routes/raid/group/IFikaGroupRaidResponse";

@injectable()
export class FikaRaidController {
constructor(@inject("FikaMatchService") protected fikaMatchService: FikaMatchService) {
constructor(
@inject("FikaMatchService") protected fikaMatchService: FikaMatchService,
@inject("FikaGroupService") protected fikaGroupService: FikaGroupService
) {
// empty
}

Expand All @@ -33,7 +38,9 @@ export class FikaRaidController {
* @param request
*/
public handleRaidJoin(request: IFikaRaidJoinRequestData): IFikaRaidJoinResponse {
this.fikaMatchService.addPlayerToMatch(request.serverId, request.profileId, { groupId: null, isDead: false });
const groupId = this.fikaGroupService.getGroupIdByMember(request.profileId);

this.fikaMatchService.addPlayerToMatch(request.serverId, request.profileId, { groupId, isDead: false, side: request.side });

const match = this.fikaMatchService.getMatch(request.serverId);

Expand Down Expand Up @@ -64,10 +71,19 @@ export class FikaRaidController {
* Handle /fika/raid/gethost
* @param request
*/
public handleRaidGethost(request: IFikaRaidServerIdRequestData): IFikaRaidGethostResponse {
const match = this.fikaMatchService.getMatch(request.serverId);
public handleRaidGethost(request: IFikaRaidServerIdRequestData, sessionID: string): IFikaRaidGethostResponse {
let match = this.fikaMatchService.getMatch(request.serverId);
if (!match) {
return;
const groupId = this.fikaGroupService.getGroupIdByMember(sessionID);
const leader = this.fikaGroupService.getGroupLeader(groupId);
if (leader._id !== sessionID) {
const matchId = this.fikaMatchService.getMatchIdByPlayer(leader._id);
if (matchId) {
match = this.fikaMatchService.getMatch(matchId);
}
}

if (!match) return;
}

return {
Expand All @@ -81,14 +97,24 @@ export class FikaRaidController {
* Handle /fika/raid/spawnpoint
* @param request
*/
public handleRaidSpawnpoint(request: IFikaRaidServerIdRequestData): IFikaRaidSpawnpointResponse {
public handleRaidSpawnpoint(request: IFikaRaidServerIdRequestData, sessionID: string): IFikaRaidSpawnpointResponse {
const match = this.fikaMatchService.getMatch(request.serverId);
if (!match) {
return;
}

const groupId = this.fikaGroupService.getGroupIdByMember(sessionID);
if (!groupId) {
return;
}

const spawnpoint = match.spawnPoint[groupId];
if (!spawnpoint) {
return;
}

return {
spawnpoint: match.spawnPoint,
spawnpoint
};
}

Expand All @@ -107,4 +133,32 @@ export class FikaRaidController {
playersSpawnPlace: match.raidConfig.playersSpawnPlace
};
}

/**
* Handle /fika/raid/group
* @param request
* @returns
*/
public handleGetGroupRaid(sessionID: string): IFikaGroupRaidResponse {
const groupId = this.fikaGroupService.getGroupIdByMember(sessionID);
const leader = this.fikaGroupService.getGroupLeader(groupId);

if (!leader) {
const match = this.fikaMatchService.getMatchIdByPlayer(sessionID);
if (match) {
return {
serverId: match
}
}
} else {
const match = this.fikaMatchService.getMatchIdByPlayer(leader._id);
if (match) {
return {
serverId: match
}
}
}

return { serverId: '' }
}
}
2 changes: 1 addition & 1 deletion src/controllers/FikaUpdateController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export class FikaUpdateController {
* @param request
*/
public handleSpawnpoint(request: IFikaUpdateSpawnpointRequestData): void {
this.fikaMatchService.setMatchSpawnPoint(request.serverId, request.name);
this.fikaMatchService.setMatchSpawnPoint(request.serverId, request.name, request.groupId);
}

/**
Expand Down
Loading