OnRconCommand
OnRconCommand is called each time an RCON client sends a command over the websocket console, before the server dispatches it through Covalence. Returning a non-null value stops the command from reaching the normal command handler.
object OnRconCommand(System.Net.IPEndPoint userEndPoint, string command, string[] args)Parameters
| Parameter | Type | Description |
|---|---|---|
userEndPoint | System.Net.IPEndPoint | The IPEndPoint of the RCON client that sent the command. Use userEndPoint.Address to identify or compare the remote address. This signature is the one fired by RemoteConsole.OnMessage. |
command | string | The first token of the message, lowercased by the server, for example 'say' or 'server.save'. Compare against this to match a specific RCON command. |
args | string[] | The remaining tokens after the command, already split on whitespace. Empty array when no arguments were supplied; null-check before indexing. |
Return value
Returning null lets the message continue to covalence.Server.Command(command, args) and the command executes normally. Returning any non-null value makes the patched method return immediately, so the command is silently dropped and never reaches the server console handler.
How it works
This hook fires inside RemoteConsole.OnMessage after the incoming websocket frame has been parsed into a message, split into tokens, and the first token lowercased. At that point the endpoint, the command word, and the argument array are handed to Interface.CallHook("OnRconCommand", ...). It runs for every RCON message, including ones sent through tools, the built-in web console, or a configured RCON client. The same hook name is also called from RustCore.IOnRconMessage with an IPAddress instead of an IPEndPoint, so the parameter types you declare decide which call site reaches your method.
Use userEndPoint.Address to whitelist trusted admin IPs, inspect command to match specific verbs like kick or ban, and read args for the target. Because it fires before dispatch, this is the place to block or rewrite sensitive commands without editing server config. Declaring IPEndPoint receives the websocket path; declaring IPAddress receives the RustCore path; a parameter typed as object would match both. Keep the method cheap since RCON traffic can be frequent during admin sessions.
Other signatures
Oxide also calls OnRconCommand from other places in the game with these parameter types. Declare the overload you need, or several:
object OnRconCommand(System.Net.IPAddress ipAddress, string message, string[] arg)
Example plugin: Block and log destructive RCON commands
using System.Linq;
using System;
using System.Collections.Generic;
using System.Net;
using Newtonsoft.Json;
using Oxide.Core;
namespace Oxide.Plugins
{
[Info("Rcon Command Guard", "RustPluginGenerator", "1.0.0")]
[Description("Blocks and logs destructive RCON commands, optionally restricting them to trusted IPs")]
public class RconCommandGuard : RustPlugin
{
private class PluginConfig
{
[JsonProperty("Blocked commands")]
public List<string> BlockedCommands = new List<string> { "quit", "restart", "kill", "ban", "kick" };
[JsonProperty("Trusted IPs (empty disables IP check)")]
public List<string> TrustedIps = new List<string>();
[JsonProperty("Log all RCON commands")]
public bool LogAll = false;
}
private PluginConfig config;
protected override void LoadDefaultConfig() => config = new PluginConfig();
protected override void LoadConfig()
{
base.LoadConfig();
try
{
config = Config.ReadObject<PluginConfig>();
if (config == null) throw new Exception();
}
catch
{
PrintWarning("Configuration file is invalid, using defaults");
LoadDefaultConfig();
}
SaveConfig();
}
protected override void SaveConfig() => Config.WriteObject(config);
protected override void LoadDefaultMessages()
{
lang.RegisterMessages(new Dictionary<string, string>
{
["Blocked"] = "[RCON] Command '{0}' from {1} was blocked by the server.",
["Logged"] = "[RCON] {0} ran '{1}'"
}, this);
}
private string Msg(string key, string userId = null, params object[] args) =>
string.Format(lang.GetMessage(key, this, userId), args);
private object OnRconCommand(IPEndPoint userEndPoint, string command, string[] args)
{
if (userEndPoint == null || string.IsNullOrEmpty(command)) return null;
if (args == null) args = new string[0];
string address = userEndPoint.Address != null ? userEndPoint.Address.ToString() : "unknown";
string joined = args.Length > 0 ? command + " " + string.Join(" ", args) : command;
bool blocked = config.BlockedCommands.Contains(command);
if (blocked && config.TrustedIps.Count > 0 && !config.TrustedIps.Contains(address))
{
PrintWarning(Msg("Blocked", null, command, address));
return true;
}
if (blocked && config.TrustedIps.Count == 0)
{
PrintWarning(Msg("Blocked", null, command, address));
return true;
}
if (config.LogAll)
{
PrintWarning(Msg("Logged", null, address, joined));
}
return null;
}
}
}The plugin watches every RCON command through OnRconCommand. A configurable set of blocked commands (defaults include quit, restart, and kill) is checked against the incoming command word, and a configurable list of allowed admin IPs can be enforced for anything destructive. When a command is blocked, the plugin logs the endpoint, command, and arguments with PrintWarning and returns true to stop dispatch. Safe commands return null and run untouched. IP whitelisting is optional: leave the list empty to disable it, or add trusted addresses to restrict blocking-only mode. The configuration loads with sensible defaults so the plugin works out of the box.
Common use cases
Restrict dangerous commands to trusted IPs
Compare
userEndPoint.Address.ToString()against a whitelist and returntruefor anything outside it when the command is destructive. This protects against leaked RCON passwords being used from unexpected networks.Audit RCON usage
Log every command, its arguments, and the source address so server owners can review what admins and third-party tools did. Return
nullso the commands still run.Block scripts that call server shutdown
Intercept commands like
quit,restart, orserver.savethat can disrupt a live wipe, and returntrueto swallow them while notifying a Discord webhook or a staff member in chat.
Pitfalls
Command is already lowercased
The server lowercases the first token before the hook fires, so compare against lowercase strings. Comparing with
equals("Kick")will never match and the block silently fails.Only one call site per signature
The
IPEndPointsignature corresponds to websocket RCON, while theIPAddresssignature corresponds to the RustCore integration. If a command keeps bypassing your block, check whether it came through the other path.Returning true swallows silently
Blocked commands produce no client-facing error unless you send one yourself. If you return
true, notify the sender through your own logging or the caller may assume their command succeeded.
Build a plugin with OnRconCommand
Describe what should happen and get a compiled plugin that uses this hook.
Edit the prompt on the next screen. 2 free plugins a month, no card.
Last updated Oct 26, 2026. Found a mistake? Email support@rustplugingenerator.com.
Build a plugin with OnRconCommand
Generate