PavlovVR-Rcon 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package PavlovVR-Rcon --version 1.1.0
NuGet\Install-Package PavlovVR-Rcon -Version 1.1.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="PavlovVR-Rcon" Version="1.1.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add PavlovVR-Rcon --version 1.1.0
#r "nuget: PavlovVR-Rcon, 1.1.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.
// Install PavlovVR-Rcon as a Cake Addin
#addin nuget:?package=PavlovVR-Rcon&version=1.1.0

// Install PavlovVR-Rcon as a Cake Tool
#tool nuget:?package=PavlovVR-Rcon&version=1.1.0

PavlovVR-Rcon

A library to interface with Pavlov VR servers, execute RCON commands and process their replies.

PCVR only, Shack is not supported.

Available on NuGet: https://www.nuget.org/packages/PavlovVR-Rcon/

Usage

Connecting

PavlovRcon rcon = new("host.com", 9100, "password");
await rcon.Connect(CancellationToken.None);

If your server resolves an IPv6 through an AAAA record but your Pavlov VR server only binds on IPv4, you can specify an optional forceIpv4 parameter in the constructor to force IPv4:

PavlovRcon rcon = new("host.com", 9100, "password", true);

Running commands

ServerInfoReply serverInfo = await new ServerInfoCommand().ExecuteCommand(rcon);
Console.WriteLine(serverInfo.ServerInfo.ServerName);
InspectPlayerReply inspectPlayer = await new InspectPlayerCommand(76561198142010443).ExecuteCommand(rcon);
Console.WriteLine(inspectPlayer.PlayerInfo.Score);
string reply = await rcon.SendTextCommand("CustomCommand", new[] { "parameter1", "parameter2" });

You can also create custom reply classes to automatically parse the reply:

{
  "Command": "CustomCommand",
  "CustomStuff": {
    "SomeCustomValue": "Something"
  },
  "Successful": true
}
public class CustomData
{
  public string SomeCustomValue { get; init; } = string.Empty;
}

public class CustomReply : BaseReply
{
  public CustomData CustomStuff { get; init; } = new();
}

CustomReply reply = await rcon.SendCommand<CustomReply>("MyCommand");
Console.WriteLine(reply.CustomStuff.SomeCustomValue);

and also use a custom command class:

public class CustomCommand : BaseCommand<CustomReply>
{
  public CustomCommand(string someParameter) : base("MyCommand")
  {
    this.addParameter(someParameter);
  }
}

CustomReply reply = await new CustomCommand("myParameter").ExecuteCommand(rcon);

Note: While the server is switching maps, commands will fail since the server can not process any RCON commands during this time. This will also set rcon.Connected to false, since the connection status is based on the success of the last executed command. Therefore, if the server becomes offline, rcon.Connected may still be true but ExecuteCommand will throw an exception. In these cases you may simply call Connect again until it succeeds.

Available commands

Except for Help and Disconnect, all commands from http://wiki.pavlov-vr.com/index.php?title=Dedicated_server#Rcon_Overview_and_Commands are available.

To quote the Pavlov VR wiki:

What is important if you are issuing commands using a program at high frequency is that you open one connection and put all of the commands through that open connection with a small (.1 sec is fine) delay. What you don't want to do is open a new connection for each command or shove all of the commands through super fast. First causes performance issues and the second dropped commands.

This, again, is a limitation of the server.

Notes

Setting the command timeout

After executing a command, the reply will be received. The default timeout for this operation is two seconds. You can change this timeout by setting rcon.CommandTimeout to an appropriate value in milliseconds.

ServerInfo.PlayerCount

Pavlov is... mentally challenged, and reports the RCON client as a player (sometimes, not always). Because of that you may see PlayerCount to be bigger than the actual player count. It is therefore recommended to instead use RefreshListCommand and count the actual players.

Exceptions

Connecting and executing commands will throw exceptions if they do not succeed. This includes commands that have been sent to the server but are replied with "Successful": false. It is therefore recommended that you try-catch any connection and command execution methods to handle errors like:

  • Unable to connect
  • Timeout
  • Command failed

If any errors occur, the exception will contain inner exceptions until the source exception is reached (for timeouts in commands, for example, you would get CommandFailedException with CommandTimeoutException with OperationCanceledException, or if the Json reply could not be parsed you would get CommandFailedException with UnexpectedRconResponseException with the underlying exception). This way you should be able to pinpoint the error cause in code, to handle the error appropriately.

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

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
1.2.0 62 4/15/2024
1.1.0 323 1/1/2023
1.0.4 296 12/10/2022
1.0.3 317 11/17/2022
1.0.2 338 11/15/2022
1.0.1 343 11/13/2022
1.0.0 348 11/13/2022