Files
factorio-clusterio/plugins/player_auth/instance.ts
bbassieandClaude Opus 5.5 e94abe51c9 Lint with Oxlint through Vite+ instead of ESLint
Replace ESLint, typescript-eslint, eslint-plugin-node and the flat
config helpers with vite-plus, which runs Oxlint for vp lint. The rules
are carried over from eslint.config.mjs by @oxlint/migrate into the lint
section of the root vite.config.ts. The formatting rules ESLint
deprecated run as @stylistic rules through Oxlint's JS plugin support,
and disable comments naming them are updated to the @stylistic names.

@stylistic understands TypeScript syntax that the core rules skipped,
so the autofix adds missing semicolons and spaces in type literals and
aliases. Leading | and & in multiline types stay where they were.

Oxlint's node/no-sync also reports identifiers ending in Sync that are
not calls. The test helper techSync is renamed and the two other names
are ignored.

Refs #1127

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-27 22:53:13 +00:00

57 lines
1.6 KiB
TypeScript

import type { InstancePluginContext } from "@clusterio/host";
import { FetchPlayerCodeRequest, SetVerifyCodeRequest } from "./messages.js";
type IpcPlayerAuth = {
type: "open_dialog",
player: string,
} | {
type: "set_verify_code",
player: string,
verify_code: string,
};
export default async function loadInstancePlugin(context: InstancePluginContext) {
const { instance, host, logger, plugin } = context;
async function sendRcon(command: string) {
await instance.sendRcon(command, false, plugin.name);
}
async function handleEvent(event: IpcPlayerAuth) {
if (event.type === "open_dialog") {
if (!host.connector.connected) {
await sendRcon(`/web-login error ${event.player} login is temporarily unavailable`);
return;
}
let response;
try {
response = await instance.sendTo("controller", new FetchPlayerCodeRequest(event.player));
} catch (err: any) {
await sendRcon(`/web-login error ${event.player} ${err.message}`);
return;
}
await sendRcon(`/web-login open ${event.player} ${response.controllerUrl} ${response.playerCode}`);
} else if (event.type === "set_verify_code") {
try {
await instance.sendTo("controller", new SetVerifyCodeRequest(event.player, event.verify_code));
} catch (err: any) {
await sendRcon(`/web-login error ${event.player} ${err.message}`);
return;
}
await sendRcon(`/web-login code_set ${event.player}`);
}
}
instance.server.on(
"ipc-player_auth",
(ipcPlayerAuth: IpcPlayerAuth) => handleEvent(ipcPlayerAuth).catch(
err => logger.error(`Error handling event:\n${err.stack}`)
)
);
}