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

Moving Client room-to-room #65

Closed
oyed opened this issue Jun 30, 2017 · 10 comments
Closed

Moving Client room-to-room #65

oyed opened this issue Jun 30, 2017 · 10 comments

Comments

@oyed
Copy link
Contributor

oyed commented Jun 30, 2017

Is this possible? For example, having Rooms as Maps in an MMO game. Once a "door" is triggered, the room will move the player to the next specified room.

@endel
Copy link
Member

endel commented Jun 30, 2017

Hi @oyed,

Currently, the only way to achieve this is by manually sending a message from the server to the client you want to move, and, from the client-side, request to join into that room. See dummy example below:

Server-side:

// "previous_room" handler
this.send(client, { letsMoveTo: "next_room" });

Client-side

var previousRoom = client.join("previous_room");

previousRoom.onData.add(function(data) {
    var nextRoom = client.join(data.letsMoveTo);
});

@oyed
Copy link
Contributor Author

oyed commented Jun 30, 2017

@endel Thanks - can I persist Client (Player) Data through rooms?

@endel
Copy link
Member

endel commented Jun 30, 2017

@oyed you're welcome! You'd need to persist the user data somewhere in between connections, such as a database or in memory.

I wouldn't recommend persisting in NodeJS's process, since when upgrading to the next version of the server (0.6.x) will break things. In the current version (0.5.x) it will be fine because it's a single process. Version 0.6.x will introduce multiple processes, and your rooms may live in a different process.

@endel endel added the question label Jun 30, 2017
@seiyria
Copy link
Contributor

seiyria commented Jun 30, 2017

This is something I do as well (I have an RPG where each map is a room). Basically, I do it exactly as endel described - I tell the client to teleport, and the client initiates the request. I do some cleanup on the server, save the player, then when it leaves the room and joins the next one, the x, y, etc are already set. When the next version comes out, you'll be able to do promise validation in canJoin which will make it so you can check the database to verify that the map you're on is the map you should be on (for example).

@oyed
Copy link
Contributor Author

oyed commented Jul 1, 2017

Thanks for the help!

@xfause
Copy link

xfause commented Jun 28, 2020

after 3 years. is there any update?
new method like jumpToRoom()?
or this solution still useable?

@endel
Copy link
Member

endel commented Jun 28, 2020

Hi @xfause, there are a couple of different ways of achieving this.

What I do on mazmorra is:

  • the server sends a message to the client, with the new level info (e.g. "go to level 7")
  • the client receives that message, and disconnects from the previous room, and connects to the next one, given the provided info from the server

A more "secure" way of handling this, would be to use the matchMaker API in the server-side, and send the "seat reservation" data through a message for the client, and the client can the call .consumeSeatReservation().

You still need to connect and disconnect from the rooms manually, as the framework does not consider how your front-end is structured.

@arief0303
Copy link

arief0303 commented Jul 14, 2023

Can someone please elaborate the syntax in more detail? I'm facing difficulty in this exact scenario. As every time I leave a room , i'm getting "WebSocket is already in CLOSING or CLOSED state." error. Thank you.

@atuncer
Copy link

atuncer commented Oct 15, 2023

why can't we force join a client

@endel
Copy link
Member

endel commented Oct 16, 2023

@atuncer the problem I see currently in allowing the SERVER to force the client to join is that we don't have a declarative way for the CLIENT to properly listen to this event and set up its callbacks.

I'm very open to an API/feature proposal to allow this. It would be nice to have this feature for version 1.0 with a good API.

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

6 participants