/source-rcon-library

A source RCON (https://developer.valvesoftware.com/wiki/Source_RCON_Protocol) server library

Primary LanguageC#MIT LicenseMIT

source-rcon-logo

Source RCON Library

Source RCON Library is an easy to use, single-class solution to create a Valve source RCON server which supports authentication, IP Whitelisting, a command manager and much more!

Table of contents

NuGet

Install-Package source-rcon-server

Examples

Hosted Examples

Server

2018-01-28_12-49-23

https://github.com/Subtixx/source-rcon-library/tree/master/Examples/ServerExample

Client

2018-01-28_12-52-10-e

https://github.com/Subtixx/source-rcon-library/tree/master/Examples/ClientExample

Setup

Minimum setup server

var server = new RemoteConServer(IPAddress.Any, 27015);
server.StartListening();

Configuration

This library allows you to configure certain things, here I'll explain what you can configure and how it affects the server.

EmptyPayloadKick

When the client is authenticated (already entered his password), the server checks the payload (or body as it's called on the wiki) before processing the packet. If the payload is empty and EmptyPayloadKick is true, the client gets disconnected from the RCON server.

EnableIpWhitelist / IpWhitelist

Sometimes it's necessary to protect the RCON server from intruders. This setting will allow you to specify a wildcard based IP Whitelist to check against when a new client connects.

InvalidPacketKick

The server will ensure that the client will only sent packets (after authentication) that are of type ExecCommand. If this is not the case, and the setting is true, the client will be disconnected if he sents a packet with a different type.

MaxPasswordTries

To protect the server against brute force attacks it checks if the client has exceeded the maximum allowed of tries specified by this setting. If he has he will be disconnected immediately

Password

This is the password that has to be entered before any commands can be executed

SendAuthImmediately

Sometimes client libraries don't match the specification, this was the case when testing the library. If you've trouble using a specific client, and haven't tried setting this to true this might help. (If not please open an issue!)

UseCustomCommandHandler / OnCommandReceived

Sometimes you just want to do it yourself. Setting UseCustomCommandHandler to true and adding an eventhandler to OnCommandReceived will ignore the built-in CommandManager and sent all commands to the eventhandler instead

Debug

This will sent debug messages to System.Diagnostics.Debug.WriteLine and Console.WriteLine

MaxConnectionsPerIp

To disallow spamming the server with connections you can limit how many clients can connect from a single IP

MaxConnections

With this setting you can limit how many total connections the server accepts at once

IpBanList

Temporary list of IPs which are banned. You have to handle saving and loading yourself. Additionally this allows you to make a command (For example called rcon-ban to ban specific clients from the RCON connections). The value (since it's a dictionary) specifies the unix timestamp (Use DateTimeExtensions to get that value) when the ban is lifted. To ban someone forever you can use int.MaxValue

BanMinutes

This specifies how long a client will be banned when he fails to authenticate MaxPasswordTries.

Adding Commands

There are two main ways to create commands, either as LAMBDA expression or as Class Method. You can optionally specify a usage and description to in a custom help command (Example is in RCONServerLibExample), if you don't specify it it'll be empty by default.

public void Add(string name, CommandHandler handler)
public void Add(string name, string description, CommandHandler handler)
public void Add(string name, string usage, string description, CommandHandler handler)

LAMBDA expression

public static class Program
{
    public static int Main(string[] args)
    {
        var server = new RemoteConServer(IPAddress.Any, 27015);
        server.CommandManager.Add("hello", "Echos back world", (command, arguments) => {
            return "world";
        });
    }
}

Class Method

public static class Program
{
    public static int Main(string[] args)
    {
        var server = new RemoteConServer(IPAddress.Any, 27015);
        server.CommandManager.Add("hello", "", Hello_Command);
        
        server.StartListening();
        while (true)
        {
        }
    }
    
    public string Hello_Command(string command, IList<string> args)
    {
        return "world";
    }
}

Contributing

Not much here yet. Feel free to fork and sent pull-requests.

ToDo List

  • Split packets at 4096 bytes

References