RCON command lib.
$ dotnet add package RCON.Net.CommandsGeneric command helpers and base types for building typed RCON commands.
RCON.Net.Commands provides the foundational abstractions for command building and response parsing:
Install via NuGet:
dotnet add package RCON.Net.Commands
The core abstraction for all command implementations.
public interface ICommand
{
/// <summary>
/// Builds the command string to send to the server.
/// </summary>
string Build();
/// <summary>
/// Parses a server response into a typed result.
/// </summary>
T? Parse<T>(string response) where T : class;
}
Base class for implementing custom commands with common functionality.
public abstract class CommandBase : ICommand
{
public abstract string Build();
public virtual T? Parse<T>(string response) where T : class
{
// Default parsing logic
return response as T;
}
}
Implement the ICommand interface or extend CommandBase:
public class CustomCommand : CommandBase
{
private readonly string _argument;
public CustomCommand(string argument)
{
_argument = argument ?? throw new ArgumentNullException(nameof(argument));
}
public override string Build()
{
return $"custom {_argument}";
}
public override T? Parse<T>(string response) where T : class
{
// Parse response and return typed result
return null;
}
}
using RCON.Core;
using RCON.Commands;
// Create client
var client = RconClientBuilder.Create()
.WithHost("127.0.0.1")
.WithPort(25575)
.WithPassword("password")
.Build();
await client.ConnectAsync();
// Create and execute command
var command = new CustomCommand("value");
var response = await client.ExecuteAsync(command.Build());
var result = command.Parse<CustomResult>(response);
await client.DisconnectAsync();
Commands support type-safe response parsing:
public class ListCommand : CommandBase
{
public override string Build() => "list";
public override T? Parse<T>(string response) where T : class
{
if (typeof(T) == typeof(PlayerList))
{
var lines = response.Split('\n');
var playerList = new PlayerList { Players = ParsePlayers(lines) };
return playerList as T;
}
return null;
}
}
✅ Type-safe command building
✅ Generic response parsing
✅ Extensible architecture
✅ No external dependencies
✅ Simple, intuitive API
MIT License - See LICENSE file for details.