Multiplay 일시적인 Room 접속 제한하기
4 분
원하는 시점에 방 접근을 제한하거나 허용하기 위해 잠금 및 잠금 해제 기능을 사용할 수 있습니다.
📘 다음 가이드를 참조하십시오. [ZEPETO.Multiplay(Server) API]
잠금
잠금 기능은 방 접근을 제한하는 기능입니다.
await this.lock();
잠금 해제
잠금 해제 기능은 방 접근을 허용하는 기능입니다. 하지만 현재 연결된 사람 수가 방에 허용된 최대 인원 수와 같으면 방을 잠금 해제할 수 없습니다.
await this.unlock();
예제
다음은 잠금 및 잠금 해제 기능을 사용하는 예제 코드입니다.
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);
}
}
}👍 잠금과 개인 기능의 차이
- 잠금된 멀티플레이어 방은 ZEPETO 방 목록에 표시되지 않으며 초대 없이 들어갈 수 없습니다.
- 개인 멀티플레이어 방은 ZEPETO 방 목록에 표시되지 않지만 초대는 가능합니다.