Skip to content
CometWorksPublic

About

Hangar plugin for Magnetar.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Hangar

Server-only Space Engineers plugin for Magnetar.

Prerequisites

Projects

  • ServerPlugin - Magnetar plugin entry point and server runtime code.
  • Shared - common plugin helpers and interfaces.

This repository builds only the Magnetar server plugin.

Build

Install the Space Engineers Dedicated Server build references and the .NET SDK required by the project, then build:

dotnet build Hangar.sln -c Debug

The plugin output is:

ServerPlugin/bin/Debug/net10.0/Hangar.dll

The plugin version lives in Version.Build.props, which is committed and imported by Directory.Build.props. Bump the version there at a single place.

Directory.Build.props auto-detects the Dedicated Server (Dedicated64) and the Magnetar installation (Magnetar) on Windows and Linux. To override them, set them in Directory.Build.props.user, which is not committed. setup.py writes that file with the auto-detected Dedicated Server folder.

Configuration

Magnetar stores configuration through the Plugin SDK config system. An empty StorageRoot keeps the declared default in configuration and resolves to Space Engineers user data/Hangar on a standalone server.

In a cluster, Hangar ignores StorageRoot and uses PluginStorage.GetSharedDirectory automatically. Grid blobs and per-player entry indexes/cooldowns live there; operational changes never rewrite the canonical Plugin SDK configuration on individual nodes. Per-player file locks coordinate slot limits, cooldowns and consumption across nodes. Broadcasts are not used as the source of truth because starting nodes would miss earlier messages.

AdminSafeZonesOnly keeps saving and loading inside admin safe zones, the ones an admin or the world made rather than a safe zone block, such as a world's trade stations. An entry remembers the zone it was saved in. A grid loaded in that zone goes back where it was saved; in another zone it loads near the player and is pulled inside the zone, and a zone with no room for it refuses the load.

DefaultLoadMode says where a loaded grid comes back, NearPlayer or OriginalPosition. By default it is in front of the player, and players may ask for that with !hangar load <grid> true in the other mode as well. Two options change that; at their defaults Hangar behaves as it did before they came:

  • PlayersMayChooseLoadPlace (default on). Off: !hangar load <grid> true is refused and the default mode decides for everyone.
  • LoadClearOfGridSpheres (default off). On: a grid loaded at its original position, however far that is from the player, must also stay clear of other grids' bounding spheres. When its sphere would meet one, on any cluster node, it goes to the nearest spot clear of all of them and of the terrain, within 10 km, and the reply says how far it moved. So a ship stored from inside a station's shipyard comes back outside the station. A grid saved inside a safe zone may stay in one; any other stays out of them. Off, it is moved aside only when its box hits something. AdminSafeZonesOnly places grids its own way and doesn't use this.

Other server plugins can check or charge for a load through ServerPlugin.HangarHooks.BeforeLoad, which they set by reflection. Hangar calls it once the grid's spot is found, with the player's identity id, the zone the grid was saved in, the zone it comes back in (with LoadClearOfGridSpheres, always the zone it was saved in) and its PCU. A non-null result refuses the load, and the player gets it as the reply.

They can also store grids for a player who didn't ask, with HangarHooks.Store. It takes the player's Steam id and name, the grids and a point: the entry records the admin safe zone at that point. The grids leave the world whatever RemoveOriginalOnSave says. The save cooldown, majority ownership and AdminSafeZonesOnly don't apply and the cooldown doesn't start, but the slot limit and an entry's block and PCU limits do. The result says whether it was stored, whether the player has no free slot, and any other reason.

A plugin that reads the stored ships, as a wealth count does, lists a player's entries with Plugin.Instance.Storage.ListPlayerEntries and reads an entry's grids with Storage.ReadBlob(entry.BlobPath), which gives the bytes of the .sbc file, or null when it is gone. ReadBlob works wherever the storage is. The blobs are files under StorageRoot only on a server or cluster without the storage service.

The cluster provides the storage. On one Host the launcher sets CLUSTER_SHARED_ROOT, a directory all nodes see, which must support advisory file locks and atomic rename; Quasar provides it automatically. A cluster on several Host machines runs the cluster's storage service instead (CLUSTER_STORAGE): the nodes of every Host reach the same data over the network through the Plugin SDK's shared store, each call is one round trip to the main Host, and a player's record is replaced with compare-and-set on the version it was read at instead of under a lock file. Nothing blocks when a Host's link is down: the command answers that the storage is not reachable and leaves the grid where it is. The files are the same in both cases (Players/<steam id>.xml, GridBlobs/<steam id>/<guid>.sbc), so a cluster can change from one to the other without converting anything.

