tsconfig update; fix function signature; test: add .default

This commit is contained in:
Luciole committed 2023-08-14 14:34:56 +02:00
1 parent a26dcf5075
commit f2736bae40
8 files changed
+61 -24

No files matched your search

+39 -8
View File
@@ -64,7 +64,7 @@ export default class ControlConnection extends BaseConnection {
this._version = registerData.version;
this.connector.on("connect", () => {
this.connector._socket.clusterio_ignore_dump = Boolean(this.ws_dumper);
this.connector._socket!.clusterio_ignore_dump = Boolean(this.ws_dumper);
});
this.connector.on("close", () => {
if (this.logTransport) {
@@ -264,11 +264,21 @@ export default class ControlConnection extends BaseConnection {
async handleInstanceDetailsGetRequest(request: lib.InstanceDetailsGetRequest) {
let instance = this._controller.getRequestInstance(request.instanceId);
let assigned_host: number|null|undefined = instance.config.get("instance.assigned_host");
if (assigned_host === null) {
assigned_host = undefined;
}
let game_port: number|null|undefined = instance.game_port
if (game_port === null) {
game_port = undefined;
}
return new lib.InstanceDetails(
instance.config.get("instance.name"),
instance.id,
instance.config.get("instance.assigned_host"),
instance.game_port,
assigned_host,
game_port,
instance.status,
);
}
@@ -276,11 +286,21 @@ export default class ControlConnection extends BaseConnection {
async handleInstanceDetailsListRequest() {
let list = [];
for (let instance of this._controller.instances!.values()) {
let assigned_host: number|null|undefined = instance.config.get("instance.assigned_host");
if (assigned_host === null) {
assigned_host = undefined;
}
let game_port: number|null|undefined = instance.game_port
if (game_port === null) {
game_port = undefined;
}
list.push(new lib.InstanceDetails(
instance.config.get("instance.name"),
instance.id,
instance.config.get("instance.assigned_host"),
instance.game_port,
assigned_host,
game_port,
instance.status,
));
}
@@ -296,12 +316,23 @@ export default class ControlConnection extends BaseConnection {
this.instanceSubscriptions.all
|| this.instanceSubscriptions.instanceIds.includes(instance.id)
) {
let assigned_host: number|null|undefined = instance.config.get("instance.assigned_host");
if (assigned_host === null) {
assigned_host = undefined;
}
let game_port: number|null|undefined = instance.game_port
if (game_port === null) {
game_port = undefined;
}
this.send(new lib.InstanceDetailsUpdateEvent(
new lib.InstanceDetails(
instance.config.get("instance.name"),
instance.id,
instance.config.get("instance.assigned_host"),
instance.game_port,
assigned_host,
game_port,
instance.status,
)
));
@@ -954,7 +985,7 @@ export default class ControlConnection extends BaseConnection {
this.send(new lib.DebugWsMessageEvent(data.direction, data.content));
}
};
this.connector._socket.clusterio_ignore_dump = true;
this.connector._socket!.clusterio_ignore_dump = true;
this._controller.debugEvents.on("message", this.ws_dumper);
}
}
+1 -5
View File
@@ -1,6 +1,7 @@
import type { IncomingMessage } from "http";
import type { Duplex } from "stream";
import type Controller from "./Controller";
import type { WebSocketClusterio } from "./WsServerConnector";
import jwt from "jsonwebtoken";
import WebSocket, { WebSocketServer } from "ws";
@@ -12,11 +13,6 @@ import ControlConnection from "./ControlConnection";
import HostConnection, { HostInfo } from "./HostConnection";
import WsServerConnector from "./WsServerConnector";
export interface WebSocketClusterio extends WebSocket {
clusterio_ignore_dump: boolean | undefined;
}
const packageVersion = require("../package.json").version;
const wsMessageCounter = new lib.Counter(
+15 -3
View File
@@ -5,6 +5,11 @@ import events from "events";
import * as lib from "@clusterio/lib";
const { logger } = lib;
export interface WebSocketClusterio extends WebSocket {
clusterio_ignore_dump?: boolean;
}
/**
* Connector for controller connections
*
@@ -13,6 +18,7 @@ const { logger } = lib;
*/
export default class WsServerConnector extends lib.WebSocketBaseConnector {
_timeoutId: NodeJS.Timeout | null = null;
declare _socket: WebSocketClusterio | null;
constructor(
dst: lib.Address,
@@ -47,7 +53,7 @@ export default class WsServerConnector extends lib.WebSocketBaseConnector {
* @param account - account data to provide to control connection
*/
ready(
socket: WebSocket,
socket: WebSocket.WebSocket,
src: lib.Address,
sessionToken: string,
account: lib.AccountDetails | undefined
@@ -84,7 +90,7 @@ export default class WsServerConnector extends lib.WebSocketBaseConnector {
// It's possible the previous connection hasn't closed yet due to a
// stale connection. Terminate it if so.
if (this._state === "connected") {
if (this._state === "connected" && this._socket !== null) {
this._socket.terminate();
this._socket.once("close", () => this.continue(socket, lastSeq));
return;
@@ -117,6 +123,10 @@ export default class WsServerConnector extends lib.WebSocketBaseConnector {
}
_attachSocketHandlers() {
if (this._socket === null) {
throw new Error("this._socket is null");
}
this.startHeartbeat();
this._socket.on("close", (code: number, reason: string) => {
@@ -188,7 +198,9 @@ export default class WsServerConnector extends lib.WebSocketBaseConnector {
}
this._closing = true;
this._socket.close(code, reason);
if (this._socket !== null) {
this._socket.close(code, reason);
}
await events.once(this, "close");
}