Commit Graph
43 Commits
Author SHA1 Message Date
Hornwitser 75cd6d38db Fix instance exit notification
Fix improper notification on Factorio server exit causing plugins and
the instance tracking to fail.
2020-04-04 15:14:23 +02:00
Hornwitser 65494a0a91 Move basicType to lib/helpers
Move the basicType function from the config lib to a shared helpers lib.
2020-04-03 20:51:28 +02:00
Hornwitser f05100c94d Remove unused files
Remove left over files that are no longer in use.
2020-04-03 20:51:28 +02:00
Hornwitser c2df80a17f Move test/json to test/file/json
Move the json test files for the lib/database tests to test/file/json to
be consistent with the location of test files for other tests.
2020-04-03 20:51:28 +02:00
Hornwitser f9f0e5b5f7 Move test/temp to temp/test
Move the temporary files generated by the the tests to the top level
directory temp.
2020-04-03 20:51:28 +02:00
Hornwitser ae86781b0d Add support for multiple Factorio installs
Allow the factorio_directory specified in the slave config to contain
multiple Factorio installs and add factior.version instance option to
select which install to use for the given instance.
2020-04-03 20:51:28 +02:00
Hornwitser d4e072f376 Rewrite reconnection logic
Implement proper session tracking and resume on reconnect for the
WebSocket server.
2020-04-02 21:58:44 +02:00
Hornwitser 43ce6aa58c Pass validation errors with InvalidMessage error
Pass the array describing the validation errors occuring with the
InvalidMessage error throw and print it to the console.
2020-04-02 14:39:18 +02:00
Hornwitser 677512512e Replace socket.io with plain WebSocket
Replace socket.io with plain WebSocket using the ws library as it
doesn't really provide any useful tools over plain WebSocket when it
comes to implementing reliable communication that works across
reconnects.  The widespread browser support for WebSocket also means
it has little value to add for the web interface over WebSocket.
2020-03-22 02:10:54 +01:00
Hornwitser 808bd6b453 Validate messages sent
Validate messages sent over links with the json schema provided from
them.  This aids debugging as an exception will be thrown from the code
sending the bad content.
2020-03-22 02:10:54 +01:00
Hornwitser 5e5149dc93 Implement new configuration system
Replace current configuration mess with a trimmed down version of the
original vision of #200.  Configs are collection of config groups that
have fields that can be set.  These groups allow organizing the fields
as well as opertunity for plugins to add their own groups.  By default
plugins have an auto generated group with the enabled field.
2020-03-09 20:48:13 +01:00
Hornwitser 892c803496 Add on_server_startup event
Add startup event to the Clusterio module API which is raised at startup
of a Factorio server.  This is to server as a replacement for the
on_init and on_configuration_changed events which cannot be used in
modules.

Adds clusterio_patch_number global from the patcher in order to
implement this.  This is a number that's incremented every time the save
is patched.
2020-01-05 23:19:34 +01:00
Hornwitser b8fb73f863 Add Factorio to Clusterio communication API
Add send_json to the Clusterio module's API which allows sending
arbitrary tables serialized as JSON to plugins that listen on the
channel specified.
2020-01-04 17:34:16 +01:00
Hornwitser 66aa7e1e43 Add clusterio module with API for lua code
Add a shared API for lua code through a module named clusterio.
2020-01-04 17:34:16 +01:00
Hornwitser c091dc341e Implement require option for modules
Implement option allowing files to be required from control.lua be
specified in modules.json.
2020-01-04 17:34:16 +01:00
Hornwitser e89e54ee27 Implement dependencies specification for modules
Implement dependency ordering and version checking for modules.
2020-01-04 17:34:16 +01:00
Hornwitser 80bd75ba16 Rework module loading
Change module loading to use a module.json file describing the module
and patch in all files in a directory path passed to the patcher instead
of having to pass the files names and their content.  This allows the
specification of which files should be passed to the event_handler lib
and an easy implementation of loading stand alone modules.
2020-01-04 17:34:16 +01:00
Hornwitser 8229d1955c Skip broken Prometheus client tests
Skip Prometheus client tests that assume the environment is isolated
from the rest of the tests.
2019-12-20 19:14:35 +01:00
Hornwitser b4c7824101 Add homebrew Prometheus client
Add an implementation of a Prometheus client.  This is because the
prom-client implementation seems to have missunderstood how Prometheus
is supposed to work and doesn't allow updating collectors via
asynchronous callback.
2019-12-20 19:14:35 +01:00
Hornwitser bcceae687f Reimplement plugin system
Implement a new plugin system based subclassing pre-defined base clases
and communicating with pre-defined link messages.
2019-12-14 17:48:56 +01:00
Hornwitser e5115df28b Implement broadcast for events
Add broadcastTo property to events that broadcasts them to all entities
of the specified target that's downstream to the connection it was sent
to.
2019-12-13 22:37:58 +01:00
Hornwitser f0afbf0a33 Complete test coverage for lib/link/link.js
Add tests for the remaining uncovered lines in lib/link/link.js.
2019-12-13 21:57:05 +01:00
Hornwitser 5d8fa4e4ce Refactor instance communication
Change Instance class to be a subclass of Link and refactor the
communication to and establisment of instances to use a virtual
connection between the slave and the instance.  This is simplifies the
implementation of plugin communication for instances.

