mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-13 15:14:52 +09:00
Refactor user and instance manager (#837)
* Refactor UserManager to use Datastore * Rename lib.User to UserDetails also adds to/fromUserDetails * Fix existing tests * Add user class tests * Add tests for finaliseUsers * Move HostDetails to own file with tests * Move InstanceDetails to its own file with tests * Rename HostInfo and add tests * Rename InstanceInfo and add tests - Also changes the names of the host properties related to instances - Also removes the need to specify the location of InstanceInfo * Make json round trip test validate schema * Add InstanceManager * Fix lint errors * Extra tests * Add final test coverage * Add one last test to InstanceManager * Response to comments * Use generator rather than return anonumous generator Co-authored-by: Hornwitser <github@hornwitser.no> * Fix lint issue with generator --------- Co-authored-by: Hornwitser <github@hornwitser.no>
This commit is contained in:
1 parent
5bea930d05
commit
2235294c59
60 files changed
+3371
-1227
No files matched your search
@@ -1,4 +1,4 @@
|
||||
import { BaseControllerPlugin, type InstanceInfo } from "@clusterio/controller";
|
||||
import { BaseControllerPlugin, type InstanceRecord } from "@clusterio/controller";
|
||||
import type { IpcPlayerData } from "./messages";
|
||||
|
||||
import fs from "fs-extra";
|
||||
@@ -51,7 +51,7 @@ export class ControllerPlugin extends BaseControllerPlugin {
|
||||
this.controller.handle(msg.DatabaseStatsRequest, this.handleDatabaseStatsRequest.bind(this));
|
||||
}
|
||||
|
||||
async onInstanceStatusChanged(instance: InstanceInfo) {
|
||||
async onInstanceStatusChanged(instance: InstanceRecord) {
|
||||
let instanceId = instance.id;
|
||||
if (["unassigned", "deleted"].includes(instance.status)) {
|
||||
for (let [playerName, acquisitionRecord] of this.acquiredPlayers) {
|
||||
|
||||
@@ -152,13 +152,13 @@ export class ControllerPlugin extends BaseControllerPlugin {
|
||||
for (let [player, entry] of this.players) {
|
||||
if (entry.playerCode === playerCode && entry.expiresMs > Date.now()) {
|
||||
if (entry.verifyCode === verifyCode) {
|
||||
let user = this.controller.userManager.getByName(player);
|
||||
let user = this.controller.users.getByName(player);
|
||||
if (!user) {
|
||||
res.send({ error: true, message: "invalid user" });
|
||||
return;
|
||||
}
|
||||
|
||||
let token = this.controller.userManager.signUserToken(user);
|
||||
let token = this.controller.users.signUserToken(user);
|
||||
res.send({ verified: true, token });
|
||||
return;
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ describe("player_auth", function() {
|
||||
describe("/api/player_auth/servers", function() {
|
||||
it("should return a list of running servers with player_auth loaded", async function() {
|
||||
function addInstance(id, status, load, name) {
|
||||
controllerPlugin.controller.instances.set(id, {
|
||||
controllerPlugin.controller.instances.records.set(id, {
|
||||
config: {
|
||||
get(field) {
|
||||
if (field === "player_auth.load_plugin") {
|
||||
@@ -85,7 +85,7 @@ describe("player_auth", function() {
|
||||
const result = await fetch(`${controllerUrl}/api/player_auth/servers`);
|
||||
assert.deepEqual(await result.json(), ["running loaded", "unnamed server"]);
|
||||
for (let id of [1, 2, 3, 4, 5]) {
|
||||
controllerPlugin.controller.instances.delete(id);
|
||||
controllerPlugin.controller.instances.records.delete(id);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -286,8 +286,8 @@ describe("player_auth", function() {
|
||||
new SetVerifyCodeRequest("test", verify_code)
|
||||
);
|
||||
|
||||
const user = controllerPlugin.controller.userManager.getByName("test");
|
||||
const token = controllerPlugin.controller.userManager.signUserToken(user);
|
||||
const user = controllerPlugin.controller.users.getByName("test");
|
||||
const token = controllerPlugin.controller.users.signUserToken(user);
|
||||
const verifyResult = await postJSON(
|
||||
`${controllerUrl}/api/player_auth/verify`,
|
||||
{ player_code: playerCode, verify_code, verify_token }
|
||||
|
||||
Reference in new issue
Block a user