-
Notifications
You must be signed in to change notification settings - Fork 41
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
Ability to serialize/deserialize Schema on the server side #115
Comments
Some related discord discussions: Original conversation: https://discord.com/channels/525739117951320081/526083188108296202/880867521824170005 Follow up when encodeAll / decode wasn't working: https://discord.com/channels/525739117951320081/526083188108296202/889878308983046215. |
as a workaround: in the and in the at least thats how i do it :) and maybe its worth for your game to auto save the state every 5 minutes in case server crashes. so only 5 minutes of game gets lost. |
@Wenish so I am not using the rest of colyseus, just the schema. Also I don't think what you are proposing will work because not all the internal values are saved (most importantly the ids of the fields meaning the diff that gets sent after reloading the data breaks). Check out the gist I had sent before: https://gist.github.com/jrabek/6303d3f94b82c692de7721f0fc331f8c |
@jrabek im talking about a workaround where you write your own mapper from the schema to your database model and visa versa. not using any built in function you try to use. |
Thanks for the update @lpsandaruwan! Definitely would love to try out colyseus again! I must have missed With this approach will the cloned state work with per client filters? |
Hi @jrabek cc @endel |
@lpsandaruwan I had a chance to play with your suggestion and while I don't see the exception I also don't see the correct behavior when decoding from an encoded state and then cloning. You can check out my experiment here https://github.com/jrabek/colyseus-schema-experiments/tree/main. I put a few notes in the README.md. |
Thank you @jrabek. Will look into this. |
Hi @jrabek
|
Thanks for the follow-up! I'll check when I have a second this week. |
@lpsandaruwan sorry for the delay and thanks again for the follow up! I tried this out locally and the initial results look really promising! I'll need to spend some more time with it but this seems like an acceptable approach to the original problem. |
Hmmm, I may have spoken too soon. It seems that any modification to the state followed by a save/load cycle result in the full state getting sent to all clients. Per client filtering is working as expected but the full state is always sent. So it seems like the data required to know what the last state update was is lost when doing a serialization/deserialization. To be extra sure I added a small test that simple sets a string in the state to
If
If |
So I guess the option at this point would be to serialize the state to the database continually, but only as a backup. If the server crashes it can reread the state and would send the full update to the clients to ensure they are back in sync. Which is probably what you want anyway. |
Thanks again @endel for the great multiplayer game framework! If you would provide some basic guidance on this enhancement I would be happy to implement it in a PR.
Summary
This is a request for a Schema method for completely serializing/deserializing the server Schema (i.e. game state) so that it can be persisted in a database.
Motivation
In the current colyseus server architecture, the game state (i.e. some Schema derived class) persists in memory in one specific server.
One of the shortcomings is that it prevents seamless deploys and crash recovery since the game state is in memory and therefore lost when the server process is killed. For certain game types (e.g. long running games, games involving money) it is critical that game state is not lost.
To support a more robust game state, the ability to fully serialize the server Schema in a way that it could be stored in a database is needed.
Currently there are two ways to serialize the server Schema neither of which are meant for deserializing it later.
For (2) this is what happens when the server state is serialized/deserialized using encodeAll / decode: https://gist.github.com/jrabek/6303d3f94b82c692de7721f0fc331f8c.
The text was updated successfully, but these errors were encountered: