Table of Contents

Class RustPlus

Namespace
RustPlusApi
Assembly
RustPlusApi.dll

Initializes a new instance of the RustPlus class, connecting to a Rust+ server using the specified parameters.

public class RustPlus : RustPlusSocket, IRustPlus, IRustPlusSocket, IDisposable, IAsyncDisposable
Inheritance
RustPlus
Implements
Inherited Members

Constructors

RustPlus(RustPlusConnection, RustPlusSocketOptions?, ILoggerFactory?)

Initializes a new instance of the RustPlus class, connecting to a Rust+ server using the specified parameters.

public RustPlus(RustPlusConnection connection, RustPlusSocketOptions? options = null, ILoggerFactory? loggerFactory = null)

Parameters

connection RustPlusConnection

The server endpoint and player credentials to connect as.

options RustPlusSocketOptions

Tuning options (timeouts, keep-alive, buffer size); defaults are used when null.

loggerFactory ILoggerFactory

Routes the client's diagnostics into your logging stack; logging is disabled (a no-op NullLogger) when null.

See Also

Methods

CheckSubscriptionAsync(ulong, CancellationToken)

Checks the subscription status of an alarm asynchronously.

public Task<Response<SubscriptionInfo?>> CheckSubscriptionAsync(ulong alarmId, CancellationToken cancellationToken = default)

Parameters

alarmId ulong

The ID of the alarm entity.

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response<SubscriptionInfo>>

A Task<TResult> representing the asynchronous operation. The task result contains a Response<T> with the subscription information.

GetAlarmInfoAsync(ulong, CancellationToken)

Retrieves the information of an alarm asynchronously.

public Task<Response<SmartDeviceInfo?>> GetAlarmInfoAsync(ulong entityId, CancellationToken cancellationToken = default)

Parameters

entityId ulong

The ID of the alarm entity.

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response<SmartDeviceInfo>>

A Task<TResult> representing the asynchronous operation. The task result contains a Response<T> with the alarm information.

Remarks

The underlying getEntityInfo request also subscribes this connection to the entity's EntityChanged broadcasts server-side — even when the read itself fails on a type mismatch.

GetClanChatAsync(CancellationToken)

Retrieves the clan chat asynchronously.

public Task<Response<ClanChatInfo?>> GetClanChatAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response<ClanChatInfo>>

A Task<TResult> representing the asynchronous operation. The task result contains a Response<T> with the clan chat information.

GetClanInfoAsync(CancellationToken)

Retrieves the clan information asynchronously.

public Task<Response<ClanInfo?>> GetClanInfoAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response<ClanInfo>>

A Task<TResult> representing the asynchronous operation. The task result contains a Response<T> with the clan information.

GetEntityInfoAsync<T>(ulong, Func<AppMessage, T>, CancellationToken)

Retrieves the information of an entity asynchronously.

protected Task<Response<T?>> GetEntityInfoAsync<T>(ulong entityId, Func<AppMessage, T> selector, CancellationToken cancellationToken = default)

Parameters

entityId ulong

The ID of the entity.

selector Func<AppMessage, T>

The function to select the entity information from the response.

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response<T>>

A Task<TResult> representing the asynchronous operation. The task result contains a Response<T> with the entity information.

Type Parameters

T

The type of the entity information.

Remarks

The underlying getEntityInfo request also subscribes this connection to the entity's EntityChanged broadcasts server-side — even when the mapping of the reply fails.

GetInfoAsync(CancellationToken)

Retrieves the server information asynchronously.

public Task<Response<ServerInfo?>> GetInfoAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response<ServerInfo>>

A Task<TResult> representing the asynchronous operation. The task result contains a Response<T> with the server information.

GetMapAsync(CancellationToken)

Retrieves the server map asynchronously.

public Task<Response<ServerMap?>> GetMapAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response<ServerMap>>

A Task<TResult> representing the asynchronous operation. The task result contains a Response<T> with the server map.

GetMapMarkersAsync(CancellationToken)

Retrieves the map markers asynchronously.

public Task<Response<MapMarkers?>> GetMapMarkersAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response<MapMarkers>>

A Task<TResult> representing the asynchronous operation. The task result contains a Response<T> with the map markers.

GetNexusAuthAsync(string, CancellationToken)

Retrieves the Nexus authentication asynchronously.

public Task<Response<NexusAuth?>> GetNexusAuthAsync(string appKey, CancellationToken cancellationToken = default)