Replace InstanceRequest with a forwardTo option to Request which does
the task of forwarding in a much cleaner way.
2019-12-13 21:57:05 +01:00
Hornwitser 47cff048f0 Improve link error messages
Reverse the reversal of source/target in message errors and add link
source and target to the error given when a validator is missing on a
link.
2019-12-13 21:39:54 +01:00
Hornwitser b24778dce6 Add filter argument to getNewestFile
Add filter predicate to allow filtering out files that are not desired
from getNewestFile.  This is useful for filtering out .tmp.zip files.
2019-12-13 21:39:54 +01:00
Hornwitser c6fd46e3c3 Replace sources/targets with links in messages
Replace the sources/targets concept with a links array in the message
definitions.  Fixes the problem of the actual links the messages applies
to being ambigious when there's multiple sources and targets.
2019-11-30 00:08:10 +01:00
Hornwitser bfff297d9a Add tests for clusterctl's output formatting
Add tests for formatOutput and formatOutputColored by using the same
lines as the line parser uses for testing.
2019-11-30 00:08:10 +01:00
Hornwitser 3bccbac496 Refactor to a connector based concept in lib/link
Remove connection and client subclasses of Link and put the connection
logic into a "connector" class.  The connector deals with sending
and receiving messages, handling the connection and reconnection of lost
connections and giving sequence numbers to messages.

This move the logic of the actual connection away from the link
sub-classes, which in turn means the connection should be a lot easier
to mock in tests.
2019-11-30 00:08:10 +01:00
Hornwitser f2c3006046 Remove obsolete fileOps code
Remove sync functions that should not be used as well as of functions
that provide functionality that is already implemented by fs-extra.
2019-11-23 15:18:20 +01:00
Hornwitser 7a2abaa5db Daemonize slave
Rework client.js to support running multiple instances at once and be
managed remotely and implement the neccessary communication
infrastructure for this.

Due to circular dependencies on the implementation of this the master
branch is significantly broken after this.
2019-11-23 15:16:47 +01:00
Hornwitser bc41f7afa6 Clean up generateSSLcert test
Remove dependency to fileOps in generateSSLcert test file and clean up
the code to follow a higher standard.
2019-11-21 22:25:15 +01:00
Hornwitser 65f75d86e6 Add id based database load and save functions
Add functions to save and load a Map of objects indexed by the id
property in the objects.
2019-11-21 22:25:15 +01:00
Hornwitser fcae3ef0c1 Use detected Factorio version
Remove Factorio_version from the config file and use the detected
version of Factorio instead.
2019-11-21 22:25:11 +01:00
Hornwitser 6f5534c45b Test for numeric strings in addItem and removeItem
Add tests asserting that numeric strings passed to the addItem and
removeItem methods to ItemDatabes throws.
2019-10-28 19:46:22 +01:00
Hornwitser 9a2b2c9f8d Speed up generateSSLcert test
Significantly speed up the generateSSLtest by reducing the bits in the
key from 2048 to 512.
2019-10-28 19:46:22 +01:00
Hornwitser ff3fc3b94b Remove .js suffix in require paths
Remove the .js suffix in require paths to make requires consistent
across the project.
2019-10-28 19:45:34 +01:00
Hornwitser 1a035e849e Replace Hotpatch with save patching
Remove Hotpatch and implement a save patcher in its place.  The save
patcher takes a normal Factorio save and adds modules to it that's
loaded by a generated control.lua file.  This greatly reduces the
difficulty of adding an existing game to Clusterio and using scenario
code in plugins.

The mechanism for selecting what code to patch into the saves from
plugins is temorary and expected to change with #220.
2019-10-24 22:49:16 +02:00
Hornwitser 079e31cf05 Implement hashStream
Add a hashStream method to lib/hash that does the same as hashFile only
with a stream instead of a file path and implement tests for both of
these methods.
2019-10-24 22:49:16 +02:00
Hornwitser 93480c8b29 Refactor getFactorioLocale
Move getFactorioLocale to the new lib/factorio namespace and refactor it
to use async functions instead of callbacks.  Split tests into
integration with factorio and testing of the function itself.

Also removes the cacheing from the function itself as this breaks the
isolated testing of it.
2019-10-14 18:56:46 +02:00
Hornwitser a01b971ba2 Rewrite Factorio server spawning
Break out the server process management to a new FactorioServer class in
lib/factorio.  This class takes responsibility for managing a factorio
server, communicating with it and handling the stopping of it.  It also
replaces the previous effort to do this in lib/factorioServer.

This change also updates the version of rcon-client, and since the
author of it has updated it to use UTF-8 the fork is no longer
necessary.  It also removes the messageInterface implementation
in favor of just calling the rcon-client library directly since
this has rate limiting logic built in.

The lib/factorio library is intended to abstract all the interfacing
that happens with Factorio.
2019-10-14 18:56:46 +02:00
Hornwitser 6b4ab6660c Generate instance ID separate from rcon password
Create a random instance ID using Math.random instead of deriving it
from the RCON password with a hombrew hash algorithm.  Remove
stringUtils as it's no longer needed.
2019-10-14 15:51:45 +02:00
Hornwitser cbcf868c9e Refactor fileOps.getNewestFile
Simplify getNewestFile by converting it to an async function, use the
fs-extra promise based fs functions and remove the files argument as
well as the callback.

Refactors the tests as well to use the test/temp folder.
2019-10-14 15:51:45 +02:00
Hornwitser a63c341209 Move unit tests to test/ folder
Move unit tests for client, master, and the lib to test/ and move plugin
unit tests to <plugin dir>/test.
2019-09-14 14:49:52 +02:00