RustTip

CanUserLogin

OxideCarbonPlayer

Called to determine whether to user login.

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

void CanUserLogin(string username, string userid, string ip)
Works — the game method in this build is the one the hook was written for.

Parameters

username
string
userid
string
ip
string

Return value

voidBehaviour is not described.

Example

private void CanUserLogin(string username, string userid, string ip)
{
    Puts("CanUserLogin");
}

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

Where it is called

Oxide core (Oxide.Rust)
RustCore::IOnUserApprove(Connection connection)

Oxide core code — the hook is called from here

// …
    }
}

// Let covalence know
Covalence.PlayerManager.PlayerJoin(connection.userid, playerName);

// Call hooks for plugins
object loginSpecific = Interface.CallHook("CanClientLogin", connection);
object loginCovalence = Interface.CallHook("CanUserLogin", playerName, connectionId, connectionIp);
object canLogin = loginSpecific is null ? loginCovalence : loginSpecific;
if (canLogin is string || canLogin is bool loginBlocked && !loginBlocked)
{
    ConnectionAuth.Reject(connection, canLogin is string ? canLogin.ToString() : lang.GetMessage("ConnectionRejected", this, connectionId));
    return true;
}

// Call hooks for plugins
// …

Injection point

Rust.opj (Oxide)
void ConnectionAuth.OnNewConnection(Network.Connection)

Injected internal hook IOnUserApprove — this hook is called by its handler in the Oxide/Carbon core

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

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

// …
		DebugEx.Log(connection.ToString() + " has auth level 2");
		connection.authLevel = 2u;
	}
	if (DeveloperList.Contains(connection.userid))
	{
		DebugEx.Log(connection.ToString() + " is a developer");
		connection.authLevel = 3u;
	}
	if (Interface.CallHook("IOnUserApprove", connection) != null)
	{
		return;
	}
	m_AuthConnection.Add(connection);
	StartCoroutine(AuthorisationRoutine(connection));
}

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.