Parameters

appKey string

The app key for Nexus authentication.

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response<NexusAuth>>

A Task<TResult> representing the asynchronous operation. The task result contains a Response<T> with the Nexus authentication.

GetSmartDeviceInfoAsync(ulong, CancellationToken)

Retrieves the state of a binary-state smart device (a smart switch or a smart alarm) asynchronously, whichever of the two types the entity actually is. The server replies with the entity's actual type and switch/alarm payloads are identical, so this method reads mixed device sets without tracking each entity's type.

public Task<Response<SmartDeviceInfo?>> GetSmartDeviceInfoAsync(ulong entityId, CancellationToken cancellationToken = default)

Parameters

entityId ulong

The ID of the smart device entity.

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response<SmartDeviceInfo>>

A Task<TResult> representing the asynchronous operation. The task result contains a Response<T> with the smart device information.

Remarks

The underlying getEntityInfo request also subscribes this connection to the entity's EntityChanged broadcasts server-side — even when the read itself fails on a type mismatch.

GetSmartSwitchInfoAsync(ulong, CancellationToken)

Retrieves the information of a smart switch asynchronously.

public Task<Response<SmartDeviceInfo?>> GetSmartSwitchInfoAsync(ulong entityId, CancellationToken cancellationToken = default)

Parameters

entityId ulong

The ID of the smart switch entity.

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response<SmartDeviceInfo>>

A Task<TResult> representing the asynchronous operation. The task result contains a Response<T> with the smart switch information.

Remarks

The underlying getEntityInfo request also subscribes this connection to the entity's EntityChanged broadcasts server-side — even when the read itself fails on a type mismatch.

GetStorageMonitorInfoAsync(ulong, CancellationToken)

Retrieves the information of a storage monitor asynchronously.

public Task<Response<StorageMonitorInfo?>> GetStorageMonitorInfoAsync(ulong entityId, CancellationToken cancellationToken = default)

Parameters

entityId ulong

The ID of the storage monitor entity.

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response<StorageMonitorInfo>>

A Task<TResult> representing the asynchronous operation. The task result contains a Response<T> with the storage monitor information.

Remarks

The underlying getEntityInfo request also subscribes this connection to the entity's EntityChanged broadcasts server-side — even when the read itself fails on a type mismatch.

GetTeamChatAsync(CancellationToken)

Retrieves the team chat information asynchronously.

public Task<Response<TeamChatInfo?>> GetTeamChatAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response<TeamChatInfo>>

A Task<TResult> representing the asynchronous operation. The task result contains a Response<T> with the team chat information.

GetTeamInfoAsync(CancellationToken)

Retrieves the team information asynchronously.

public Task<Response<TeamInfo?>> GetTeamInfoAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response<TeamInfo>>

A Task<TResult> representing the asynchronous operation. The task result contains a Response<T> with the team information.

GetTimeAsync(CancellationToken)

Retrieves the current time information asynchronously.

public Task<Response<TimeInfo?>> GetTimeAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response<TimeInfo>>

A Task<TResult> representing the asynchronous operation. The task result contains a Response<T> with the time information.

KickFromTeamAsync(ulong, CancellationToken)

Kicks a player out of the team asynchronously.

public Task<Response> KickFromTeamAsync(ulong steamId, CancellationToken cancellationToken = default)

Parameters

steamId ulong

The Steam ID of the player to kick.

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response>

A Task<TResult> representing the asynchronous operation. The task result contains a payload-free Response indicating the success of the operation.

ParseNotification(AppBroadcast?)

Parses the notification received from the Rust+ server.

protected override void ParseNotification(AppBroadcast? broadcast)

Parameters

broadcast AppBroadcast

The broadcast received from the server.

ProcessAckRequestAsync(AppRequest, CancellationToken)

Processes an acknowledge-only request asynchronously: success is the absence of a server error, and no payload is returned.

protected Task<Response> ProcessAckRequestAsync(AppRequest request, CancellationToken cancellationToken = default)

Parameters

request AppRequest

The request to be processed.

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response>

A Task<TResult> whose result is a payload-free Response.

Exceptions

InvalidOperationException

Thrown when the client is not connected.

ProcessRequestAsync<T>(AppRequest, Func<AppMessage, T>, Func<AppBroadcast, bool>?, CancellationToken)

Processes the request asynchronously and returns the result.

