RustPlusApi 1.4.0

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package RustPlusApi --version 1.4.0
                    
NuGet\Install-Package RustPlusApi -Version 1.4.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RustPlusApi" Version="1.4.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RustPlusApi" Version="1.4.0" />
                    
Directory.Packages.props
<PackageReference Include="RustPlusApi" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RustPlusApi --version 1.4.0
                    
#r "nuget: RustPlusApi, 1.4.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RustPlusApi@1.4.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RustPlusApi&version=1.4.0
                    
Install as a Cake Addin
#tool nuget:?package=RustPlusApi&version=1.4.0
                    
Install as a Cake Tool

RustPlusApi

This is a C# client for the Rust+ API. It allows you to interact with the Rust+ server.

The library provides two classes to interact with the Rust+ API: RustPlusLegacy and RustPlus.

  • RustPlusLegacy is the original implementation based on the .RustPlus.proto file.
  • RustPlus is a new implementation that returns a response based on ./Data/Response.cs object.

RustPlusLegacy is mark as obsolete and will be removed in the future. It is recommended to use RustPlus for new projects.

RustPlusLegacy

![WARNING] Obsolete: This class is marked as obsolete and will be removed in the future. Use RustPlus instead.

First, instantiate the RustPlusLegacy class with the necessary parameters:

var rustPlusApi = new RustPlusLegacy(server, port, playerId, playerToken, useFacepunchProxy);

Parameters:

  • server: The IP address of the Rust+ server.
  • port: The port dedicated for the Rust+ companion app (not the one used to connect in-game).
  • playerId: Your Steam ID.
  • playerToken: Your player token acquired with FCM.
  • useFacepunchProxy: Specifies whether to use the Facepunch proxy. Default is false.

Then, connect to the Rust+ server:

await rustPlusApi.ConnectAsync();

There are plenty of methods to interact with the Rust+ server such as:

uint entityId = 123456789;
var response = await rustPlus.GetEntityInfoLegacyAsync(entityId);

or

var response = await rustPlus.GetInfoLegacyAsync();

you can also make your own request:

var request = new AppRequest
{
    GetTime = new AppEmpty()
};
await rustPlus.SendRequestAsync(request);

The response with be an AppMessage that is a direct representation of ./Protobuf/RustPlus.proto file.

Feel free to explore the RustPlusLegacy class to find all convenient methods to use.


You can subscribe to events to handle specific actions:

rustPlusApi.Connecting += (sender, _) => { /* handle connecting event */ };
rustPlusApi.Connected += (sender, _) => { /* handle connected event */ };

rustPlusApi.MessageReceived += (sender, message) => { /* handle every message receive from the socket */ };
rustPlusApi.NotificationReceived += (sender, message) => { /* handle every notification (no direct request) from the socket */ };
rustPlusApi.ResponseReceived += (sender, message) => { /* handle every response (answer to a request) from the socket */ };

rustPlusApi.Disconnecting += (sender, _) => { /* handle disconnecting event */ };
rustPlusApi.Disconnected += (sender, _) => { /* handle disconnected event */ };

rustPlusApi.ErrorOccurred += (sender, ex) => { /* handle error event */ };

Remember to dispose the RustPlusLegacy instance when you're done:

rustPlusApi.DisconnectAsync(); 

RustPlus

Such as the RustPlusLegacy, you need to instantiate the RustPlus class with the necessary parameters:

var rustPlusApi = new RustPlus(server, port, playerId, playerToken, useFacepunchProxy);

There are quite the same methods as RustPlusLegacy but the response is a direct representation of ./Data/Response.cs object.

public class Response<T>
{
    public bool IsSuccess { get; set; }
    public Error? Error { get; set; }
    public T? Data { get; set; }
}

public class Error
{
    public string? Message { get; set; }
}

For example, to get the entity info:

uint smartSwitchId = 123456789;
var response = await rustPlus.GetSmartSwitchInfoAsync(smartSwitchId);

Response will be a Response<SmartSwitchInfo> object.

public class SmartSwitchInfo
{
    public bool IsActive { get; set; }
}

You can also subscribe to more events to handle specific actions:

rustPlusApi.OnSmartSwitchTriggered += (sender, smartSwitch) => { /* handle smart switch triggered event */ };
rustPlusApi.OnStorageMonitorTriggered += (sender, storageMonitor) => { /* handle storage monitor triggered event */ };

rustPlusApi.OnTeamChatReceived += (sender, message) => { /* handle team chat received event */ };

To be able to receive these events, you need to previously make a request on the given entity or chat.

For example, to receive the smart switch triggered event, you need to make a request on the smart switch entity:

rustPlus.OnSmartSwitchTriggered += (_, message) =>
{
    // ...
};

const uint entityId = 123456789;
var message = await rustPlus.GetSmartSwitchInfoAsync(entityId);

Each time the smart switch is triggered, the event will be fired.


Remember to dispose the RustPlus instance when you're done (such as RustPlusLegacy):

rustPlusApi.DisconnectAsync(); 
Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on RustPlusApi:

Package Downloads
RustPlusApi.Camera

Camera session control (keep-alive, turret/PTZ helpers) and frame rendering for Rust+. Renders AppCameraRays into images via SixLabors.ImageSharp; keep it out of the core if you only need the raw camera protocol.

RustPlusApi.Extensions.DependencyInjection

Microsoft.Extensions.DependencyInjection registration extensions for the RustPlusApi Rust+ client.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on RustPlusApi:

Repository Stars
Pronwan/rustplus-desktop
Rust+ Desktop App (unofficial)