You can use the lock, unlock function to restrict or allow room access at your desired timing.
Please refer to the following guide. [ZEPETO.Multiplay(Server) API]
Lock
The lock function is a function restricts room access.
await this.lock();
Unlock
The unlock function is a function that allows room access.
But, if the number of people who are currently connected is the same as the maximum number of people allowed in the room, the room cannot be unlocked.
await this.unlock();
Example
The following is an example code that uses the lock and unlock functions.
import { Sandbox, SandboxOptions, SandboxPlayer } from 'ZEPETO.Multiplay';
export default class extends Sandbox {
onCreate(options: SandboxOptions) {
}
async onJoin(client: SandboxPlayer) {
try {
if (this.clients.length > 8) {
await this.lock();
}
} catch(e) {
console.error(e);
}
}
async onLeave(client: SandboxPlayer, consented?: boolean){
try {
if (this.clients.length <= 8) {
await this.unlock();
}
} catch(e) {
console.error(e);
}
}
}
Difference between lock and private functions
- The locked multiplayer room is not visible in the ZEPETO room list and cannot be entered by invitation.
- Private multiplayer rooms are not shown in the list of ZEPETO rooms, but invitations are acceptable.