Skip to content

Commit

Permalink
Add configurable session timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
Lacyway committed Jun 9, 2024
1 parent 0b0123a commit 5bbe36c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion assets/configs/fika.jsonc
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
},
"server": {
"giftedItemsLoseFIR": true,
"launcherListAllProfiles": false
"launcherListAllProfiles": false,
"sessionTimeout": 5
}
}
1 change: 1 addition & 0 deletions src/models/fika/config/IFikaConfigServer.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export interface IFikaConfigServer {
giftedItemsLoseFIR: boolean;
launcherListAllProfiles: boolean;
sessionTimeout: number;
}
9 changes: 7 additions & 2 deletions src/services/FikaMatchService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { IFikaMatch } from "../models/fika/IFikaMatch";
import { IFikaPlayer } from "../models/fika/IFikaPlayer";
import { IFikaRaidCreateRequestData } from "../models/fika/routes/raid/create/IFikaRaidCreateRequestData";

import { FikaConfig } from "../utils/FikaConfig";

@injectable()
export class FikaMatchService {
protected matches: Map<string, IFikaMatch>;
Expand All @@ -19,6 +21,7 @@ export class FikaMatchService {
@inject("WinstonLogger") protected logger: ILogger,
@inject("LocationController") protected locationController: LocationController,
@inject("SaveServer") protected saveServer: SaveServer,
@inject("FikaConfig") protected fikaConfig: FikaConfig,
) {
this.matches = new Map();
this.timeoutIntervals = new Map();
Expand All @@ -29,6 +32,8 @@ export class FikaMatchService {
* @param matchId
*/
private addTimeoutInterval(matchId: string): void {
const fikaConfig = this.fikaConfig.getConfig();

if (this.timeoutIntervals.has(matchId)) {
this.removeTimeoutInterval(matchId);
}
Expand All @@ -40,8 +45,8 @@ export class FikaMatchService {

match.timeout++;

// if it timed out 5 times or more, end the match
if (match.timeout >= 5) {
// if it timed out 'sessionTimeout' times or more, end the match
if (match.timeout >= fikaConfig.server.sessionTimeout) {
this.endMatch(matchId, FikaMatchEndSessionMessage.PING_TIMEOUT_MESSAGE);
}
}, 60 * 1000),
Expand Down

0 comments on commit 5bbe36c

Please sign in to comment.