Skip to content

Commit

Permalink
Merge pull request #50 from stayintarkov/feature/raid-status
Browse files Browse the repository at this point in the history
Refactor to support a Raid Status (WAITING, IN GAME etc)
  • Loading branch information
paulov-t committed May 7, 2024
2 parents 94e6291 + 918828e commit 6f3eae6
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 49 deletions.
25 changes: 11 additions & 14 deletions src/CoopMatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ import { WebSocketHandler } from "./WebSocketHandler";
import { ILocationBase } from "@spt-aki/models/eft/common/ILocationBase";
import { LocationController } from "@spt-aki/controllers/LocationController";
import { IGetLocationRequestData } from "@spt-aki/models/eft/location/IGetLocationRequestData";

export enum CoopMatchStatus {
Loading,
InGame,
Complete
}
import { MPMatchStatus } from "./MPMatchStatus";

export class CoopMatchEndSessionMessages {
static HOST_SHUTDOWN_MESSAGE: string = "host-shutdown"
Expand All @@ -37,9 +32,6 @@ export class CoopMatch {
/** The time the match was last updated. Useful for clearing out old matches. */
LastUpdateDateTime: Date = new Date();

/** The state of the match. */
State: any;

/** The expected number of players. Used to hold the match before starting. Unused. */
ExpectedNumberOfPlayers: number = 1;

Expand Down Expand Up @@ -79,7 +71,7 @@ export class CoopMatch {
PreviousSentData: string[] = [];
PreviousSentDataMaxSize: number = 128;

Status: CoopMatchStatus = CoopMatchStatus.Loading;
Status: MPMatchStatus = MPMatchStatus.Loading;
Settings: any = {};
LocationData: ILocationBase;
Location: string;
Expand All @@ -103,7 +95,7 @@ export class CoopMatch {
public constructor(inData: any) {

this.ServerId = inData.serverId;
this.Status = CoopMatchStatus.Loading;
this.Status = MPMatchStatus.Loading;
this.CreatedDateTime = new Date(Date.now());
this.LastUpdateDateTime = new Date(Date.now());

Expand Down Expand Up @@ -132,7 +124,7 @@ export class CoopMatch {
this.GameVersion = inData.gameVersion;
this.SITVersion = inData.sitVersion;
this.AuthorizedUsers.push(inData.serverId);
this.Status = CoopMatchStatus.Loading;
this.Status = MPMatchStatus.Loading;
this.CreatedDateTime = new Date(Date.now());
this.LastUpdateDateTime = new Date(Date.now());

Expand Down Expand Up @@ -244,6 +236,10 @@ export class CoopMatch {
}
}

if (info.status !== undefined) {
this.UpdateStatus(info.status);
}

this.LastUpdateDateTime = new Date(Date.now());

const serializedData = JSON.stringify(info);
Expand All @@ -261,8 +257,9 @@ export class CoopMatch {
WebSocketHandler.Instance.sendToWebSockets(this.ConnectedUsers, undefined, serializedData);
}

public UpdateStatus(inStatus: CoopMatchStatus) {
public UpdateStatus(inStatus: MPMatchStatus) {
this.Status = inStatus;
console.log(`Updated server:[${this.ServerId}] to status [${inStatus}]`);
}

public PlayerJoined(profileId: string): boolean {
Expand Down Expand Up @@ -307,7 +304,7 @@ export class CoopMatch {
console.log(`COOP SESSION ${this.ServerId} HAS BEEN ENDED: ${reason}`);
WebSocketHandler.Instance.sendToWebSockets(this.ConnectedPlayers, undefined, JSON.stringify({ "endSession": true, reason: reason }));

this.Status = CoopMatchStatus.Complete;
this.Status = MPMatchStatus.Complete;

//clearTimeout(this.SendLastDataInterval);
// clearTimeout(this.CheckStartTimeout);
Expand Down
5 changes: 4 additions & 1 deletion src/CoopMatchResponse.ts → src/MPMatchResponse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
export class CoopMatchResponse {
import { MPMatchStatus } from "./MPMatchStatus";

export class MPMatchResponse {
ServerId: string;
HostProfileId: string;
HostName: string;
Expand All @@ -12,4 +14,5 @@ export class CoopMatchResponse {
IsPasswordLocked: boolean;
Protocol: string;
IPAddress: string;
Status: MPMatchStatus;
}
7 changes: 7 additions & 0 deletions src/MPMatchStatus.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
export enum MPMatchStatus {
Loading,
WaitingForPlayers,
WaitingToStart,
InGame,
Complete
}
41 changes: 7 additions & 34 deletions src/StayInTarkovMod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";

import { IGetLocationRequestData } from "@spt-aki/models/eft/location/IGetLocationRequestData";
import { CoopConfig } from "./CoopConfig";
import { CoopMatch, CoopMatchEndSessionMessages, CoopMatchStatus } from "./CoopMatch";
import { CoopMatch, CoopMatchEndSessionMessages } from "./CoopMatch";
import { MPMatchStatus } from "./MPMatchStatus";
import { WebSocketHandler } from "./WebSocketHandler";
import { NatHelper } from "./NatHelper";

Expand All @@ -23,12 +24,6 @@ import { ConfigServer } from "@spt-aki/servers/ConfigServer";

import { SITConfig } from "./SITConfig";

// -------------------------------------------------------------------------
// Custom Traders (needs to be refactored into SITCustomTraders.ts)
import { CoopMatchResponse } from "./CoopMatchResponse";
import { friendlyAI } from "./FriendlyAI";
// -------------------------------------------------------------------------

// Overrides ---------------------------------------------------------------
import { BundleLoaderOverride } from "./Overrides/BundleLoaderOverride";
import { LauncherControllerOverride } from "./Overrides/LauncherControllerOverride";
Expand All @@ -48,6 +43,7 @@ import { ProfileCallbacks } from "@spt-aki/callbacks/ProfileCallbacks";
import { HashUtil } from "@spt-aki/utils/HashUtil";
import { SITHelpers } from "./SITHelpers";
import { UPNPHelper } from "./upnp/UPNPHelper";
import { MPMatchResponse } from "./MPMatchResponse";
// -------------------------------------------------------------------------

@injectable()
Expand Down Expand Up @@ -219,28 +215,6 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
return output;
}
),
new RouteAction(
"/coop/server/friendlyAI",
// eslint-disable-next-line @typescript-eslint/no-unused-vars
(url: string, info: any, sessionID: string, output: string): any =>
{

const splitUrl = url.split("/");
const matchId = splitUrl.pop();

var friendlyAI: friendlyAI;
if(matchId !== undefined) {
// console.log("matchId:" + matchId);
const coopMatch = this.getCoopMatch(matchId);
if(coopMatch !== undefined)
friendlyAI = coopMatch.friendlyAI;
}


output = JSON.stringify(friendlyAI);
return output;
}
),
/* Fix for downloading bundle files with extension not ending with .bundle */
new RouteAction(
"/files/bundle",
Expand All @@ -261,7 +235,7 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
url: "/coop/server/getAllForLocation",
action: (url, info: any, sessionId: string, output) => {
// console.log(info);
const matches : CoopMatchResponse[] = [];
const matches : MPMatchResponse[] = [];
const profiles = this.saveServer.getProfiles();
for(let itemKey in CoopMatch.CoopMatches) {

Expand Down Expand Up @@ -290,7 +264,7 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
continue;

// Create the custom CoopMatchResponse with the exact Json values needed by the Client
const matchResponse = new CoopMatchResponse();
const matchResponse = new MPMatchResponse();
// Account Id / Server Id
matchResponse.HostProfileId = itemKey;

Expand Down Expand Up @@ -323,6 +297,8 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
matchResponse.Protocol = m.Protocol;
// IP Address (v4)
matchResponse.IPAddress = m.IPAddress;
// Status
matchResponse.Status = m.Status;

matches.push(matchResponse);
}
Expand Down Expand Up @@ -362,9 +338,6 @@ export class StayInTarkovMod implements IPreAkiLoadMod, IPostDBLoadMod
if(CoopMatch.CoopMatches[cm].Time != info.timeVariant)
continue;

if (CoopMatch.CoopMatches[cm].Status == CoopMatchStatus.Complete)
continue;

// Player starting the server has 5 minutes to load into a raid
if (CoopMatch.CoopMatches[cm].LastUpdateDateTime < new Date(Date.now() - ((1000 * 60) * 5)))
continue;
Expand Down

0 comments on commit 6f3eae6

Please sign in to comment.