The storage service needs Magnetar 2.4.3.13 or later (Plugin SDK contract 1.2). On an older Magnetar Hangar works as before on a plain server and on a one-Host cluster, and refuses to load in a cluster that announces a storage service. Update all nodes of a cluster together. A node on the previous Hangar version reads and writes the same files and corrupts nothing, but it drops the claims this version puts into a player's record while a save or a load is in flight. A downgrade needs no step: the previous version reads the records as they are.

Hangar refuses to start in a cluster when legacy config entries or cooldowns are present. This version does not migrate them. Keep the original standalone config and grid blobs intact; start with an empty cluster Hangar or migrate the data separately before enabling the plugin there.

Development and deployment

Load the working copy through a Magnetar development folder: start Magnetar with -sources and add the repository with the Sources button. Magnetar then compiles the plugin from source.

Builds deploy nothing by default. To copy the build into <MagnetarData>/Local, set MagnetarData (the Magnetar config folder) in Directory.Build.props.user or pass it to a single build:

dotnet build Hangar.sln -p:MagnetarData=$HOME/.config/Magnetar/Magnetar

Hangar.xml is the MagnetarHub metadata file for server-side publication.

Tests

tests/ holds an in-game test suite. It starts a Magnetar server with this working copy of the plugin, joins it with two headless game clients and drives them through the Remote plugin: player A is an administrator, player B has no rights. The tests paste grids, run the chat commands and check the results on the server, in the stored files and in the replies. It runs on Linux only.

What it covers:

  • Saving a grid by name, by entity id or by looking at it, and loading it back: blocks, inventory, static grids, ownership with and without the transfer to the loader, near the player or at the original position, keeping the original on save, rotor heads and docked ships with and without connected grids, a pilot getting out, and a load moved aside when another grid took its spot (test_save_load.py)
  • PlayersMayChooseLoadPlace and LoadClearOfGridSpheres: the saved spot however far the player is, the nearest spot clear of another grid's bounding sphere, a ship stored from a shipyard, safe zones, and the defaults behaving as before (test_where_saved.py, and a config from before the options in test_restart.py)
  • Who may save what and how often: majority ownership, the slot, block and PCU limits, the save cooldown, and the plugin switched off (test_rules.py)
  • The !hangar and !h commands: list, info, entry selectors, remove and delete, status, enable and disable, permissions, bad input, two players' hangars, the blocking of other hangar commands, and the patches on the vanilla grid storage (test_commands.py)
  • Stored grids, cooldowns and config across a server restart, and a broken config file (test_restart.py)
  • Two cluster nodes sharing one storage: entries, slot limit and cooldown across nodes, and a node with legacy standalone entries (test_cluster.py)
  • Admin safe zones only: saving and loading outside a zone, a grid back in its own zone or pulled into another one, a zone too small for it, and the BeforeLoad and Store hooks (test_zones.py)

The world is the game's Empty World with the two test players, written fresh for every run; each test pastes its own grids at a spot of its own. tests/probe is a test-only server plugin the server loads next to Hangar: it reports grids, owners and inventories on the server, changes the plugin config and stored cooldowns at runtime, and seats, moves and connects things the clients can't, so the tests need no restart for each config.

The cluster tests run two Magnetar servers with CLUSTER_NODE_ID and one CLUSTER_SHARED_ROOT, which is what puts Hangar into its cluster storage mode. There is no gateway or World Authority, and player A is on both nodes at once from two clients.

Running

You need the Space Engineers client and Dedicated Server from Steam, Magnetar and Pulsar installed, uv, and working copies of Remote and DirectTransport. The rig takes the ports, client ids and folders from a test slot of the se workspace (testing/parallel-test-work), and waits for free memory before each process it starts.

uv run pytest

Where GitHub's API rate limits Magnetar, export PULSAR_GITHUB_TOKEN for it to download its hub plugins with. HG_SKIP_CLUSTER=1 leaves out the cluster tests.

A full run takes about 25 minutes, a third of it the server restarts and the cluster nodes. tests/rig.py lists the environment variables that point the rig at other installations and working copies. To keep the server and clients running between runs while you work on a test:

uv run python tests/session.py start
HG_ATTACH=1 HG_KEEP=1 uv run pytest tests/test_commands.py
uv run python tests/session.py stop

Functionality is inspired by and reimplements the original Torch plugin QuantumHangar by Casimir255 (license: Apache-2.0): https://github.com/Casimir255/QuantumHangar)

About

Hangar plugin for Magnetar.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages