https://github.com/untodesu/rcon-dotnet
Valve RCON Protocol implementation for .NET
https://github.com/untodesu/rcon-dotnet
async client-server csharp rcon rcon-protocol
Last synced: about 1 year ago
JSON representation
Valve RCON Protocol implementation for .NET
- Host: GitHub
- URL: https://github.com/untodesu/rcon-dotnet
- Owner: untodesu
- License: bsd-2-clause
- Created: 2020-02-25T17:18:54.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2021-02-11T11:05:26.000Z (over 5 years ago)
- Last Synced: 2023-08-21T09:38:22.153Z (almost 3 years ago)
- Topics: async, client-server, csharp, rcon, rcon-protocol
- Language: C#
- Homepage:
- Size: 15.6 KB
- Stars: 9
- Watchers: 1
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: readme.md
- License: license.txt
Awesome Lists containing this project
README
# Rcon for .NET
[Valve RCON Protocol](https://developer.valvesoftware.com/wiki/Source_RCON_Protocol) implementation library.
**This contains:**
* RCON Client Interface
* RCON Server Interface
* RCON Client
* RCON Server
# Installation
#### Package Manager
```
PM> Install-Package Rcon -Version 1.0.0
```
#### .NET CLI
```
> dotnet add package Rcon --version 1.0.0
```
#### Project file
```xml
```
# Usage example
## Client
```cs
using System;
using System.Threading.Tasks;
using Rcon;
namespace RconClient
{
static class Program
{
static async Task Main(string[] args)
{
RconClient client = new RconClient();
await client.ConnectAsync("127.0.0.1", 25575);
await client.AuthenticateAsync("super_secret_password");
if(!client.Authenticated) {
Console.WriteLine("Invalid password!!");
return;
}
for(;;) {
Console.Write("> ");
string response = await client.SendCommandAsync(Console.ReadLine());
if(!String.IsNullOrEmpty(response)) {
Console.WriteLine("] {0}", response);
}
}
}
}
}
```
## Server
```cs
using System;
using Rcon;
using Rcon.Events;
namespace RconServer
{
class Program
{
static void Main(string[] args)
{
using(RconServer server = new RconServer("super_secret_password", 25575)) {
server.OnClientCommandReceived += Server_OnClientCommandReceived;
server.OnClientConnected += Server_OnClientConnected;
server.OnClientAuthenticated += Server_OnClientAuthenticated;
server.OnClientDisconnected += Server_OnClientDisconnected;
server.Start();
}
}
static void Server_OnClientAuthenticated(object sender, ClientAuthenticatedEventArgs e)
{
Console.WriteLine("{0} authenticated", e.Client.Client.LocalEndPoint);
}
static void Server_OnClientDisconnected(object sender, ClientDisconnectedEventArgs e)
{
Console.WriteLine("{0} disconnected", e.EndPoint);
}
static void Server_OnClientConnected(object sender, ClientConnectedEventArgs e)
{
Console.WriteLine("{0} connected", e.Client.Client.LocalEndPoint);
}
static string Server_OnClientCommandReceived(object sender, ClientSentCommandEventArgs e)
{
Console.WriteLine("{0}: {1}", e.Client.Client.LocalEndPoint, e.Command);
return e.Command;
}
}
}
```
# Documentation
Still not, but there are some external docs:
* [Valve Developer Community](https://developer.valvesoftware.com/wiki/Source_RCON_Protocol)
* [Minecraft(?) wiki](https://wiki.vg/RCON)