Skip to content

untodesu/rcon-dotnet

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rcon for .NET

Valve 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

<PackageReference Include="Rcon" Version="1.0.0" />

Usage example

Client

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

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: