OnServerCommand
OxideCarbonServerCalled when a server console command is executed.
Useful for auditing or overriding server-side console commands.
object OnServerCommand(ConsoleSystem.Arg arg)Works — the game method in this build is the one the hook was written for.
Parameters
- arg
- ConsoleSystem.Arg
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 OnServerCommand(ConsoleSystem.Arg arg)
{
Puts("OnServerCommand");
// 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.
Where it is called
Oxide core (Oxide.Rust)
RustCore::IOnServerCommand(ConsoleSystem.Arg arg)
Oxide core code — the hook is called from here
// …
// Ignore all chat messages
if (arg.cmd.FullName == "chat.say" || arg.cmd.FullName == "chat.teamsay" || arg.cmd.FullName == "chat.localsay")
{
return null;
}
// Is the command blocked?
object commandSpecific = Interface.CallHook("OnServerCommand", arg);
object commandCovalence = Interface.CallHook("OnServerCommand", arg.cmd.FullName, RustCommandSystem.ExtractArgs(arg));
object canBlock = commandSpecific is null ? commandCovalence : commandSpecific;
if (canBlock != null)
{
return true;
}
return null;
// …Injection point
Rust.opj (Oxide)
bool ConsoleSystem.Internal(ConsoleSystem.Arg)
Injected internal hook IOnServerCommand — this hook is called by its handler in the Oxide/Carbon core
WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: UseArgumentString (a0)Facepunch.Console.dll
Where it is called (this branch's game code)
private static bool Internal(Arg arg)
{
if (arg.Invalid)
{
return false;
}
object returnvar = Interface.CallHook("IOnServerCommand", arg);
if (returnvar is bool)
{
return (bool)returnvar;
}
if (!arg.HasPermission())
{
arg.ReplyWith("You cannot run this command");
return false;
// …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.