protected Task<Response<T?>> ProcessRequestAsync<T>(AppRequest request, Func<AppMessage, T> successSelector, Func<AppBroadcast, bool>? broadcastReplyMatcher = null, CancellationToken cancellationToken = default)

Parameters

request AppRequest

The request to be processed.

successSelector Func<AppMessage, T>

The function to select the result from the response.

broadcastReplyMatcher Func<AppBroadcast, bool>

When non-null, the success reply is delivered as a broadcast (no seq) and is matched by this predicate, so the selector reads response.Broadcast rather than response.Response. Unrelated broadcasts stay pure notifications.

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response<T>>

A Task<TResult> representing the asynchronous operation. The task result contains a Response<T> with the processed result.

Type Parameters

T

The type of the result.

Remarks

A success-selector exception (other than OperationCanceledException) is returned as a failed Response<T> carrying the exception message — a successful server reply never surfaces as a thrown exception.

Exceptions

InvalidOperationException

Thrown when the client is not connected.

PromoteToLeaderAsync(ulong, CancellationToken)

Promotes a player to leader asynchronously.

public Task<Response> PromoteToLeaderAsync(ulong steamId, CancellationToken cancellationToken = default)

Parameters

steamId ulong

The Steam ID of the player to promote.

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response>

A Task<TResult> representing the asynchronous operation. The task result contains a payload-free Response indicating the success of the operation.

SendCameraInputAsync(CameraButtons, float, float, CancellationToken)

Sends input (movement/mouse/buttons) to the subscribed camera asynchronously.

public Task<Response> SendCameraInputAsync(CameraButtons buttons, float mouseDeltaX = 0, float mouseDeltaY = 0, CancellationToken cancellationToken = default)

Parameters

buttons CameraButtons

The pressed CameraButtons bitmask.

mouseDeltaX float

The horizontal mouse delta.

mouseDeltaY float

The vertical mouse delta.

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response>

A Task<TResult> representing the asynchronous operation. The task result contains a payload-free Response indicating the success of the operation.

SendClanMessageAsync(string, CancellationToken)

Sends a clan message asynchronously.

public Task<Response> SendClanMessageAsync(string message, CancellationToken cancellationToken = default)

Parameters

message string

The message to send.

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response>

A Task<TResult> representing the asynchronous operation. The task result contains a payload-free Response indicating the success of the operation.

SendTeamMessageAsync(string, CancellationToken)

Sends a team message asynchronously.

public Task<Response<TeamMessage?>> SendTeamMessageAsync(string message, CancellationToken cancellationToken = default)

Parameters

message string

The message to send.

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response<TeamMessage>>

A Task<TResult> representing the asynchronous operation. The task result contains a Response<T> with the team message.

SetClanMotdAsync(string, CancellationToken)

Sets the clan message of the day (MOTD) asynchronously.

public Task<Response> SetClanMotdAsync(string message, CancellationToken cancellationToken = default)

Parameters

message string

The message to set as the clan MOTD.

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response>

A Task<TResult> representing the asynchronous operation. The task result contains a payload-free Response indicating the success of the operation.

SetSmartSwitchValueAsync(ulong, bool, CancellationToken)

Sets the value of a smart switch asynchronously.

public Task<Response<SmartDeviceInfo?>> SetSmartSwitchValueAsync(ulong smartSwitchId, bool smartSwitchValue, CancellationToken cancellationToken = default)

Parameters

smartSwitchId ulong

The ID of the smart switch entity.

smartSwitchValue bool

The value to set for the smart switch.

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response<SmartDeviceInfo>>

A Task<TResult> representing the asynchronous operation. The task result contains a Response<T> with the updated smart switch information.

SetSubscriptionAsync(ulong, bool, CancellationToken)

Sets the subscription status of an entity asynchronously.

public Task<Response> SetSubscriptionAsync(ulong entityId, bool doSubscribe = true, CancellationToken cancellationToken = default)

Parameters

entityId ulong

The ID of the entity.

doSubscribe bool

Specifies whether to subscribe or unsubscribe.

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response>

A Task<TResult> representing the asynchronous operation. The task result contains a payload-free Response indicating the success of the operation.

StrobeSmartSwitchAsync(ulong, int, bool, CancellationToken)

Strobes a smart switch asynchronously.

public Task<Response<SmartDeviceInfo?>> StrobeSmartSwitchAsync(ulong entityId, int timeoutMilliseconds = 1000, bool value = true, CancellationToken cancellationToken = default)

