<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Create New Room according to specified condition(solved)]]></title><description><![CDATA[<p>I am using colyseus version 0.14.18.  My requirement is after 2 players are joined the game then no other players can join that room while spectators can. How can i achieve this. Please help. I am sharing my code below.</p>
<p>class MyRoom extends colyseus.Room {<br />
maxClinets = 50;</p>
<pre><code>onCreate(options) {
    console.log(&quot;New Room created!&quot;, options);
    this.dispatcher = new command.Dispatcher(this);
    this.setState(new GameState());

    // Broadcast chat messages
    this.onMessage('chat', (client, message) =&gt; {
        this.broadcast('chat', {sessionId: client.sessionId, message: `${this.state.players[client.sessionId].name}: ${message}`});
    });

    this.dispatcher.dispatch(new BoardCommand.SetupBoard(), {});
}

onJoin(client, options) {
    this.dispatcher.dispatch(new PlayerCommand.OnJoin(), {sessionId: client.sessionId, playerData: options});
    this.broadcast(&quot;chat&quot;, {sessionId: client.sessionId, message: `${this.state.players[client.sessionId].name} Joined`});

    //if 2 players joined then roll 1 dices for each player for turn
    if (this.state.players.size === 2) {

    }
}

async onLeave(client, consented) {
    // Broadcast leaving to room chat
    this.broadcast('chat', {sessionId: client.sessionId, message: `${this.state.players[client.sessionId].name} disconnected`}, {except: client});
    console.log(`${this.state.players[client.sessionId].name} disconnected`);

    this.dispatcher.dispatch(new PlayerCommand.OnLeave(), {
        sessionId: client.sessionId,
        consented
    });

    // Player has lost connection and player is not spectator
    if (!consented &amp;&amp; !this.state.players.get(client.sessionId).isSpectator) {
        try {
            await this.allowReconnection(client, 60);

            // Regains connection
            this.dispatcher.dispatch(new PlayerCommand.OnConnect(), {sessionId: client.sessionId});
            this.broadcast('chat', {sessionId: client.sessionId, message: `${this.state.players[client.sessionId].name} has returned`});
            console.log(`${this.state.players[client.sessionId].name} has returned!`);
        } catch (exc) {
            // ...or times out
            this.dispatcher.dispatch(new PlayerCommand.OnReconnectTimeout(), {sessionId: client.sessionId});
        }
    }
}

onDispose() {
    console.log(&quot;Dispose BackgammonRoom&quot;);
    this.dispatcher.stop();
}
</code></pre>
<p>}</p>
<p>module.exports = {MyRoom};</p>
]]></description><link>http://discuss.colyseus.io/topic/590/create-new-room-according-to-specified-condition-solved</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Jul 2026 10:30:50 GMT</lastBuildDate><atom:link href="http://discuss.colyseus.io/topic/590.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 08 Mar 2022 06:22:25 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Create New Room according to specified condition(solved) on Fri, 15 Apr 2022 10:49:20 GMT]]></title><description><![CDATA[<p>I am using colyseus version 0.14.18.  My requirement is after 2 players are joined the game then no other players can join that room while spectators can. How can i achieve this. Please help. I am sharing my code below.</p>
<p>class MyRoom extends colyseus.Room {<br />
maxClinets = 50;</p>
<pre><code>onCreate(options) {
    console.log(&quot;New Room created!&quot;, options);
    this.dispatcher = new command.Dispatcher(this);
    this.setState(new GameState());

    // Broadcast chat messages
    this.onMessage('chat', (client, message) =&gt; {
        this.broadcast('chat', {sessionId: client.sessionId, message: `${this.state.players[client.sessionId].name}: ${message}`});
    });

    this.dispatcher.dispatch(new BoardCommand.SetupBoard(), {});
}

onJoin(client, options) {
    this.dispatcher.dispatch(new PlayerCommand.OnJoin(), {sessionId: client.sessionId, playerData: options});
    this.broadcast(&quot;chat&quot;, {sessionId: client.sessionId, message: `${this.state.players[client.sessionId].name} Joined`});

    //if 2 players joined then roll 1 dices for each player for turn
    if (this.state.players.size === 2) {

    }
}

async onLeave(client, consented) {
    // Broadcast leaving to room chat
    this.broadcast('chat', {sessionId: client.sessionId, message: `${this.state.players[client.sessionId].name} disconnected`}, {except: client});
    console.log(`${this.state.players[client.sessionId].name} disconnected`);

    this.dispatcher.dispatch(new PlayerCommand.OnLeave(), {
        sessionId: client.sessionId,
        consented
    });

    // Player has lost connection and player is not spectator
    if (!consented &amp;&amp; !this.state.players.get(client.sessionId).isSpectator) {
        try {
            await this.allowReconnection(client, 60);

            // Regains connection
            this.dispatcher.dispatch(new PlayerCommand.OnConnect(), {sessionId: client.sessionId});
            this.broadcast('chat', {sessionId: client.sessionId, message: `${this.state.players[client.sessionId].name} has returned`});
            console.log(`${this.state.players[client.sessionId].name} has returned!`);
        } catch (exc) {
            // ...or times out
            this.dispatcher.dispatch(new PlayerCommand.OnReconnectTimeout(), {sessionId: client.sessionId});
        }
    }
}

onDispose() {
    console.log(&quot;Dispose BackgammonRoom&quot;);
    this.dispatcher.stop();
}
</code></pre>
<p>}</p>
<p>module.exports = {MyRoom};</p>
]]></description><link>http://discuss.colyseus.io/post/1757</link><guid isPermaLink="true">http://discuss.colyseus.io/post/1757</guid><dc:creator><![CDATA[zack1991]]></dc:creator><pubDate>Fri, 15 Apr 2022 10:49:20 GMT</pubDate></item><item><title><![CDATA[Reply to Create New Room according to specified condition(solved) on Tue, 08 Mar 2022 12:08:19 GMT]]></title><description><![CDATA[<p>Hi Zack!<br />
Currently there's no concepts like &quot;Player&quot; or &quot;Spectators&quot; in Colyseus, but &quot;Clients&quot;.<br />
So  if (this.state.players.size === 2), your custom player lock should be true and if that happens,<br />
spectators are still allowed to join in the room onAuth, but not Players.<br />
Use maxClients to control max number of players + spectators.<br />
This is my personal opinion.</p>
]]></description><link>http://discuss.colyseus.io/post/1759</link><guid isPermaLink="true">http://discuss.colyseus.io/post/1759</guid><dc:creator><![CDATA[COCO]]></dc:creator><pubDate>Tue, 08 Mar 2022 12:08:19 GMT</pubDate></item><item><title><![CDATA[Reply to Create New Room according to specified condition(solved) on Thu, 10 Mar 2022 17:13:26 GMT]]></title><description><![CDATA[<p>Hi COCO,<br />
Thanks for your reply, after 2 players are joined the room it will be available in pool so when a 3rd player try to join the room this room will be available to join. My requirement is when 2 players are joined then room should not be available in the pool and when 3rd player try to join the room a new room should be created. I have tried to lock the room after 2 players are joined so it will be removed from the pool which is fine but when i am trying to join this room as spectator from my lobbyroom using matchmaker api i got error message &quot;The room is locked&quot;. Can you please help how can i handle this scenario. If you share some code it will be better for me to understand.</p>
<p>Thanks.</p>
]]></description><link>http://discuss.colyseus.io/post/1764</link><guid isPermaLink="true">http://discuss.colyseus.io/post/1764</guid><dc:creator><![CDATA[zack1991]]></dc:creator><pubDate>Thu, 10 Mar 2022 17:13:26 GMT</pubDate></item><item><title><![CDATA[Reply to Create New Room according to specified condition(solved) on Invalid Date]]></title><description><![CDATA[<p>hi <a class="plugin-mentions-user plugin-mentions-a" href="http://discuss.colyseus.io/uid/1470">@zack1991</a> , my recommendation: since you can have the same players connected in more than one room at the time, then you can make 2 rooms:<br />
1 - for the two players that will handle the entire game-play<br />
2 - for everyone (spectators and players), then you can make your players broadcast to the second room their &quot;movements&quot; and all the information you want to make &quot;public&quot;, that way you can have all spectators getting those updates.</p>
<p>Does this make sense for your flow?<br />
Unfortunatelly I don't have any code examples for that specific case, though I have examples of users connected to more than one room, but that shouldn't be the issue for you.<br />
Also you can check the colyseus showcase and look into other projects, or in the colyseus examples.</p>
<p>Best,<br />
Damian</p>
]]></description><link>http://discuss.colyseus.io/post/1766</link><guid isPermaLink="true">http://discuss.colyseus.io/post/1766</guid><dc:creator><![CDATA[dpastorini]]></dc:creator><pubDate>Invalid Date</pubDate></item></channel></rss>