Torch Management Suite for Space Engineers

repository·master·Indexed 41 days ago

https://github.com/torchapi/torch

A management suite and server extender for Space Engineers that provides administrators with a WPF user interface, remote chat interaction, real-time entity management, and a plugin system. It includes tools for managing server configurations, whitelists, and a comprehensive CLI command system with hierarchical permissions and attribute-based command modules.

Tokens
4.5K
Snippets
16
Records
21
Agent score
51%

What's inside Torch

  1. What is Torch?

    master

    Torch is a management tool for Space Engineers server administrators, designed as the successor to SE Server Extender. It provides a WPF-based user interface for live server management and includes a plugin system for extensibility.

    Key capabilities include:

    • Chat: Interact with game chat and execute commands remotely.
    • Entity Manager: Real-time modification of in-game entities (e.g., stopping grids, changing block settings) without joining the game.
    • Configuration Editor: An organized interface for managing server settings.
    • Plugin System: Allows for custom server behavior through extensions.
  2. Build Torch from source

    master

    To build Torch, you must have a complete Space Engineers Dedicated Server installation on your machine. The build process requires a symlink to the DedicatedServer64 folder so the solution can resolve DLL references.

    Steps:

    1. Locate your Space Engineers Dedicated Server installation.
    2. Run the Setup batch file provided in the repository.
    3. When prompted, enter the full path to the DedicatedServer64 folder of your installation.
    4. Open the solution to begin building.
  3. Install Torch.Server

    master

    To install Torch, download the latest release and extract it to a dedicated directory.

    Steps:

    1. Download the latest Torch release from the build server.
    2. Unzip the contents into its own directory.
    3. Run the executable. Torch will automatically download the Space Engineers Dedicated Server (DS) and generate required files.

    Note for existing installations: If you already have a Dedicated Server installed, you can unzip the Torch files directly into the folder containing the DedicatedServer64 directory.

    # Download and unzip the release, then run the executable
    # If using an existing DS, unzip into the folder containing DedicatedServer64
  4. Manage server restarts and stops

    master

    Torch allows for scheduled or delayed server shutdowns and restarts. These commands initiate a countdown that notifies players via chat.

    • restart [countdownSeconds] [save]: Initiates a restart. If save is true, the server will attempt to save the game before restarting. A countdown will be displayed in chat.
    • stop [save] [countdownSeconds]: Initiates a shutdown. Similar to restart, it supports a countdown and an optional save.
    • restart cancel: If a restart countdown is currently active, this command will abort the process.
    • stop cancel: If a stop countdown is currently active, this command will abort the process.
    # Restart the server in 5 minutes (300 seconds) with a save
    restart 300 true
    
    # Stop the server immediately without saving
    stop false 0
    
    # Cancel a pending restart
    restart cancel
  5. Understand Command Syntax and Parameter Parsing

    master

    Torch generates a SyntaxHelp string for every command to show users how to call it in chat. The syntax follows these rules:

    • Required Parameters: Represented by <Type Name> (e.g., <String name>).
    • Optional Parameters: Represented by [Type Name] (e.g., [Int32 age]). These are parameters that have a default value in the method signature.
    • Command Path: Commands can be nested using a path. If a module is defined with a path, the command is invoked as !path command.

    Parameter Conversion: Torch uses TypeDescriptor to convert string arguments from the chat into the specific types required by your command method (e.g., converting "123" to an int). If a conversion fails, the command invocation will fail.

  6. Understand the Permission structure

    master

    Permissions in Torch are structured hierarchically using the Permission class.

    • Path: A string[] representing the hierarchical path to the permission (e.g., ["commands", "kick"]).
    • Allow: A bool indicating whether the permission is granted or denied.
    • Children: A Dictionary<string, Permission> that allows for nested permission nodes, enabling fine-grained control over sub-commands or specific features.
  7. Use built-in Torch server commands

    master

    Torch provides several built-in commands that can be executed via the server interface to manage the server state, plugins, and player information. Commands have different permission levels; some require Admin status.

    ### Example Command Usage
    # Note: Commands are typically typed into the game chat or server console.
    
    # Check server version
    ver
    
    # List loaded plugins
    plugins
    
    # Save the game
    save
  8. Define new chat commands in Torch

    master

    In Torch, you can define chat commands using two primary methods: by providing a manual CommandAction delegate or by using reflection on methods within a CommandModule class decorated with attributes.

    Method 1: Manual Command Definition

    You can instantiate a Command directly by passing a name, description, and a CommandAction delegate. The CommandAction delegate has the signature void (CommandContext context, object[] arguments).

    Method 2: Attribute-based Command Modules

    For a more structured approach, you can define commands as methods within a class that inherits from CommandModule. This method uses reflection to automatically parse parameters and permissions.

    Requirements for Attribute-based Commands:

    1. The declaring type must be a subclass of CommandModule.
    2. The method must be decorated with a [Command] attribute.
    3. (Optional) The method can be decorated with a [Permission] attribute to set the MinimumPromoteLevel.
    4. (Optional) The class can be decorated with a [Category] attribute to define a command path (e.g., !module command).

    When using the attribute-based approach, Torch automatically handles parameter conversion from strings to the types defined in your method signature.

    // Example of the attribute-based approach
    [Category(Path = "admin")]
    public class MyModule : CommandModule
    {
        [Command(Name = "greet", Description = "Greets a player")]
        [Permission(PromoteLevel = MyPromoteLevel.Admin)]
        public void Greet(string playerName, int age)
        {
            // Logic here
        }
    }
  9. Manage user and group memberships

    master

    Torch uses a relationship between PermissionUser and PermissionGroup to control access.

    • To add a user to a group: Use PermissionUser.AddToGroup(group) or PermissionGroup.AddMember(user). Both methods ensure the relationship is synchronized between the user's group list and the group's member list.
    • To remove a user from a group: Use PermissionUser.RemoveFromGroup(group) or PermissionGroup.RemoveMember(user).

    Users are identified by their SteamID (ulong).

    // Adding a user to a group
    PermissionUser user = new PermissionUser(steamId);
    PermissionGroup adminGroup = system.Groups["Admin"];
    user.AddToGroup(adminGroup);
    
    // Removing a user from a group
    user.RemoveFromGroup(adminGroup);
  10. Reload plugins via command line

    master

    If you have updated a plugin or need to refresh its state, you can use the reload command. This requires Admin permissions.

    • To reload all plugins: reload
    • To reload a specific plugin: reload <plugin_name>

    Note: Some plugins may not support reloading if they have not implemented the necessary logic or if the BypassIsReloadableFlag is not set in the configuration.

    # Reload all plugins
    reload
    
    # Reload a specific plugin named 'MyCoolPlugin'
    reload MyCoolPlugin
  11. Define command metadata with CommandAttribute

    master

    Use the CommandAttribute to decorate classes that serve as CLI commands. This attribute provides the metadata required for the CLI to identify the command's name, description, help text, and its position within a command hierarchy.

    Hierarchy Support

    You can define a command hierarchy using space-delimited strings in the constructor. For example, a command string of "parent child command" will result in a path of ["parent", "child", "command"] and a command name of "command".

    [Command("compute model train", "Trains a machine learning model", "Use this to start the training process")]
    public class TrainCommand
    {
        // Command implementation
    }
  12. Configure command permissions with MyPromoteLevel

    master

    Every command has a MinimumPromoteLevel which determines the authorization required to execute it. By default, commands are set to MyPromoteLevel.Admin if no level is specified.

    When defining commands via attributes, use the [Permission] attribute to specify the required level:

    [Permission(PromoteLevel = MyPromoteLevel.Admin)]