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!
Install-Package source-rcon-server
https://github.com/Subtixx/source-rcon-library/tree/master/Examples/ServerExample
https://github.com/Subtixx/source-rcon-library/tree/master/Examples/ClientExample
var server = new RemoteConServer(IPAddress.Any, 27015);
server.StartListening();
This library allows you to configure certain things, here I'll explain what you can configure and how it affects the server.
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.
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.
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.
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
This is the password that has to be entered before any commands can be executed
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!)
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
This will sent debug messages to System.Diagnostics.Debug.WriteLine
and Console.WriteLine
To disallow spamming the server with connections you can limit how many clients can connect from a single IP
With this setting you can limit how many total connections the server accepts at once
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
This specifies how long a client will be banned when he fails to authenticate MaxPasswordTries
.
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)
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";
});
}
}
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";
}
}
Not much here yet. Feel free to fork and sent pull-requests.
- TWaalen for fixing the UnitTests
- Split packets at 4096 bytes