Merge pull request #318 from Hornwitser/restructure-project

Restructure project
This commit is contained in:
Daniel authored and GitHub committed 2020-09-21 11:57:43 -07:00
commit bca949f7be
135 files changed
+425 -630

No files matched your search

+1
View File
@@ -0,0 +1 @@
packages/master/static
+2 -2
View File
@@ -28,7 +28,7 @@ dist/
# Autogenerated docs output # Autogenerated docs output
/docs/api /docs/api
node_modules/* node_modules
Factorio* Factorio*
/factorio /factorio
@@ -41,7 +41,7 @@ Factorio*
package-lock.json package-lock.json
mod_cache.json mod_cache.json
static/export static/export
static/external packages/master/static/external
saves saves
/temp/ /temp/
+2 -1
View File
@@ -6,7 +6,8 @@ before_install:
- tar -xf factorio.tar.gz - tar -xf factorio.tar.gz
- npm install -g codecov - npm install -g codecov
script: script:
- node build-mod --bump-patch --factorio-version 0.18 --output-dir sharedMods - npx lerna bootstrap --no-ci
- node packages/lib/build_mod --bump-patch --factorio-version 0.18 --output-dir sharedMods
- curl -o sharedMods/subspace_storage_1.99.1.zip -L https://github.com/clusterio/factorioClusterioMod/releases/download/1.99.1/subspace_storage_1.99.1.zip - curl -o sharedMods/subspace_storage_1.99.1.zip -L https://github.com/clusterio/factorioClusterioMod/releases/download/1.99.1/subspace_storage_1.99.1.zip
- npm run-script ci-cover - npm run-script ci-cover
- cat temp/test/integration/log.txt - cat temp/test/integration/log.txt
+1 -1
View File
@@ -15,7 +15,7 @@ Version 2.0.0
- Daemonized slaves. Slaves now have the ability to run multiple Factorio - Daemonized slaves. Slaves now have the ability to run multiple Factorio
instances, starting and stopping them individually. To manage this the instances, starting and stopping them individually. To manage this the
local command line interface has been replaced with a remote interface on local command line interface has been replaced with a remote interface on
the master server that can be accessed through the clusterctl cli tool. the master server that can be accessed through the clusterioctl cli tool.
- Rewritten the communication between slaves and the master from scratch. The - Rewritten the communication between slaves and the master from scratch. The
new system is based on a WebSocket connection between the slaves and the new system is based on a WebSocket connection between the slaves and the
master server and provides efficient validated bi-directonal communication. master server and provides efficient validated bi-directonal communication.
+25 -39
View File
@@ -105,12 +105,13 @@ supported on EOL Ubuntu releases so make sure you're on a recent release of Ubun
Master and all slaves: Master and all slaves:
wget -qO - https://deb.nodesource.com/setup_12.x | sudo -E bash - wget -qO - https://deb.nodesource.com/setup_12.x | sudo -E bash -
sudo apt install -y nodejs python-dev git build-essential sudo apt install -y nodejs
git clone -b master https://github.com/clusterio/factorioClusterio.git mkdir clusterio
cd factorioClusterio cd clusterio
npm init -y
npm install @clusterio/master @clusterio/slave @clusterio/ctl
wget -O factorio.tar.gz https://www.factorio.com/get-download/latest/headless/linux64 wget -O factorio.tar.gz https://www.factorio.com/get-download/latest/headless/linux64
tar -xf factorio.tar.gz tar -xf factorio.tar.gz
npm install --only=production
downloads and installs nodejs, git and clusterio. To specify a version, change "latest" in the link to a version number like 0.14.21. downloads and installs nodejs, git and clusterio. To specify a version, change "latest" in the link to a version number like 0.14.21.
@@ -136,30 +137,19 @@ The -v flag is used to specify the instance directory. Your instances (save file
**Warning**: These instructions are for the unstable master version and is not **Warning**: These instructions are for the unstable master version and is not
recommended for use, see [the 1.2.x branch][1.2.x] for how to install the stable version. recommended for use, see [the 1.2.x branch][1.2.x] for how to install the stable version.
Clusterio is built up of multiple parts. Here is a quick guide:
Master = master.js
Server host (Slave) = slave.js + factorio server
Game Client = The people connecting to the server
**Requirements** **Requirements**
download and install nodeJS 12 from http://nodejs.org. Clusterio runs on Node.js v12 and download and install nodeJS 12 from http://nodejs.org. Clusterio runs on Node.js v12 and
up, v11.13.0+ and v10.16.0+. up, v11.13.0+ and v10.16.0+.
download and install git from https://git-scm.com/
reboot when you are done, then proceed to the next steps. *reboots matter*
**Master** **Master**
1. Open PowerShell or Command prompt in the directory you want to install to and run the following commands. 1. Open PowerShell or Command prompt in the directory you want to install to and run the following commands.
git clone -b master https://github.com/clusterio/factorioClusterio mkdir clusterio
cd factorioClusterio cd clusterio
npm install --only=production npm init -y
npm install @clusterio/master @clusterio/slave @clusterio/ctl
2. Obtain Factorio by either of these two methods: 2. Obtain Factorio by either of these two methods:
@@ -198,12 +188,12 @@ Before you can manage the cluster you need to bootstrap an admin account
for it. Replace `<username>` with your Factorio username (do not make for it. Replace `<username>` with your Factorio username (do not make
up a new username here). up a new username here).
node master bootstrap create-admin <username> npx clusteriomaster bootstrap create-admin <username>
node master bootstrap create-ctl-config <username> npx clusteriomaster bootstrap create-ctl-config <username>
The first command creates a user account with the given name and The first command creates a user account with the given name and
promotes it to a cluster admin. The second one sets up a promotes it to a cluster admin. The second one sets up a
`config-control.json` config for clusterctl to connect to the master `config-control.json` config for clusterioctl to connect to the master
server under the given user account. server under the given user account.
@@ -213,7 +203,7 @@ It's necessary to run the master server in order for anything to work.
Once you've completed the setup run the following command to start it Once you've completed the setup run the following command to start it
up: up:
node master run npx clusteriomaster run
### Slaves ### Slaves
@@ -223,7 +213,7 @@ master server. In order for slaves to connect to the master server they
need a valid authentication token, you can create a slave config with need a valid authentication token, you can create a slave config with
a valid token with the following command. a valid token with the following command.
node clusterctl slave create-config --name Local --generate-token npx clusterioctl slave create-config --name Local --generate-token
This will write a new `config-slave.json` file in the current directory This will write a new `config-slave.json` file in the current directory
(you can change the location with the `--output` option) with the name, (you can change the location with the `--output` option) with the name,
@@ -232,30 +222,30 @@ the config for a remote slave you will need to have set the
`master.external_address` option to the URL the master server can be `master.external_address` option to the URL the master server can be
reached on. reached on.
You can list the config of a slave on the slave itself with the `node You can list the config of a slave on the slave itself with the `npx
slave config list` command. Use `node slave config --help` for more clusterioslave config list` command. Use `npx clusterioslave config
information. --help` for more information.
Once the config is set up run the slave with Once the config is set up run the slave with
node slave run npx clusterioslave run
### Instances ### Instances
Instances are created, managed and started from the master server. For Instances are created, managed and started from the master server. For
now the only interface available is the `clusterctl` command line tool now the only interface available is the `clusterioctl` command line tool
included in Clusterio. You can run this tool from any slave, or the included in Clusterio. You can run this tool from any slave, or the
master server without having to set up a config, if you want to manage master server without having to set up a config, if you want to manage
the cluster from somewhere else you will need to set the the cluster from somewhere else you will need to set the
`control.master_url` and `control.master_token` options with the `node `control.master_url` and `control.master_token` options with the `node
clusterctl control-config set` command: clusterioctl control-config set` command:
The basic operations to start a new instance is the following The basic operations to start a new instance is the following
node clusterctl instance create "My instance" npx clusterioctl instance create "My instance"
node clusterctl instance assign "My instance" "Local" npx clusterioctl instance assign "My instance" "Local"
node clusterctl instance start "My instance" npx clusterioctl instance start "My instance"
The first line creates the instance configuration on the master server. The first line creates the instance configuration on the master server.
The second assigns the instance to a slave which creates the instance The second assigns the instance to a slave which creates the instance
@@ -263,8 +253,8 @@ directory and files needed to run the instance on the given slave. The
third line starts the instance, which creates a new save if there are no third line starts the instance, which creates a new save if there are no
save games present. save games present.
There are many more commands available with clusterctl. See There are many more commands available with clusterioctl. See
`node clusterctl --help` for a full list of them. `npx clusterioctl --help` for a full list of them.
## Plugins ## Plugins
@@ -298,7 +288,3 @@ TLDR: the tested fix is:
- select TCP and select specific local ports and type in the ports that you want to open (comma separated) and click next > 3 times - select TCP and select specific local ports and type in the ports that you want to open (comma separated) and click next > 3 times
- give the rule a name (like 'web server' or something), give it a description (optionally) and click finish - give the rule a name (like 'web server' or something), give it a description (optionally) and click finish
### Other fixes for other potential problems:
Sometimes the install fails. Try `node ./lib/npmPostinstall` to complete it.
+4 -3
View File
@@ -49,9 +49,10 @@ Message
There's two types of messages currently implemented apart from the There's two types of messages currently implemented apart from the
Link builtin close message and that's Request and Event. The builtin Link builtin close message and that's Request and Event. The builtin
messages are defined in [lib/link/messages.js](../lib/link/messages.js) messages are defined in
and are attached to links via the attachAllMessages function, which is [packages/lib/link/messages.js](/packages/lib/link/messages.js) and are
usally called in the Link subclass constructor. attached to links via the attachAllMessages function, which is usally
called in the Link subclass constructor.
The messages define which links they are valid on and only attaches The messages define which links they are valid on and only attaches
handlers for those links. There's also a forwarding mechanism for when handlers for those links. There's also a forwarding mechanism for when
+4 -4
View File
@@ -6,16 +6,16 @@ configuration system in Clusterio, and unless you're developing
Clusterio it's probably not going to be very useful for you.</sub> Clusterio it's probably not going to be very useful for you.</sub>
Clusterio uses a group based configuration system to manage settings for Clusterio uses a group based configuration system to manage settings for
the master server, instances, slaves, and the clusterctl utility. the master server, instances, slaves, and the clusterioctl utility.
Plugins get their own config group for the master server and instances Plugins get their own config group for the master server and instances
which they can add their own fields to. The fields are defined early in which they can add their own fields to. The fields are defined early in
the startup, and the groups and their fields for disabled plugins will the startup, and the groups and their fields for disabled plugins will
still be created. still be created.
The built-in config groups and their fields are defined in The built-in config groups and their fields are defined in
[/lib/config/definitions.js](lib/config/definitions.js) while plugins [packages/lib/config/definitions.js](/packages/lib/config/definitions.js)
can add their own config groups to the `MasterConfigGroup` and while plugins can add their own config groups to the `MasterConfigGroup`
`InstanceConfigGroup` properties of the `info.js` export using and `InstanceConfigGroup` properties of the `info.js` export using
subclasses of `PluginConfigGroup`. The plugin group has the enabled subclasses of `PluginConfigGroup`. The plugin group has the enabled
field pre-defined on it, and it's used to enable/disable plugins. field pre-defined on it, and it's used to enable/disable plugins.
+14
View File
@@ -11,6 +11,7 @@ Contents
- [Workflow](#workflow) - [Workflow](#workflow)
- [Starting a Feature Branch](#starting-a-feature-branch) - [Starting a Feature Branch](#starting-a-feature-branch)
- [Setting up the Development Environment](#setting-up-the-development-environment)
- [Checking your code for errors](#checking-your-code-for-errors) - [Checking your code for errors](#checking-your-code-for-errors)
- [Submitting a Pull Request](#submitting-a-pull-request) - [Submitting a Pull Request](#submitting-a-pull-request)
- [Editing your Feature Branch](#editing-your-feature-branch) - [Editing your Feature Branch](#editing-your-feature-branch)
@@ -56,6 +57,19 @@ from the main repository. Do not run `git pull upstream` it will mess
thing up! thing up!
### Setting up the Development Environment
The project is organized into several packages that are all managed
through Lerna. In order to get the development environment up and
running you will need to run the following commands:
npm install
npx lerna bootstrap
This installs dependencies needed by tests and links the packages up so
they work from the git work tree.
### Starting a Feature Branch ### Starting a Feature Branch
Development is done exclusively in feature branches. This means the Development is done exclusively in feature branches. This means the
+6 -6
View File
@@ -11,12 +11,12 @@
}, },
"source": { "source": {
"include": [ "include": [
"master.js", "packages/master/src/",
"slave.js", "packages/master/master.js",
"clusterctl.js", "packages/slave/slave.js",
"lib/", "packages/ctl/ctl.js",
"plugins/", "packages/lib/",
"routes.js" "plugins/"
], ],
"excludePattern": "node_modules" "excludePattern": "node_modules"
} }
+7 -7
View File
@@ -2,17 +2,17 @@ Managing a Cluster
================== ==================
Clusterio clusers are managed through the master server by using the Clusterio clusers are managed through the master server by using the
`clusterctl` command line interface which is invoked by running `clusterioctl` command line interface which is invoked by running
`node clusterctl <command>` in the clusterio directory. This document `npx clusterioctl <command>` in the clusterio directory. This document
uses the shorthand `ctl> foo` to indicate `node clusterctl foo` should uses the shorthand `ctl> foo` to indicate `npx clusterioctl foo` should
be executed. Mandatory parameters are shown in `<angles bracket>` and be executed. Mandatory parameters are shown in `<angles bracket>` and
optional pameters are in `[square brackets]`. optional pameters are in `[square brackets]`.
Before `clusterctl` can be used it needs to be configured for the Before `clusterioctl` can be used it needs to be configured for the
cluster it will connect to. The easiest way to do this is to run cluster it will connect to. The easiest way to do this is to run
`node master bootstrap create-ctl-config <username>` on the master `npx clusteriomaster bootstrap create-ctl-config <username>` on the
server, which creates the necessary `config-control.json` for managing master server, which creates the necessary `config-control.json` for
the cluster as the given user. managing the cluster as the given user.
Slaves Slaves
+4 -4
View File
@@ -230,8 +230,8 @@ there's [Requests](#requests). By convention message types ending in
`*_event` are events. The data payload of an event consists solely of `*_event` are events. The data payload of an event consists solely of
event specific properties. event specific properties.
See [lib/link/messages.js](/lib/link/messages.js) for the recognized See [packages/lib/link/messages.js](/packages/lib/link/messages.js) for
events and their contents. the recognized events and their contents.
Requests Requests
@@ -245,8 +245,8 @@ replied to with a corresponding `*_response` message. If an error
occured while processing the request an error response containing an occured while processing the request an error response containing an
error property in the data payload is sent instead. error property in the data payload is sent instead.
See [lib/link/messages.js](/lib/link/messages.js) for the recognized See [packages/lib/link/messages.js](/packages/lib/link/messages.js) for
requests and their contents. the recognized requests and their contents.
### `*_response` ### `*_response`
+16 -16
View File
@@ -19,7 +19,7 @@ Contents
- [Sending Link Messages](#sending-link-messages) - [Sending Link Messages](#sending-link-messages)
- [Handling connection events](#handling-connection-events) - [Handling connection events](#handling-connection-events)
- [Collecting Statistics](#collecting-statistics) - [Collecting Statistics](#collecting-statistics)
- [Adding Custom Commands to clusterctl](#adding-custom-commands-to-clusterctl) - [Adding Custom Commands to clusterioctl](#adding-custom-commands-to-clusterioctl)
Plugin Structure Plugin Structure
@@ -42,7 +42,7 @@ The basic file structure of a plugin is the following.
The most important file is the `info.js` file. Without it the plugin The most important file is the `info.js` file. Without it the plugin
will not recognized by Clusterio. Here's an example of it: will not recognized by Clusterio. Here's an example of it:
const link = require('lib/link'); // For messages const link = require('@clusterio/lib/link'); // For messages
module.exports = { module.exports = {
name: "foo_frobber", name: "foo_frobber",
@@ -100,7 +100,7 @@ The following properties are recognized:
Path to a Node.js module relative to the plugin directory which Path to a Node.js module relative to the plugin directory which
contains the ControlPlugin class definition for this plugin. This contains the ControlPlugin class definition for this plugin. This
is an optional paramater. A plugin can be made that only runs on is an optional paramater. A plugin can be made that only runs on
the clusterctl side. the clusterioctl side.
**messages**: **messages**:
Object with link messages definitions for this plugin. See guide Object with link messages definitions for this plugin. See guide
@@ -129,7 +129,7 @@ The plugin class should derive from its respective base class defined in
`lib/plugin`. For example, to define a MasterPlugin class the following `lib/plugin`. For example, to define a MasterPlugin class the following
code can be used: code can be used:
const plugin = require('lib/plugin'); const plugin = require('@clusterio/lib/plugin');
class MasterPlugin extends plugin.BaseMasterPlugin { class MasterPlugin extends plugin.BaseMasterPlugin {
async init() { async init() {
@@ -145,9 +145,9 @@ code can be used:
} }
For the instance plugin it's exactly the same except "Master" is For the instance plugin it's exactly the same except "Master" is
replaced with "Instance", and for the clusterctl plugin "Control" is replaced with "Instance", and for the clusterioctl plugin "Control" is
used. The available hooks that you can override are documented in the used. The available hooks that you can override are documented in the
base class [in lib/plugin.js](../lib/plugin.js). base class [in lib/plugin.js](/packages/lib/plugin.js).
It's best to avoid defining a constructor, but if you insist on defining It's best to avoid defining a constructor, but if you insist on defining
one, forward all arguments to the base class. E.g.: one, forward all arguments to the base class. E.g.:
@@ -173,7 +173,7 @@ take advantage of it by subclassing `PluginConfigGroup`, setting the
and passing it as either `MasterConfigGroup` or `InstanceConfigGroup` in and passing it as either `MasterConfigGroup` or `InstanceConfigGroup` in
the `info.js` export. For example in info.js: the `info.js` export. For example in info.js:
const config = require("lib/config"); const config = require("@clusterio/lib/config");
class MasterConfigGroup extends config.PluginConfigGroup { } class MasterConfigGroup extends config.PluginConfigGroup { }
MasterConfigGroup.groupName = "foo_frobber"; MasterConfigGroup.groupName = "foo_frobber";
@@ -550,7 +550,7 @@ from plugins optionally loaded at runtime on different computers.
In its simplest form collecting data from plugins consists of defining In its simplest form collecting data from plugins consists of defining
the metric and updating it somewhere in the plugin code. For example: the metric and updating it somewhere in the plugin code. For example:
const { Counter } = require('lib/prometheus'); const { Counter } = require('@clusterio/lib/prometheus');
const fooMetric = new Counter( const fooMetric = new Counter(
'clusterio_foo_frobber_foo_metric', "Measures the level of foo", 'clusterio_foo_frobber_foo_metric', "Measures the level of foo",
@@ -567,7 +567,7 @@ naming scheme.
For metrics that are per-instance, you must define an `instance_id` label and For metrics that are per-instance, you must define an `instance_id` label and
set it accordingly, for example: set it accordingly, for example:
const { Counter } = require('lib/prometheus'); const { Counter } = require('@clusterio/lib/prometheus');
const barMetric = new Gauge( const barMetric = new Gauge(
'clusterio_foo_frobber_bar_metric', "Bar instance level", 'clusterio_foo_frobber_bar_metric', "Bar instance level",
@@ -591,14 +591,14 @@ hook on both master and instance plugins that is run before the
metrics in the default registry are collected. metrics in the default registry are collected.
Adding Custom Commands to clusterctl Adding Custom Commands to clusterioctl
------------------------------------ --------------------------------------
The control entrypoint for plugins allows you to extend clustectl with The control entrypoint for plugins allows you to extend clustectl with
your own commands. The creation of custom commands typically starts your own commands. The creation of custom commands typically starts
with defining a command tree for the plugin: with defining a command tree for the plugin:
const { Command, CommandTree } = require("lib/command"); const { Command, CommandTree } = require("@clusterio/lib/command");
const fooFrobberCommands = new CommandTree({ const fooFrobberCommands = new CommandTree({
name: "foo-frobber", description: "Foo Frobber Plugin commands" name: "foo-frobber", description: "Foo Frobber Plugin commands"
}); });
@@ -630,18 +630,18 @@ and
for setting up positional and optional arguments to commands). The for setting up positional and optional arguments to commands). The
`handler` is an async function that's invoked when the command is `handler` is an async function that's invoked when the command is
executed and it's passed the parsed command line arguments and a executed and it's passed the parsed command line arguments and a
reference to the `Control` class of clusterctl. It's possible to optain reference to the `Control` class of clusterioctl. It's possible to optain
a reference to the plugin class with `control.plugins.get(info.name)`. a reference to the plugin class with `control.plugins.get(info.name)`.
Note that messages sent from clusterctl needs to have Note that messages sent from clusterioctl needs to have
`"control-master"` as a part of the links array for it to be accepted by `"control-master"` as a part of the links array for it to be accepted by
the master server, see [Defining Link Messages](#defining-link-messages) the master server, see [Defining Link Messages](#defining-link-messages)
for how to define the messages that can be sent to the master. for how to define the messages that can be sent to the master.
To have the command tree become part of clusterctl it needs to be added To have the command tree become part of clusterioctl it needs to be added
to the rootCommand tree in `addCommands` callback of the Control plugin: to the rootCommand tree in `addCommands` callback of the Control plugin:
const plugin = require("lib/plugin"); const plugin = require("@clusterio/lib/plugin");
class ControlPlugin extends plugin.BaseControlPlugin { class ControlPlugin extends plugin.BaseControlPlugin {
async addCommands(rootCommand) { async addCommands(rootCommand) {
+6
View File
@@ -0,0 +1,6 @@
{
"packages": [
"packages/*"
],
"version": "2.0.0-alpha0"
}
-299
View File
@@ -1,299 +0,0 @@
// This file will be rewritten from scratch
/* eslint-disable */
/**
Provides tools to manage mods in a clusterio install
@module
*/
"use strict";
const asTable = require("as-table").configure({delimiter: " | "});
const moment = require("moment");
const syncRequest = require("sync-request");
const fs = require("fs-extra");
const https = require("follow-redirects").https;
const factorioAPI = require("node-factorio-api");
const sLog = require("single-line-log").stdout;
const query = require("cli-interact").getYesNo;
const path = require("path");
const fileOps = require("lib/fileOps");
function ellipse(str, max){
return str.length > (max - 3) ? str.substring(0,max-3) + "..." : str;
}
// https://stackoverflow.com/questions/15900485/correct-way-to-convert-size-in-bytes-to-kb-mb-gb-in-javascript
function formatBytes(size, decimals) {
if (bytes === 0) return "0 Bytes";
const k = 1024;
const dm = decimals < 0 ? 0 : decimals;
const sizes = ["Bytes", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i];
}
/**
Lists mods for an instance as a table. Warning, handles printing internally.
@param {Object} config - Obsolete config
@param {Instance} instance - Instance object, see slave.js
@example
var modManager = require("modManager");
modManager.listMods(config, instance);
// console.logs table of mods installed on instance
// if instance.name is shared:
// console.logs mods located in /sharedMods as a nice table
*/
async function listMods(config, instance) {
return new Promise((resolve, reject) => {
if (true) {
factorioAPI.init(false, instance.path("instanceMods"), instance.path("saves"), instance.server.version);
factorioAPI.authenticate({
username: config.username,
token: config.token,
require_ownership: false,
}).then(token => {
console.log("* Currently installed:");
factorioAPI.readModZips().then(list => {
console.log(asTable(list.map(mod => {
return {
name:(mod.title || mod.name),
version:mod.version,
date:mod.date,
factorio_ver:mod.factorio_version,
author:mod.author,
};
})));
});
// Had issues earlier due to bug in node-factorio-api, see https://github.com/Danacus/node-factorio-api/issues/2
// bug is resolved, thanks to @Danacus and @brotherpot
factorioAPI.getModsFromSaves().then(list => {
console.log("* Mods used in save:");
console.log(asTable(list[0].mods));
});
}).catch(reason => {
console.log("Failed to authenticate to factorio.com! Please check your connection and the username+token used for authentication in config.json");
resolve();
});
} else {
// list shared mods in /sharedMods/
factorioAPI.init(false, "sharedMods/", "", instance.server.version);
factorioAPI.authenticate({
username: config.username,
token: config.token,
require_ownership: false,
}).then(() => {
console.log("\r\n");
console.log("* Mods shared by all instances:");
factorioAPI.getInstalledMods().then(mods => {
console.log(asTable(mods));
resolve();
});
}).catch(e => {
reject(new Error(e));
});
}
// get JSON data about GH releases
/*let res = syncRequest('GET', 'https://api.github.com/repos/Danielv123/factorioClusterioMod/releases', {"headers":{"User-Agent":"factorioClusterio"}});
let url = JSON.parse(res.getBody())[0].assets[0].browser_download_url;
let name = JSON.parse(res.getBody())[0].assets[0].name;
console.log(JSON.parse(res.getBody()))
*/
});
}
/**
Searches mods.factorio.com for mods matching a search term and prints
the results to console as a neat looking table
@param {Object} config - Obsolete config
@param {string} searchTerm What to search for
*/
async function findMods(config, searchTerm) {
return new Promise((resolve, reject) => {
factorioAPI.init(false);
factorioAPI.authenticate({
username: config.username,
token: config.token,
require_ownership: false,
}).then(token => {
factorioAPI.searchMods(searchTerm).then(mods => {
let result = asTable(mods.reverse().map(mod => {
return {
title:ellipse(mod.title, 50),
name:ellipse(mod.name, 30),
downloads:mod.downloads_count,
updated: moment(mod.updated_at).format("DD.MM.YY"),
latest_version: mod.latest_release.version,
owner:mod.owner,
//license: mod.license_name,
};
}));
resolve(result);
// console.log(result);
});
}).catch(e => {
if (e.contains("Insufficient information")) console.log("We are missing some parameters required for logging in! Make sure your factorio username and token are specified in config.json.");
reject(new Error(e));
});
});
}
async function addMod(config, term, instance) {
return new Promise((resolve, reject) => {
if (instance.name == "shared") {
var modDirectory = "sharedMods";
} else {
var modDirectory = instance.path("instanceMods");
}
if (term && term.length > 0) {
if (term.includes("mods.factorio.com/mods/")) { // https://mods.factorio.com/mods/Danielv123/ChooChoo
// treat it as a link download
factorioAPI.init(false, modDirectory, "", instance.server.version);
factorioAPI.authenticate({
username: config.username,
token: config.token,
require_ownership: false,
}).then(() => {
factorioAPI.searchMods(term.split("/")[term.split("/").length-1]).then(body => {
console.log("Im gonna download: "+body[0].name + " in version: " + body[0].latest_release.version);
factorioAPI.downloadMod( {name: body[0].name, version: body[0].latest_release.version}).then(()=>{
console.log("Mod downloaded");
resolve();
});
});
});
} else if (term.includes("github.com")) { // https://github.com/Danielv123/factorioClusterioMod
// treat it as a github releases download
let apiURL = "https://api.github.com/repos/" + term.split("/")[3] + "/" + term.split("/")[4] + "/releases"; // https://api.github.com/repos/Danielv123/factorioClusterioMod/releases
let res = syncRequest("GET", apiURL, {"headers":{"User-Agent":"factorioClusterio"}});
let url = JSON.parse(res.getBody())[0].assets[0].browser_download_url;
let name = JSON.parse(res.getBody())[0].assets[0].name;
if (url) {
console.log("Downloading " + url);
let file = fs.createWriteStream(path.join(modDirectory, name));
let bytesDownloaded = 0;
let downloadStartTime = Date.now();
https.get(url, function(response) {
let bytesToDownload = response.headers["content-length"];
response.pipe(file);
response.on("data", chunk => {
bytesDownloaded += chunk.length;
let downloadTimeElapsed = Date.now() - downloadStartTime;
let bytesPerSecond = bytesDownloaded / (downloadTimeElapsed/1000);
let timeToComplete = Math.floor((bytesToDownload - bytesDownloaded)/bytesPerSecond);
sLog("Downloading "+name+" "+(bytesDownloaded/bytesToDownload*100).toPrecision(3)+"% ("+formatBytes(bytesDownloaded)+" / "+formatBytes(bytesToDownload)+")\r\n"+
"about "+timeToComplete+" seconds remaining ("+formatBytes(bytesPerSecond)+"/s)");
}).on("end", x => {
sLog.clear();
console.log(" Downloaded in "+moment.utc(moment.duration(Date.now()-downloadStartTime).as("milliseconds")).format("mm:ss")); // because sLog.clear() doesn't seem to do the job of ending the line properly
resolve();
});
});
}
} else {
// treat it as a search and download the top result
factorioAPI.init(false, modDirectory, "", instance.server.version);
factorioAPI.authenticate({
username: config.username,
token: config.token,
require_ownership: false,
}).then(() => {
factorioAPI.searchMods(term).then(body => {
console.log(body);
console.log("Im gonna download: "+body[0].name + " in version: " + body[0].latest_release.version);
factorioAPI.downloadMod( {name: body[0].name, version: body[0].latest_release.version}).then(()=>{
console.log("Mod downloaded");
resolve();
});
});
});
}
} else {
reject(new Error("Invalid search term"));
}
});
}
async function removeMod(config, term, instance, force = false) {
return new Promise((resolve, reject) => {
if (instance.name == "shared") {
var modDirectory = "sharedMods";
} else {
var modDirectory = instance.path("instanceMods");
}
if (term && typeof term == "string" && term.length > 0) {
let mods = fs.readdirSync(modDirectory);
let modsMatchingFilter = mods.filter(mod => mod.toLowerCase().includes(term.toLowerCase()));
if (modsMatchingFilter.length < 1) {
console.log("No mods found matching search");
} else if (modsMatchingFilter.length == 1) {
console.log("Deleting "+modsMatchingFilter[0]);
fs.unlinkSync(path.join(modDirectory, modsMatchingFilter[0]));
console.log("Deleted.");
} else if (modsMatchingFilter.length > 1) {
console.log("Found multiple mods");
modsMatchingFilter.forEach(mod => console.log(mod));
if (query("Delete all mods matching filter?")) {
let modsToDelete = modsMatchingFilter.length;
for (let i = 0; i < modsToDelete; i++) {
fs.unlinkSync(path.join(modDirectory, modsMatchingFilter[i]));
console.log("Deleted "+modsMatchingFilter[i]);
}
} else console.log("Did not delete mods.");
}
resolve();
} else {
reject(new Error("Invalid search term"));
}
});
}
// 'https://api.github.com/repos/Danielv123/factorioClusterioMod/releases'
/**
Download mod from github repo by looking for the first binary download in
the latest release, saving it to /sharedMods
@param {string} url a github repo URL, for example https://api.github.com/repos/Danielv123/factorioClusterioMod/releases. Must link to /releases
*/
function downloadFromGitURL(url) {
console.log("Downloading mod from "+url);
// get JSON data about releases
let res = syncRequest("GET", url, {"headers":{"User-Agent":"factorioClusterio"}});
let downloadUrl = JSON.parse(res.getBody())[0].assets[0].browser_download_url;
let name = JSON.parse(res.getBody())[0].assets[0].name;
console.log(JSON.parse(res.getBody()));
if (downloadUrl) {
console.log(downloadUrl);
let file = fs.createWriteStream("sharedMods/"+name);
https.get(downloadUrl, function(response) {
response.pipe(file);
console.log("Downloaded "+name);
});
}
}
/*
function findUpdates() {
console.log("Downloading mods...");
// get JSON data about releases
let res = syncRequest('GET', 'https://api.github.com/repos/Danielv123/factorioClusterioMod/releases', {"headers":{"User-Agent":"factorioClusterio"}});
let url = JSON.parse(res.getBody())[0].assets[0].browser_download_url;
let name = JSON.parse(res.getBody())[0].assets[0].name;
console.log(JSON.parse(res.getBody()))
}*/
module.exports = {
listMods,
findMods,
addMod,
removeMod,
downloadFromGitURL,
};
-5
View File
@@ -1,5 +0,0 @@
{
"name": "lib",
"description": "Internal library for factorioClusterio"
}
+12 -55
View File
@@ -1,18 +1,14 @@
{ {
"name": "clusterio", "name": "root",
"version": "2.0.0-alpha", "private": true,
"description": "Interserver communication for factorio",
"repository": "https://github.com/clusterio/factorioClusterio",
"main": "master.js",
"scripts": { "scripts": {
"test": "mocha --exit --check-leaks -R spec --recursive test plugins/*/test", "test": "mocha --exit --check-leaks -R spec --recursive test plugins/*/test",
"fast-test": "FAST_TEST=y npm test", "fast-test": "FAST_TEST=y npm test",
"cover": "nyc npm test", "cover": "nyc npm test",
"fast-cover": "FAST_TEST=y nyc npm test", "fast-cover": "FAST_TEST=y nyc npm test",
"ci-cover": "nyc --reporter=lcovonly npm run-script test", "ci-cover": "nyc --reporter=lcovonly npm run-script test",
"lint": "eslint \"*.js\" lib plugins test", "lint": "eslint \"*.js\" packages plugins test",
"docs": "jsdoc --configure docs/jsdoc.json", "docs": "jsdoc --configure docs/jsdoc.json",
"install": "node lib/npmPostinstall",
"bundle-dependencies": "bundle-dependencies" "bundle-dependencies": "bundle-dependencies"
}, },
"nyc": { "nyc": {
@@ -21,63 +17,24 @@
"plugins/*/test/**" "plugins/*/test/**"
] ]
}, },
"keywords": [
"factorio"
],
"author": "Danielv123",
"license": "MIT",
"engines": { "engines": {
"node": ">=10.16 <11 || >= 11.13" "node": ">=10.16 <11 || >= 11.13"
}, },
"dependencies": {
"as-table": "^1.0.31",
"base64url": "^3.0.0",
"body-parser": "^1.18.2",
"chalk": "^3.0.0",
"cli-interact": "^0.1.9",
"compression": "^1.7.2",
"cookie-parser": "^1.4.3",
"deepmerge": "^4.0.0",
"ejs": "^2.5.7",
"express": "^4.16.2",
"express-fileupload": "1.2.0",
"follow-redirects": "^1.5.0",
"fs-extra": "^8.1.0",
"ini": "^1.3.5",
"jimp": "^0.12.1",
"jsonwebtoken": "^8.2.1",
"jszip": "^3.2.2",
"lib": "file:./lib",
"luamin": "^1.0.4",
"minimist": "^1.2.0",
"moment": "^2.22.2",
"needle": "^2.4.0",
"node-factorio-api": "^0.3.8",
"node-forge": "^0.10.0",
"phin": "^3.4.1",
"pidusage": "^2.0.18",
"rcon-client": "^4.2.0",
"request": "^2.83.0",
"sanitizer": "^0.1.3",
"semver": "^7.1.1",
"set-blocking": "^2.0.0",
"simple-git": "^1.96.0",
"single-line-log": "^1.1.2",
"sync-request": "^4.0.1",
"typescript-collections": "^1.3.2",
"ws": "^7.2.3",
"yargs": "^14.2.0"
},
"devDependencies": { "devDependencies": {
"@clusterio/ctl": "file:./packages/ctl",
"@clusterio/lib": "file:./packages/lib",
"@clusterio/master": "file:packages/master",
"@clusterio/slave": "file:./packages/slave",
"eslint": "^7.2.0", "eslint": "^7.2.0",
"fs-extra": "^8.1.0",
"html5-validator": "^1.2.1", "html5-validator": "^1.2.1",
"jsdoc": "^3.6.3", "jsdoc": "^3.6.3",
"klaw": "^3.0.0", "jsonwebtoken": "^8.2.1",
"jszip": "^3.2.2",
"lerna": "^3.22.1",
"mocha": "^6.2.0", "mocha": "^6.2.0",
"mocha-sinon": "^2.1.0",
"mocha.parallel": "^0.15.5", "mocha.parallel": "^0.15.5",
"nock": "^11.3.0",
"nyc": "^14.1.1", "nyc": "^14.1.1",
"sinon": "^7.4.1" "phin": "^3.4.1"
} }
} }
+18 -14
View File
@@ -1,21 +1,23 @@
#!/usr/bin/env node
/** /**
* Command line interface for controlling a Clusterio cluster * Command line interface for controlling a Clusterio cluster
* @module * @module ctl/ctl
*/ */
"use strict"; "use strict";
const jwt = require("jsonwebtoken");
const fs = require("fs-extra"); const fs = require("fs-extra");
const yargs = require("yargs"); const yargs = require("yargs");
const version = require("./package").version; const version = require("./package").version;
const asTable = require("as-table").configure({ delimiter: " | " }); const asTable = require("as-table").configure({ delimiter: " | " });
const chalk = require("chalk"); const chalk = require("chalk");
const events = require("events"); const events = require("events");
const path = require("path");
const link = require("lib/link"); const link = require("@clusterio/lib/link");
const errors = require("lib/errors"); const errors = require("@clusterio/lib/errors");
const config = require("lib/config"); const config = require("@clusterio/lib/config");
const plugin = require("lib/plugin"); const plugin = require("@clusterio/lib/plugin");
const command = require("lib/command"); const command = require("@clusterio/lib/command");
/** /**
@@ -520,7 +522,7 @@ class ControlConnector extends link.WebSocketClientConnector {
console.log("SOCKET | registering control"); console.log("SOCKET | registering control");
this.sendHandshake("register_control", { this.sendHandshake("register_control", {
token: this._token, token: this._token,
agent: "clusterctl", agent: "clusterioctl",
version: version, version: version,
}); });
} }
@@ -575,7 +577,7 @@ class Control extends link.Link {
async function startControl() { async function startControl() {
yargs yargs
.scriptName("clusterctl") .scriptName("clusterioctl")
.usage("$0 <command> [options]") .usage("$0 <command> [options]")
.option("config", { .option("config", {
nargs: 1, nargs: 1,
@@ -589,7 +591,7 @@ async function startControl() {
.strict() .strict()
; ;
const rootCommands = new command.CommandTree({ name: "clusterctl", description: "Manage cluster" }); const rootCommands = new command.CommandTree({ name: "clusterioctl", description: "Manage cluster" });
rootCommands.add(slaveCommands); rootCommands.add(slaveCommands);
rootCommands.add(instanceCommands); rootCommands.add(instanceCommands);
rootCommands.add(permissionCommands); rootCommands.add(permissionCommands);
@@ -608,7 +610,9 @@ async function startControl() {
continue; continue;
} }
let { ControlPlugin } = require(`./plugins/${pluginInfo.name}/${pluginInfo.controlEntrypoint}`); // XXX Does not work on Windows
let pluginPath = path.relative(__dirname, path.join("plugins", pluginInfo.name));
let { ControlPlugin } = require(path.join(pluginPath, pluginInfo.controlEntrypoint));
let controlPlugin = new ControlPlugin(pluginInfo); let controlPlugin = new ControlPlugin(pluginInfo);
controlPlugins.set(pluginInfo.name, controlPlugin); controlPlugins.set(pluginInfo.name, controlPlugin);
await controlPlugin.init(); await controlPlugin.init();
@@ -737,9 +741,9 @@ I version of clusterio. Expect things to break. I
); );
} else { } else {
console.error(` console.error(`
+-------------------------------+ +---------------------------------+
| Unable to to start clusterctl | | Unable to to start clusterioctl |
+-------------------------------+` +---------------------------------+`
); );
} }
+27
View File
@@ -0,0 +1,27 @@
{
"name": "@clusterio/ctl",
"description": "Clusterio command line management tool",
"author": "Hornwitser",
"license": "MIT",
"version": "2.0.0-alpha0",
"main": "ctl.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"bin": {
"clusterioctl": "./ctl.js"
},
"keywords": [
"factorio"
],
"engines": {
"node": ">=10.16 <11 || >= 11.13"
},
"dependencies": {
"@clusterio/lib": "=2.0.0-alpha0",
"as-table": "^1.0.31",
"chalk": "^3.0.0",
"fs-extra": "^8.1.0",
"yargs": "^14.2.0"
}
}
File renamed without changes.
+7 -7
View File
@@ -1,17 +1,17 @@
/** /**
* Command library * Command library
* *
* Data types and utilites for commands to clusterctl's CLI. * Data types and utilites for commands to clusterioctl's CLI.
* *
* @author Hornwitser * @author Hornwitser
* @module * @module lib/command
*/ */
"use strict"; "use strict";
const link = require("lib/link"); const link = require("@clusterio/lib/link");
const errors = require("lib/errors"); const errors = require("@clusterio/lib/errors");
/** /**
* Represents a command that can be runned by clusterctl * Represents a command that can be runned by clusterioctl
* @static * @static
*/ */
class Command { class Command {
@@ -25,7 +25,7 @@ class Command {
* @param {function(args, control)} handler - * @param {function(args, control)} handler -
* Async function invoked when the command is executed. Is given * Async function invoked when the command is executed. Is given
* the parsed args and a reference to the {@link * the parsed args and a reference to the {@link
* module:clusterctl.Control} instance. * module:ctl/ctl.Control} instance.
*/ */
constructor({ definition, handler }) { constructor({ definition, handler }) {
if (definition[0] instanceof Array) { if (definition[0] instanceof Array) {
@@ -52,7 +52,7 @@ class Command {
* A node in the command tree that can hold commands and sub trees * A node in the command tree that can hold commands and sub trees
* *
* Container which can contain {@link module:lib/command.Command}s and other * Container which can contain {@link module:lib/command.Command}s and other
* CommandTrees. This is used by clusterctl to hold the full tree of * CommandTrees. This is used by clusterioctl to hold the full tree of
* available commands, you may extend this tree by using a control plugin, * available commands, you may extend this tree by using a control plugin,
* see {@link module:lib/plugin.BaseControlPlugin#addCommands} * see {@link module:lib/plugin.BaseControlPlugin#addCommands}
* *
@@ -4,7 +4,7 @@
const events = require("events"); const events = require("events");
const util = require("util"); const util = require("util");
const { basicType } = require("lib/helpers"); const { basicType } = require("@clusterio/lib/helpers");
/** /**
File renamed without changes.
File renamed without changes.
+2 -2
View File
@@ -1,14 +1,14 @@
/** /**
* Implementation of master databases * Implementation of master databases
* *
* @module * @module lib/database
* @author Hornwitser * @author Hornwitser
*/ */
"use strict"; "use strict";
const fs = require("fs-extra"); const fs = require("fs-extra");
const { basicType } = require("lib/helpers"); const { basicType } = require("@clusterio/lib/helpers");
/** /**
+1 -1
View File
@@ -1,6 +1,6 @@
/** /**
* Errors thrown in Clusterio * Errors thrown in Clusterio
* @module * @module lib/errors
*/ */
"use strict"; "use strict";
@@ -6,7 +6,7 @@ const ini = require("ini");
const Jimp = require("jimp"); const Jimp = require("jimp");
const JSZip = require("jszip"); const JSZip = require("jszip");
const buildMod = require("../../build-mod"); const buildMod = require("@clusterio/lib/build_mod");
/** /**
* Generate the export mod needed for exportData * Generate the export mod needed for exportData
@@ -5,7 +5,7 @@
*/ */
"use strict"; "use strict";
module.exports = { module.exports = {
...require("lib/factorio/export"), ...require("./export"),
...require("lib/factorio/patch"), ...require("./patch"),
...require("lib/factorio/server"), ...require("./server"),
}; };
@@ -7,7 +7,7 @@ const jszip = require("jszip");
const path = require("path"); const path = require("path");
const semver = require("semver"); const semver = require("semver");
const hash = require("lib/hash"); const hash = require("@clusterio/lib/hash");
const knownScenarios = { const knownScenarios = {
@@ -9,7 +9,7 @@ const crypto = require("crypto");
const ini = require("ini"); const ini = require("ini");
const rconClient = require("rcon-client"); const rconClient = require("rcon-client");
const errors = require("lib/errors"); const errors = require("@clusterio/lib/errors");
/** /**
File renamed without changes.
File renamed without changes.
+1 -1
View File
@@ -1,6 +1,6 @@
/** /**
* Hashing functions * Hashing functions
* @module * @module lib/hash
*/ */
"use strict"; "use strict";
const crypto = require("crypto"); const crypto = require("crypto");
+1 -1
View File
@@ -1,6 +1,6 @@
/** /**
* Collection of small utilites that are useful in multiple places. * Collection of small utilites that are useful in multiple places.
* @module * @module lib/helpers
*/ */
"use strict"; "use strict";
@@ -3,8 +3,8 @@
const events = require("events"); const events = require("events");
const WebSocket = require("ws"); const WebSocket = require("ws");
const schema = require("lib/schema"); const schema = require("@clusterio/lib/schema");
const errors = require("lib/errors"); const errors = require("@clusterio/lib/errors");
/** /**
@@ -5,7 +5,7 @@
*/ */
"use strict"; "use strict";
module.exports = { module.exports = {
...require("lib/link/link"), ...require("./link"),
...require("lib/link/messages"), ...require("./messages"),
...require("lib/link/connectors"), ...require("./connectors"),
}; };
@@ -1,9 +1,9 @@
// Implementation of Link class // Implementation of Link class
"use strict"; "use strict";
const schema = require("lib/schema"); const schema = require("@clusterio/lib/schema");
const errors = require("lib/errors"); const errors = require("@clusterio/lib/errors");
const messages = require("lib/link/messages"); const messages = require("./messages");
// Some definitions for the terminology used here: // Some definitions for the terminology used here:
// link: Either side of a master - client connection // link: Either side of a master - client connection
@@ -1,7 +1,7 @@
// Message definitions for links // Message definitions for links
"use strict"; "use strict";
const schema = require("lib/schema"); const schema = require("@clusterio/lib/schema");
const errors = require("lib/errors"); const errors = require("@clusterio/lib/errors");
/** /**
* Represents a message that can be sent over the link * Represents a message that can be sent over the link
+1 -1
View File
@@ -1,6 +1,6 @@
/** /**
* Utilities for dealing with Lua * Utilities for dealing with Lua
* @module * @module lib/luaTools
*/ */
"use strict"; "use strict";
@@ -1,6 +1,6 @@
/** /**
* Helper functions related to objects * Helper functions related to objects
* @module * @module lib/objectOps
*/ */
"use strict"; "use strict";
+26
View File
@@ -0,0 +1,26 @@
{
"name": "@clusterio/lib",
"description": "Shared library for Clusterio",
"version": "2.0.0-alpha0",
"repository": "https://github.com/clusterio/factorioClusterio",
"license": "MIT",
"keywords": [
"factorio"
],
"engines": {
"node": ">=10.16 <11 || >= 11.13"
},
"dependencies": {
"fs-extra": "^8.1.0",
"ini": "^1.3.5",
"jimp": "^0.12.1",
"jsonwebtoken": "^8.2.1",
"jszip": "^3.2.2",
"klaw": "^3.0.0",
"node-forge": "^0.10.0",
"rcon-client": "^4.2.0",
"semver": "^7.1.1",
"ws": "^7.2.3",
"yargs": "^14.2.0"
}
}
+14 -12
View File
@@ -1,12 +1,12 @@
/** /**
* Plugin interfaces and utilities. * Plugin interfaces and utilities.
* @module * @module lib/plugin
*/ */
"use strict"; "use strict";
const fs = require("fs-extra"); const fs = require("fs-extra");
const path = require("path"); const path = require("path");
const errors = require("lib/errors"); const errors = require("@clusterio/lib/errors");
/** /**
@@ -42,7 +42,7 @@ class BaseInstancePlugin {
/** /**
* Instance the plugin started for * Instance the plugin started for
* @type {module:slave~Instance} * @type {module:slave/slave~Instance}
*/ */
this.instance = instance; this.instance = instance;
@@ -52,7 +52,7 @@ class BaseInstancePlugin {
* With the exepction of accessing the slave's config you should * With the exepction of accessing the slave's config you should
* avoid ineracting with the slave object directly. * avoid ineracting with the slave object directly.
* *
* @type {module:slave~Slave} * @type {module:slave/slave~Slave}
*/ */
this.slave = slave; this.slave = slave;
} }
@@ -181,7 +181,7 @@ class BaseInstancePlugin {
* Plugins must stop sending messages to the master, or are forwarded * Plugins must stop sending messages to the master, or are forwarded
* via the master server after the prepare disconnect has been handled. * via the master server after the prepare disconnect has been handled.
* *
* @param {module:master~SlaveConnection} connection - * @param {module:master/master~SlaveConnection} connection -
* The connection to the slave preparing to disconnect. * The connection to the slave preparing to disconnect.
*/ */
async onPrepareMasterDisconnect(connection) { } async onPrepareMasterDisconnect(connection) { }
@@ -283,7 +283,7 @@ class BaseMasterPlugin {
* *
* Invoked when the connection to the slave has been closed. * Invoked when the connection to the slave has been closed.
* *
* @param {module:master~SlaveConnection} connection - * @param {module:master/master~SlaveConnection} connection -
* The connection the event occured on. * The connection the event occured on.
* @param {string} event - one of connect, drop, and close * @param {string} event - one of connect, drop, and close
*/ */
@@ -298,7 +298,7 @@ class BaseMasterPlugin {
* Plugins must stop sending messages to the slave in question after the * Plugins must stop sending messages to the slave in question after the
* prepare disconnect has been handled. * prepare disconnect has been handled.
* *
* @param {module:master~SlaveConnection} connection - * @param {module:master/master~SlaveConnection} connection -
* The connection to the slave preparing to disconnect. * The connection to the slave preparing to disconnect.
*/ */
async onPrepareSlaveDisconnect(connection) { } async onPrepareSlaveDisconnect(connection) { }
@@ -339,10 +339,10 @@ class BaseMasterPlugin {
} }
/** /**
* Base class for clusterctl plugins * Base class for clusterioctl plugins
* *
* Control plugins are subclasses of this class which get instantiated by * Control plugins are subclasses of this class which get instantiated by
* clusterctl in order to extend its functionallity. To be discovered the * clusterioctl in order to extend its functionallity. To be discovered the
* class must be exported under the name `ControlPlugin` in the module * class must be exported under the name `ControlPlugin` in the module
* specified by the `controlEntrypoint` in the plugin's info.js file. * specified by the `controlEntrypoint` in the plugin's info.js file.
* *
@@ -364,12 +364,12 @@ class BaseControlPlugin {
/** /**
* Called to add commands to the command line interface. * Called to add commands to the command line interface.
* *
* Invoked by clusterctl to let plugins add commands. `rootCommand` is * Invoked by clusterioctl to let plugins add commands. `rootCommand` is
* the top level command node which the plugin should add its own {@link * the top level command node which the plugin should add its own {@link
* module:lib/command.CommandTree} to. * module:lib/command.CommandTree} to.
* *
* @param {module:lib/command.CommandTree} rootCommand - * @param {module:lib/command.CommandTree} rootCommand -
* Root of the clusterctl command tree. * Root of the clusterioctl command tree.
*/ */
async addCommands(rootCommand) { } async addCommands(rootCommand) { }
} }
@@ -392,7 +392,9 @@ async function loadPluginInfos(baseDir) {
try { try {
// Note: Require path is relative to this module // Note: Require path is relative to this module
pluginInfo = require(path.posix.join("..", baseDir, pluginDir, "info")); // XXX Does not work on Windows
let pluginPath = path.relative(__dirname, path.join(baseDir, pluginDir));
pluginInfo = require(path.join(pluginPath, "info"));
} catch (err) { } catch (err) {
if (err.code === "MODULE_NOT_FOUND") { if (err.code === "MODULE_NOT_FOUND") {
File renamed without changes.
+1 -1
View File
@@ -1,6 +1,6 @@
/** /**
* JSON schemas used for validating link messages * JSON schemas used for validating link messages
* @module * @module lib/schema
*/ */
"use strict"; "use strict";
const ajv = new (require("ajv"))({ const ajv = new (require("ajv"))({
+1 -1
View File
@@ -4,7 +4,7 @@
* Defines data types for users, roles and permissions. * Defines data types for users, roles and permissions.
* *
* @author Hornwitser * @author Hornwitser
* @module * @module lib/users
*/ */
"use strict"; "use strict";
const jwt = require("jsonwebtoken"); const jwt = require("jsonwebtoken");
+21 -17
View File
@@ -1,15 +1,17 @@
#!/usr/bin/env node
/** /**
* Clusterio master server * Clusterio master server
* *
* Facilitates communication between slaves and control of the cluster * Facilitates communication between slaves and control of the cluster
* through WebSocet connections, and hosts a webserver for browser * through WebSocet connections, and hosts a webserver for browser
* interfaces and Prometheus statistics export. It is remotely controlled * interfaces and Prometheus statistics export. It is remotely controlled
* by {@link module:clusterctl}. * by {@link module:ctl/ctl}.
* *
* @module * @module master/master
* @author Danielv123, Hornwitser * @author Danielv123, Hornwitser
* @example * @example
* node master run * npx clusteriomaster run
*/ */
// Attempt updating // Attempt updating
@@ -17,7 +19,6 @@
// updater.update().then(console.log); // updater.update().then(console.log);
"use strict"; "use strict";
const deepmerge = require("deepmerge");
const path = require("path"); const path = require("path");
const fs = require("fs-extra"); const fs = require("fs-extra");
const jwt = require("jsonwebtoken"); const jwt = require("jsonwebtoken");
@@ -39,15 +40,15 @@ let debugEvents = new events.EventEmitter();
let pluginList = {}; let pluginList = {};
// homebrew modules // homebrew modules
const generateSSLcert = require("lib/generateSSLcert"); const generateSSLcert = require("./src/generate_ssl_cert");
const database = require("lib/database"); const database = require("@clusterio/lib/database");
const schema = require("lib/schema"); const schema = require("@clusterio/lib/schema");
const link = require("lib/link"); const link = require("@clusterio/lib/link");
const errors = require("lib/errors"); const errors = require("@clusterio/lib/errors");
const plugin = require("lib/plugin"); const plugin = require("@clusterio/lib/plugin");
const prometheus = require("lib/prometheus"); const prometheus = require("@clusterio/lib/prometheus");
const config = require("lib/config"); const config = require("@clusterio/lib/config");
const users = require("lib/users"); const users = require("@clusterio/lib/users");
const express = require("express"); const express = require("express");
const compression = require("compression"); const compression = require("compression");
@@ -87,9 +88,10 @@ app.use(function(req, res, next){
next(); next();
}); });
require("./routes")(app); require("./src/routes")(app);
// Set folder to serve static content from (the website) // Set folder to serve static content from (the website)
app.use(express.static("static")); app.use(express.static(path.join(__dirname, "static")));
app.use(express.static("static")); // Used for data export files
const endpointHitCounter = new prometheus.Counter( const endpointHitCounter = new prometheus.Counter(
"clusterio_master_http_endpoint_hits_total", "clusterio_master_http_endpoint_hits_total",
@@ -1482,7 +1484,9 @@ async function loadPlugins(pluginInfos) {
let MasterPlugin = plugin.BaseMasterPlugin; let MasterPlugin = plugin.BaseMasterPlugin;
try { try {
if (pluginInfo.masterEntrypoint) { if (pluginInfo.masterEntrypoint) {
({ MasterPlugin } = require(`./plugins/${pluginInfo.name}/${pluginInfo.masterEntrypoint}`)); // XXX Does not work on Windows
let pluginPath = path.relative(__dirname, path.join("plugins", pluginInfo.name));
({ MasterPlugin } = require(path.join(pluginPath, pluginInfo.masterEntrypoint)));
} }
let masterPlugin = new MasterPlugin( let masterPlugin = new MasterPlugin(
@@ -1578,7 +1582,7 @@ async function startServer() {
.command("bootstrap", "Bootstrap access to cluster", yargs => { .command("bootstrap", "Bootstrap access to cluster", yargs => {
yargs yargs
.command("create-admin <name>", "Create a cluster admin") .command("create-admin <name>", "Create a cluster admin")
.command("create-ctl-config <name>", "Create clusterctl config for the given user", yargs => { .command("create-ctl-config <name>", "Create clusterioctl config for the given user", yargs => {
yargs.option("output", { yargs.option("output", {
describe: "Path to output config (- for stdout)", type: "string", describe: "Path to output config (- for stdout)", type: "string",
nargs: 1, default: "config-control.json", nargs: 1, default: "config-control.json",
File renamed without changes.
+40
View File
@@ -0,0 +1,40 @@
{
"name": "@clusterio/master",
"description": "Implementation of Clusterio master server",
"author": "Hornwitser",
"license": "MIT",
"version": "2.0.0-alpha0",
"main": "master.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"install": "node npm_post_install"
},
"bin": {
"clusteriomaster": "./master.js"
},
"keywords": [
"factorio"
],
"engines": {
"node": ">=10.16 <11 || >= 11.13"
},
"dependencies": {
"@clusterio/lib": "=2.0.0-alpha0",
"body-parser": "^1.18.2",
"compression": "^1.7.2",
"cookie-parser": "^1.4.3",
"ejs": "^2.5.7",
"express": "^4.16.2",
"express-fileupload": "1.2.0",
"fs-extra": "^8.1.0",
"jsonwebtoken": "^8.2.1",
"jszip": "^3.2.2",
"moment": "^2.22.2",
"node-factorio-api": "^0.3.8",
"node-forge": "^0.10.0",
"request": "^2.83.0",
"set-blocking": "^2.0.0",
"ws": "^7.2.3",
"yargs": "^14.2.0"
}
}
@@ -13,7 +13,7 @@ module.exports = async function({
doLogging = false, doLogging = false,
} = {}){ } = {}){
function log(t) { function log(t) {
if(doLogging) console.log("lib/generateSSLcert.js | "+t); if(doLogging) console.log("src/generate_ssl_cert.js | "+t);
} }
log("Generating SSL certificate with "+bits+" bits at "+sslCertPath); log("Generating SSL certificate with "+bits+" bits at "+sslCertPath);
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Before

Width:  |  Height:  |  Size: 3.2 KiB

After

Width:  |  Height:  |  Size: 3.2 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 34 KiB

After

Width:  |  Height:  |  Size: 34 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 2.8 KiB

After

Width:  |  Height:  |  Size: 2.8 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 4.0 KiB

After

Width:  |  Height:  |  Size: 4.0 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 7.3 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 15 KiB

After

Width:  |  Height:  |  Size: 15 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 16 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 32 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 5.2 KiB

After

Width:  |  Height:  |  Size: 5.2 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 7.3 KiB

After

Width:  |  Height:  |  Size: 7.3 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 8.0 KiB

After

Width:  |  Height:  |  Size: 8.0 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 35 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 35 KiB

After

Width:  |  Height:  |  Size: 35 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 1.4 KiB

After

Width:  |  Height:  |  Size: 1.4 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 2.4 KiB

After

Width:  |  Height:  |  Size: 2.4 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 12 KiB

After

Width:  |  Height:  |  Size: 12 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

File renamed without changes.
File renamed without changes.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 24 KiB

After

Width:  |  Height:  |  Size: 24 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 74 KiB

After

Width:  |  Height:  |  Size: 74 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 7.1 KiB

After

Width:  |  Height:  |  Size: 7.1 KiB

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Before

Width:  |  Height:  |  Size: 20 KiB

After

Width:  |  Height:  |  Size: 20 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 23 KiB

File renamed without changes.

Before

Width:  |  Height:  |  Size: 5.6 KiB

After

Width:  |  Height:  |  Size: 5.6 KiB

File renamed without changes.
File renamed without changes.
+28
View File
@@ -0,0 +1,28 @@
{
"name": "@clusterio/slave",
"description": "Implementation of Clusterio slave server",
"author": "Hornwitser",
"license": "MIT",
"version": "2.0.0-alpha0",
"main": "slave.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"bin": {
"clusterioslave": "./slave.js"
},
"keywords": [
"factorio"
],
"engines": {
"node": ">=10.16 <11 || >= 11.13"
},
"dependencies": {
"@clusterio/lib": "=2.0.0-alpha0",
"fs-extra": "^8.1.0",
"phin": "^3.4.1",
"pidusage": "^2.0.18",
"set-blocking": "^2.0.0",
"yargs": "^14.2.0"
}
}
+20 -16
View File
@@ -1,14 +1,16 @@
#!/usr/bin/env node
/** /**
* Clusterio slave * Clusterio slave
* *
* Connects to the master server and hosts Factorio servers that can * Connects to the master server and hosts Factorio servers that can
* communicate with the cluster. It is remotely controlled by {@link * communicate with the cluster. It is remotely controlled by {@link
* module:master}. * module:master/master}.
* *
* @module * @module slave/slave
* @author Danielv123, Hornwitser * @author Danielv123, Hornwitser
* @example * @example
* node slave run * npx clusterioslave run
*/ */
"use strict"; "use strict";
const fs = require("fs-extra"); const fs = require("fs-extra");
@@ -22,14 +24,14 @@ const util = require("util");
const version = require("./package").version; const version = require("./package").version;
// internal libraries // internal libraries
const fileOps = require("lib/fileOps"); const fileOps = require("@clusterio/lib/fileOps");
const factorio = require("lib/factorio"); const factorio = require("@clusterio/lib/factorio");
const link = require("lib/link"); const link = require("@clusterio/lib/link");
const plugin = require("lib/plugin"); const plugin = require("@clusterio/lib/plugin");
const errors = require("lib/errors"); const errors = require("@clusterio/lib/errors");
const prometheus = require("lib/prometheus"); const prometheus = require("@clusterio/lib/prometheus");
const luaTools = require("lib/luaTools"); const luaTools = require("@clusterio/lib/luaTools");
const config = require("lib/config"); const config = require("@clusterio/lib/config");
const instanceRconCommandsCounter = new prometheus.Counter( const instanceRconCommandsCounter = new prometheus.Counter(
@@ -198,7 +200,9 @@ class Instance extends link.Link{
async _loadPlugin(pluginInfo, slave) { async _loadPlugin(pluginInfo, slave) {
let pluginLoadStarted = Date.now(); let pluginLoadStarted = Date.now();
let { InstancePlugin } = require(`./plugins/${pluginInfo.name}/${pluginInfo.instanceEntrypoint}`); // XXX Does not work on Windows
let pluginPath = path.relative(__dirname, path.join("plugins", pluginInfo.name));
let { InstancePlugin } = require(path.join(pluginPath, pluginInfo.instanceEntrypoint));
let instancePlugin = new InstancePlugin(pluginInfo, this, slave); let instancePlugin = new InstancePlugin(pluginInfo, this, slave);
this.plugins.set(pluginInfo.name, instancePlugin); this.plugins.set(pluginInfo.name, instancePlugin);
await instancePlugin.init(); await instancePlugin.init();
@@ -1110,7 +1114,7 @@ class Slave extends link.Link {
* Initialize and connect an unloaded instance * Initialize and connect an unloaded instance
* *
* @param {number} instanceId - ID of instance to initialize. * @param {number} instanceId - ID of instance to initialize.
* @returns {module:slave~InstanceConnection} connection to instance. * @returns {module:slave/slave~InstanceConnection} connection to instance.
*/ */
async _connectInstance(instanceId) { async _connectInstance(instanceId) {
let instanceInfo = this.instanceInfos.get(instanceId); let instanceInfo = this.instanceInfos.get(instanceId);
@@ -1423,9 +1427,9 @@ async function startSlave() {
console.error("ERROR invalid config!"); console.error("ERROR invalid config!");
console.error( console.error(
"Master server requires an access token for socket operations. As clusterio\n"+ "Master server requires an access token for socket operations. As clusterio\n"+
"slaves depends upon this, please set your token using the command node slave\n"+ "slaves depends upon this, please set your token using the command npx\n"+
"config set slave.master_token <token>. You can generate an auth token using\n"+ "clusterioslave config set slave.master_token <token>. You can generate an\n"+
"using node clusterctl generate-slave-token." "auth token using npx clusterioctl generate-slave-token."
); );
process.exitCode = 1; process.exitCode = 1;
return; return;
+2 -2
View File
@@ -1,7 +1,7 @@
"use strict"; "use strict";
const plugin = require("lib/plugin"); const plugin = require("@clusterio/lib/plugin");
const info = require("./info"); const info = require("./info");
const command = require("lib/command"); const command = require("@clusterio/lib/command");
const globalChatCommands = new command.CommandTree({ name: "global-chat", description: "Global Chat plugin commands" }); const globalChatCommands = new command.CommandTree({ name: "global-chat", description: "Global Chat plugin commands" });
+2 -2
View File
@@ -1,6 +1,6 @@
"use strict"; "use strict";
let link = require("lib/link"); let link = require("@clusterio/lib/link");
let plugin = require("lib/plugin"); let plugin = require("@clusterio/lib/plugin");
module.exports = { module.exports = {
name: "global_chat", name: "global_chat",
+2 -2
View File
@@ -2,8 +2,8 @@
* @module * @module
*/ */
"use strict"; "use strict";
const plugin = require("lib/plugin"); const plugin = require("@clusterio/lib/plugin");
const luaTools = require("lib/luaTools"); const luaTools = require("@clusterio/lib/luaTools");
/** /**
+1 -1
View File
@@ -1,5 +1,5 @@
"use strict"; "use strict";
const link = require("lib/link"); const link = require("@clusterio/lib/link");
// schema used for syncing technologies to and from the master // schema used for syncing technologies to and from the master
+2 -4
View File
@@ -1,8 +1,6 @@
"use strict"; "use strict";
const needle = require("needle"); const plugin = require("@clusterio/lib/plugin");
const luaTools = require("@clusterio/lib/luaTools");
const plugin = require("lib/plugin");
const luaTools = require("lib/luaTools");
function unexpectedError(err) { function unexpectedError(err) {
+1 -1
View File
@@ -2,7 +2,7 @@
const fs = require("fs-extra"); const fs = require("fs-extra");
const path = require("path"); const path = require("path");
const plugin = require("lib/plugin"); const plugin = require("@clusterio/lib/plugin");
class MasterPlugin extends plugin.BaseMasterPlugin { class MasterPlugin extends plugin.BaseMasterPlugin {
+1 -1
View File
@@ -1,5 +1,5 @@
"use strict"; "use strict";
let link = require("lib/link"); let link = require("@clusterio/lib/link");
module.exports = { module.exports = {
name: "statistics_exporter", name: "statistics_exporter",
+2 -2
View File
@@ -1,6 +1,6 @@
"use strict"; "use strict";
const plugin = require("lib/plugin"); const plugin = require("@clusterio/lib/plugin");
const { Gauge } = require("lib/prometheus"); const { Gauge } = require("@clusterio/lib/prometheus");
const instancePlayerCount = new Gauge( const instancePlayerCount = new Gauge(
Loaded 100 of 135 files, more files were not shown because too many files have changed in this diff. Show more