Initial release for SPT 3.9

This commit is contained in:
2024-07-20 18:08:38 +02:00
parent 7df25ba694
commit c83da69a3e
713 changed files with 34110 additions and 1 deletions

15
types/servers/ConfigServer.d.ts vendored Normal file
View File

@@ -0,0 +1,15 @@
import { ConfigTypes } from "@spt/models/enums/ConfigTypes";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { JsonUtil } from "@spt/utils/JsonUtil";
import { VFS } from "@spt/utils/VFS";
export declare class ConfigServer {
protected logger: ILogger;
protected vfs: VFS;
protected jsonUtil: JsonUtil;
protected configs: Record<string, any>;
protected readonly acceptableFileExtensions: string[];
constructor(logger: ILogger, vfs: VFS, jsonUtil: JsonUtil);
getConfig<T>(configType: ConfigTypes): T;
getConfigByString<T>(configType: string): T;
initialize(): void;
}

6
types/servers/DatabaseServer.d.ts vendored Normal file
View File

@@ -0,0 +1,6 @@
import { IDatabaseTables } from "@spt/models/spt/server/IDatabaseTables";
export declare class DatabaseServer {
protected tableData: IDatabaseTables;
getTables(): IDatabaseTables;
setTables(tableData: IDatabaseTables): void;
}

37
types/servers/HttpServer.d.ts vendored Normal file
View File

@@ -0,0 +1,37 @@
/// <reference types="node" />
import { IncomingMessage, ServerResponse } from "node:http";
import { ApplicationContext } from "@spt/context/ApplicationContext";
import { HttpServerHelper } from "@spt/helpers/HttpServerHelper";
import { IHttpConfig } from "@spt/models/spt/config/IHttpConfig";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { DatabaseServer } from "@spt/servers/DatabaseServer";
import { IHttpListener } from "@spt/servers/http/IHttpListener";
import { WebSocketServer } from "@spt/servers/WebSocketServer";
import { LocalisationService } from "@spt/services/LocalisationService";
export declare class HttpServer {
protected logger: ILogger;
protected databaseServer: DatabaseServer;
protected httpServerHelper: HttpServerHelper;
protected localisationService: LocalisationService;
protected httpListeners: IHttpListener[];
protected configServer: ConfigServer;
protected applicationContext: ApplicationContext;
protected webSocketServer: WebSocketServer;
protected httpConfig: IHttpConfig;
protected started: boolean;
constructor(logger: ILogger, databaseServer: DatabaseServer, httpServerHelper: HttpServerHelper, localisationService: LocalisationService, httpListeners: IHttpListener[], configServer: ConfigServer, applicationContext: ApplicationContext, webSocketServer: WebSocketServer);
/**
* Handle server loading event
*/
load(): void;
protected handleRequest(req: IncomingMessage, resp: ServerResponse): void;
/**
* Check against hardcoded values that determine its from a local address
* @param remoteAddress Address to check
* @returns True if its local
*/
protected isLocalRequest(remoteAddress: string): boolean;
protected getCookies(req: IncomingMessage): Record<string, string>;
isStarted(): boolean;
}

43
types/servers/RagfairServer.d.ts vendored Normal file
View File

