RustTip

OnServerCommand

OxideCarbonServer

Called when a server console command is executed.

Useful for auditing or overriding server-side console commands.

object OnServerCommand(ConsoleSystem.Arg arg)
Работает — метод игры в этой сборке тот же, под который написан хук.

Параметры

arg
ConsoleSystem.Arg

Возвращаемое значение

objectВерните не null, чтобы отменить действие игры.

Пример

object — можно повлиять на игру: вернуть значение, чтобы изменить или отменить действие.

private object OnServerCommand(ConsoleSystem.Arg arg)
{
    Puts("OnServerCommand");

    // ничего не меняем — игра продолжит как обычно
    return null;

    // повлиять на игру:
    // return false; // не null — действие игры отменяется
}

Работает и в Oxide, и в Carbon: Carbon загружает плагины Oxide без изменений.

Где вызывается

ядро Oxide (Oxide.Rust)
RustCore::IOnServerCommand(ConsoleSystem.Arg arg)

Код ядра Oxide — отсюда вызывается хук

// …

// 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;
// …

Место встраивания

Rust.opj (Oxide)
bool ConsoleSystem.Internal(ConsoleSystem.Arg)

Встроен служебный хук IOnServerCommand — этот хук вызывает его обработчик в ядре Oxide/Carbon

РаботаетReturnBehavior: ExitWhenValidTypeArgumentBehavior: UseArgumentString (a0)Facepunch.Console.dll

Где вызывается (код игры этой ветки)

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;
// …

Источники: Rust.opj из OxideMod/Oxide.Rust (MIT) и метаданные хуков документации Carbon (MIT). Код методов — декомпиляция сервера этой ветки.