Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create a new game room #83

Closed
hayesmaker opened this issue Dec 23, 2014 · 2 comments
Closed

Create a new game room #83

hayesmaker opened this issue Dec 23, 2014 · 2 comments

Comments

@hayesmaker
Copy link

Am I completely missing something from the documentation/API or is there a way for a user to manually create a new game room?... The only way I see to go from the lobby to a game room is to have auto create rooms set to true, and wait for number of players... which isn't really what I want, cuz I want users to create rooms themselves to play with friends.

@dariusk
Copy link
Collaborator

dariusk commented Dec 23, 2014

What you would do is have the server listen for a message from the client/user, and then run cloak.createRoom on receiving that message from a user. You can see this in the Grow21 example code.

Client sends message to the server asking for a new room:

createRoom: function() {
var newRoomElement = document.getElementById('new-room');
var newRoomUIElement = document.getElementById('new-room-ui');
if (newRoomElement.value.trim() === '') {
newRoomUIElement.innerHTML += '<p>Enter a valid username!</p>';
return;
}
cloak.message('createRoom', {
name: escape(newRoomElement.value)
});

Server listens for the message and makes a room when received:

https://github.com/incompl/cloak/blob/master/examples/grow21/server/server.js#L88-L94

@hayesmaker
Copy link
Author

Gotcha, dunno how I missed it from the docs... :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants