Multiplayer savegame #7047

Open
phosit wants to merge 2 commits from phosit/0ad:mp-savegame into main
Member

This PR allows to save and later load multiplayer games.
This PR is also usefull rebalance after a client is kicked.

We might unfreze more settings (victory condition, player color...) in future PRs.

Continuation of https://code.wildfiregames.com/D4770
Compared to the phab version it uses the filetransferer, download is done when the loading screan is shown and an issue with player names is fixed.

This PR allows to save and later load multiplayer games. This PR is also usefull rebalance after a client is kicked. We might unfreze more settings (victory condition, player color...) in future PRs. Continuation of https://code.wildfiregames.com/D4770 Compared to the phab version it uses the filetransferer, download is done when the loading screan is shown and an issue with player names is fixed.
phosit added 2 commits 2024-09-15 09:40:41 +02:00
Multiplayer saved games
Some checks failed
0ad-freebsd/pipeline/pr-main There was a failure building this commit
0ad-linux/pipeline/pr-main There was a failure building this commit
checkrefs / checkrefs (pull_request) Successful in 1m1s
pre-commit / build (pull_request) Successful in 1m17s
0ad-windows/pipeline/pr-main There was a failure building this commit
0ad-macos/pipeline/pr-main There was a failure building this commit
05c0bb07d1
Enables to save multiplayer games.
When the savegame is loaded, the settings are frozen (except the non-AI-player assignment settings).
phosit requested review from Imarok 2024-09-15 09:40:41 +02:00
phosit requested review from s0600204 2024-09-15 09:40:41 +02:00
phosit requested review from wraitii 2024-09-15 09:40:41 +02:00
phosit requested review from marder 2024-09-15 09:40:41 +02:00
phosit changed title from mp-savegame to Multiplayer savegame 2024-09-15 09:41:56 +02:00
Member

This is a great one, thank you!

Some suggestions come to mind:

  • Clear m_SavedState (and possibly other data) as soon as it's no longer in use.

For future patches:

  • Introduce checksums in the saved game data file and use them for data integrity.
  • Introduce comprehensive checks on clients to ensure that they can trust the data they receive and handle security risks.
  • Ensure that all participants have successfully completed loading the game before anyone can start the simulation and, after that, ensure that everyone starts playing at the same time.
This is a great one, thank you! Some suggestions come to mind: - [x] Clear m_SavedState (and possibly other data) as soon as it's no longer in use. For future patches: - Introduce checksums in the saved game data file and use them for data integrity. - Introduce comprehensive checks on clients to ensure that they can trust the data they receive and handle security risks. - Ensure that all participants have successfully completed loading the game before anyone can start the simulation and, after that, ensure that everyone starts playing at the same time.

@phosit let me know if you want to test this sometime.
I'd suggest that a super awesome addition could be a periodical autosave but that should be a separate PR.

@phosit let me know if you want to test this sometime. I'd suggest that a super awesome addition could be a periodical autosave but that should be a separate PR.
Author
Member
  • Clear m_SavedState (and possibly other data) as soon as it's no longer in use.

That should be easy.

  • Introduce multiplayer checksums in the saved game data and use them for data integrity.

Do you mean adding a checksum to the saved game (on disk) or when transfereding it to the clients? In both cases it should be done in it's own commit.

  • Introduce comprehensive checks to ensure that the saved game data is compatible with all the participants' game versions and mods.

There is already a warning when one loads an incompatible game. Same for joining games via Lobby.

  • Introduce comprehensive checks on clients to ensure that they can trust the data they receive and handle security risks.

Do you want to protect against a host loading a game where they have an advantage?
A protection would be to send the id (as chat message) when the host saves a game. And then show the id in the gamesetup. The clients could check that it's the same.
Don't know about security risks, rejoin-gamestate already would have the same risks.

  • Ensure that all participants have successfully completed loading the game before anyone can start the simulation and, after that, ensure that everyone starts playing at the same time.

The game starts when all clients have loaded the game. One would have to edit JS to bypass that. That's hard to prevent.

