Save after the last player disconnects from vanilla server #3981
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is the bug?
This fix references issue #3773. When the last player leaves a server, the world does not automatically save, meaning within that time frame data loss is possible.
How did you fix the bug?
I fixed the bug by making a check to see if there are any players in the server after the update in the main loop. If there are no players after the update was made (updates are only executed when there is at least 1 player in the server) then the server will save the world.
Are there alternatives to your fix?
You could make the check further down in the update execution (within the
Update(...)
method itself or deeper) after the call toHasClients = false;
happens and then run the world save. I think the option presented in this pull request is fine, but it could clutter the main loop in the future.We should also wait to see if there is any more information on this dedicated server functionality before considering merging or consider alternatives like a mod for this feature.