@@ -0,0 +1,43 @@
import { RagfairOfferGenerator } from "@spt/generators/RagfairOfferGenerator";
import { TraderAssortHelper } from "@spt/helpers/TraderAssortHelper";
import { TraderHelper } from "@spt/helpers/TraderHelper";
import { IRagfairOffer } from "@spt/models/eft/ragfair/IRagfairOffer";
import { ISearchRequestData } from "@spt/models/eft/ragfair/ISearchRequestData";
import { IRagfairConfig } from "@spt/models/spt/config/IRagfairConfig";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { LocalisationService } from "@spt/services/LocalisationService";
import { RagfairCategoriesService } from "@spt/services/RagfairCategoriesService";
import { RagfairOfferService } from "@spt/services/RagfairOfferService";
import { RagfairRequiredItemsService } from "@spt/services/RagfairRequiredItemsService";
export declare class RagfairServer {
protected logger: ILogger;
protected ragfairOfferGenerator: RagfairOfferGenerator;
protected ragfairOfferService: RagfairOfferService;
protected ragfairCategoriesService: RagfairCategoriesService;
protected ragfairRequiredItemsService: RagfairRequiredItemsService;
protected localisationService: LocalisationService;
protected traderHelper: TraderHelper;
protected traderAssortHelper: TraderAssortHelper;
protected configServer: ConfigServer;
protected ragfairConfig: IRagfairConfig;
constructor(logger: ILogger, ragfairOfferGenerator: RagfairOfferGenerator, ragfairOfferService: RagfairOfferService, ragfairCategoriesService: RagfairCategoriesService, ragfairRequiredItemsService: RagfairRequiredItemsService, localisationService: LocalisationService, traderHelper: TraderHelper, traderAssortHelper: TraderAssortHelper, configServer: ConfigServer);
load(): Promise<void>;
update(): Promise<void>;
/**
* Get traders who need to be periodically refreshed
* @returns string array of traders
*/
getUpdateableTraders(): string[];
getAllActiveCategories(fleaUnlocked: boolean, searchRequestData: ISearchRequestData, offers: IRagfairOffer[]): Record<string, number>;
/**
* Disable/Hide an offer from flea
* @param offerId
*/
hideOffer(offerId: string): void;
getOffer(offerID: string): IRagfairOffer;
getOffers(): IRagfairOffer[];
removeOfferStack(offerID: string, amount: number): void;
doesOfferExist(offerId: string): boolean;
addPlayerOffers(): void;
}

88
types/servers/SaveServer.d.ts vendored Normal file
View File

@@ -0,0 +1,88 @@
import { SaveLoadRouter } from "@spt/di/Router";
import { ISptProfile, Info } from "@spt/models/eft/profile/ISptProfile";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { LocalisationService } from "@spt/services/LocalisationService";
import { HashUtil } from "@spt/utils/HashUtil";
import { JsonUtil } from "@spt/utils/JsonUtil";
import { VFS } from "@spt/utils/VFS";
export declare class SaveServer {
protected vfs: VFS;
protected saveLoadRouters: SaveLoadRouter[];
protected jsonUtil: JsonUtil;
protected hashUtil: HashUtil;
protected localisationService: LocalisationService;
protected logger: ILogger;
protected configServer: ConfigServer;
protected profileFilepath: string;
protected profiles: {};
protected onBeforeSaveCallbacks: {};
protected saveMd5: {};
constructor(vfs: VFS, saveLoadRouters: SaveLoadRouter[], jsonUtil: JsonUtil, hashUtil: HashUtil, localisationService: LocalisationService, logger: ILogger, configServer: ConfigServer);
/**
* Add callback to occur prior to saving profile changes
* @param id Id for save callback
* @param callback Callback to execute prior to running SaveServer.saveProfile()
*/
addBeforeSaveCallback(id: string, callback: (profile: Partial<ISptProfile>) => Partial<ISptProfile>): void;
/**
* Remove a callback from being executed prior to saving profile in SaveServer.saveProfile()
* @param id Id of callback to remove
*/
removeBeforeSaveCallback(id: string): void;
/**
* Load all profiles in /user/profiles folder into memory (this.profiles)
*/
load(): void;
/**
* Save changes for each profile from memory into user/profiles json
*/
save(): void;
/**
* Get a player profile from memory
* @param sessionId Session id
* @returns ISptProfile
*/
getProfile(sessionId: string): ISptProfile;
profileExists(id: string): boolean;
/**
* Get all profiles from memory
* @returns Dictionary of ISptProfile
*/
getProfiles(): Record<string, ISptProfile>;
/**
* Delete a profile by id
* @param sessionID Id of profile to remove
* @returns true when deleted, false when profile not found
*/
deleteProfileById(sessionID: string): boolean;
/**
* Create a new profile in memory with empty pmc/scav objects
* @param profileInfo Basic profile data
*/
createProfile(profileInfo: Info): void;
/**
* Add full profile in memory by key (info.id)
* @param profileDetails Profile to save
*/
addProfile(profileDetails: ISptProfile): void;
/**
* Look up profile json in user/profiles by id and store in memory
* Execute saveLoadRouters callbacks after being loaded into memory
* @param sessionID Id of profile to store in memory
*/
loadProfile(sessionID: string): void;
/**
* Save changes from in-memory profile to user/profiles json
* Execute onBeforeSaveCallbacks callbacks prior to being saved to json
* @param sessionID profile id (user/profiles/id.json)
* @returns time taken to save in MS
*/
saveProfile(sessionID: string): number;
/**
* Remove a physical profile json from user/profiles
* @param sessionID Profile id to remove
* @returns true if file no longer exists
*/
removeProfile(sessionID: string): boolean;
}

