RustTip

CanNetworkTo

OxideCarbonNetwork

Called to determine whether to network to.

Return true to allow the action and false to block it.

object CanNetworkTo(BaseNetworkable baseNetworkable, BasePlayer player)
object CanNetworkTo(BasePlayer basePlayer, BasePlayer player)
Works — the game method in this build is the one the hook was written for.

Parameters

baseNetworkable
BaseNetworkable
player
BasePlayer

Return value

objectThe returned value replaces the game result; null lets the game decide.

Example

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

private object CanNetworkTo(BaseNetworkable baseNetworkable, BasePlayer player)
{
    Puts("CanNetworkTo");

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

    // to affect the game:
    // return false; // your value instead of the game result
}

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

Injection point 1

Rust.opj (Oxide)
bool BaseNetworkable.ShouldNetworkTo(BasePlayer)

Passes: BaseNetworkable baseNetworkable, BasePlayer player

WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: AllAssembly-CSharp.dll

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

public virtual bool ShouldNetworkTo(BasePlayer player)
{
	object returnvar = Interface.CallHook("CanNetworkTo", this, player);
	if (returnvar is bool)
	{
		return (bool)returnvar;
	}
	if (net.group == null)
	{
		return true;
	}
// …

Injection point 2

Rust.opj (Oxide)
bool BasePlayer.ShouldNetworkTo(BasePlayer)

Passes: BasePlayer basePlayer, BasePlayer player

WorksReturnBehavior: ExitWhenValidTypeArgumentBehavior: AllAssembly-CSharp.dll

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

public override bool ShouldNetworkTo(BasePlayer player)
{
	object returnvar = Interface.CallHook("CanNetworkTo", this, player);
	if (returnvar is bool)
	{
		return (bool)returnvar;
	}
	bool flag = ShouldNetworkToSkipOcclusion(player);
	if (flag && ServerOcclusion.OcclusionEnabled && SupportsServerOcclusion() && player.SupportsServerOcclusion() && this != player)
	{
		flag = OcclusionGetCachedVisibility(player);
// …

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.