@@ -16,8 +16,9 @@ import { InitializeGame } from '../core/initialize';
1616import * as StorageAPI from './db/base' ;
1717import { Server , Game } from '../types' ;
1818
19- const createGameMetadata = ( { gameName } ) : Server . GameMetadata => ( {
19+ const createGameMetadata = ( { gameName, unlisted } ) : Server . GameMetadata => ( {
2020 gameName,
21+ unlisted,
2122 players : { } ,
2223 setupData : { } ,
2324} ) ;
@@ -31,15 +32,17 @@ const createGameMetadata = ({ gameName }): Server.GameMetadata => ({
3132 * @param {object } setupData - User-defined object that's available
3233 * during game setup.
3334 * @param {object } lobbyConfig - Configuration options for the lobby.
35+ * @param {boolean } unlisted - Whether the game should be excluded from public listing.
3436 */
3537export const CreateGame = async (
3638 db : StorageAPI . Sync | StorageAPI . Async ,
3739 game : Game ,
3840 numPlayers : number ,
3941 setupData : object ,
40- lobbyConfig : Server . LobbyConfig
42+ lobbyConfig : Server . LobbyConfig ,
43+ unlisted : boolean
4144) => {
42- const gameMetadata = createGameMetadata ( { gameName : game . name } ) ;
45+ const gameMetadata = createGameMetadata ( { gameName : game . name , unlisted } ) ;
4346
4447 const state = InitializeGame ( {
4548 game,
@@ -106,6 +109,8 @@ export const addApiToServer = ({
106109 const gameName = ctx . params . name ;
107110 // User-data to pass to the game setup function.
108111 const setupData = ctx . request . body . setupData ;
112+ // Whether the game should be excluded from public listing.
113+ const unlisted = ctx . request . body . unlisted ;
109114 // The number of players for this game instance.
110115 let numPlayers = parseInt ( ctx . request . body . numPlayers ) ;
111116 if ( ! numPlayers ) {
@@ -118,7 +123,8 @@ export const addApiToServer = ({
118123 game ,
119124 numPlayers ,
120125 setupData ,
121- lobbyConfig
126+ lobbyConfig ,
127+ unlisted
122128 ) ;
123129
124130 ctx . body = {
@@ -134,15 +140,17 @@ export const addApiToServer = ({
134140 const { metadata } = await ( db as StorageAPI . Async ) . fetch ( gameID , {
135141 metadata : true ,
136142 } ) ;
137- rooms . push ( {
138- gameID,
139- players : Object . values ( metadata . players ) . map ( ( player : any ) => {
140- // strip away credentials
141- const { credentials, ...strippedInfo } = player ;
142- return strippedInfo ;
143- } ) ,
144- setupData : metadata . setupData ,
145- } ) ;
143+ if ( ! metadata . unlisted ) {
144+ rooms . push ( {
145+ gameID,
146+ players : Object . values ( metadata . players ) . map ( ( player : any ) => {
147+ // strip away credentials
148+ const { credentials, ...strippedInfo } = player ;
149+ return strippedInfo ;
150+ } ) ,
151+ setupData : metadata . setupData ,
152+ } ) ;
153+ }
146154 }
147155 ctx . body = {
148156 rooms : rooms ,
@@ -243,6 +251,7 @@ export const addApiToServer = ({
243251 const gameID = ctx . params . id ;
244252 const playerID = ctx . request . body . playerID ;
245253 const credentials = ctx . request . body . credentials ;
254+ const unlisted = ctx . request . body . unlisted ;
246255 const { metadata } = await ( db as StorageAPI . Async ) . fetch ( gameID , {
247256 metadata : true ,
248257 } ) ;
@@ -280,7 +289,8 @@ export const addApiToServer = ({
280289 game ,
281290 numPlayers ,
282291 setupData ,
283- lobbyConfig
292+ lobbyConfig ,
293+ unlisted
284294 ) ;
285295 metadata . nextRoomID = nextRoomID ;
286296
0 commit comments