mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-16 15:30:41 +09:00
Fix code style errors
Remove extra whitespace, use more consistent spacing, add missing semicolons, using dangling commas, break up long lines, consistent multiline operator placement, add missing JSDoc strings and so on.
This commit is contained in:
1 parent
97e05c0610
commit
7314dc99c8
71 files changed
+403
-290
No files matched your search
@@ -12,6 +12,6 @@ const info: lib.PluginDeclaration = {
|
||||
messages: [
|
||||
ChatEvent,
|
||||
],
|
||||
}
|
||||
};
|
||||
|
||||
export default info;
|
||||
@@ -60,6 +60,6 @@ const info: lib.PluginDeclaration = {
|
||||
],
|
||||
webEntrypoint: "./web",
|
||||
routes: ["/inventory"],
|
||||
}
|
||||
};
|
||||
|
||||
export default info;
|
||||
export default info;
|
||||
@@ -1,10 +1,14 @@
|
||||
import * as lib from "@clusterio/lib";
|
||||
import { AcquireRequest, AcquireResponse, ReleaseRequest, UploadRequest, DownloadRequest, DownloadResponse } from "./messages";
|
||||
import {
|
||||
AcquireRequest, AcquireResponse, ReleaseRequest, UploadRequest, DownloadRequest, DownloadResponse,
|
||||
} from "./messages";
|
||||
|
||||
type IpcPlayerName = {
|
||||
player_name: string
|
||||
}
|
||||
export type IpcPlayerData = { //.\module\serialize.lua:serialize.serialize_player()
|
||||
|
||||
// .\module\serialize.lua:serialize.serialize_player()
|
||||
export type IpcPlayerData = {
|
||||
generation: number,
|
||||
controller: string,
|
||||
name: string,
|
||||
@@ -34,6 +38,7 @@ type IpcAcquireResponse = {
|
||||
* Splits string into array of strings with max of a certain length
|
||||
* @param chunkSize - Max length of each chunk
|
||||
* @param string - String to split into chunks
|
||||
* @returns array of substrings
|
||||
*/
|
||||
function chunkify(chunkSize: number, string: string): string[] {
|
||||
return string.match(new RegExp(`.{1,${chunkSize}}`, "g")) || [];
|
||||
@@ -48,21 +53,37 @@ export class InstancePlugin extends lib.BaseInstancePlugin {
|
||||
this.disconnecting = false;
|
||||
|
||||
// Handle IPC from scenario script
|
||||
this.instance.server.on("ipc-inventory_sync_acquire", (request: IpcPlayerName) => this.handleAcquire(request)
|
||||
.catch(err => this.logger.error(`Error handling ipc-inventory_sync_acquire:\n${err.stack}`)));
|
||||
this.instance.server.on("ipc-inventory_sync_release", (request: IpcPlayerName) => this.handleRelease(request)
|
||||
.catch(err => this.logger.error(`Error handling ipc-inventory_sync_release:\n${err.stack}`)));
|
||||
this.instance.server.on("ipc-inventory_sync_upload", (player_data: IpcPlayerData) => this.handleUpload(player_data)
|
||||
.catch(err => this.logger.error(`Error handling ipc-inventory_sync_upload:\n${err.stack}`)));
|
||||
this.instance.server.on("ipc-inventory_sync_download", (request: IpcPlayerName) => this.handleDownload(request)
|
||||
.catch(err => this.logger.error(`Error handling ipc-inventory_sync_download:\n${err.stack}`)));
|
||||
this.instance.server.on(
|
||||
"ipc-inventory_sync_acquire",
|
||||
(request: IpcPlayerName) => this.handleAcquire(request).catch(
|
||||
err => this.logger.error(`Error handling ipc-inventory_sync_acquire:\n${err.stack}`)
|
||||
),
|
||||
);
|
||||
this.instance.server.on(
|
||||
"ipc-inventory_sync_release",
|
||||
(request: IpcPlayerName) => this.handleRelease(request).catch(
|
||||
err => this.logger.error(`Error handling ipc-inventory_sync_release:\n${err.stack}`)
|
||||
),
|
||||
);
|
||||
this.instance.server.on(
|
||||
"ipc-inventory_sync_upload",
|
||||
(player_data: IpcPlayerData) => this.handleUpload(player_data).catch(
|
||||
err => this.logger.error(`Error handling ipc-inventory_sync_upload:\n${err.stack}`)
|
||||
),
|
||||
);
|
||||
this.instance.server.on(
|
||||
"ipc-inventory_sync_download",
|
||||
(request: IpcPlayerName) => this.handleDownload(request).catch(
|
||||
err => this.logger.error(`Error handling ipc-inventory_sync_download:\n${err.stack}`)
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
async onPrepareControllerDisconnect() {
|
||||
this.disconnecting = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
onControllerConnectionEvent(event: "connect" | "drop" | "resume" | "close") {
|
||||
if (event === "connect") {
|
||||
this.disconnecting = false;
|
||||
|
||||
@@ -6,7 +6,7 @@ import { StringEnum } from "@clusterio/lib";
|
||||
const jsonPlayerData = Type.Object({
|
||||
generation: Type.Number(),
|
||||
name: Type.String(),
|
||||
})
|
||||
});
|
||||
|
||||
export class AcquireResponse {
|
||||
constructor(
|
||||
@@ -45,7 +45,7 @@ export class AcquireRequest {
|
||||
static jsonSchema = Type.Object({
|
||||
"instanceId": Type.Number(),
|
||||
"playerName": Type.String(),
|
||||
})
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof AcquireRequest.jsonSchema>): AcquireRequest {
|
||||
return new this(json.instanceId, json.playerName);
|
||||
@@ -68,7 +68,7 @@ export class ReleaseRequest {
|
||||
static jsonSchema = Type.Object({
|
||||
"instanceId": Type.Integer(),
|
||||
"playerName": Type.String(),
|
||||
})
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof ReleaseRequest.jsonSchema>) {
|
||||
return new this(json.instanceId, json.playerName);
|
||||
@@ -108,7 +108,7 @@ export class DownloadResponse {
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"playerData": Type.Optional(jsonPlayerData),
|
||||
})
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof DownloadResponse.jsonSchema>): DownloadResponse {
|
||||
return new this(json.playerData as IpcPlayerData);
|
||||
@@ -132,7 +132,7 @@ export class DownloadRequest {
|
||||
static jsonSchema = Type.Object({
|
||||
"instanceId": Type.Integer(),
|
||||
"playerName": Type.String(),
|
||||
})
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof DownloadRequest.jsonSchema>) {
|
||||
return new this(json.instanceId, json.playerName);
|
||||
@@ -153,8 +153,8 @@ class DatabaseStatsResponse {
|
||||
"largestEntry": Type.Object({
|
||||
"name": Type.String(),
|
||||
"size": Type.Number(),
|
||||
})
|
||||
})
|
||||
}),
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof DatabaseStatsResponse.jsonSchema>): DatabaseStatsResponse {
|
||||
return new this(json.databaseSize, json.databaseEntries, json.largestEntry);
|
||||
|
||||
@@ -56,13 +56,21 @@ export class ControllerPlugin extends lib.BaseControllerPlugin {
|
||||
res.send(servers);
|
||||
});
|
||||
|
||||
this.controller.app.post("/api/player_auth/player_code", express.json(), (req: Request, res: Response, next: any) => {
|
||||
this.handlePlayerCode(req, res).catch(next);
|
||||
});
|
||||
this.controller.app.post(
|
||||
"/api/player_auth/player_code",
|
||||
express.json(),
|
||||
(req: Request, res: Response, next: any) => {
|
||||
this.handlePlayerCode(req, res).catch(next);
|
||||
}
|
||||
);
|
||||
|
||||
this.controller.app.post("/api/player_auth/verify", express.json(), (req: Request, res: Response, next: any) => {
|
||||
this.handleVerify(req, res).catch(next);
|
||||
});
|
||||
this.controller.app.post(
|
||||
"/api/player_auth/verify",
|
||||
express.json(),
|
||||
(req: Request, res: Response, next: any) => {
|
||||
this.handleVerify(req, res).catch(next);
|
||||
}
|
||||
);
|
||||
|
||||
this.controller.handle(FetchPlayerCodeRequest, this.handleFetchPlayerCodeRequest.bind(this));
|
||||
this.controller.handle(SetVerifyCodeRequest, this.handleSetVerifyCodeRequest.bind(this));
|
||||
|
||||
@@ -2,7 +2,7 @@ import * as lib from "@clusterio/lib";
|
||||
|
||||
import { FetchPlayerCodeRequest, SetVerifyCodeRequest } from "./messages";
|
||||
|
||||
type ipcPlayerAuth = {
|
||||
type IpcPlayerAuth = {
|
||||
type: "open_dialog",
|
||||
player: string,
|
||||
} | {
|
||||
@@ -17,12 +17,15 @@ export class InstancePlugin extends lib.BaseInstancePlugin {
|
||||
throw new Error("player_auth plugin requires save patching.");
|
||||
}
|
||||
|
||||
this.instance.server.on("ipc-player_auth", (ipcPlayerAuth: ipcPlayerAuth) => this.handleEvent(ipcPlayerAuth).catch(
|
||||
err => this.logger.error(`Error handling event:\n${err.stack}`)
|
||||
));
|
||||
this.instance.server.on(
|
||||
"ipc-player_auth",
|
||||
(ipcPlayerAuth: IpcPlayerAuth) => this.handleEvent(ipcPlayerAuth).catch(
|
||||
err => this.logger.error(`Error handling event:\n${err.stack}`)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
async handleEvent(event: ipcPlayerAuth) {
|
||||
async handleEvent(event: IpcPlayerAuth) {
|
||||
if (event.type === "open_dialog") {
|
||||
if (!this.host.connector.connected) {
|
||||
await this.sendRcon(`/web-login error ${event.player} login is temporarily unavailable`);
|
||||
|
||||
@@ -10,7 +10,7 @@ class FetchPlayerCodeResponse {
|
||||
static jsonSchema = Type.Object({
|
||||
"playerCode": Type.String(),
|
||||
"controllerUrl": Type.String(),
|
||||
})
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof FetchPlayerCodeResponse.jsonSchema>): FetchPlayerCodeResponse {
|
||||
return new this(json.playerCode, json.controllerUrl);
|
||||
@@ -32,7 +32,7 @@ export class FetchPlayerCodeRequest {
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"player": Type.String(),
|
||||
})
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof FetchPlayerCodeRequest.jsonSchema>): FetchPlayerCodeRequest {
|
||||
return new this(json.player);
|
||||
@@ -55,7 +55,7 @@ export class SetVerifyCodeRequest {
|
||||
static jsonSchema = Type.Object({
|
||||
"player": Type.String(),
|
||||
"verifyCode": Type.String(),
|
||||
})
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof SetVerifyCodeRequest.jsonSchema>): SetVerifyCodeRequest {
|
||||
return new this(json.player, json.verifyCode);
|
||||
|
||||
@@ -19,7 +19,7 @@ export class ContributionEvent {
|
||||
"name": Type.String(),
|
||||
"level": Type.Integer(),
|
||||
"contribution": Type.Number(),
|
||||
})
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof ContributionEvent.jsonSchema>): ContributionEvent {
|
||||
return new this(json.name, json.level, json.contribution);
|
||||
@@ -39,7 +39,7 @@ export class TechnologyProgress {
|
||||
"name": Type.String(),
|
||||
"level": Type.Integer(),
|
||||
"progress": Type.Number(),
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
export class ProgressEvent {
|
||||
@@ -57,8 +57,8 @@ export class ProgressEvent {
|
||||
static jsonSchema = Type.Object({
|
||||
"technologies": Type.Array(
|
||||
TechnologyProgress.jsonSchema
|
||||
)
|
||||
})
|
||||
),
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof ProgressEvent.jsonSchema>): ProgressEvent {
|
||||
return new this(json.technologies);
|
||||
@@ -81,7 +81,7 @@ export class FinishedEvent {
|
||||
static jsonSchema = Type.Object({
|
||||
"name": Type.String(),
|
||||
"level": Type.Integer(),
|
||||
})
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof FinishedEvent.jsonSchema>): FinishedEvent {
|
||||
return new this(json.name, json.level);
|
||||
@@ -100,9 +100,10 @@ export class TechnologySync {
|
||||
static jsonSchema = Type.Tuple([
|
||||
Type.String(),
|
||||
Type.Integer(),
|
||||
Type.Union([ Type.Number(), Type.Null() ]),
|
||||
Type.Union([Type.Number(), Type.Null()]),
|
||||
Type.Boolean(),
|
||||
])
|
||||
]);
|
||||
|
||||
toJSON() {
|
||||
return [this.name, this.level, this.progress, this.researched];
|
||||
}
|
||||
|
||||
@@ -186,7 +186,9 @@ export class ControllerPlugin extends lib.BaseControllerPlugin {
|
||||
// use fancy neural net to calculate a "fair" dole division rate.
|
||||
if (method === "neural_dole") {
|
||||
for (let item of request.items) {
|
||||
let count = this.neuralDole.divider({ name: item.name, count: item.count, instanceId, instanceName });
|
||||
let count = this.neuralDole.divider(
|
||||
{ name: item.name, count: item.count, instanceId, instanceName }
|
||||
);
|
||||
if (count > 0) {
|
||||
itemsRemoved.push(new Item(item.name, count));
|
||||
}
|
||||
|
||||
@@ -99,7 +99,8 @@ export class NeuralDole {
|
||||
// If the server regularly can't fulfill requests, this number grows until
|
||||
// it can. Then it slowly shrinks back down.
|
||||
let _doleDivisionFactor: { [key:string]: number } = {};
|
||||
export function doleDivider({
|
||||
export function doleDivider(
|
||||
{
|
||||
object,
|
||||
items,
|
||||
logItemTransfers,
|
||||
|
||||
@@ -73,7 +73,8 @@ export class InstancePlugin extends lib.BaseInstancePlugin {
|
||||
return;
|
||||
}
|
||||
|
||||
const fromIpcItems = items.map(item => new Item(item[0], item[1]))
|
||||
|
||||
const fromIpcItems = items.map(item => new Item(item[0], item[1]));
|
||||
this.instance.sendTo("controller", new PlaceEvent(fromIpcItems));
|
||||
|
||||
if (this.instance.config.get("subspace_storage.log_item_transfers")) {
|
||||
@@ -85,7 +86,7 @@ export class InstancePlugin extends lib.BaseInstancePlugin {
|
||||
// request items --------------------------------------------------------------
|
||||
async requestItems(requestItems: IpcItems) {
|
||||
// Request the items all at once
|
||||
let fromIpcItems = requestItems.map(item => new Item(item[0], item[1]))
|
||||
let fromIpcItems = requestItems.map(item => new Item(item[0], item[1]));
|
||||
let items = await this.instance.sendTo("controller", new RemoveRequest(fromIpcItems));
|
||||
|
||||
if (!items.length) {
|
||||
|
||||
@@ -37,8 +37,8 @@ export class PlaceEvent {
|
||||
}
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"items": Type.Array(Item.jsonSchema)
|
||||
})
|
||||
"items": Type.Array(Item.jsonSchema),
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof PlaceEvent.jsonSchema>): PlaceEvent {
|
||||
return new this(json.items.map(item => Item.fromJSON(item)));
|
||||
@@ -58,8 +58,8 @@ export class RemoveRequest {
|
||||
}
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"items": Type.Array(Item.jsonSchema)
|
||||
})
|
||||
"items": Type.Array(Item.jsonSchema),
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof RemoveRequest.jsonSchema>): RemoveRequest {
|
||||
return new this(json.items.map(item => Item.fromJSON(item)));
|
||||
@@ -91,8 +91,8 @@ export class UpdateStorageEvent {
|
||||
}
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"items": Type.Array(Item.jsonSchema)
|
||||
})
|
||||
"items": Type.Array(Item.jsonSchema),
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof UpdateStorageEvent.jsonSchema>): UpdateStorageEvent {
|
||||
return new this(json.items.map(item => Item.fromJSON(item)));
|
||||
@@ -113,8 +113,8 @@ export class SetStorageSubscriptionRequest {
|
||||
}
|
||||
|
||||
static jsonSchema = Type.Object({
|
||||
"storage": Type.Boolean()
|
||||
})
|
||||
"storage": Type.Boolean(),
|
||||
});
|
||||
|
||||
static fromJSON(json: Static<typeof SetStorageSubscriptionRequest.jsonSchema>): SetStorageSubscriptionRequest {
|
||||
return new this(json.storage);
|
||||
|
||||
Reference in new issue
Block a user