23
types/servers/WebSocketServer.d.ts vendored Normal file
View File

@@ -0,0 +1,23 @@
/// <reference types="node" />
import http, { IncomingMessage } from "node:http";
import { WebSocket, Server } from "ws";
import { HttpServerHelper } from "@spt/helpers/HttpServerHelper";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { IWebSocketConnectionHandler } from "@spt/servers/ws/IWebSocketConnectionHandler";
import { LocalisationService } from "@spt/services/LocalisationService";
import { JsonUtil } from "@spt/utils/JsonUtil";
import { RandomUtil } from "@spt/utils/RandomUtil";
export declare class WebSocketServer {
protected logger: ILogger;
protected randomUtil: RandomUtil;
protected jsonUtil: JsonUtil;
protected localisationService: LocalisationService;
protected httpServerHelper: HttpServerHelper;
protected webSocketConnectionHandlers: IWebSocketConnectionHandler[];
protected webSocketServer: Server;
constructor(logger: ILogger, randomUtil: RandomUtil, jsonUtil: JsonUtil, localisationService: LocalisationService, httpServerHelper: HttpServerHelper, webSocketConnectionHandlers: IWebSocketConnectionHandler[]);
getWebSocketServer(): Server;
setupWebSocket(httpServer: http.Server): void;
protected getRandomisedMessage(): string;
protected wsOnConnection(ws: WebSocket, req: IncomingMessage): void;
}

8
types/servers/http/HttpMethods.d.ts vendored Normal file
View File

@@ -0,0 +1,8 @@
export declare enum HttpMethods {
OPTIONS = "OPTIONS",
GET = "GET",
POST = "POST",
PUT = "PUT",
PATCH = "PATCH",
DELETE = "DELETE"
}

6
types/servers/http/IHttpListener.d.ts vendored Normal file
View File

@@ -0,0 +1,6 @@
/// <reference types="node" />
import { IncomingMessage, ServerResponse } from "node:http";
export interface IHttpListener {
canHandle(sessionId: string, req: IncomingMessage): boolean;
handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): Promise<void>;
}

36
types/servers/http/SptHttpListener.d.ts vendored Normal file
View File

