RustTip

OnSendCommand

OxideCarbonServer

Called when a server console command is executed.

Useful for auditing or overriding server-side console commands.

object OnSendCommand(Network.Connection cn, string strCommand, object[] args)
object OnSendCommand(List<Network.Connection> cn, string strCommand, object[] args)
Works — the game method in this build is the one the hook was written for.

Parameters

cn
Network.Connection
strCommand
string
args
object[]

Return value

objectReturn non-null to cancel the game action.

Example

object — you can affect the game: return a value to change or cancel the action.

private object OnSendCommand(Network.Connection cn, string strCommand, object[] args)
{
    Puts("OnSendCommand");

    // change nothing — the game continues as usual
    return null;

    // to affect the game:
    // return false; // non-null cancels the game action
}

Works in both Oxide and Carbon: Carbon loads Oxide plugins as is.

Injection point 1

Rust.opj (Oxide)
void ConsoleNetwork.SendClientCommand(Network.Connection, string, object[])

Passes: Network.Connection cn, string strCommand, object[] args

WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: UseArgumentString (a0, a1, a2)Assembly-CSharp.dll

Where it is called (this branch's game code)

public static void SendClientCommand(Connection cn, string strCommand, params object[] args)
{
	if (Net.sv.IsConnected())
	{
		if (Interface.CallHook("OnSendCommand", cn, strCommand, args) != null)
		{
			return;
		}
		NetWrite netWrite = Net.sv.StartWrite();
		netWrite.PacketID(Message.Type.ConsoleCommand);
		string val = ConsoleSystem.BuildCommand(strCommand, args);
		netWrite.String(val);
		NetProfileCapture.Annotate(netWrite, strCommand);
// …

Injection point 2

Rust.opj (Oxide)
void ConsoleNetwork.SendClientCommand(List<Network.Connection>, string, object[])

Passes: List<Network.Connection> cn, string strCommand, object[] args

WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: UseArgumentString (a0, a1, a2)Assembly-CSharp.dll

Where it is called (this branch's game code)

[PoolAnalyzerNonCaching]
public static void SendClientCommand(List<Connection> cn, string strCommand, params object[] args)
{
	if (Net.sv.IsConnected())
	{
		if (Interface.CallHook("OnSendCommand", cn, strCommand, args) != null)
		{
			return;
		}
		NetWrite netWrite = Net.sv.StartWrite();
		netWrite.PacketID(Message.Type.ConsoleCommand);
		netWrite.String(ConsoleSystem.BuildCommand(strCommand, args));
		NetProfileCapture.Annotate(netWrite, strCommand);
		netWrite.Send(new SendInfo(cn));
// …

Sources: Rust.opj from OxideMod/Oxide.Rust (MIT) and hook metadata of the Carbon documentation (MIT). Method code is decompiled from this branch's server.