Integration Guide

Updated 3 weeks ago

ScarletRCON Integration Guide

Optional Integration (No Hard Dependency)

For mods that want RCON support when available but don't require it:

Implementation

  • Add the source package to your .csproj:
<PackageReference Include="ScarletRCON.SourceSupport" Version="1.1.*" PrivateAssets="all" />
  • Declare the BepInEx dependency:
[BepInDependency("markvaaz.ScarletRCON", BepInDependency.DependencyFlags.SoftDependency)]
public class MyPlugin : BasePlugin
  • Use the shared namespace:
using ScarletRCON.Shared;
  • Register and clean up commands:
public void Load()
{
    RconCommandRegistrar.RegisterAll();
}

public void Unload()
{
    RconCommandRegistrar.UnregisterAssembly();
}
  • Create your command class:
[RconCommandCategory("Mod Commands")]
public class ModCommands
{
    [RconCommand("check", "Checks mod status")]
    public static string CheckStatus() 
    {
        return "Mod is functioning normally";
    }
}

Key Points:

  • Commands only register if ScarletRCON is present
  • No errors will occur if ScarletRCON isn't installed
  • Full control over registration timing

Direct Integration (With Dependency)

For mods requiring guaranteed RCON functionality:

Implementation

  • Add the package reference:
<PackageReference Include="ScarletRCON" Version="1.1.*" />
  • Declare the BepInEx dependency:
[BepInDependency("markvaaz.ScarletRCON")]
public class MyPlugin : BasePlugin
  • Register and clean up commands:
public void Load()
{
    CommandHandler.RegisterAll();
}

public void Unload()
{
    CommandHandler.UnregisterAssembly();
}
  • Create commands with enhanced features:
[RconCommandCategory("Admin")]
public class AdminCommands
{
    [RconCommand("admin.restart", "Restarts server services", "<delaySeconds>")]
    public static string RestartServices(int delaySeconds)
    {
        // Implementation
        return $"Server restarting in {delaySeconds} seconds";
    }
}

Key Features:

  • Automatic command management
  • Advanced RCON capabilities
  • Proper cleanup during unload

Best Practices

For both integration methods:

  1. Command Design:

    • Keep command names clear and consistent (mod.function.action)
    • Include descriptive help text
    • Specify parameter requirements in usage
  2. Error Handling:

    • Return user-friendly error messages
    • Validate all input parameters
    • Handle exceptions gracefully
  3. Organization:

    • Group related commands with categories
    • Separate commands into logical classes
    • Consider command prefixes for related functions

For more details on command creation, see the Custom Commands Documentation.