@@ -0,0 +1,36 @@
/// <reference types="node" />
/// <reference types="node" />
import { IncomingMessage, ServerResponse } from "node:http";
import { Serializer } from "@spt/di/Serializer";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { HttpRouter } from "@spt/routers/HttpRouter";
import { IHttpListener } from "@spt/servers/http/IHttpListener";
import { LocalisationService } from "@spt/services/LocalisationService";
import { HttpResponseUtil } from "@spt/utils/HttpResponseUtil";
import { JsonUtil } from "@spt/utils/JsonUtil";
export declare class SptHttpListener implements IHttpListener {
protected httpRouter: HttpRouter;
protected serializers: Serializer[];
protected logger: ILogger;
protected requestsLogger: ILogger;
protected jsonUtil: JsonUtil;
protected httpResponse: HttpResponseUtil;
protected localisationService: LocalisationService;
constructor(httpRouter: HttpRouter, // TODO: delay required
serializers: Serializer[], logger: ILogger, requestsLogger: ILogger, jsonUtil: JsonUtil, httpResponse: HttpResponseUtil, localisationService: LocalisationService);
canHandle(_: string, req: IncomingMessage): boolean;
handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): Promise<void>;
/**
* Send http response to the client
* @param sessionID Player id
* @param req Incoming request
* @param resp Outgoing response
* @param body Buffer
* @param output Server generated response data
*/
sendResponse(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: Buffer, output: string): void;
getResponse(sessionID: string, req: IncomingMessage, body: Buffer): Promise<string>;
protected getBodyInfo(body: Buffer, requestUrl?: any): any;
sendJson(resp: ServerResponse, output: string, sessionID: string): void;
sendZlibJson(resp: ServerResponse, output: string, sessionID: string): void;
}

View File

@@ -0,0 +1,8 @@
/// <reference types="node" />
import { IncomingMessage } from "node:http";
import { WebSocket } from "ws";
export interface IWebSocketConnectionHandler {
getSocketId(): string;
getHookUrl(): string;
onConnection(ws: WebSocket, req: IncomingMessage): void;
}

View File

@@ -0,0 +1,32 @@
/// <reference types="node" />
/// <reference types="node" />
import { IncomingMessage } from "http";
import { WebSocket } from "ws";
import { ProfileHelper } from "@spt/helpers/ProfileHelper";
import { IWsNotificationEvent } from "@spt/models/eft/ws/IWsNotificationEvent";
import { IHttpConfig } from "@spt/models/spt/config/IHttpConfig";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ConfigServer } from "@spt/servers/ConfigServer";
import { IWebSocketConnectionHandler } from "@spt/servers/ws/IWebSocketConnectionHandler";
import { ISptWebSocketMessageHandler } from "@spt/servers/ws/message/ISptWebSocketMessageHandler";
import { LocalisationService } from "@spt/services/LocalisationService";
import { JsonUtil } from "@spt/utils/JsonUtil";
export declare class SptWebSocketConnectionHandler implements IWebSocketConnectionHandler {
protected logger: ILogger;
protected profileHelper: ProfileHelper;
protected localisationService: LocalisationService;
protected configServer: ConfigServer;
protected jsonUtil: JsonUtil;
protected sptWebSocketMessageHandlers: ISptWebSocketMessageHandler[];
protected httpConfig: IHttpConfig;
protected webSockets: Map<string, WebSocket>;
protected defaultNotification: IWsNotificationEvent;
protected websocketPingHandler: NodeJS.Timeout | undefined;
constructor(logger: ILogger, profileHelper: ProfileHelper, localisationService: LocalisationService, configServer: ConfigServer, jsonUtil: JsonUtil, sptWebSocketMessageHandlers: ISptWebSocketMessageHandler[]);
getSocketId(): string;
getHookUrl(): string;
onConnection(ws: WebSocket, req: IncomingMessage): void;
sendMessage(sessionID: string, output: IWsNotificationEvent): void;
isConnectionWebSocket(sessionID: string): boolean;
getSessionWebSocket(sessionID: string): WebSocket;
}

View File

@@ -0,0 +1,8 @@
import { RawData, WebSocket } from "ws";
import { ILogger } from "@spt/models/spt/utils/ILogger";
import { ISptWebSocketMessageHandler } from "@spt/servers/ws/message/ISptWebSocketMessageHandler";
export declare class DefaultSptWebSocketMessageHandler implements ISptWebSocketMessageHandler {
protected logger: ILogger;
constructor(logger: ILogger);
onSptMessage(sessionId: string, client: WebSocket, message: RawData): void;
}

View File

@@ -0,0 +1,4 @@
import { RawData, WebSocket } from "ws";
export interface ISptWebSocketMessageHandler {
onSptMessage(sessionID: string, client: WebSocket, message: RawData): void;
}