Comments (10)
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.
from colyseus.
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).
from colyseus.
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.
from colyseus.
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);
});
from colyseus.
@endel Thanks - can I persist Client (Player) Data through rooms?
from colyseus.
@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.
from colyseus.
Thanks for the help!
from colyseus.
after 3 years. is there any update?
new method like jumpToRoom()?
or this solution still useable?
from colyseus.
why can't we force join a client
from colyseus.
@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.
from colyseus.
Related Issues (20)
- [Bug]: Colyseus throws an exception when a client tries to reconnect after leaving HOT 3
- [Bug]: Stats reports negative player count HOT 2
- TypeError: roomHistory.clients is not iterable HOT 7
- [Bug]: Uncaught Error: ChangeTree: missing index for field "undefined"
- [Bug]: Map Schema Removing value creates issue HOT 2
- [Bug]: tsx must be loaded with --import instead of --loader HOT 4
- [Feature]: need Request in static onAuth HOT 6
- [Bug]: Cannot use Matchmaker w/o Server HOT 1
- [Bug]: Error code lost when throwing ServerError in onCreate HOT 2
- [Bug]: Cant join rooms from react typescript Application HOT 2
- [Feature]: UDP HOT 3
- [Bug]: States are not triggered in the expected order HOT 4
- [Bug]: clients and server both get stuck if the server threw an exception HOT 3
- [Bug]: When TypeScript target is "es2022", Server breaks HOT 3
- [Bug]: Module '"net"' has no exported member 'ServerOpts'. HOT 3
- Scalability and Content Security Policies inside Discord Activities (Discord Embedded SDK) HOT 1
- Server doesn't restart after 0.15 upgrade HOT 3
- Roadmap for @colyseus/schema 3.0 HOT 4
- [Feature]: Make Room have generic parameters for the UserData and AuthData (defaulting to any) HOT 1
- [Bug]: Matchmaker Player Stats can be inaccurate HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from colyseus.