Skip to content

密碼保護房間

步驟1: 允許匹配程序識別 "password" 字段.

filterBy() 中定義 "password" 字段.

gameServer
  .define("battle", BattleRoom)
  .filterBy(['password'])

步驟2: 不列出房間

create()joinOrCreate() 已獲取密碼, 則將房間列為私人房間:

export class BattleRoom extends Room {

  onCreate(options) {
    if (options.password) {
      this.setPrivate();
    }
  }

}

Back to top