Parameters

entityId ulong

The ID of the smart switch entity.

timeoutMilliseconds int

The duration of each state in milliseconds.

value bool

The initial value of the smart switch.

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response<SmartDeviceInfo>>

A Task<TResult> representing the asynchronous operation. The task result contains a Response<T> with the updated smart switch information.

SubscribeToCameraAsync(string, CancellationToken)

Subscribes to a camera asynchronously, starting the OnCameraRaysReceived stream.

public Task<Response<CameraInfo?>> SubscribeToCameraAsync(string cameraId, CancellationToken cancellationToken = default)

Parameters

cameraId string

The identifier of the camera/CCTV entity to subscribe to.

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response<CameraInfo>>

A Task<TResult> representing the asynchronous operation. The task result contains a Response<T> with the camera information.

ToggleSmartSwitchAsync(ulong, CancellationToken)

Toggles a smart switch asynchronously.

public Task<Response<SmartDeviceInfo?>> ToggleSmartSwitchAsync(ulong entityId, CancellationToken cancellationToken = default)

Parameters

entityId ulong

The ID of the smart switch entity.

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response<SmartDeviceInfo>>

A Task<TResult> representing the asynchronous operation. The task result contains a Response<T> with the updated smart switch information.

UnsubscribeFromCameraAsync(CancellationToken)

Unsubscribes from the currently subscribed camera asynchronously.

public Task<Response> UnsubscribeFromCameraAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

A token to observe for cancellation requests.

Returns

Task<Response>

A Task<TResult> representing the asynchronous operation. The task result contains a payload-free Response indicating the success of the operation.

Events

OnCameraRaysReceived

Occurs when a camera frame is received for the subscribed camera, providing a CameraRaysEventArg.

public event EventHandler<CameraRaysEventArg>? OnCameraRaysReceived

Event Type

EventHandler<CameraRaysEventArg>

OnClanChanged

Occurs when the clan changes (roles, members, MOTD, …), providing a ClanChangedEventArg.

public event EventHandler<ClanChangedEventArg>? OnClanChanged

Event Type

EventHandler<ClanChangedEventArg>

OnClanChatReceived

Occurs when a clan chat message is received, providing a ClanMessageEventArg.

public event EventHandler<ClanMessageEventArg>? OnClanChatReceived

Event Type

EventHandler<ClanMessageEventArg>

OnEntityChanged

Occurs for every EntityChanged broadcast, before any device-type heuristic, with the full raw payload. The broadcast carries no entity type; consumers that know their paired entity ids should route on Id — this is the reliable channel when the OnSmartDeviceTriggered/OnStorageMonitorTriggered heuristics cannot classify a payload.

public event EventHandler<EntityChangedEventArg>? OnEntityChanged

Event Type

EventHandler<EntityChangedEventArg>

OnSmartDeviceTriggered

Occurs when an EntityChanged broadcast is classified as a binary-state smart device (a smart switch or a smart alarm): the payload carries no container state (no items, no capacity, no protection). The broadcast omits the entity type, so a storage broadcast whose payload is only value is indistinguishable from a switch and lands here too — route on OnEntityChanged with your paired entity ids when that matters.

public event EventHandler<SmartDeviceEventArg>? OnSmartDeviceTriggered

Event Type

EventHandler<SmartDeviceEventArg>

OnStorageMonitorTriggered

Occurs when an EntityChanged broadcast is classified as a storage monitor: the payload carries items, a capacity, or tool-cupboard protection. Storage broadcasts with value == true and no items carry no contents snapshot and are NOT raised here (they remain observable via OnEntityChanged). Tool-cupboard broadcasts are sometimes partial — capacity may be absent and only the protection flag identifies them.

public event EventHandler<StorageMonitorEventArg>? OnStorageMonitorTriggered

Event Type

EventHandler<StorageMonitorEventArg>

OnTeamChanged

Occurs when the team changes (members, map notes, leader, …), providing a TeamChangedEventArg.

public event EventHandler<TeamChangedEventArg>? OnTeamChanged

Event Type

EventHandler<TeamChangedEventArg>

OnTeamChatReceived

Occurs when a team chat message is received, providing a TeamMessageEventArg.

public event EventHandler<TeamMessageEventArg>? OnTeamChatReceived

Event Type

EventHandler<TeamMessageEventArg>

See Also