playerConnectRequest
Asks your gamemode whether a player may join, before they are let in. The server has already checked the nickname, the number of players, the game version and address bans.
Renamed in 0.28 from connectRequest; see renamed names.
Signature
Section titled “Signature”server.on("playerConnectRequest", ({ nickname, address, clientBuild }) => ConnectDecision | false | Promise<ConnectDecision | false>)Parameters
Section titled “Parameters”| Name | Type | Description |
|---|---|---|
nickname |
string |
The nickname the player chose. |
address |
string |
The player’s network address; what an address ban matches. |
clientBuild |
string |
The client build the player’s launcher reports. Unverified. |
Returns
Section titled “Returns”{ allow: true } lets the player in. { allow: false, reason } refuses them with a reason they see in their launcher (up to 128 bytes); false refuses them with “Refused by the server.” Returning nothing lets them in. The first refusal stops the handlers after it. See how decisions work.
Example
Section titled “Example”A small nickname allowlist. A production mode can replace the lookup with its own account policy.
import { server } from "nativemp";
const allowedNames = new Set(["Alice", "Bob"]);server.on("playerConnectRequest", ({ nickname }) => { const allowed = allowedNames.has(nickname); return allowed ? { allow: true } : { allow: false, reason: "This server is whitelisted. Apply on our Discord." };});Related
Section titled “Related”playerConnected: the player is inplayers.banAddress: ban an address