Formatting for servers.
This commit is contained in:
parent
b90fb8c8b9
commit
ca9ab9bcc8
@ -15,7 +15,7 @@ export class ConfigServer
|
||||
constructor(
|
||||
@inject("WinstonLogger") protected logger: ILogger,
|
||||
@inject("VFS") protected vfs: VFS,
|
||||
@inject("JsonUtil") protected jsonUtil: JsonUtil
|
||||
@inject("JsonUtil") protected jsonUtil: JsonUtil,
|
||||
)
|
||||
{
|
||||
this.initialize();
|
||||
@ -36,9 +36,9 @@ export class ConfigServer
|
||||
this.logger.debug("Importing configs...");
|
||||
|
||||
// Get all filepaths
|
||||
const filepath = (globalThis.G_RELEASE_CONFIGURATION)
|
||||
? "Aki_Data/Server/configs/"
|
||||
: "./assets/configs/";
|
||||
const filepath = (globalThis.G_RELEASE_CONFIGURATION) ?
|
||||
"Aki_Data/Server/configs/" :
|
||||
"./assets/configs/";
|
||||
const files = this.vfs.getFiles(filepath);
|
||||
|
||||
// Add file content to result
|
||||
@ -48,7 +48,10 @@ export class ConfigServer
|
||||
{
|
||||
const fileName = this.vfs.stripExtension(file);
|
||||
const filePathAndName = `${filepath}${file}`;
|
||||
this.configs[`aki-${fileName}`] = this.jsonUtil.deserializeJsonC<any>(this.vfs.readFile(filePathAndName), filePathAndName);
|
||||
this.configs[`aki-${fileName}`] = this.jsonUtil.deserializeJsonC<any>(
|
||||
this.vfs.readFile(filePathAndName),
|
||||
filePathAndName,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -16,7 +16,7 @@ export class DatabaseServer
|
||||
traders: undefined,
|
||||
globals: undefined,
|
||||
server: undefined,
|
||||
settings: undefined
|
||||
settings: undefined,
|
||||
};
|
||||
|
||||
public getTables(): IDatabaseTables
|
||||
|
@ -1,5 +1,5 @@
|
||||
import http, { IncomingMessage, ServerResponse } from "node:http";
|
||||
import { inject, injectAll, injectable } from "tsyringe";
|
||||
import { inject, injectable, injectAll } from "tsyringe";
|
||||
|
||||
import { ApplicationContext } from "@spt-aki/context/ApplicationContext";
|
||||
import { ContextVariableType } from "@spt-aki/context/ContextVariableType";
|
||||
@ -9,8 +9,8 @@ import { IHttpConfig } from "@spt-aki/models/spt/config/IHttpConfig";
|
||||
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
||||
import { ConfigServer } from "@spt-aki/servers/ConfigServer";
|
||||
import { DatabaseServer } from "@spt-aki/servers/DatabaseServer";
|
||||
import { WebSocketServer } from "@spt-aki/servers/WebSocketServer";
|
||||
import { IHttpListener } from "@spt-aki/servers/http/IHttpListener";
|
||||
import { WebSocketServer } from "@spt-aki/servers/WebSocketServer";
|
||||
import { LocalisationService } from "@spt-aki/services/LocalisationService";
|
||||
|
||||
@injectable()
|
||||
@ -26,7 +26,7 @@ export class HttpServer
|
||||
@injectAll("HttpListener") protected httpListeners: IHttpListener[],
|
||||
@inject("ConfigServer") protected configServer: ConfigServer,
|
||||
@inject("ApplicationContext") protected applicationContext: ApplicationContext,
|
||||
@inject("WebSocketServer") protected webSocketServer: WebSocketServer
|
||||
@inject("WebSocketServer") protected webSocketServer: WebSocketServer,
|
||||
)
|
||||
{
|
||||
this.httpConfig = this.configServer.getConfig(ConfigTypes.HTTP);
|
||||
@ -49,7 +49,9 @@ export class HttpServer
|
||||
/* Config server to listen on a port */
|
||||
httpServer.listen(this.httpConfig.port, this.httpConfig.ip, () =>
|
||||
{
|
||||
this.logger.success(this.localisationService.getText("started_webserver_success", this.httpServerHelper.getBackendUrl()));
|
||||
this.logger.success(
|
||||
this.localisationService.getText("started_webserver_success", this.httpServerHelper.getBackendUrl()),
|
||||
);
|
||||
});
|
||||
|
||||
httpServer.on("error", (e: any) =>
|
||||
|
@ -28,7 +28,7 @@ export class RagfairServer
|
||||
@inject("LocalisationService") protected localisationService: LocalisationService,
|
||||
@inject("TraderHelper") protected traderHelper: TraderHelper,
|
||||
@inject("TraderAssortHelper") protected traderAssortHelper: TraderAssortHelper,
|
||||
@inject("ConfigServer") protected configServer: ConfigServer
|
||||
@inject("ConfigServer") protected configServer: ConfigServer,
|
||||
)
|
||||
{
|
||||
this.ragfairConfig = this.configServer.getConfig(ConfigTypes.RAGFAIR);
|
||||
@ -79,7 +79,7 @@ export class RagfairServer
|
||||
*/
|
||||
protected getUpdateableTraders(): string[]
|
||||
{
|
||||
return Object.keys(this.ragfairConfig.traders).filter(x => this.ragfairConfig.traders[x]);
|
||||
return Object.keys(this.ragfairConfig.traders).filter((x) => this.ragfairConfig.traders[x]);
|
||||
}
|
||||
|
||||
public getAllCategories(): Record<string, number>
|
||||
@ -99,7 +99,7 @@ export class RagfairServer
|
||||
public hideOffer(offerId: string): void
|
||||
{
|
||||
const offers = this.ragfairOfferService.getOffers();
|
||||
const offer = offers.find(x => x._id === offerId);
|
||||
const offer = offers.find((x) => x._id === offerId);
|
||||
|
||||
if (!offer)
|
||||
{
|
||||
|
@ -23,7 +23,7 @@ export class SaveServer
|
||||
@inject("JsonUtil") protected jsonUtil: JsonUtil,
|
||||
@inject("HashUtil") protected hashUtil: HashUtil,
|
||||
@inject("LocalisationService") protected localisationService: LocalisationService,
|
||||
@inject("WinstonLogger") protected logger: ILogger
|
||||
@inject("WinstonLogger") protected logger: ILogger,
|
||||
)
|
||||
{}
|
||||
|
||||
@ -144,7 +144,7 @@ export class SaveServer
|
||||
|
||||
this.profiles[profileInfo.id] = {
|
||||
info: profileInfo,
|
||||
characters: { pmc: {}, scav: {}}
|
||||
characters: {pmc: {}, scav: {}},
|
||||
};
|
||||
}
|
||||
|
||||
|
@ -15,14 +15,13 @@ import { RandomUtil } from "@spt-aki/utils/RandomUtil";
|
||||
@injectable()
|
||||
export class WebSocketServer
|
||||
{
|
||||
|
||||
constructor(
|
||||
@inject("WinstonLogger") protected logger: ILogger,
|
||||
@inject("RandomUtil") protected randomUtil: RandomUtil,
|
||||
@inject("ConfigServer") protected configServer: ConfigServer,
|
||||
@inject("LocalisationService") protected localisationService: LocalisationService,
|
||||
@inject("JsonUtil") protected jsonUtil: JsonUtil,
|
||||
@inject("HttpServerHelper") protected httpServerHelper: HttpServerHelper
|
||||
@inject("HttpServerHelper") protected httpServerHelper: HttpServerHelper,
|
||||
)
|
||||
{
|
||||
this.httpConfig = this.configServer.getConfig(ConfigTypes.HTTP);
|
||||
@ -31,7 +30,7 @@ export class WebSocketServer
|
||||
protected httpConfig: IHttpConfig;
|
||||
protected defaultNotification: INotification = {
|
||||
type: NotificationType.PING,
|
||||
eventId: "ping"
|
||||
eventId: "ping",
|
||||
};
|
||||
|
||||
protected webSockets: Record<string, WebSocket.WebSocket> = {};
|
||||
@ -40,13 +39,17 @@ export class WebSocketServer
|
||||
public setupWebSocket(httpServer: http.Server): void
|
||||
{
|
||||
const webSocketServer = new WebSocket.Server({
|
||||
server: httpServer
|
||||
server: httpServer,
|
||||
});
|
||||
|
||||
webSocketServer.addListener("listening", () =>
|
||||
{
|
||||
this.logger.success(this.localisationService.getText("websocket-started", this.httpServerHelper.getWebsocketUrl()));
|
||||
this.logger.success(`${this.localisationService.getText("server_running")}, ${this.getRandomisedMessage()}!`);
|
||||
this.logger.success(
|
||||
this.localisationService.getText("websocket-started", this.httpServerHelper.getWebsocketUrl()),
|
||||
);
|
||||
this.logger.success(
|
||||
`${this.localisationService.getText("server_running")}, ${this.getRandomisedMessage()}!`,
|
||||
);
|
||||
});
|
||||
|
||||
webSocketServer.addListener("connection", this.wsOnConnection.bind(this));
|
||||
@ -79,9 +82,9 @@ export class WebSocketServer
|
||||
return this.localisationService.getRandomTextThatMatchesPartialKey("server_start_meme_");
|
||||
}
|
||||
|
||||
return (globalThis.G_RELEASE_CONFIGURATION)
|
||||
? `${this.localisationService.getText("server_start_success")}!`
|
||||
: this.localisationService.getText("server_start_success");
|
||||
return (globalThis.G_RELEASE_CONFIGURATION) ?
|
||||
`${this.localisationService.getText("server_start_success")}!` :
|
||||
this.localisationService.getText("server_start_success");
|
||||
}
|
||||
|
||||
public isConnectionWebSocket(sessionID: string): boolean
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { IncomingHttpHeaders, IncomingMessage, ServerResponse } from "node:http";
|
||||
import zlib from "node:zlib";
|
||||
import { inject, injectAll, injectable } from "tsyringe";
|
||||
import { inject, injectable, injectAll } from "tsyringe";
|
||||
|
||||
import { Serializer } from "@spt-aki/di/Serializer";
|
||||
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
||||
@ -13,7 +13,6 @@ import { JsonUtil } from "@spt-aki/utils/JsonUtil";
|
||||
@injectable()
|
||||
export class AkiHttpListener implements IHttpListener
|
||||
{
|
||||
|
||||
constructor(
|
||||
@inject("HttpRouter") protected httpRouter: HttpRouter, // TODO: delay required
|
||||
@injectAll("Serializer") protected serializers: Serializer[],
|
||||
@ -21,7 +20,7 @@ export class AkiHttpListener implements IHttpListener
|
||||
@inject("RequestsLogger") protected requestsLogger: ILogger,
|
||||
@inject("JsonUtil") protected jsonUtil: JsonUtil,
|
||||
@inject("HttpResponseUtil") protected httpResponse: HttpResponseUtil,
|
||||
@inject("LocalisationService") protected localisationService: LocalisationService
|
||||
@inject("LocalisationService") protected localisationService: LocalisationService,
|
||||
)
|
||||
{
|
||||
}
|
||||
@ -96,7 +95,13 @@ export class AkiHttpListener implements IHttpListener
|
||||
* @param body Buffer
|
||||
* @param output Server generated response data
|
||||
*/
|
||||
public sendResponse(sessionID: string, req: IncomingMessage, resp: ServerResponse, body: Buffer, output: string): void
|
||||
public sendResponse(
|
||||
sessionID: string,
|
||||
req: IncomingMessage,
|
||||
resp: ServerResponse,
|
||||
body: Buffer,
|
||||
output: string,
|
||||
): void
|
||||
{
|
||||
const info = this.getBodyInfo(body);
|
||||
let handled = false;
|
||||
@ -136,9 +141,9 @@ export class AkiHttpListener implements IHttpListener
|
||||
if (globalThis.G_LOG_REQUESTS)
|
||||
{
|
||||
// Parse quest info into object
|
||||
const data = (typeof info === "object")
|
||||
? info
|
||||
: this.jsonUtil.deserialize(info);
|
||||
const data = (typeof info === "object") ?
|
||||
info :
|
||||
this.jsonUtil.deserialize(info);
|
||||
|
||||
const log = new Request(req.method, new RequestData(req.url, req.headers, data));
|
||||
this.requestsLogger.info(`REQUEST=${this.jsonUtil.serialize(log)}`);
|
||||
@ -157,8 +162,8 @@ export class AkiHttpListener implements IHttpListener
|
||||
|
||||
protected getBodyInfo(body: Buffer, requestUrl = null): any
|
||||
{
|
||||
const text = (body) ? body.toString() : "{}";
|
||||
const info = (text) ? this.jsonUtil.deserialize<any>(text, requestUrl) : {};
|
||||
const text = body ? body.toString() : "{}";
|
||||
const info = text ? this.jsonUtil.deserialize<any>(text, requestUrl) : {};
|
||||
return info;
|
||||
}
|
||||
|
||||
@ -175,7 +180,6 @@ export class AkiHttpListener implements IHttpListener
|
||||
resp.writeHead(200, "OK", {"Content-Type": "application/json", "Set-Cookie": `PHPSESSID=${sessionID}`});
|
||||
zlib.deflate(output, (_, buf) => resp.end(buf));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
class RequestData
|
||||
@ -183,7 +187,7 @@ class RequestData
|
||||
constructor(
|
||||
public url: string,
|
||||
public headers: IncomingHttpHeaders,
|
||||
public data?: any
|
||||
public data?: any,
|
||||
)
|
||||
{}
|
||||
}
|
||||
@ -192,7 +196,7 @@ class Request
|
||||
{
|
||||
constructor(
|
||||
public type: string,
|
||||
public req: RequestData
|
||||
public req: RequestData,
|
||||
)
|
||||
{}
|
||||
}
|
||||
@ -201,7 +205,7 @@ class Response
|
||||
{
|
||||
constructor(
|
||||
public type: string,
|
||||
public response: any
|
||||
public response: any,
|
||||
)
|
||||
{}
|
||||
}
|
@ -5,5 +5,5 @@ export enum HttpMethods
|
||||
POST = "POST",
|
||||
PUT = "PUT",
|
||||
PATCH = "PATCH",
|
||||
DELETE = "DELETE"
|
||||
DELETE = "DELETE",
|
||||
}
|
@ -2,6 +2,6 @@ import { IncomingMessage, ServerResponse } from "node:http";
|
||||
|
||||
export interface IHttpListener
|
||||
{
|
||||
canHandle(sessionId: string, req: IncomingMessage): boolean
|
||||
handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): void
|
||||
canHandle(sessionId: string, req: IncomingMessage): boolean;
|
||||
handle(sessionId: string, req: IncomingMessage, resp: ServerResponse): void;
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user