Updated types

This commit is contained in:
Chomp 2024-12-15 11:52:19 +00:00
parent 223acdc708
commit c51864317b
280 changed files with 4200 additions and 84 deletions

View File

@ -3,11 +3,13 @@ import { OnUpdate } from "@spt/di/OnUpdate";
import { ICoreConfig } from "@spt/models/spt/config/ICoreConfig";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { SaveServer } from "@spt/servers/SaveServer";
import { BackupService } from "@spt/services/BackupService";
export declare class SaveCallbacks implements OnLoad, OnUpdate {
protected saveServer: SaveServer;
protected configServer: ConfigServer;
protected backupService: BackupService;
protected coreConfig: ICoreConfig;
constructor(saveServer: SaveServer, configServer: ConfigServer);
constructor(saveServer: SaveServer, configServer: ConfigServer, backupService: BackupService);
onLoad(): Promise<void>;
getRoute(): string;
onUpdate(secondsSinceLastRun: number): Promise<boolean>;

View File

@ -1,5 +1,8 @@
import { IDialogueChatBot } from "@spt/helpers/Dialogue/IDialogueChatBot";
import { DialogueHelper } from "@spt/helpers/DialogueHelper";
import { NotificationSendHelper } from "@spt/helpers/NotificationSendHelper";
import { ProfileHelper } from "@spt/helpers/ProfileHelper";
import { IDeleteFriendRequest } from "@spt/models/eft/dialog/IDeleteFriendRequest";
import { IFriendRequestData } from "@spt/models/eft/dialog/IFriendRequestData";
import { IFriendRequestSendResponse } from "@spt/models/eft/dialog/IFriendRequestSendResponse";
import { IGetAllAttachmentsResponse } from "@spt/models/eft/dialog/IGetAllAttachmentsResponse";
@ -20,11 +23,13 @@ export declare class DialogueController {
protected saveServer: SaveServer;
protected timeUtil: TimeUtil;
protected dialogueHelper: DialogueHelper;
protected notificationSendHelper: NotificationSendHelper;
protected profileHelper: ProfileHelper;
protected mailSendService: MailSendService;
protected localisationService: LocalisationService;
protected configServer: ConfigServer;
protected dialogueChatBots: IDialogueChatBot[];
constructor(logger: ILogger, saveServer: SaveServer, timeUtil: TimeUtil, dialogueHelper: DialogueHelper, mailSendService: MailSendService, localisationService: LocalisationService, configServer: ConfigServer, dialogueChatBots: IDialogueChatBot[]);
constructor(logger: ILogger, saveServer: SaveServer, timeUtil: TimeUtil, dialogueHelper: DialogueHelper, notificationSendHelper: NotificationSendHelper, profileHelper: ProfileHelper, mailSendService: MailSendService, localisationService: LocalisationService, configServer: ConfigServer, dialogueChatBots: IDialogueChatBot[]);
registerChatBot(chatBot: IDialogueChatBot): void;
/** Handle onUpdate spt event */
update(): void;
@ -151,4 +156,6 @@ export declare class DialogueController {
protected messageHasExpired(message: IMessage): boolean;
/** Handle client/friend/request/send */
sendFriendRequest(sessionID: string, request: IFriendRequestData): IFriendRequestSendResponse;
/** Handle client/friend/delete */
deleteFriend(sessionID: string, request: IDeleteFriendRequest): void;
}

View File

@ -2,6 +2,7 @@ import { ItemHelper } from "@spt/helpers/ItemHelper";
import { IPmcData } from "@spt/models/eft/common/IPmcData";
import { Common, ICounterKeyValue, IStats } from "@spt/models/eft/common/tables/IBotBase";
import { IItem } from "@spt/models/eft/common/tables/IItem";
import { ISearchFriendResponse } from "@spt/models/eft/profile/ISearchFriendResponse";
import { ISptProfile } from "@spt/models/eft/profile/ISptProfile";
import { IValidateNicknameRequestData } from "@spt/models/eft/profile/IValidateNicknameRequestData";
import { BonusType } from "@spt/models/enums/BonusType";
@ -90,6 +91,24 @@ export declare class ProfileHelper {
* @returns ISptProfile object
*/
getFullProfile(sessionID: string): ISptProfile | undefined;
/**
* Get full representation of a players profile JSON by the account ID, or undefined if not found
* @param accountId Account ID to find
* @returns
*/
getFullProfileByAccountId(accountID: string): ISptProfile | undefined;
/**
* Retrieve a ChatRoomMember formatted profile for the given session ID
* @param sessionID The session ID to return the profile for
* @returns
*/
getChatRoomMemberFromSessionId(sessionID: string): ISearchFriendResponse | undefined;
/**
* Retrieve a ChatRoomMember formatted profile for the given PMC profile data
* @param pmcProfile The PMC profile data to format into a ChatRoomMember structure
* @returns
*/
getChatRoomMemberFromPmcProfile(pmcProfile: IPmcData): ISearchFriendResponse;
/**
* Get a PMC profile by its session id
* @param sessionID Profile id to return

View File

@ -8,4 +8,5 @@ export interface Info {
Side: string;
Level: number;
MemberCategory: number;
SelectedMemberCategory: number;
}

View File

@ -19,6 +19,8 @@ export interface ISptProfile {
traderPurchases?: Record<string, Record<string, ITraderPurchaseData>>;
/** Achievements earned by player */
achievements: Record<string, number>;
/** List of friend profile IDs */
friends: string[];
}
export declare class ITraderPurchaseData {
count: number;

View File

@ -0,0 +1,5 @@
import { IWsNotificationEvent } from "@spt/models/eft/ws/IWsNotificationEvent";
import { ISearchFriendResponse } from "../profile/ISearchFriendResponse";
export interface IWsFriendsListAccept extends IWsNotificationEvent {
profile: ISearchFriendResponse;
}

View File

@ -1,4 +1,4 @@
export interface IWsNotificationEvent {
type: string;
eventId: string;
eventId?: string;
}

View File

@ -1,5 +1,6 @@
export declare enum ConfigTypes {
AIRDROP = "spt-airdrop",
BACKUP = "spt-backup",
BOT = "spt-bot",
PMC = "spt-pmc",
CORE = "spt-core",

View File

@ -0,0 +1,12 @@
import { IBaseConfig } from "@spt/models/spt/config/IBaseConfig";
export interface IBackupConfig extends IBaseConfig {
kind: "spt-backup";
enabled: boolean;
maxBackups: number;
directory: string;
backupInterval: IBackupConfigInterval;
}
export interface IBackupConfigInterval {
enabled: boolean;
intervalMinutes: number;
}

View File

@ -0,0 +1,98 @@
import { PreSptModLoader } from "@spt/loaders/PreSptModLoader";
import { IBackupConfig } from "@spt/models/spt/config/IBackupConfig";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
export declare class BackupService {
protected logger: ILogger;
protected preSptModLoader: PreSptModLoader;
protected configServer: ConfigServer;
protected backupConfig: IBackupConfig;
protected readonly activeServerMods: string[];
protected readonly profileDir = "./user/profiles";
constructor(logger: ILogger, preSptModLoader: PreSptModLoader, configServer: ConfigServer);
/**
* Initializes the backup process.
*
* This method orchestrates the profile backup service. Handles copying profiles to a backup directory and cleaning
* up old backups if the number exceeds the configured maximum.
*
* @returns A promise that resolves when the backup process is complete.
*/
init(): Promise<void>;
/**
* Fetches the names of all JSON files in the profile directory.
*
* This method normalizes the profile directory path and reads all files within it. It then filters the files to
* include only those with a `.json` extension and returns their names.
*
* @returns A promise that resolves to an array of JSON file names.
*/
protected fetchProfileFiles(): Promise<string[]>;
/**
* Check to see if the backup service is enabled via the config.
*
* @returns True if enabled, false otherwise.
*/
protected isEnabled(): boolean;
/**
* Generates the target directory path for the backup. The directory path is constructed using the `directory` from
* the configuration and the current backup date.
*
* @returns The target directory path for the backup.
*/
protected generateBackupTargetDir(): string;
/**
* Generates a formatted backup date string in the format `YYYY-MM-DD_hh-mm-ss`.
*
* @returns The formatted backup date string.
*/
protected generateBackupDate(): string;
/**
* Cleans up old backups in the backup directory.
*
* This method reads the backup directory, and sorts backups by modification time. If the number of backups exceeds
* the configured maximum, it deletes the oldest backups.
*
* @returns A promise that resolves when the cleanup is complete.
*/
protected cleanBackups(): Promise<void>;
/**
* Retrieves and sorts the backup file paths from the specified directory.
*
* @param dir - The directory to search for backup files.
* @returns A promise that resolves to an array of sorted backup file paths.
*/
private getBackupPaths;
/**
* Compares two backup folder names based on their extracted dates.
*
* @param a - The name of the first backup folder.
* @param b - The name of the second backup folder.
* @returns The difference in time between the two dates in milliseconds, or `null` if either date is invalid.
*/
private compareBackupDates;
/**
* Extracts a date from a folder name string formatted as `YYYY-MM-DD_hh-mm-ss`.
*
* @param folderName - The name of the folder from which to extract the date.
* @returns A Date object if the folder name is in the correct format, otherwise null.
*/
private extractDateFromFolderName;
/**
* Removes excess backups from the backup directory.
*
* @param backups - An array of backup file names to be removed.
* @returns A promise that resolves when all specified backups have been removed.
*/
private removeExcessBackups;
/**
* Start the backup interval if enabled in the configuration.
*/
protected startBackupInterval(): void;
/**
* Get an array of active server mod details.
*
* @returns An array of mod names.
*/
protected getActiveServerMods(): string[];
}

View File

@ -3,11 +3,13 @@ import { OnUpdate } from "@spt/di/OnUpdate";
import { ICoreConfig } from "@spt/models/spt/config/ICoreConfig";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { SaveServer } from "@spt/servers/SaveServer";
import { BackupService } from "@spt/services/BackupService";
export declare class SaveCallbacks implements OnLoad, OnUpdate {
protected saveServer: SaveServer;
protected configServer: ConfigServer;
protected backupService: BackupService;
protected coreConfig: ICoreConfig;
constructor(saveServer: SaveServer, configServer: ConfigServer);
constructor(saveServer: SaveServer, configServer: ConfigServer, backupService: BackupService);
onLoad(): Promise<void>;
getRoute(): string;
onUpdate(secondsSinceLastRun: number): Promise<boolean>;

View File

@ -1,5 +1,8 @@
import { IDialogueChatBot } from "@spt/helpers/Dialogue/IDialogueChatBot";
import { DialogueHelper } from "@spt/helpers/DialogueHelper";
import { NotificationSendHelper } from "@spt/helpers/NotificationSendHelper";
import { ProfileHelper } from "@spt/helpers/ProfileHelper";
import { IDeleteFriendRequest } from "@spt/models/eft/dialog/IDeleteFriendRequest";
import { IFriendRequestData } from "@spt/models/eft/dialog/IFriendRequestData";
import { IFriendRequestSendResponse } from "@spt/models/eft/dialog/IFriendRequestSendResponse";
import { IGetAllAttachmentsResponse } from "@spt/models/eft/dialog/IGetAllAttachmentsResponse";
@ -20,11 +23,13 @@ export declare class DialogueController {
protected saveServer: SaveServer;
protected timeUtil: TimeUtil;
protected dialogueHelper: DialogueHelper;
protected notificationSendHelper: NotificationSendHelper;
protected profileHelper: ProfileHelper;
protected mailSendService: MailSendService;
protected localisationService: LocalisationService;
protected configServer: ConfigServer;
protected dialogueChatBots: IDialogueChatBot[];
constructor(logger: ILogger, saveServer: SaveServer, timeUtil: TimeUtil, dialogueHelper: DialogueHelper, mailSendService: MailSendService, localisationService: LocalisationService, configServer: ConfigServer, dialogueChatBots: IDialogueChatBot[]);
constructor(logger: ILogger, saveServer: SaveServer, timeUtil: TimeUtil, dialogueHelper: DialogueHelper, notificationSendHelper: NotificationSendHelper, profileHelper: ProfileHelper, mailSendService: MailSendService, localisationService: LocalisationService, configServer: ConfigServer, dialogueChatBots: IDialogueChatBot[]);
registerChatBot(chatBot: IDialogueChatBot): void;
/** Handle onUpdate spt event */
update(): void;
@ -151,4 +156,6 @@ export declare class DialogueController {
protected messageHasExpired(message: IMessage): boolean;
/** Handle client/friend/request/send */
sendFriendRequest(sessionID: string, request: IFriendRequestData): IFriendRequestSendResponse;
/** Handle client/friend/delete */
deleteFriend(sessionID: string, request: IDeleteFriendRequest): void;
}

View File

@ -2,6 +2,7 @@ import { ItemHelper } from "@spt/helpers/ItemHelper";
import { IPmcData } from "@spt/models/eft/common/IPmcData";
import { Common, ICounterKeyValue, IStats } from "@spt/models/eft/common/tables/IBotBase";
import { IItem } from "@spt/models/eft/common/tables/IItem";
import { ISearchFriendResponse } from "@spt/models/eft/profile/ISearchFriendResponse";
import { ISptProfile } from "@spt/models/eft/profile/ISptProfile";
import { IValidateNicknameRequestData } from "@spt/models/eft/profile/IValidateNicknameRequestData";
import { BonusType } from "@spt/models/enums/BonusType";
@ -90,6 +91,24 @@ export declare class ProfileHelper {
* @returns ISptProfile object
*/
getFullProfile(sessionID: string): ISptProfile | undefined;
/**
* Get full representation of a players profile JSON by the account ID, or undefined if not found
* @param accountId Account ID to find
* @returns
*/
getFullProfileByAccountId(accountID: string): ISptProfile | undefined;
/**
* Retrieve a ChatRoomMember formatted profile for the given session ID
* @param sessionID The session ID to return the profile for
* @returns
*/
getChatRoomMemberFromSessionId(sessionID: string): ISearchFriendResponse | undefined;
/**
* Retrieve a ChatRoomMember formatted profile for the given PMC profile data
* @param pmcProfile The PMC profile data to format into a ChatRoomMember structure
* @returns
*/
getChatRoomMemberFromPmcProfile(pmcProfile: IPmcData): ISearchFriendResponse;
/**
* Get a PMC profile by its session id
* @param sessionID Profile id to return

View File

@ -8,4 +8,5 @@ export interface Info {
Side: string;
Level: number;
MemberCategory: number;
SelectedMemberCategory: number;
}

View File

@ -19,6 +19,8 @@ export interface ISptProfile {
traderPurchases?: Record<string, Record<string, ITraderPurchaseData>>;
/** Achievements earned by player */
achievements: Record<string, number>;
/** List of friend profile IDs */
friends: string[];
}
export declare class ITraderPurchaseData {
count: number;

View File

@ -0,0 +1,5 @@
import { IWsNotificationEvent } from "@spt/models/eft/ws/IWsNotificationEvent";
import { ISearchFriendResponse } from "../profile/ISearchFriendResponse";
export interface IWsFriendsListAccept extends IWsNotificationEvent {
profile: ISearchFriendResponse;
}

View File

@ -1,4 +1,4 @@
export interface IWsNotificationEvent {
type: string;
eventId: string;
eventId?: string;
}

View File

@ -1,5 +1,6 @@
export declare enum ConfigTypes {
AIRDROP = "spt-airdrop",
BACKUP = "spt-backup",
BOT = "spt-bot",
PMC = "spt-pmc",
CORE = "spt-core",

View File

@ -0,0 +1,12 @@
import { IBaseConfig } from "@spt/models/spt/config/IBaseConfig";
export interface IBackupConfig extends IBaseConfig {
kind: "spt-backup";
enabled: boolean;
maxBackups: number;
directory: string;
backupInterval: IBackupConfigInterval;
}
export interface IBackupConfigInterval {
enabled: boolean;
intervalMinutes: number;
}

View File

@ -0,0 +1,98 @@
import { PreSptModLoader } from "@spt/loaders/PreSptModLoader";
import { IBackupConfig } from "@spt/models/spt/config/IBackupConfig";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
export declare class BackupService {
protected logger: ILogger;
protected preSptModLoader: PreSptModLoader;
protected configServer: ConfigServer;
protected backupConfig: IBackupConfig;
protected readonly activeServerMods: string[];
protected readonly profileDir = "./user/profiles";
constructor(logger: ILogger, preSptModLoader: PreSptModLoader, configServer: ConfigServer);
/**
* Initializes the backup process.
*
* This method orchestrates the profile backup service. Handles copying profiles to a backup directory and cleaning
* up old backups if the number exceeds the configured maximum.
*
* @returns A promise that resolves when the backup process is complete.
*/
init(): Promise<void>;
/**
* Fetches the names of all JSON files in the profile directory.
*
* This method normalizes the profile directory path and reads all files within it. It then filters the files to
* include only those with a `.json` extension and returns their names.
*
* @returns A promise that resolves to an array of JSON file names.
*/
protected fetchProfileFiles(): Promise<string[]>;
/**
* Check to see if the backup service is enabled via the config.
*
* @returns True if enabled, false otherwise.
*/
protected isEnabled(): boolean;
/**
* Generates the target directory path for the backup. The directory path is constructed using the `directory` from
* the configuration and the current backup date.
*
* @returns The target directory path for the backup.
*/
protected generateBackupTargetDir(): string;
/**
* Generates a formatted backup date string in the format `YYYY-MM-DD_hh-mm-ss`.
*
* @returns The formatted backup date string.
*/
protected generateBackupDate(): string;
/**
* Cleans up old backups in the backup directory.
*
* This method reads the backup directory, and sorts backups by modification time. If the number of backups exceeds
* the configured maximum, it deletes the oldest backups.
*
* @returns A promise that resolves when the cleanup is complete.
*/
protected cleanBackups(): Promise<void>;
/**
* Retrieves and sorts the backup file paths from the specified directory.
*
* @param dir - The directory to search for backup files.
* @returns A promise that resolves to an array of sorted backup file paths.
*/
private getBackupPaths;
/**
* Compares two backup folder names based on their extracted dates.
*
* @param a - The name of the first backup folder.
* @param b - The name of the second backup folder.
* @returns The difference in time between the two dates in milliseconds, or `null` if either date is invalid.
*/
private compareBackupDates;
/**
* Extracts a date from a folder name string formatted as `YYYY-MM-DD_hh-mm-ss`.
*
* @param folderName - The name of the folder from which to extract the date.
* @returns A Date object if the folder name is in the correct format, otherwise null.
*/
private extractDateFromFolderName;
/**
* Removes excess backups from the backup directory.
*
* @param backups - An array of backup file names to be removed.
* @returns A promise that resolves when all specified backups have been removed.
*/
private removeExcessBackups;
/**
* Start the backup interval if enabled in the configuration.
*/
protected startBackupInterval(): void;
/**
* Get an array of active server mod details.
*
* @returns An array of mod names.
*/
protected getActiveServerMods(): string[];
}

View File

@ -3,11 +3,13 @@ import { OnUpdate } from "@spt/di/OnUpdate";
import { ICoreConfig } from "@spt/models/spt/config/ICoreConfig";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { SaveServer } from "@spt/servers/SaveServer";
import { BackupService } from "@spt/services/BackupService";
export declare class SaveCallbacks implements OnLoad, OnUpdate {
protected saveServer: SaveServer;
protected configServer: ConfigServer;
protected backupService: BackupService;
protected coreConfig: ICoreConfig;
constructor(saveServer: SaveServer, configServer: ConfigServer);
constructor(saveServer: SaveServer, configServer: ConfigServer, backupService: BackupService);
onLoad(): Promise<void>;
getRoute(): string;
onUpdate(secondsSinceLastRun: number): Promise<boolean>;

View File

@ -1,5 +1,8 @@
import { IDialogueChatBot } from "@spt/helpers/Dialogue/IDialogueChatBot";
import { DialogueHelper } from "@spt/helpers/DialogueHelper";
import { NotificationSendHelper } from "@spt/helpers/NotificationSendHelper";
import { ProfileHelper } from "@spt/helpers/ProfileHelper";
import { IDeleteFriendRequest } from "@spt/models/eft/dialog/IDeleteFriendRequest";
import { IFriendRequestData } from "@spt/models/eft/dialog/IFriendRequestData";
import { IFriendRequestSendResponse } from "@spt/models/eft/dialog/IFriendRequestSendResponse";
import { IGetAllAttachmentsResponse } from "@spt/models/eft/dialog/IGetAllAttachmentsResponse";
@ -20,11 +23,13 @@ export declare class DialogueController {
protected saveServer: SaveServer;
protected timeUtil: TimeUtil;
protected dialogueHelper: DialogueHelper;
protected notificationSendHelper: NotificationSendHelper;
protected profileHelper: ProfileHelper;
protected mailSendService: MailSendService;
protected localisationService: LocalisationService;
protected configServer: ConfigServer;
protected dialogueChatBots: IDialogueChatBot[];
constructor(logger: ILogger, saveServer: SaveServer, timeUtil: TimeUtil, dialogueHelper: DialogueHelper, mailSendService: MailSendService, localisationService: LocalisationService, configServer: ConfigServer, dialogueChatBots: IDialogueChatBot[]);
constructor(logger: ILogger, saveServer: SaveServer, timeUtil: TimeUtil, dialogueHelper: DialogueHelper, notificationSendHelper: NotificationSendHelper, profileHelper: ProfileHelper, mailSendService: MailSendService, localisationService: LocalisationService, configServer: ConfigServer, dialogueChatBots: IDialogueChatBot[]);
registerChatBot(chatBot: IDialogueChatBot): void;
/** Handle onUpdate spt event */
update(): void;
@ -151,4 +156,6 @@ export declare class DialogueController {
protected messageHasExpired(message: IMessage): boolean;
/** Handle client/friend/request/send */
sendFriendRequest(sessionID: string, request: IFriendRequestData): IFriendRequestSendResponse;
/** Handle client/friend/delete */
deleteFriend(sessionID: string, request: IDeleteFriendRequest): void;
}

View File

@ -2,6 +2,7 @@ import { ItemHelper } from "@spt/helpers/ItemHelper";
import { IPmcData } from "@spt/models/eft/common/IPmcData";
import { Common, ICounterKeyValue, IStats } from "@spt/models/eft/common/tables/IBotBase";
import { IItem } from "@spt/models/eft/common/tables/IItem";
import { ISearchFriendResponse } from "@spt/models/eft/profile/ISearchFriendResponse";
import { ISptProfile } from "@spt/models/eft/profile/ISptProfile";
import { IValidateNicknameRequestData } from "@spt/models/eft/profile/IValidateNicknameRequestData";
import { BonusType } from "@spt/models/enums/BonusType";
@ -90,6 +91,24 @@ export declare class ProfileHelper {
* @returns ISptProfile object
*/
getFullProfile(sessionID: string): ISptProfile | undefined;
/**
* Get full representation of a players profile JSON by the account ID, or undefined if not found
* @param accountId Account ID to find
* @returns
*/
getFullProfileByAccountId(accountID: string): ISptProfile | undefined;
/**
* Retrieve a ChatRoomMember formatted profile for the given session ID
* @param sessionID The session ID to return the profile for
* @returns
*/
getChatRoomMemberFromSessionId(sessionID: string): ISearchFriendResponse | undefined;
/**
* Retrieve a ChatRoomMember formatted profile for the given PMC profile data
* @param pmcProfile The PMC profile data to format into a ChatRoomMember structure
* @returns
*/
getChatRoomMemberFromPmcProfile(pmcProfile: IPmcData): ISearchFriendResponse;
/**
* Get a PMC profile by its session id
* @param sessionID Profile id to return

View File

@ -8,4 +8,5 @@ export interface Info {
Side: string;
Level: number;
MemberCategory: number;
SelectedMemberCategory: number;
}

View File

@ -19,6 +19,8 @@ export interface ISptProfile {
traderPurchases?: Record<string, Record<string, ITraderPurchaseData>>;
/** Achievements earned by player */
achievements: Record<string, number>;
/** List of friend profile IDs */
friends: string[];
}
export declare class ITraderPurchaseData {
count: number;

View File

@ -0,0 +1,5 @@
import { IWsNotificationEvent } from "@spt/models/eft/ws/IWsNotificationEvent";
import { ISearchFriendResponse } from "../profile/ISearchFriendResponse";
export interface IWsFriendsListAccept extends IWsNotificationEvent {
profile: ISearchFriendResponse;
}

View File

@ -1,4 +1,4 @@
export interface IWsNotificationEvent {
type: string;
eventId: string;
eventId?: string;
}

View File

@ -1,5 +1,6 @@
export declare enum ConfigTypes {
AIRDROP = "spt-airdrop",
BACKUP = "spt-backup",
BOT = "spt-bot",
PMC = "spt-pmc",
CORE = "spt-core",

View File

@ -0,0 +1,12 @@
import { IBaseConfig } from "@spt/models/spt/config/IBaseConfig";
export interface IBackupConfig extends IBaseConfig {
kind: "spt-backup";
enabled: boolean;
maxBackups: number;
directory: string;
backupInterval: IBackupConfigInterval;
}
export interface IBackupConfigInterval {
enabled: boolean;
intervalMinutes: number;
}

View File

@ -0,0 +1,98 @@
import { PreSptModLoader } from "@spt/loaders/PreSptModLoader";
import { IBackupConfig } from "@spt/models/spt/config/IBackupConfig";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
export declare class BackupService {
protected logger: ILogger;
protected preSptModLoader: PreSptModLoader;
protected configServer: ConfigServer;
protected backupConfig: IBackupConfig;
protected readonly activeServerMods: string[];
protected readonly profileDir = "./user/profiles";
constructor(logger: ILogger, preSptModLoader: PreSptModLoader, configServer: ConfigServer);
/**
* Initializes the backup process.
*
* This method orchestrates the profile backup service. Handles copying profiles to a backup directory and cleaning
* up old backups if the number exceeds the configured maximum.
*
* @returns A promise that resolves when the backup process is complete.
*/
init(): Promise<void>;
/**
* Fetches the names of all JSON files in the profile directory.
*
* This method normalizes the profile directory path and reads all files within it. It then filters the files to
* include only those with a `.json` extension and returns their names.
*
* @returns A promise that resolves to an array of JSON file names.
*/
protected fetchProfileFiles(): Promise<string[]>;
/**
* Check to see if the backup service is enabled via the config.
*
* @returns True if enabled, false otherwise.
*/
protected isEnabled(): boolean;
/**
* Generates the target directory path for the backup. The directory path is constructed using the `directory` from
* the configuration and the current backup date.
*
* @returns The target directory path for the backup.
*/
protected generateBackupTargetDir(): string;
/**
* Generates a formatted backup date string in the format `YYYY-MM-DD_hh-mm-ss`.
*
* @returns The formatted backup date string.
*/
protected generateBackupDate(): string;
/**
* Cleans up old backups in the backup directory.
*
* This method reads the backup directory, and sorts backups by modification time. If the number of backups exceeds
* the configured maximum, it deletes the oldest backups.
*
* @returns A promise that resolves when the cleanup is complete.
*/
protected cleanBackups(): Promise<void>;
/**
* Retrieves and sorts the backup file paths from the specified directory.
*
* @param dir - The directory to search for backup files.
* @returns A promise that resolves to an array of sorted backup file paths.
*/
private getBackupPaths;
/**
* Compares two backup folder names based on their extracted dates.
*
* @param a - The name of the first backup folder.
* @param b - The name of the second backup folder.
* @returns The difference in time between the two dates in milliseconds, or `null` if either date is invalid.
*/
private compareBackupDates;
/**
* Extracts a date from a folder name string formatted as `YYYY-MM-DD_hh-mm-ss`.
*
* @param folderName - The name of the folder from which to extract the date.
* @returns A Date object if the folder name is in the correct format, otherwise null.
*/
private extractDateFromFolderName;
/**
* Removes excess backups from the backup directory.
*
* @param backups - An array of backup file names to be removed.
* @returns A promise that resolves when all specified backups have been removed.
*/
private removeExcessBackups;
/**
* Start the backup interval if enabled in the configuration.
*/
protected startBackupInterval(): void;
/**
* Get an array of active server mod details.
*
* @returns An array of mod names.
*/
protected getActiveServerMods(): string[];
}

View File

@ -3,11 +3,13 @@ import { OnUpdate } from "@spt/di/OnUpdate";
import { ICoreConfig } from "@spt/models/spt/config/ICoreConfig";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { SaveServer } from "@spt/servers/SaveServer";
import { BackupService } from "@spt/services/BackupService";
export declare class SaveCallbacks implements OnLoad, OnUpdate {
protected saveServer: SaveServer;
protected configServer: ConfigServer;
protected backupService: BackupService;
protected coreConfig: ICoreConfig;
constructor(saveServer: SaveServer, configServer: ConfigServer);
constructor(saveServer: SaveServer, configServer: ConfigServer, backupService: BackupService);
onLoad(): Promise<void>;
getRoute(): string;
onUpdate(secondsSinceLastRun: number): Promise<boolean>;

View File

@ -1,5 +1,8 @@
import { IDialogueChatBot } from "@spt/helpers/Dialogue/IDialogueChatBot";
import { DialogueHelper } from "@spt/helpers/DialogueHelper";
import { NotificationSendHelper } from "@spt/helpers/NotificationSendHelper";
import { ProfileHelper } from "@spt/helpers/ProfileHelper";
import { IDeleteFriendRequest } from "@spt/models/eft/dialog/IDeleteFriendRequest";
import { IFriendRequestData } from "@spt/models/eft/dialog/IFriendRequestData";
import { IFriendRequestSendResponse } from "@spt/models/eft/dialog/IFriendRequestSendResponse";
import { IGetAllAttachmentsResponse } from "@spt/models/eft/dialog/IGetAllAttachmentsResponse";
@ -20,11 +23,13 @@ export declare class DialogueController {
protected saveServer: SaveServer;
protected timeUtil: TimeUtil;
protected dialogueHelper: DialogueHelper;
protected notificationSendHelper: NotificationSendHelper;
protected profileHelper: ProfileHelper;
protected mailSendService: MailSendService;
protected localisationService: LocalisationService;
protected configServer: ConfigServer;
protected dialogueChatBots: IDialogueChatBot[];
constructor(logger: ILogger, saveServer: SaveServer, timeUtil: TimeUtil, dialogueHelper: DialogueHelper, mailSendService: MailSendService, localisationService: LocalisationService, configServer: ConfigServer, dialogueChatBots: IDialogueChatBot[]);
constructor(logger: ILogger, saveServer: SaveServer, timeUtil: TimeUtil, dialogueHelper: DialogueHelper, notificationSendHelper: NotificationSendHelper, profileHelper: ProfileHelper, mailSendService: MailSendService, localisationService: LocalisationService, configServer: ConfigServer, dialogueChatBots: IDialogueChatBot[]);
registerChatBot(chatBot: IDialogueChatBot): void;
/** Handle onUpdate spt event */
update(): void;
@ -151,4 +156,6 @@ export declare class DialogueController {
protected messageHasExpired(message: IMessage): boolean;
/** Handle client/friend/request/send */
sendFriendRequest(sessionID: string, request: IFriendRequestData): IFriendRequestSendResponse;
/** Handle client/friend/delete */
deleteFriend(sessionID: string, request: IDeleteFriendRequest): void;
}

View File

@ -2,6 +2,7 @@ import { ItemHelper } from "@spt/helpers/ItemHelper";
import { IPmcData } from "@spt/models/eft/common/IPmcData";
import { Common, ICounterKeyValue, IStats } from "@spt/models/eft/common/tables/IBotBase";
import { IItem } from "@spt/models/eft/common/tables/IItem";
import { ISearchFriendResponse } from "@spt/models/eft/profile/ISearchFriendResponse";
import { ISptProfile } from "@spt/models/eft/profile/ISptProfile";
import { IValidateNicknameRequestData } from "@spt/models/eft/profile/IValidateNicknameRequestData";
import { BonusType } from "@spt/models/enums/BonusType";
@ -90,6 +91,24 @@ export declare class ProfileHelper {
* @returns ISptProfile object
*/
getFullProfile(sessionID: string): ISptProfile | undefined;
/**
* Get full representation of a players profile JSON by the account ID, or undefined if not found
* @param accountId Account ID to find
* @returns
*/
getFullProfileByAccountId(accountID: string): ISptProfile | undefined;
/**
* Retrieve a ChatRoomMember formatted profile for the given session ID
* @param sessionID The session ID to return the profile for
* @returns
*/
getChatRoomMemberFromSessionId(sessionID: string): ISearchFriendResponse | undefined;
/**
* Retrieve a ChatRoomMember formatted profile for the given PMC profile data
* @param pmcProfile The PMC profile data to format into a ChatRoomMember structure
* @returns
*/
getChatRoomMemberFromPmcProfile(pmcProfile: IPmcData): ISearchFriendResponse;
/**
* Get a PMC profile by its session id
* @param sessionID Profile id to return

View File

@ -8,4 +8,5 @@ export interface Info {
Side: string;
Level: number;
MemberCategory: number;
SelectedMemberCategory: number;
}

View File

@ -19,6 +19,8 @@ export interface ISptProfile {
traderPurchases?: Record<string, Record<string, ITraderPurchaseData>>;
/** Achievements earned by player */
achievements: Record<string, number>;
/** List of friend profile IDs */
friends: string[];
}
export declare class ITraderPurchaseData {
count: number;

View File

@ -0,0 +1,5 @@
import { IWsNotificationEvent } from "@spt/models/eft/ws/IWsNotificationEvent";
import { ISearchFriendResponse } from "../profile/ISearchFriendResponse";
export interface IWsFriendsListAccept extends IWsNotificationEvent {
profile: ISearchFriendResponse;
}

View File

@ -1,4 +1,4 @@
export interface IWsNotificationEvent {
type: string;
eventId: string;
eventId?: string;
}

View File

@ -1,5 +1,6 @@
export declare enum ConfigTypes {
AIRDROP = "spt-airdrop",
BACKUP = "spt-backup",
BOT = "spt-bot",
PMC = "spt-pmc",
CORE = "spt-core",

View File

@ -0,0 +1,12 @@
import { IBaseConfig } from "@spt/models/spt/config/IBaseConfig";
export interface IBackupConfig extends IBaseConfig {
kind: "spt-backup";
enabled: boolean;
maxBackups: number;
directory: string;
backupInterval: IBackupConfigInterval;
}
export interface IBackupConfigInterval {
enabled: boolean;
intervalMinutes: number;
}

View File

@ -0,0 +1,98 @@
import { PreSptModLoader } from "@spt/loaders/PreSptModLoader";
import { IBackupConfig } from "@spt/models/spt/config/IBackupConfig";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
export declare class BackupService {
protected logger: ILogger;
protected preSptModLoader: PreSptModLoader;
protected configServer: ConfigServer;
protected backupConfig: IBackupConfig;
protected readonly activeServerMods: string[];
protected readonly profileDir = "./user/profiles";
constructor(logger: ILogger, preSptModLoader: PreSptModLoader, configServer: ConfigServer);
/**
* Initializes the backup process.
*
* This method orchestrates the profile backup service. Handles copying profiles to a backup directory and cleaning
* up old backups if the number exceeds the configured maximum.
*
* @returns A promise that resolves when the backup process is complete.
*/
init(): Promise<void>;
/**
* Fetches the names of all JSON files in the profile directory.
*
* This method normalizes the profile directory path and reads all files within it. It then filters the files to
* include only those with a `.json` extension and returns their names.
*
* @returns A promise that resolves to an array of JSON file names.
*/
protected fetchProfileFiles(): Promise<string[]>;
/**
* Check to see if the backup service is enabled via the config.
*
* @returns True if enabled, false otherwise.
*/
protected isEnabled(): boolean;
/**
* Generates the target directory path for the backup. The directory path is constructed using the `directory` from
* the configuration and the current backup date.
*
* @returns The target directory path for the backup.
*/
protected generateBackupTargetDir(): string;
/**
* Generates a formatted backup date string in the format `YYYY-MM-DD_hh-mm-ss`.
*
* @returns The formatted backup date string.
*/
protected generateBackupDate(): string;
/**
* Cleans up old backups in the backup directory.
*
* This method reads the backup directory, and sorts backups by modification time. If the number of backups exceeds
* the configured maximum, it deletes the oldest backups.
*
* @returns A promise that resolves when the cleanup is complete.
*/
protected cleanBackups(): Promise<void>;
/**
* Retrieves and sorts the backup file paths from the specified directory.
*
* @param dir - The directory to search for backup files.
* @returns A promise that resolves to an array of sorted backup file paths.
*/
private getBackupPaths;
/**
* Compares two backup folder names based on their extracted dates.
*
* @param a - The name of the first backup folder.
* @param b - The name of the second backup folder.
* @returns The difference in time between the two dates in milliseconds, or `null` if either date is invalid.
*/
private compareBackupDates;
/**
* Extracts a date from a folder name string formatted as `YYYY-MM-DD_hh-mm-ss`.
*
* @param folderName - The name of the folder from which to extract the date.
* @returns A Date object if the folder name is in the correct format, otherwise null.
*/
private extractDateFromFolderName;
/**
* Removes excess backups from the backup directory.
*
* @param backups - An array of backup file names to be removed.
* @returns A promise that resolves when all specified backups have been removed.
*/
private removeExcessBackups;
/**
* Start the backup interval if enabled in the configuration.
*/
protected startBackupInterval(): void;
/**
* Get an array of active server mod details.
*
* @returns An array of mod names.
*/
protected getActiveServerMods(): string[];
}

View File

@ -3,11 +3,13 @@ import { OnUpdate } from "@spt/di/OnUpdate";
import { ICoreConfig } from "@spt/models/spt/config/ICoreConfig";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { SaveServer } from "@spt/servers/SaveServer";
import { BackupService } from "@spt/services/BackupService";
export declare class SaveCallbacks implements OnLoad, OnUpdate {
protected saveServer: SaveServer;
protected configServer: ConfigServer;
protected backupService: BackupService;
protected coreConfig: ICoreConfig;
constructor(saveServer: SaveServer, configServer: ConfigServer);
constructor(saveServer: SaveServer, configServer: ConfigServer, backupService: BackupService);
onLoad(): Promise<void>;
getRoute(): string;
onUpdate(secondsSinceLastRun: number): Promise<boolean>;

View File

@ -1,5 +1,8 @@
import { IDialogueChatBot } from "@spt/helpers/Dialogue/IDialogueChatBot";
import { DialogueHelper } from "@spt/helpers/DialogueHelper";
import { NotificationSendHelper } from "@spt/helpers/NotificationSendHelper";
import { ProfileHelper } from "@spt/helpers/ProfileHelper";
import { IDeleteFriendRequest } from "@spt/models/eft/dialog/IDeleteFriendRequest";
import { IFriendRequestData } from "@spt/models/eft/dialog/IFriendRequestData";
import { IFriendRequestSendResponse } from "@spt/models/eft/dialog/IFriendRequestSendResponse";
import { IGetAllAttachmentsResponse } from "@spt/models/eft/dialog/IGetAllAttachmentsResponse";
@ -20,11 +23,13 @@ export declare class DialogueController {
protected saveServer: SaveServer;
protected timeUtil: TimeUtil;
protected dialogueHelper: DialogueHelper;
protected notificationSendHelper: NotificationSendHelper;
protected profileHelper: ProfileHelper;
protected mailSendService: MailSendService;
protected localisationService: LocalisationService;
protected configServer: ConfigServer;
protected dialogueChatBots: IDialogueChatBot[];
constructor(logger: ILogger, saveServer: SaveServer, timeUtil: TimeUtil, dialogueHelper: DialogueHelper, mailSendService: MailSendService, localisationService: LocalisationService, configServer: ConfigServer, dialogueChatBots: IDialogueChatBot[]);
constructor(logger: ILogger, saveServer: SaveServer, timeUtil: TimeUtil, dialogueHelper: DialogueHelper, notificationSendHelper: NotificationSendHelper, profileHelper: ProfileHelper, mailSendService: MailSendService, localisationService: LocalisationService, configServer: ConfigServer, dialogueChatBots: IDialogueChatBot[]);
registerChatBot(chatBot: IDialogueChatBot): void;
/** Handle onUpdate spt event */
update(): void;
@ -151,4 +156,6 @@ export declare class DialogueController {
protected messageHasExpired(message: IMessage): boolean;
/** Handle client/friend/request/send */
sendFriendRequest(sessionID: string, request: IFriendRequestData): IFriendRequestSendResponse;
/** Handle client/friend/delete */
deleteFriend(sessionID: string, request: IDeleteFriendRequest): void;
}

View File

@ -2,6 +2,7 @@ import { ItemHelper } from "@spt/helpers/ItemHelper";
import { IPmcData } from "@spt/models/eft/common/IPmcData";
import { Common, ICounterKeyValue, IStats } from "@spt/models/eft/common/tables/IBotBase";
import { IItem } from "@spt/models/eft/common/tables/IItem";
import { ISearchFriendResponse } from "@spt/models/eft/profile/ISearchFriendResponse";
import { ISptProfile } from "@spt/models/eft/profile/ISptProfile";
import { IValidateNicknameRequestData } from "@spt/models/eft/profile/IValidateNicknameRequestData";
import { BonusType } from "@spt/models/enums/BonusType";
@ -90,6 +91,24 @@ export declare class ProfileHelper {
* @returns ISptProfile object
*/
getFullProfile(sessionID: string): ISptProfile | undefined;
/**
* Get full representation of a players profile JSON by the account ID, or undefined if not found
* @param accountId Account ID to find
* @returns
*/
getFullProfileByAccountId(accountID: string): ISptProfile | undefined;
/**
* Retrieve a ChatRoomMember formatted profile for the given session ID
* @param sessionID The session ID to return the profile for
* @returns
*/
getChatRoomMemberFromSessionId(sessionID: string): ISearchFriendResponse | undefined;
/**
* Retrieve a ChatRoomMember formatted profile for the given PMC profile data
* @param pmcProfile The PMC profile data to format into a ChatRoomMember structure
* @returns
*/
getChatRoomMemberFromPmcProfile(pmcProfile: IPmcData): ISearchFriendResponse;
/**
* Get a PMC profile by its session id
* @param sessionID Profile id to return

View File

@ -8,4 +8,5 @@ export interface Info {
Side: string;
Level: number;
MemberCategory: number;
SelectedMemberCategory: number;
}

View File

@ -19,6 +19,8 @@ export interface ISptProfile {
traderPurchases?: Record<string, Record<string, ITraderPurchaseData>>;
/** Achievements earned by player */
achievements: Record<string, number>;
/** List of friend profile IDs */
friends: string[];
}
export declare class ITraderPurchaseData {
count: number;

View File

@ -0,0 +1,5 @@
import { IWsNotificationEvent } from "@spt/models/eft/ws/IWsNotificationEvent";
import { ISearchFriendResponse } from "../profile/ISearchFriendResponse";
export interface IWsFriendsListAccept extends IWsNotificationEvent {
profile: ISearchFriendResponse;
}

View File

@ -1,4 +1,4 @@
export interface IWsNotificationEvent {
type: string;
eventId: string;
eventId?: string;
}

View File

@ -1,5 +1,6 @@
export declare enum ConfigTypes {
AIRDROP = "spt-airdrop",
BACKUP = "spt-backup",
BOT = "spt-bot",
PMC = "spt-pmc",
CORE = "spt-core",

View File

@ -0,0 +1,12 @@
import { IBaseConfig } from "@spt/models/spt/config/IBaseConfig";
export interface IBackupConfig extends IBaseConfig {
kind: "spt-backup";
enabled: boolean;
maxBackups: number;
directory: string;
backupInterval: IBackupConfigInterval;
}
export interface IBackupConfigInterval {
enabled: boolean;
intervalMinutes: number;
}

View File

@ -0,0 +1,98 @@
import { PreSptModLoader } from "@spt/loaders/PreSptModLoader";
import { IBackupConfig } from "@spt/models/spt/config/IBackupConfig";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
export declare class BackupService {
protected logger: ILogger;
protected preSptModLoader: PreSptModLoader;
protected configServer: ConfigServer;
protected backupConfig: IBackupConfig;
protected readonly activeServerMods: string[];
protected readonly profileDir = "./user/profiles";
constructor(logger: ILogger, preSptModLoader: PreSptModLoader, configServer: ConfigServer);
/**
* Initializes the backup process.
*
* This method orchestrates the profile backup service. Handles copying profiles to a backup directory and cleaning
* up old backups if the number exceeds the configured maximum.
*
* @returns A promise that resolves when the backup process is complete.
*/
init(): Promise<void>;
/**
* Fetches the names of all JSON files in the profile directory.
*
* This method normalizes the profile directory path and reads all files within it. It then filters the files to
* include only those with a `.json` extension and returns their names.
*
* @returns A promise that resolves to an array of JSON file names.
*/
protected fetchProfileFiles(): Promise<string[]>;
/**
* Check to see if the backup service is enabled via the config.
*
* @returns True if enabled, false otherwise.
*/
protected isEnabled(): boolean;
/**
* Generates the target directory path for the backup. The directory path is constructed using the `directory` from
* the configuration and the current backup date.
*
* @returns The target directory path for the backup.
*/
protected generateBackupTargetDir(): string;
/**
* Generates a formatted backup date string in the format `YYYY-MM-DD_hh-mm-ss`.
*
* @returns The formatted backup date string.
*/
protected generateBackupDate(): string;
/**
* Cleans up old backups in the backup directory.
*
* This method reads the backup directory, and sorts backups by modification time. If the number of backups exceeds
* the configured maximum, it deletes the oldest backups.
*
* @returns A promise that resolves when the cleanup is complete.
*/
protected cleanBackups(): Promise<void>;
/**
* Retrieves and sorts the backup file paths from the specified directory.
*
* @param dir - The directory to search for backup files.
* @returns A promise that resolves to an array of sorted backup file paths.
*/
private getBackupPaths;
/**
* Compares two backup folder names based on their extracted dates.
*
* @param a - The name of the first backup folder.
* @param b - The name of the second backup folder.
* @returns The difference in time between the two dates in milliseconds, or `null` if either date is invalid.
*/
private compareBackupDates;
/**
* Extracts a date from a folder name string formatted as `YYYY-MM-DD_hh-mm-ss`.
*
* @param folderName - The name of the folder from which to extract the date.
* @returns A Date object if the folder name is in the correct format, otherwise null.
*/
private extractDateFromFolderName;
/**
* Removes excess backups from the backup directory.
*
* @param backups - An array of backup file names to be removed.
* @returns A promise that resolves when all specified backups have been removed.
*/
private removeExcessBackups;
/**
* Start the backup interval if enabled in the configuration.
*/
protected startBackupInterval(): void;
/**
* Get an array of active server mod details.
*
* @returns An array of mod names.
*/
protected getActiveServerMods(): string[];
}

View File

@ -3,11 +3,13 @@ import { OnUpdate } from "@spt/di/OnUpdate";
import { ICoreConfig } from "@spt/models/spt/config/ICoreConfig";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { SaveServer } from "@spt/servers/SaveServer";
import { BackupService } from "@spt/services/BackupService";
export declare class SaveCallbacks implements OnLoad, OnUpdate {
protected saveServer: SaveServer;
protected configServer: ConfigServer;
protected backupService: BackupService;
protected coreConfig: ICoreConfig;
constructor(saveServer: SaveServer, configServer: ConfigServer);
constructor(saveServer: SaveServer, configServer: ConfigServer, backupService: BackupService);
onLoad(): Promise<void>;
getRoute(): string;
onUpdate(secondsSinceLastRun: number): Promise<boolean>;

View File

@ -1,5 +1,8 @@
import { IDialogueChatBot } from "@spt/helpers/Dialogue/IDialogueChatBot";
import { DialogueHelper } from "@spt/helpers/DialogueHelper";
import { NotificationSendHelper } from "@spt/helpers/NotificationSendHelper";
import { ProfileHelper } from "@spt/helpers/ProfileHelper";
import { IDeleteFriendRequest } from "@spt/models/eft/dialog/IDeleteFriendRequest";
import { IFriendRequestData } from "@spt/models/eft/dialog/IFriendRequestData";
import { IFriendRequestSendResponse } from "@spt/models/eft/dialog/IFriendRequestSendResponse";
import { IGetAllAttachmentsResponse } from "@spt/models/eft/dialog/IGetAllAttachmentsResponse";
@ -20,11 +23,13 @@ export declare class DialogueController {
protected saveServer: SaveServer;
protected timeUtil: TimeUtil;
protected dialogueHelper: DialogueHelper;
protected notificationSendHelper: NotificationSendHelper;
protected profileHelper: ProfileHelper;
protected mailSendService: MailSendService;
protected localisationService: LocalisationService;
protected configServer: ConfigServer;
protected dialogueChatBots: IDialogueChatBot[];
constructor(logger: ILogger, saveServer: SaveServer, timeUtil: TimeUtil, dialogueHelper: DialogueHelper, mailSendService: MailSendService, localisationService: LocalisationService, configServer: ConfigServer, dialogueChatBots: IDialogueChatBot[]);
constructor(logger: ILogger, saveServer: SaveServer, timeUtil: TimeUtil, dialogueHelper: DialogueHelper, notificationSendHelper: NotificationSendHelper, profileHelper: ProfileHelper, mailSendService: MailSendService, localisationService: LocalisationService, configServer: ConfigServer, dialogueChatBots: IDialogueChatBot[]);
registerChatBot(chatBot: IDialogueChatBot): void;
/** Handle onUpdate spt event */
update(): void;
@ -151,4 +156,6 @@ export declare class DialogueController {
protected messageHasExpired(message: IMessage): boolean;
/** Handle client/friend/request/send */
sendFriendRequest(sessionID: string, request: IFriendRequestData): IFriendRequestSendResponse;
/** Handle client/friend/delete */
deleteFriend(sessionID: string, request: IDeleteFriendRequest): void;
}

View File

@ -2,6 +2,7 @@ import { ItemHelper } from "@spt/helpers/ItemHelper";
import { IPmcData } from "@spt/models/eft/common/IPmcData";
import { Common, ICounterKeyValue, IStats } from "@spt/models/eft/common/tables/IBotBase";
import { IItem } from "@spt/models/eft/common/tables/IItem";
import { ISearchFriendResponse } from "@spt/models/eft/profile/ISearchFriendResponse";
import { ISptProfile } from "@spt/models/eft/profile/ISptProfile";
import { IValidateNicknameRequestData } from "@spt/models/eft/profile/IValidateNicknameRequestData";
import { BonusType } from "@spt/models/enums/BonusType";
@ -90,6 +91,24 @@ export declare class ProfileHelper {
* @returns ISptProfile object
*/
getFullProfile(sessionID: string): ISptProfile | undefined;
/**
* Get full representation of a players profile JSON by the account ID, or undefined if not found
* @param accountId Account ID to find
* @returns
*/
getFullProfileByAccountId(accountID: string): ISptProfile | undefined;
/**
* Retrieve a ChatRoomMember formatted profile for the given session ID
* @param sessionID The session ID to return the profile for
* @returns
*/
getChatRoomMemberFromSessionId(sessionID: string): ISearchFriendResponse | undefined;
/**
* Retrieve a ChatRoomMember formatted profile for the given PMC profile data
* @param pmcProfile The PMC profile data to format into a ChatRoomMember structure
* @returns
*/
getChatRoomMemberFromPmcProfile(pmcProfile: IPmcData): ISearchFriendResponse;
/**
* Get a PMC profile by its session id
* @param sessionID Profile id to return

View File

@ -8,4 +8,5 @@ export interface Info {
Side: string;
Level: number;
MemberCategory: number;
SelectedMemberCategory: number;
}

View File

@ -19,6 +19,8 @@ export interface ISptProfile {
traderPurchases?: Record<string, Record<string, ITraderPurchaseData>>;
/** Achievements earned by player */
achievements: Record<string, number>;
/** List of friend profile IDs */
friends: string[];
}
export declare class ITraderPurchaseData {
count: number;

View File

@ -0,0 +1,5 @@
import { IWsNotificationEvent } from "@spt/models/eft/ws/IWsNotificationEvent";
import { ISearchFriendResponse } from "../profile/ISearchFriendResponse";
export interface IWsFriendsListAccept extends IWsNotificationEvent {
profile: ISearchFriendResponse;
}

View File

@ -1,4 +1,4 @@
export interface IWsNotificationEvent {
type: string;
eventId: string;
eventId?: string;
}

View File

@ -1,5 +1,6 @@
export declare enum ConfigTypes {
AIRDROP = "spt-airdrop",
BACKUP = "spt-backup",
BOT = "spt-bot",
PMC = "spt-pmc",
CORE = "spt-core",

View File

@ -0,0 +1,12 @@
import { IBaseConfig } from "@spt/models/spt/config/IBaseConfig";
export interface IBackupConfig extends IBaseConfig {
kind: "spt-backup";
enabled: boolean;
maxBackups: number;
directory: string;
backupInterval: IBackupConfigInterval;
}
export interface IBackupConfigInterval {
enabled: boolean;
intervalMinutes: number;
}

View File

@ -0,0 +1,98 @@
import { PreSptModLoader } from "@spt/loaders/PreSptModLoader";
import { IBackupConfig } from "@spt/models/spt/config/IBackupConfig";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
export declare class BackupService {
protected logger: ILogger;
protected preSptModLoader: PreSptModLoader;
protected configServer: ConfigServer;
protected backupConfig: IBackupConfig;
protected readonly activeServerMods: string[];
protected readonly profileDir = "./user/profiles";
constructor(logger: ILogger, preSptModLoader: PreSptModLoader, configServer: ConfigServer);
/**
* Initializes the backup process.
*
* This method orchestrates the profile backup service. Handles copying profiles to a backup directory and cleaning
* up old backups if the number exceeds the configured maximum.
*
* @returns A promise that resolves when the backup process is complete.
*/
init(): Promise<void>;
/**
* Fetches the names of all JSON files in the profile directory.
*
* This method normalizes the profile directory path and reads all files within it. It then filters the files to
* include only those with a `.json` extension and returns their names.
*
* @returns A promise that resolves to an array of JSON file names.
*/
protected fetchProfileFiles(): Promise<string[]>;
/**
* Check to see if the backup service is enabled via the config.
*
* @returns True if enabled, false otherwise.
*/
protected isEnabled(): boolean;
/**
* Generates the target directory path for the backup. The directory path is constructed using the `directory` from
* the configuration and the current backup date.
*
* @returns The target directory path for the backup.
*/
protected generateBackupTargetDir(): string;
/**
* Generates a formatted backup date string in the format `YYYY-MM-DD_hh-mm-ss`.
*
* @returns The formatted backup date string.
*/
protected generateBackupDate(): string;
/**
* Cleans up old backups in the backup directory.
*
* This method reads the backup directory, and sorts backups by modification time. If the number of backups exceeds
* the configured maximum, it deletes the oldest backups.
*
* @returns A promise that resolves when the cleanup is complete.
*/
protected cleanBackups(): Promise<void>;
/**
* Retrieves and sorts the backup file paths from the specified directory.
*
* @param dir - The directory to search for backup files.
* @returns A promise that resolves to an array of sorted backup file paths.
*/
private getBackupPaths;
/**
* Compares two backup folder names based on their extracted dates.
*
* @param a - The name of the first backup folder.
* @param b - The name of the second backup folder.
* @returns The difference in time between the two dates in milliseconds, or `null` if either date is invalid.
*/
private compareBackupDates;
/**
* Extracts a date from a folder name string formatted as `YYYY-MM-DD_hh-mm-ss`.
*
* @param folderName - The name of the folder from which to extract the date.
* @returns A Date object if the folder name is in the correct format, otherwise null.
*/
private extractDateFromFolderName;
/**
* Removes excess backups from the backup directory.
*
* @param backups - An array of backup file names to be removed.
* @returns A promise that resolves when all specified backups have been removed.
*/
private removeExcessBackups;
/**
* Start the backup interval if enabled in the configuration.
*/
protected startBackupInterval(): void;
/**
* Get an array of active server mod details.
*
* @returns An array of mod names.
*/
protected getActiveServerMods(): string[];
}

View File

@ -3,11 +3,13 @@ import { OnUpdate } from "@spt/di/OnUpdate";
import { ICoreConfig } from "@spt/models/spt/config/ICoreConfig";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { SaveServer } from "@spt/servers/SaveServer";
import { BackupService } from "@spt/services/BackupService";
export declare class SaveCallbacks implements OnLoad, OnUpdate {
protected saveServer: SaveServer;
protected configServer: ConfigServer;
protected backupService: BackupService;
protected coreConfig: ICoreConfig;
constructor(saveServer: SaveServer, configServer: ConfigServer);
constructor(saveServer: SaveServer, configServer: ConfigServer, backupService: BackupService);
onLoad(): Promise<void>;
getRoute(): string;
onUpdate(secondsSinceLastRun: number): Promise<boolean>;

View File

@ -1,5 +1,8 @@
import { IDialogueChatBot } from "@spt/helpers/Dialogue/IDialogueChatBot";
import { DialogueHelper } from "@spt/helpers/DialogueHelper";
import { NotificationSendHelper } from "@spt/helpers/NotificationSendHelper";
import { ProfileHelper } from "@spt/helpers/ProfileHelper";
import { IDeleteFriendRequest } from "@spt/models/eft/dialog/IDeleteFriendRequest";
import { IFriendRequestData } from "@spt/models/eft/dialog/IFriendRequestData";
import { IFriendRequestSendResponse } from "@spt/models/eft/dialog/IFriendRequestSendResponse";
import { IGetAllAttachmentsResponse } from "@spt/models/eft/dialog/IGetAllAttachmentsResponse";
@ -20,11 +23,13 @@ export declare class DialogueController {
protected saveServer: SaveServer;
protected timeUtil: TimeUtil;
protected dialogueHelper: DialogueHelper;
protected notificationSendHelper: NotificationSendHelper;
protected profileHelper: ProfileHelper;
protected mailSendService: MailSendService;
protected localisationService: LocalisationService;
protected configServer: ConfigServer;
protected dialogueChatBots: IDialogueChatBot[];
constructor(logger: ILogger, saveServer: SaveServer, timeUtil: TimeUtil, dialogueHelper: DialogueHelper, mailSendService: MailSendService, localisationService: LocalisationService, configServer: ConfigServer, dialogueChatBots: IDialogueChatBot[]);
constructor(logger: ILogger, saveServer: SaveServer, timeUtil: TimeUtil, dialogueHelper: DialogueHelper, notificationSendHelper: NotificationSendHelper, profileHelper: ProfileHelper, mailSendService: MailSendService, localisationService: LocalisationService, configServer: ConfigServer, dialogueChatBots: IDialogueChatBot[]);
registerChatBot(chatBot: IDialogueChatBot): void;
/** Handle onUpdate spt event */
update(): void;
@ -151,4 +156,6 @@ export declare class DialogueController {
protected messageHasExpired(message: IMessage): boolean;
/** Handle client/friend/request/send */
sendFriendRequest(sessionID: string, request: IFriendRequestData): IFriendRequestSendResponse;
/** Handle client/friend/delete */
deleteFriend(sessionID: string, request: IDeleteFriendRequest): void;
}

View File

@ -2,6 +2,7 @@ import { ItemHelper } from "@spt/helpers/ItemHelper";
import { IPmcData } from "@spt/models/eft/common/IPmcData";
import { Common, ICounterKeyValue, IStats } from "@spt/models/eft/common/tables/IBotBase";
import { IItem } from "@spt/models/eft/common/tables/IItem";
import { ISearchFriendResponse } from "@spt/models/eft/profile/ISearchFriendResponse";
import { ISptProfile } from "@spt/models/eft/profile/ISptProfile";
import { IValidateNicknameRequestData } from "@spt/models/eft/profile/IValidateNicknameRequestData";
import { BonusType } from "@spt/models/enums/BonusType";
@ -90,6 +91,24 @@ export declare class ProfileHelper {
* @returns ISptProfile object
*/
getFullProfile(sessionID: string): ISptProfile | undefined;
/**
* Get full representation of a players profile JSON by the account ID, or undefined if not found
* @param accountId Account ID to find
* @returns
*/
getFullProfileByAccountId(accountID: string): ISptProfile | undefined;
/**
* Retrieve a ChatRoomMember formatted profile for the given session ID
* @param sessionID The session ID to return the profile for
* @returns
*/
getChatRoomMemberFromSessionId(sessionID: string): ISearchFriendResponse | undefined;
/**
* Retrieve a ChatRoomMember formatted profile for the given PMC profile data
* @param pmcProfile The PMC profile data to format into a ChatRoomMember structure
* @returns
*/
getChatRoomMemberFromPmcProfile(pmcProfile: IPmcData): ISearchFriendResponse;
/**
* Get a PMC profile by its session id
* @param sessionID Profile id to return

View File

@ -8,4 +8,5 @@ export interface Info {
Side: string;
Level: number;
MemberCategory: number;
SelectedMemberCategory: number;
}

View File

@ -19,6 +19,8 @@ export interface ISptProfile {
traderPurchases?: Record<string, Record<string, ITraderPurchaseData>>;
/** Achievements earned by player */
achievements: Record<string, number>;
/** List of friend profile IDs */
friends: string[];
}
export declare class ITraderPurchaseData {
count: number;

View File

@ -0,0 +1,5 @@
import { IWsNotificationEvent } from "@spt/models/eft/ws/IWsNotificationEvent";
import { ISearchFriendResponse } from "../profile/ISearchFriendResponse";
export interface IWsFriendsListAccept extends IWsNotificationEvent {
profile: ISearchFriendResponse;
}

View File

@ -1,4 +1,4 @@
export interface IWsNotificationEvent {
type: string;
eventId: string;
eventId?: string;
}

View File

@ -1,5 +1,6 @@
export declare enum ConfigTypes {
AIRDROP = "spt-airdrop",
BACKUP = "spt-backup",
BOT = "spt-bot",
PMC = "spt-pmc",
CORE = "spt-core",

View File

@ -0,0 +1,12 @@
import { IBaseConfig } from "@spt/models/spt/config/IBaseConfig";
export interface IBackupConfig extends IBaseConfig {
kind: "spt-backup";
enabled: boolean;
maxBackups: number;
directory: string;
backupInterval: IBackupConfigInterval;
}
export interface IBackupConfigInterval {
enabled: boolean;
intervalMinutes: number;
}

View File

@ -0,0 +1,98 @@
import { PreSptModLoader } from "@spt/loaders/PreSptModLoader";
import { IBackupConfig } from "@spt/models/spt/config/IBackupConfig";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
export declare class BackupService {
protected logger: ILogger;
protected preSptModLoader: PreSptModLoader;
protected configServer: ConfigServer;
protected backupConfig: IBackupConfig;
protected readonly activeServerMods: string[];
protected readonly profileDir = "./user/profiles";
constructor(logger: ILogger, preSptModLoader: PreSptModLoader, configServer: ConfigServer);
/**
* Initializes the backup process.
*
* This method orchestrates the profile backup service. Handles copying profiles to a backup directory and cleaning
* up old backups if the number exceeds the configured maximum.
*
* @returns A promise that resolves when the backup process is complete.
*/
init(): Promise<void>;
/**
* Fetches the names of all JSON files in the profile directory.
*
* This method normalizes the profile directory path and reads all files within it. It then filters the files to
* include only those with a `.json` extension and returns their names.
*
* @returns A promise that resolves to an array of JSON file names.
*/
protected fetchProfileFiles(): Promise<string[]>;
/**
* Check to see if the backup service is enabled via the config.
*
* @returns True if enabled, false otherwise.
*/
protected isEnabled(): boolean;
/**
* Generates the target directory path for the backup. The directory path is constructed using the `directory` from
* the configuration and the current backup date.
*
* @returns The target directory path for the backup.
*/
protected generateBackupTargetDir(): string;
/**
* Generates a formatted backup date string in the format `YYYY-MM-DD_hh-mm-ss`.
*
* @returns The formatted backup date string.
*/
protected generateBackupDate(): string;
/**
* Cleans up old backups in the backup directory.
*
* This method reads the backup directory, and sorts backups by modification time. If the number of backups exceeds
* the configured maximum, it deletes the oldest backups.
*
* @returns A promise that resolves when the cleanup is complete.
*/
protected cleanBackups(): Promise<void>;
/**
* Retrieves and sorts the backup file paths from the specified directory.
*
* @param dir - The directory to search for backup files.
* @returns A promise that resolves to an array of sorted backup file paths.
*/
private getBackupPaths;
/**
* Compares two backup folder names based on their extracted dates.
*
* @param a - The name of the first backup folder.
* @param b - The name of the second backup folder.
* @returns The difference in time between the two dates in milliseconds, or `null` if either date is invalid.
*/
private compareBackupDates;
/**
* Extracts a date from a folder name string formatted as `YYYY-MM-DD_hh-mm-ss`.
*
* @param folderName - The name of the folder from which to extract the date.
* @returns A Date object if the folder name is in the correct format, otherwise null.
*/
private extractDateFromFolderName;
/**
* Removes excess backups from the backup directory.
*
* @param backups - An array of backup file names to be removed.
* @returns A promise that resolves when all specified backups have been removed.
*/
private removeExcessBackups;
/**
* Start the backup interval if enabled in the configuration.
*/
protected startBackupInterval(): void;
/**
* Get an array of active server mod details.
*
* @returns An array of mod names.
*/
protected getActiveServerMods(): string[];
}

View File

@ -3,11 +3,13 @@ import { OnUpdate } from "@spt/di/OnUpdate";
import { ICoreConfig } from "@spt/models/spt/config/ICoreConfig";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { SaveServer } from "@spt/servers/SaveServer";
import { BackupService } from "@spt/services/BackupService";
export declare class SaveCallbacks implements OnLoad, OnUpdate {
protected saveServer: SaveServer;
protected configServer: ConfigServer;
protected backupService: BackupService;
protected coreConfig: ICoreConfig;
constructor(saveServer: SaveServer, configServer: ConfigServer);
constructor(saveServer: SaveServer, configServer: ConfigServer, backupService: BackupService);
onLoad(): Promise<void>;
getRoute(): string;
onUpdate(secondsSinceLastRun: number): Promise<boolean>;

View File

@ -1,5 +1,8 @@
import { IDialogueChatBot } from "@spt/helpers/Dialogue/IDialogueChatBot";
import { DialogueHelper } from "@spt/helpers/DialogueHelper";
import { NotificationSendHelper } from "@spt/helpers/NotificationSendHelper";
import { ProfileHelper } from "@spt/helpers/ProfileHelper";
import { IDeleteFriendRequest } from "@spt/models/eft/dialog/IDeleteFriendRequest";
import { IFriendRequestData } from "@spt/models/eft/dialog/IFriendRequestData";
import { IFriendRequestSendResponse } from "@spt/models/eft/dialog/IFriendRequestSendResponse";
import { IGetAllAttachmentsResponse } from "@spt/models/eft/dialog/IGetAllAttachmentsResponse";
@ -20,11 +23,13 @@ export declare class DialogueController {
protected saveServer: SaveServer;
protected timeUtil: TimeUtil;
protected dialogueHelper: DialogueHelper;
protected notificationSendHelper: NotificationSendHelper;
protected profileHelper: ProfileHelper;
protected mailSendService: MailSendService;
protected localisationService: LocalisationService;
protected configServer: ConfigServer;
protected dialogueChatBots: IDialogueChatBot[];
constructor(logger: ILogger, saveServer: SaveServer, timeUtil: TimeUtil, dialogueHelper: DialogueHelper, mailSendService: MailSendService, localisationService: LocalisationService, configServer: ConfigServer, dialogueChatBots: IDialogueChatBot[]);
constructor(logger: ILogger, saveServer: SaveServer, timeUtil: TimeUtil, dialogueHelper: DialogueHelper, notificationSendHelper: NotificationSendHelper, profileHelper: ProfileHelper, mailSendService: MailSendService, localisationService: LocalisationService, configServer: ConfigServer, dialogueChatBots: IDialogueChatBot[]);
registerChatBot(chatBot: IDialogueChatBot): void;
/** Handle onUpdate spt event */
update(): void;
@ -151,4 +156,6 @@ export declare class DialogueController {
protected messageHasExpired(message: IMessage): boolean;
/** Handle client/friend/request/send */
sendFriendRequest(sessionID: string, request: IFriendRequestData): IFriendRequestSendResponse;
/** Handle client/friend/delete */
deleteFriend(sessionID: string, request: IDeleteFriendRequest): void;
}

View File

@ -2,6 +2,7 @@ import { ItemHelper } from "@spt/helpers/ItemHelper";
import { IPmcData } from "@spt/models/eft/common/IPmcData";
import { Common, ICounterKeyValue, IStats } from "@spt/models/eft/common/tables/IBotBase";
import { IItem } from "@spt/models/eft/common/tables/IItem";
import { ISearchFriendResponse } from "@spt/models/eft/profile/ISearchFriendResponse";
import { ISptProfile } from "@spt/models/eft/profile/ISptProfile";
import { IValidateNicknameRequestData } from "@spt/models/eft/profile/IValidateNicknameRequestData";
import { BonusType } from "@spt/models/enums/BonusType";
@ -90,6 +91,24 @@ export declare class ProfileHelper {
* @returns ISptProfile object
*/
getFullProfile(sessionID: string): ISptProfile | undefined;
/**
* Get full representation of a players profile JSON by the account ID, or undefined if not found
* @param accountId Account ID to find
* @returns
*/
getFullProfileByAccountId(accountID: string): ISptProfile | undefined;
/**
* Retrieve a ChatRoomMember formatted profile for the given session ID
* @param sessionID The session ID to return the profile for
* @returns
*/
getChatRoomMemberFromSessionId(sessionID: string): ISearchFriendResponse | undefined;
/**
* Retrieve a ChatRoomMember formatted profile for the given PMC profile data
* @param pmcProfile The PMC profile data to format into a ChatRoomMember structure
* @returns
*/
getChatRoomMemberFromPmcProfile(pmcProfile: IPmcData): ISearchFriendResponse;
/**
* Get a PMC profile by its session id
* @param sessionID Profile id to return

View File

@ -8,4 +8,5 @@ export interface Info {
Side: string;
Level: number;
MemberCategory: number;
SelectedMemberCategory: number;
}

View File

@ -19,6 +19,8 @@ export interface ISptProfile {
traderPurchases?: Record<string, Record<string, ITraderPurchaseData>>;
/** Achievements earned by player */
achievements: Record<string, number>;
/** List of friend profile IDs */
friends: string[];
}
export declare class ITraderPurchaseData {
count: number;

View File

@ -0,0 +1,5 @@
import { IWsNotificationEvent } from "@spt/models/eft/ws/IWsNotificationEvent";
import { ISearchFriendResponse } from "../profile/ISearchFriendResponse";
export interface IWsFriendsListAccept extends IWsNotificationEvent {
profile: ISearchFriendResponse;
}

View File

@ -1,4 +1,4 @@
export interface IWsNotificationEvent {
type: string;
eventId: string;
eventId?: string;
}

View File

@ -1,5 +1,6 @@
export declare enum ConfigTypes {
AIRDROP = "spt-airdrop",
BACKUP = "spt-backup",
BOT = "spt-bot",
PMC = "spt-pmc",
CORE = "spt-core",

View File

@ -0,0 +1,12 @@
import { IBaseConfig } from "@spt/models/spt/config/IBaseConfig";
export interface IBackupConfig extends IBaseConfig {
kind: "spt-backup";
enabled: boolean;
maxBackups: number;
directory: string;
backupInterval: IBackupConfigInterval;
}
export interface IBackupConfigInterval {
enabled: boolean;
intervalMinutes: number;
}

View File

@ -0,0 +1,98 @@
import { PreSptModLoader } from "@spt/loaders/PreSptModLoader";
import { IBackupConfig } from "@spt/models/spt/config/IBackupConfig";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
export declare class BackupService {
protected logger: ILogger;
protected preSptModLoader: PreSptModLoader;
protected configServer: ConfigServer;
protected backupConfig: IBackupConfig;
protected readonly activeServerMods: string[];
protected readonly profileDir = "./user/profiles";
constructor(logger: ILogger, preSptModLoader: PreSptModLoader, configServer: ConfigServer);
/**
* Initializes the backup process.
*
* This method orchestrates the profile backup service. Handles copying profiles to a backup directory and cleaning
* up old backups if the number exceeds the configured maximum.
*
* @returns A promise that resolves when the backup process is complete.
*/
init(): Promise<void>;
/**
* Fetches the names of all JSON files in the profile directory.
*
* This method normalizes the profile directory path and reads all files within it. It then filters the files to
* include only those with a `.json` extension and returns their names.
*
* @returns A promise that resolves to an array of JSON file names.
*/
protected fetchProfileFiles(): Promise<string[]>;
/**
* Check to see if the backup service is enabled via the config.
*
* @returns True if enabled, false otherwise.
*/
protected isEnabled(): boolean;
/**
* Generates the target directory path for the backup. The directory path is constructed using the `directory` from
* the configuration and the current backup date.
*
* @returns The target directory path for the backup.
*/
protected generateBackupTargetDir(): string;
/**
* Generates a formatted backup date string in the format `YYYY-MM-DD_hh-mm-ss`.
*
* @returns The formatted backup date string.
*/
protected generateBackupDate(): string;
/**
* Cleans up old backups in the backup directory.
*
* This method reads the backup directory, and sorts backups by modification time. If the number of backups exceeds
* the configured maximum, it deletes the oldest backups.
*
* @returns A promise that resolves when the cleanup is complete.
*/
protected cleanBackups(): Promise<void>;
/**
* Retrieves and sorts the backup file paths from the specified directory.
*
* @param dir - The directory to search for backup files.
* @returns A promise that resolves to an array of sorted backup file paths.
*/
private getBackupPaths;
/**
* Compares two backup folder names based on their extracted dates.
*
* @param a - The name of the first backup folder.
* @param b - The name of the second backup folder.
* @returns The difference in time between the two dates in milliseconds, or `null` if either date is invalid.
*/
private compareBackupDates;
/**
* Extracts a date from a folder name string formatted as `YYYY-MM-DD_hh-mm-ss`.
*
* @param folderName - The name of the folder from which to extract the date.
* @returns A Date object if the folder name is in the correct format, otherwise null.
*/
private extractDateFromFolderName;
/**
* Removes excess backups from the backup directory.
*
* @param backups - An array of backup file names to be removed.
* @returns A promise that resolves when all specified backups have been removed.
*/
private removeExcessBackups;
/**
* Start the backup interval if enabled in the configuration.
*/
protected startBackupInterval(): void;
/**
* Get an array of active server mod details.
*
* @returns An array of mod names.
*/
protected getActiveServerMods(): string[];
}

View File

@ -3,11 +3,13 @@ import { OnUpdate } from "@spt/di/OnUpdate";
import { ICoreConfig } from "@spt/models/spt/config/ICoreConfig";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { SaveServer } from "@spt/servers/SaveServer";
import { BackupService } from "@spt/services/BackupService";
export declare class SaveCallbacks implements OnLoad, OnUpdate {
protected saveServer: SaveServer;
protected configServer: ConfigServer;
protected backupService: BackupService;
protected coreConfig: ICoreConfig;
constructor(saveServer: SaveServer, configServer: ConfigServer);
constructor(saveServer: SaveServer, configServer: ConfigServer, backupService: BackupService);
onLoad(): Promise<void>;
getRoute(): string;
onUpdate(secondsSinceLastRun: number): Promise<boolean>;

View File

@ -1,5 +1,8 @@
import { IDialogueChatBot } from "@spt/helpers/Dialogue/IDialogueChatBot";
import { DialogueHelper } from "@spt/helpers/DialogueHelper";
import { NotificationSendHelper } from "@spt/helpers/NotificationSendHelper";
import { ProfileHelper } from "@spt/helpers/ProfileHelper";
import { IDeleteFriendRequest } from "@spt/models/eft/dialog/IDeleteFriendRequest";
import { IFriendRequestData } from "@spt/models/eft/dialog/IFriendRequestData";
import { IFriendRequestSendResponse } from "@spt/models/eft/dialog/IFriendRequestSendResponse";
import { IGetAllAttachmentsResponse } from "@spt/models/eft/dialog/IGetAllAttachmentsResponse";
@ -20,11 +23,13 @@ export declare class DialogueController {
protected saveServer: SaveServer;
protected timeUtil: TimeUtil;
protected dialogueHelper: DialogueHelper;
protected notificationSendHelper: NotificationSendHelper;
protected profileHelper: ProfileHelper;
protected mailSendService: MailSendService;
protected localisationService: LocalisationService;
protected configServer: ConfigServer;
protected dialogueChatBots: IDialogueChatBot[];
constructor(logger: ILogger, saveServer: SaveServer, timeUtil: TimeUtil, dialogueHelper: DialogueHelper, mailSendService: MailSendService, localisationService: LocalisationService, configServer: ConfigServer, dialogueChatBots: IDialogueChatBot[]);
constructor(logger: ILogger, saveServer: SaveServer, timeUtil: TimeUtil, dialogueHelper: DialogueHelper, notificationSendHelper: NotificationSendHelper, profileHelper: ProfileHelper, mailSendService: MailSendService, localisationService: LocalisationService, configServer: ConfigServer, dialogueChatBots: IDialogueChatBot[]);
registerChatBot(chatBot: IDialogueChatBot): void;
/** Handle onUpdate spt event */
update(): void;
@ -151,4 +156,6 @@ export declare class DialogueController {
protected messageHasExpired(message: IMessage): boolean;
/** Handle client/friend/request/send */
sendFriendRequest(sessionID: string, request: IFriendRequestData): IFriendRequestSendResponse;
/** Handle client/friend/delete */
deleteFriend(sessionID: string, request: IDeleteFriendRequest): void;
}

View File

@ -2,6 +2,7 @@ import { ItemHelper } from "@spt/helpers/ItemHelper";
import { IPmcData } from "@spt/models/eft/common/IPmcData";
import { Common, ICounterKeyValue, IStats } from "@spt/models/eft/common/tables/IBotBase";
import { IItem } from "@spt/models/eft/common/tables/IItem";
import { ISearchFriendResponse } from "@spt/models/eft/profile/ISearchFriendResponse";
import { ISptProfile } from "@spt/models/eft/profile/ISptProfile";
import { IValidateNicknameRequestData } from "@spt/models/eft/profile/IValidateNicknameRequestData";
import { BonusType } from "@spt/models/enums/BonusType";
@ -90,6 +91,24 @@ export declare class ProfileHelper {
* @returns ISptProfile object
*/
getFullProfile(sessionID: string): ISptProfile | undefined;
/**
* Get full representation of a players profile JSON by the account ID, or undefined if not found
* @param accountId Account ID to find
* @returns
*/
getFullProfileByAccountId(accountID: string): ISptProfile | undefined;
/**
* Retrieve a ChatRoomMember formatted profile for the given session ID
* @param sessionID The session ID to return the profile for
* @returns
*/
getChatRoomMemberFromSessionId(sessionID: string): ISearchFriendResponse | undefined;
/**
* Retrieve a ChatRoomMember formatted profile for the given PMC profile data
* @param pmcProfile The PMC profile data to format into a ChatRoomMember structure
* @returns
*/
getChatRoomMemberFromPmcProfile(pmcProfile: IPmcData): ISearchFriendResponse;
/**
* Get a PMC profile by its session id
* @param sessionID Profile id to return

View File

@ -8,4 +8,5 @@ export interface Info {
Side: string;
Level: number;
MemberCategory: number;
SelectedMemberCategory: number;
}

View File

@ -19,6 +19,8 @@ export interface ISptProfile {
traderPurchases?: Record<string, Record<string, ITraderPurchaseData>>;
/** Achievements earned by player */
achievements: Record<string, number>;
/** List of friend profile IDs */
friends: string[];
}
export declare class ITraderPurchaseData {
count: number;

View File

@ -0,0 +1,5 @@
import { IWsNotificationEvent } from "@spt/models/eft/ws/IWsNotificationEvent";
import { ISearchFriendResponse } from "../profile/ISearchFriendResponse";
export interface IWsFriendsListAccept extends IWsNotificationEvent {
profile: ISearchFriendResponse;
}

View File

@ -1,4 +1,4 @@
export interface IWsNotificationEvent {
type: string;
eventId: string;
eventId?: string;
}

View File

@ -1,5 +1,6 @@
export declare enum ConfigTypes {
AIRDROP = "spt-airdrop",
BACKUP = "spt-backup",
BOT = "spt-bot",
PMC = "spt-pmc",
CORE = "spt-core",

View File

@ -0,0 +1,12 @@
import { IBaseConfig } from "@spt/models/spt/config/IBaseConfig";
export interface IBackupConfig extends IBaseConfig {
kind: "spt-backup";
enabled: boolean;
maxBackups: number;
directory: string;
backupInterval: IBackupConfigInterval;
}
export interface IBackupConfigInterval {
enabled: boolean;
intervalMinutes: number;
}

View File

@ -0,0 +1,98 @@
import { PreSptModLoader } from "@spt/loaders/PreSptModLoader";
import { IBackupConfig } from "@spt/models/spt/config/IBackupConfig";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
export declare class BackupService {
protected logger: ILogger;
protected preSptModLoader: PreSptModLoader;
protected configServer: ConfigServer;
protected backupConfig: IBackupConfig;
protected readonly activeServerMods: string[];
protected readonly profileDir = "./user/profiles";
constructor(logger: ILogger, preSptModLoader: PreSptModLoader, configServer: ConfigServer);
/**
* Initializes the backup process.
*
* This method orchestrates the profile backup service. Handles copying profiles to a backup directory and cleaning
* up old backups if the number exceeds the configured maximum.
*
* @returns A promise that resolves when the backup process is complete.
*/
init(): Promise<void>;
/**
* Fetches the names of all JSON files in the profile directory.
*
* This method normalizes the profile directory path and reads all files within it. It then filters the files to
* include only those with a `.json` extension and returns their names.
*
* @returns A promise that resolves to an array of JSON file names.
*/
protected fetchProfileFiles(): Promise<string[]>;
/**
* Check to see if the backup service is enabled via the config.
*
* @returns True if enabled, false otherwise.
*/
protected isEnabled(): boolean;
/**
* Generates the target directory path for the backup. The directory path is constructed using the `directory` from
* the configuration and the current backup date.
*
* @returns The target directory path for the backup.
*/
protected generateBackupTargetDir(): string;
/**
* Generates a formatted backup date string in the format `YYYY-MM-DD_hh-mm-ss`.
*
* @returns The formatted backup date string.
*/
protected generateBackupDate(): string;
/**
* Cleans up old backups in the backup directory.
*
* This method reads the backup directory, and sorts backups by modification time. If the number of backups exceeds
* the configured maximum, it deletes the oldest backups.
*
* @returns A promise that resolves when the cleanup is complete.
*/
protected cleanBackups(): Promise<void>;
/**
* Retrieves and sorts the backup file paths from the specified directory.
*
* @param dir - The directory to search for backup files.
* @returns A promise that resolves to an array of sorted backup file paths.
*/
private getBackupPaths;
/**
* Compares two backup folder names based on their extracted dates.
*
* @param a - The name of the first backup folder.
* @param b - The name of the second backup folder.
* @returns The difference in time between the two dates in milliseconds, or `null` if either date is invalid.
*/
private compareBackupDates;
/**
* Extracts a date from a folder name string formatted as `YYYY-MM-DD_hh-mm-ss`.
*
* @param folderName - The name of the folder from which to extract the date.
* @returns A Date object if the folder name is in the correct format, otherwise null.
*/
private extractDateFromFolderName;
/**
* Removes excess backups from the backup directory.
*
* @param backups - An array of backup file names to be removed.
* @returns A promise that resolves when all specified backups have been removed.
*/
private removeExcessBackups;
/**
* Start the backup interval if enabled in the configuration.
*/
protected startBackupInterval(): void;
/**
* Get an array of active server mod details.
*
* @returns An array of mod names.
*/
protected getActiveServerMods(): string[];
}

View File

@ -3,11 +3,13 @@ import { OnUpdate } from "@spt/di/OnUpdate";
import { ICoreConfig } from "@spt/models/spt/config/ICoreConfig";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { SaveServer } from "@spt/servers/SaveServer";
import { BackupService } from "@spt/services/BackupService";
export declare class SaveCallbacks implements OnLoad, OnUpdate {
protected saveServer: SaveServer;
protected configServer: ConfigServer;
protected backupService: BackupService;
protected coreConfig: ICoreConfig;
constructor(saveServer: SaveServer, configServer: ConfigServer);
constructor(saveServer: SaveServer, configServer: ConfigServer, backupService: BackupService);
onLoad(): Promise<void>;
getRoute(): string;
onUpdate(secondsSinceLastRun: number): Promise<boolean>;

View File

@ -1,5 +1,8 @@
import { IDialogueChatBot } from "@spt/helpers/Dialogue/IDialogueChatBot";
import { DialogueHelper } from "@spt/helpers/DialogueHelper";
import { NotificationSendHelper } from "@spt/helpers/NotificationSendHelper";
import { ProfileHelper } from "@spt/helpers/ProfileHelper";
import { IDeleteFriendRequest } from "@spt/models/eft/dialog/IDeleteFriendRequest";
import { IFriendRequestData } from "@spt/models/eft/dialog/IFriendRequestData";
import { IFriendRequestSendResponse } from "@spt/models/eft/dialog/IFriendRequestSendResponse";
import { IGetAllAttachmentsResponse } from "@spt/models/eft/dialog/IGetAllAttachmentsResponse";
@ -20,11 +23,13 @@ export declare class DialogueController {
protected saveServer: SaveServer;
protected timeUtil: TimeUtil;
protected dialogueHelper: DialogueHelper;
protected notificationSendHelper: NotificationSendHelper;
protected profileHelper: ProfileHelper;
protected mailSendService: MailSendService;
protected localisationService: LocalisationService;
protected configServer: ConfigServer;
protected dialogueChatBots: IDialogueChatBot[];
constructor(logger: ILogger, saveServer: SaveServer, timeUtil: TimeUtil, dialogueHelper: DialogueHelper, mailSendService: MailSendService, localisationService: LocalisationService, configServer: ConfigServer, dialogueChatBots: IDialogueChatBot[]);
constructor(logger: ILogger, saveServer: SaveServer, timeUtil: TimeUtil, dialogueHelper: DialogueHelper, notificationSendHelper: NotificationSendHelper, profileHelper: ProfileHelper, mailSendService: MailSendService, localisationService: LocalisationService, configServer: ConfigServer, dialogueChatBots: IDialogueChatBot[]);
registerChatBot(chatBot: IDialogueChatBot): void;
/** Handle onUpdate spt event */
update(): void;
@ -151,4 +156,6 @@ export declare class DialogueController {
protected messageHasExpired(message: IMessage): boolean;
/** Handle client/friend/request/send */
sendFriendRequest(sessionID: string, request: IFriendRequestData): IFriendRequestSendResponse;
/** Handle client/friend/delete */
deleteFriend(sessionID: string, request: IDeleteFriendRequest): void;
}

View File

@ -2,6 +2,7 @@ import { ItemHelper } from "@spt/helpers/ItemHelper";
import { IPmcData } from "@spt/models/eft/common/IPmcData";
import { Common, ICounterKeyValue, IStats } from "@spt/models/eft/common/tables/IBotBase";
import { IItem } from "@spt/models/eft/common/tables/IItem";
import { ISearchFriendResponse } from "@spt/models/eft/profile/ISearchFriendResponse";
import { ISptProfile } from "@spt/models/eft/profile/ISptProfile";
import { IValidateNicknameRequestData } from "@spt/models/eft/profile/IValidateNicknameRequestData";
import { BonusType } from "@spt/models/enums/BonusType";
@ -90,6 +91,24 @@ export declare class ProfileHelper {
* @returns ISptProfile object
*/
getFullProfile(sessionID: string): ISptProfile | undefined;
/**
* Get full representation of a players profile JSON by the account ID, or undefined if not found
* @param accountId Account ID to find
* @returns
*/
getFullProfileByAccountId(accountID: string): ISptProfile | undefined;
/**
* Retrieve a ChatRoomMember formatted profile for the given session ID
* @param sessionID The session ID to return the profile for
* @returns
*/
getChatRoomMemberFromSessionId(sessionID: string): ISearchFriendResponse | undefined;
/**
* Retrieve a ChatRoomMember formatted profile for the given PMC profile data
* @param pmcProfile The PMC profile data to format into a ChatRoomMember structure
* @returns
*/
getChatRoomMemberFromPmcProfile(pmcProfile: IPmcData): ISearchFriendResponse;
/**
* Get a PMC profile by its session id
* @param sessionID Profile id to return

View File

@ -8,4 +8,5 @@ export interface Info {
Side: string;
Level: number;
MemberCategory: number;
SelectedMemberCategory: number;
}

View File

@ -19,6 +19,8 @@ export interface ISptProfile {
traderPurchases?: Record<string, Record<string, ITraderPurchaseData>>;
/** Achievements earned by player */
achievements: Record<string, number>;
/** List of friend profile IDs */
friends: string[];
}
export declare class ITraderPurchaseData {
count: number;

View File

@ -0,0 +1,5 @@
import { IWsNotificationEvent } from "@spt/models/eft/ws/IWsNotificationEvent";
import { ISearchFriendResponse } from "../profile/ISearchFriendResponse";
export interface IWsFriendsListAccept extends IWsNotificationEvent {
profile: ISearchFriendResponse;
}

View File

@ -1,4 +1,4 @@
export interface IWsNotificationEvent {
type: string;
eventId: string;
eventId?: string;
}

View File

@ -1,5 +1,6 @@
export declare enum ConfigTypes {
AIRDROP = "spt-airdrop",
BACKUP = "spt-backup",
BOT = "spt-bot",
PMC = "spt-pmc",
CORE = "spt-core",

View File

@ -0,0 +1,12 @@
import { IBaseConfig } from "@spt/models/spt/config/IBaseConfig";
export interface IBackupConfig extends IBaseConfig {
kind: "spt-backup";
enabled: boolean;
maxBackups: number;
directory: string;
backupInterval: IBackupConfigInterval;
}
export interface IBackupConfigInterval {
enabled: boolean;
intervalMinutes: number;
}

View File

@ -0,0 +1,98 @@
import { PreSptModLoader } from "@spt/loaders/PreSptModLoader";
import { IBackupConfig } from "@spt/models/spt/config/IBackupConfig";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
export declare class BackupService {
protected logger: ILogger;
protected preSptModLoader: PreSptModLoader;
protected configServer: ConfigServer;
protected backupConfig: IBackupConfig;
protected readonly activeServerMods: string[];
protected readonly profileDir = "./user/profiles";
constructor(logger: ILogger, preSptModLoader: PreSptModLoader, configServer: ConfigServer);
/**
* Initializes the backup process.
*
* This method orchestrates the profile backup service. Handles copying profiles to a backup directory and cleaning
* up old backups if the number exceeds the configured maximum.
*
* @returns A promise that resolves when the backup process is complete.
*/
init(): Promise<void>;
/**
* Fetches the names of all JSON files in the profile directory.
*
* This method normalizes the profile directory path and reads all files within it. It then filters the files to
* include only those with a `.json` extension and returns their names.
*
* @returns A promise that resolves to an array of JSON file names.
*/
protected fetchProfileFiles(): Promise<string[]>;
/**
* Check to see if the backup service is enabled via the config.
*
* @returns True if enabled, false otherwise.
*/
protected isEnabled(): boolean;
/**
* Generates the target directory path for the backup. The directory path is constructed using the `directory` from
* the configuration and the current backup date.
*
* @returns The target directory path for the backup.
*/
protected generateBackupTargetDir(): string;
/**
* Generates a formatted backup date string in the format `YYYY-MM-DD_hh-mm-ss`.
*
* @returns The formatted backup date string.
*/
protected generateBackupDate(): string;
/**
* Cleans up old backups in the backup directory.
*
* This method reads the backup directory, and sorts backups by modification time. If the number of backups exceeds
* the configured maximum, it deletes the oldest backups.
*
* @returns A promise that resolves when the cleanup is complete.
*/
protected cleanBackups(): Promise<void>;
/**
* Retrieves and sorts the backup file paths from the specified directory.
*
* @param dir - The directory to search for backup files.
* @returns A promise that resolves to an array of sorted backup file paths.
*/
private getBackupPaths;
/**
* Compares two backup folder names based on their extracted dates.
*
* @param a - The name of the first backup folder.
* @param b - The name of the second backup folder.
* @returns The difference in time between the two dates in milliseconds, or `null` if either date is invalid.
*/
private compareBackupDates;
/**
* Extracts a date from a folder name string formatted as `YYYY-MM-DD_hh-mm-ss`.
*
* @param folderName - The name of the folder from which to extract the date.
* @returns A Date object if the folder name is in the correct format, otherwise null.
*/
private extractDateFromFolderName;
/**
* Removes excess backups from the backup directory.
*
* @param backups - An array of backup file names to be removed.
* @returns A promise that resolves when all specified backups have been removed.
*/
private removeExcessBackups;
/**
* Start the backup interval if enabled in the configuration.
*/
protected startBackupInterval(): void;
/**
* Get an array of active server mod details.
*
* @returns An array of mod names.
*/
protected getActiveServerMods(): string[];
}

Some files were not shown because too many files have changed in this diff Show More