mirror of
https://github.com/clusterio/clusterio.git
synced 2026-11-17 15:33:12 +09:00
Implement mod pack storage
Add ModPack data type with corresponding storage on the master, messages to create, update and delete them, as well as commands to invoke them. The ModPack data type contains a list of mods with versions and optional sha1 hashes, and mod settings to be used.
This commit is contained in:
1 parent
dfcbc559b8
commit
9fb3d6d8db
16 files changed
+987
-3
No files matched your search
@@ -6,6 +6,7 @@ const events = require("events");
|
||||
const phin = require("phin");
|
||||
|
||||
const libBuildMod = require("@clusterio/lib/build_mod");
|
||||
const libData = require("@clusterio/lib/data");
|
||||
const libHash = require("@clusterio/lib/hash");
|
||||
const libLink = require("@clusterio/lib/link");
|
||||
const libUsers = require("@clusterio/lib/users");
|
||||
@@ -820,6 +821,70 @@ describe("Integration of Clusterio", function() {
|
||||
});
|
||||
});
|
||||
|
||||
describe("mod-pack create", function() {
|
||||
it("should create a mod-pack", async function() {
|
||||
await execCtl("mod-pack create empty-pack 1.1");
|
||||
let response = await libLink.messages.listModPacks.send(getControl());
|
||||
assert(response.list.some(modPack => modPack.name === "empty-pack"), "created pack is not in the list");
|
||||
});
|
||||
it("should allow setting all fields", async function() {
|
||||
await execCtl(
|
||||
"mod-pack create full-pack 0.17 " +
|
||||
"--description Description " +
|
||||
"--mods empty_mod:1.0.0 " +
|
||||
"--bool-setting startup MyBool true " +
|
||||
"--int-setting runtime-global MyInt 1235 " +
|
||||
"--double-setting runtime-global MyDouble 12.25 " +
|
||||
"--string-setting runtime-per-user MyString a-string"
|
||||
);
|
||||
let response = await libLink.messages.listModPacks.send(getControl());
|
||||
let modPack = response.list.find(entry => entry.name === "full-pack");
|
||||
assert(modPack, "created mod pack not found");
|
||||
let reference = new libData.ModPack();
|
||||
reference.id = modPack.id;
|
||||
reference.name = "full-pack";
|
||||
reference.description = "Description";
|
||||
reference.factorioVersion = "0.17";
|
||||
reference.mods.set("empty_mod", { name: "empty_mod", version: "1.0.0" });
|
||||
reference.settings["startup"].set("MyBool", { value: true });
|
||||
reference.settings["runtime-global"].set("MyInt", { value: 1235 });
|
||||
reference.settings["runtime-global"].set("MyDouble", { value: 12.25 });
|
||||
reference.settings["runtime-per-user"].set("MyString", { value: "a-string" });
|
||||
assert.deepEqual(new libData.ModPack(modPack), reference);
|
||||
});
|
||||
});
|
||||
|
||||
describe("mod-pack list", function() {
|
||||
it("runs", async function() {
|
||||
await execCtl("mod-pack list");
|
||||
});
|
||||
});
|
||||
|
||||
describe("mod-pack show", function() {
|
||||
it("runs", async function() {
|
||||
await execCtl("mod-pack show empty-pack");
|
||||
});
|
||||
});
|
||||
|
||||
describe("mod-pack edit", function() {
|
||||
it("runs", async function() {
|
||||
await execCtl("mod-pack edit full-pack --factorio-version 1.2");
|
||||
let response = await libLink.messages.listModPacks.send(getControl());
|
||||
let modPack = response.list.find(entry => entry.name === "full-pack");
|
||||
assert(modPack, "created mod pack not found");
|
||||
assert.equal(modPack.factorio_version, "1.2");
|
||||
});
|
||||
});
|
||||
|
||||
describe("mod-pack delete", function() {
|
||||
it("deletes the pack", async function() {
|
||||
await execCtl("mod-pack delete full-pack");
|
||||
let response = await libLink.messages.listModPacks.send(getControl());
|
||||
let modPack = response.list.find(entry => entry.name === "full-pack");
|
||||
assert(!modPack, "mod pack not deleted");
|
||||
});
|
||||
});
|
||||
|
||||
describe("mod upload", function() {
|
||||
it("uploads a mod", async function() {
|
||||
await libBuildMod.build({
|
||||
|
||||
@@ -29,6 +29,7 @@ class TestControl extends libLink.Link {
|
||||
this.instanceUpdates = [];
|
||||
this.saveListUpdates = [];
|
||||
this.modUpdates = [];
|
||||
this.modPackUpdates = [];
|
||||
this.userUpdates = [];
|
||||
|
||||
this.connector.on("connect", () => {
|
||||
@@ -75,6 +76,10 @@ class TestControl extends libLink.Link {
|
||||
this.modUpdates.push(message.data.mod);
|
||||
}
|
||||
|
||||
async modPackUpdateEventHandler(message) {
|
||||
this.modPackUpdates.push(message.data.mod_pack);
|
||||
}
|
||||
|
||||
async userUpdateEventHandler(message) {
|
||||
this.userUpdates.push(message.data);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,94 @@
|
||||
"use strict";
|
||||
const assert = require("assert").strict;
|
||||
const zlib = require("zlib");
|
||||
|
||||
const libSchema = require("@clusterio/lib/schema");
|
||||
const ModPack = require("@clusterio/lib/data/ModPack");
|
||||
|
||||
|
||||
describe("lib/data/ModPack", function() {
|
||||
describe("class ModPack", function() {
|
||||
it("should round trip serialize", function() {
|
||||
const validate = libSchema.compile(ModPack.jsonSchema);
|
||||
function check(pack) {
|
||||
const json = JSON.parse(JSON.stringify(pack));
|
||||
if (!validate(json)) {
|
||||
throw validate.errors;
|
||||
}
|
||||
assert.deepEqual(new ModPack(json), pack);
|
||||
const packStringed = ModPack.fromModPackString(pack.toModPackString(true));
|
||||
packStringed.id = pack.id;
|
||||
assert.deepEqual(packStringed, pack);
|
||||
}
|
||||
|
||||
check(new ModPack());
|
||||
check(new ModPack({ name: "MyPack" }));
|
||||
check(new ModPack({ description: "My Description" }));
|
||||
check(new ModPack({ factorio_version: "2.0" }));
|
||||
check(new ModPack({ mods: [
|
||||
{ name: "subspace_storage", version: "1.99.8" },
|
||||
{ name: "clusterio_lib", version: "0.1.2", hash: "sha1:012345abcd" },
|
||||
]}));
|
||||
check(new ModPack({ settings: {
|
||||
"startup": {
|
||||
"bool-setting": { "value": true },
|
||||
},
|
||||
"runtime-global": {
|
||||
"number-setting": { "value": 123 },
|
||||
},
|
||||
"runtime-per-user": {
|
||||
"string-setting": { "value": "a string" },
|
||||
},
|
||||
}}));
|
||||
check(new ModPack({ deleted: true }));
|
||||
check(new ModPack({
|
||||
name: "Super pack",
|
||||
description: "Every option at once.",
|
||||
factorio_version: "2.0",
|
||||
mods: [
|
||||
{ name: "subspace_storage", version: "1.99.8" },
|
||||
{ name: "clusterio_lib", version: "0.1.2", hash: "sha1:012345abcd" },
|
||||
],
|
||||
settings: {
|
||||
"startup": {
|
||||
"bool-setting": { "value": true },
|
||||
},
|
||||
"runtime-global": {
|
||||
"number-setting": { "value": 123 },
|
||||
},
|
||||
"runtime-per-user": {
|
||||
"string-setting": { "value": "a string" },
|
||||
},
|
||||
},
|
||||
deleted: true,
|
||||
}));
|
||||
});
|
||||
|
||||
it("should sort integer factorio versions lexicographically", function() {
|
||||
let unsortedVersions = ["1.0", "1.1.0", "0.1", "3.0.0", "1.2", "0.3.1", "0.3.3", "2.1.1", "0.0.1"];
|
||||
let sortedVersions = ["0.0.1", "0.1", "0.3.1", "0.3.3", "1.0", "1.1.0", "1.2", "2.1.1", "3.0.0"];
|
||||
let factorioMods = unsortedVersions.map(v => new ModPack({ factorio_version: v }));
|
||||
factorioMods.sort((a, b) => a.integerFactorioVersion - b.integerFactorioVersion);
|
||||
assert.deepEqual(factorioMods.map(mod => mod.factorioVersion), sortedVersions);
|
||||
});
|
||||
|
||||
describe(".fromModPackString()", function() {
|
||||
it("should handle malformed strings", function() {
|
||||
assert.throws(
|
||||
() => ModPack.fromModPackString("AMalformedString"),
|
||||
new Error("Malformed mod pack string: zlib inflate failed")
|
||||
);
|
||||
assert.throws(
|
||||
// eslint-disable-next-line node/no-sync
|
||||
() => ModPack.fromModPackString(Buffer.from(zlib.deflateSync("Not Json")).toString("base64")),
|
||||
new Error("Malformed mod pack string: Unexpected token N in JSON at position 0")
|
||||
);
|
||||
assert.throws(
|
||||
// eslint-disable-next-line node/no-sync
|
||||
() => ModPack.fromModPackString(Buffer.from(zlib.deflateSync('{"i":1}')).toString("base64")),
|
||||
new Error("Malformed mod pack string: Schema validation failed")
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user