> - [ ] Clear m_SavedState (and possibly other data) as soon as it's no longer in use. That should be easy. > - [ ] Introduce multiplayer checksums in the saved game data and use them for data integrity. Do you mean adding a checksum to the saved game (on disk) or when transfereding it to the clients? In both cases it should be done in it's own commit. > - [ ] Introduce comprehensive checks to ensure that the saved game data is compatible with all the participants' game versions and mods. There is already a warning when one loads an incompatible game. Same for joining games via Lobby. > - [ ] Introduce comprehensive checks on clients to ensure that they can trust the data they receive and handle security risks. Do you want to protect against a host loading a game where they have an advantage? A protection would be to send the id (as chat message) when the host saves a game. And then show the id in the gamesetup. The clients could check that it's the same. Don't know about security risks, rejoin-gamestate already would have the same risks. > - [ ] Ensure that all participants have successfully completed loading the game before anyone can start the simulation and, after that, ensure that everyone starts playing at the same time. The game starts when all clients have loaded the game. One would have to edit JS to bypass that. That's hard to prevent.
First-time contributor

Introduce multiplayer checksums in the saved game data and use them for data integrity.

The game is already sending hashes of the game state on a regular basis to check for OOS. Assuming that that has complete coverage then a corrupted save game would be detected by the OOS system.

Introduce comprehensive checks on clients to ensure that they can trust the data they receive and handle security risks.

I consider security important. I think that this PR does not add any new potential security vulnerabilities, because it basically uses the existing join-in-progress feature to resume a saved state.

I think that more checks should be done, but in a separate PR. This PR has taken a long time to get to this point and we don't want to have mission creep.

If you are able to help with writing code that does security checks then it would be greatly appreciated.

> Introduce multiplayer checksums in the saved game data and use them for data integrity. The game is already sending hashes of the game state on a regular basis to check for OOS. Assuming that that has complete coverage then a corrupted save game would be detected by the OOS system. > Introduce comprehensive checks on clients to ensure that they can trust the data they receive and handle security risks. I consider security important. I think that this PR does not add any new potential security vulnerabilities, because it basically uses the existing join-in-progress feature to resume a saved state. I think that more checks should be done, but in a separate PR. This PR has taken a long time to get to this point and we don't want to have mission creep. If you are able to help with writing code that does security checks then it would be greatly appreciated.
phosit force-pushed mp-savegame from 05c0bb07d1 to ed8ddc8398 2024-09-17 20:06:50 +02:00 Compare
Author
Member

m_SavedState is now cleared when it's no longer in use.
I hope it builds now with the rebase

m_SavedState is now cleared when it's no longer in use. I hope it builds now with the rebase
phosit force-pushed mp-savegame from ed8ddc8398 to a101db61e8 2024-09-18 21:44:17 +02:00 Compare
phosit force-pushed mp-savegame from a101db61e8 to 86d360a887 2024-09-19 19:28:51 +02:00 Compare
Author
Member

Seems SYNCHRONIZE got replaced by the precompiler.

Seems `SYNCHRONIZE` got replaced by the precompiler.
Author
Member

I won't fix the clang warning, because it gets fixed in #6996.

I won't fix the clang warning, because it gets fixed in #6996.
Owner

Warning has been fixed :)

Warning has been fixed :)
Some checks reported warnings
checkrefs / checkrefs (pull_request) Successful in 1m12s
Required
Details
pre-commit / build (pull_request) Successful in 1m33s
Required
Details
0ad-freebsd/pipeline/pr-main This commit is unstable
Required
Details
0ad-windows/pipeline/pr-main This commit looks good
Required
Details
0ad-linux/pipeline/pr-main This commit looks good
Required
Details
0ad-macos/pipeline/pr-main This commit looks good
Required
Details
Some required checks are missing.
This branch is out-of-date with the base branch
You are not authorized to merge this pull request.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u mp-savegame:phosit-mp-savegame
git checkout phosit-mp-savegame
Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
5 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: 0ad/0ad#7047
No description provided.