mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-20 07:43:12 +09:00
Refactor master code
Move implementation of master systems into dedicated classes for better organization.
This commit is contained in:
1 parent
8b32267858
commit
67219ede6b
19 files changed
+2135
-1932
No files matched your search
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
"use strict";
|
||||
const crypto = require("crypto");
|
||||
const express = require("express");
|
||||
const util = require("util");
|
||||
const jwt = require("jsonwebtoken");
|
||||
|
||||
@@ -46,7 +47,7 @@ class MasterPlugin extends libPlugin.BaseMasterPlugin {
|
||||
this.metrics.endpointHitCounter.labels(req.route.path).inc();
|
||||
|
||||
let servers = [];
|
||||
for (let instance of this.master.db.instances.values()) {
|
||||
for (let instance of this.master.instances.values()) {
|
||||
if (instance.status === "running" && instance.config.get("player_auth.load_plugin")) {
|
||||
servers.push(instance.config.get("factorio.settings")["name"] || "unnamed server");
|
||||
}
|
||||
@@ -54,12 +55,12 @@ class MasterPlugin extends libPlugin.BaseMasterPlugin {
|
||||
res.send(servers);
|
||||
});
|
||||
|
||||
this.master.app.post("/api/player_auth/player_code", (req, res, next) => {
|
||||
this.master.app.post("/api/player_auth/player_code", express.json(), (req, res, next) => {
|
||||
this.metrics.endpointHitCounter.labels(req.route.path).inc();
|
||||
this.handlePlayerCode(req, res).catch(next);
|
||||
});
|
||||
|
||||
this.master.app.post("/api/player_auth/verify", (req, res, next) => {
|
||||
this.master.app.post("/api/player_auth/verify", express.json(), (req, res, next) => {
|
||||
this.metrics.endpointHitCounter.labels(req.route.path).inc();
|
||||
this.handleVerify(req, res).catch(next);
|
||||
});
|
||||
@@ -142,7 +143,7 @@ class MasterPlugin extends libPlugin.BaseMasterPlugin {
|
||||
for (let [player, entry] of this.players) {
|
||||
if (entry.playerCode === playerCode && entry.expires > Date.now()) {
|
||||
if (entry.verifyCode === verifyCode) {
|
||||
let user = this.master.db.users.get(player);
|
||||
let user = this.master.userManager.users.get(player);
|
||||
if (!user) {
|
||||
res.send({ error: true, message: "invalid user" });
|
||||
return;
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
"@clusterio/lib": "^2.0.0-alpha.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"express": "^4.16.2",
|
||||
"jsonwebtoken": "^8.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
@@ -53,7 +53,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) {
|
||||
masterPlugin.master.db.instances.set(id, {
|
||||
masterPlugin.master.instances.set(id, {
|
||||
config: {
|
||||
get(field) {
|
||||
if (field === "player_auth.load_plugin") {
|
||||
@@ -78,7 +78,7 @@ describe("player_auth", function() {
|
||||
});
|
||||
assert.deepEqual(result.body, ["running loaded", "unnamed server"]);
|
||||
for (let id of [1, 2, 3, 4, 5]) {
|
||||
masterPlugin.master.db.instances.delete(id);
|
||||
masterPlugin.master.instances.delete(id);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
@@ -137,8 +137,8 @@ class MasterPlugin extends libPlugin.BaseMasterPlugin {
|
||||
}
|
||||
|
||||
} else {
|
||||
let instanceConfig = this.master.db.instances.get(instanceId);
|
||||
let instanceName = instanceConfig ? instanceConfig.get("instance.name") : "unkonwn";
|
||||
let instance = this.master.instances.get(instanceId);
|
||||
let instanceName = instance ? instance.config.get("instance.name") : "unkonwn";
|
||||
|
||||
// use fancy neural net to calculate a "fair" dole division rate.
|
||||
if (method === "neural_dole") {
|
||||
|
||||
Reference in new issue
Block a user