FAForever / downlords-faf-client

Official client for Forged Alliance Forever
https://faforever.com
MIT License
196 stars 121 forks source link

Allow watching replays while in queue #2945

Closed BlackYps closed 1 year ago

BlackYps commented 1 year ago

We store game files for replay watching separately if the related option is enabled. This prevents the problems that would occur when the game gets launched with the wrong game version once a match is found.

I also deleted the canUpdate method that always returned true.

codecov[bot] commented 1 year ago

Codecov Report

Merging #2945 (41e989f) into develop (5c88d82) will increase coverage by 0.14%. The diff coverage is 72.91%.

:exclamation: Current head 41e989f differs from pull request most recent head 2e408b4. Consider uploading reports for the commit 2e408b4 to get more accurate results

Additional details and impacted files ```diff @@ Coverage Diff @@ ## develop #2945 +/- ## ============================================= + Coverage 64.58% 64.72% +0.14% - Complexity 4886 4894 +8 ============================================= Files 556 556 Lines 20193 20187 -6 Branches 1080 1077 -3 ============================================= + Hits 13042 13067 +25 + Misses 6532 6498 -34 - Partials 619 622 +3 ``` | [Impacted Files](https://codecov.io/gh/FAForever/downlords-faf-client/pull/2945?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FAForever) | Coverage Δ | | |---|---|---| | [...ver/client/patch/SimpleHttpFeaturedModUpdater.java](https://codecov.io/gh/FAForever/downlords-faf-client/pull/2945?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FAForever#diff-c3JjL21haW4vamF2YS9jb20vZmFmb3JldmVyL2NsaWVudC9wYXRjaC9TaW1wbGVIdHRwRmVhdHVyZWRNb2RVcGRhdGVyLmphdmE=) | `16.66% <0.00%> (ø)` | | | [...client/patch/SimpleHttpFeaturedModUpdaterTask.java](https://codecov.io/gh/FAForever/downlords-faf-client/pull/2945?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FAForever#diff-c3JjL21haW4vamF2YS9jb20vZmFmb3JldmVyL2NsaWVudC9wYXRjaC9TaW1wbGVIdHRwRmVhdHVyZWRNb2RVcGRhdGVyVGFzay5qYXZh) | `0.00% <0.00%> (ø)` | | | [...orever/client/preferences/ForgedAlliancePrefs.java](https://codecov.io/gh/FAForever/downlords-faf-client/pull/2945?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FAForever#diff-c3JjL21haW4vamF2YS9jb20vZmFmb3JldmVyL2NsaWVudC9wcmVmZXJlbmNlcy9Gb3JnZWRBbGxpYW5jZVByZWZzLmphdmE=) | `81.53% <ø> (-1.32%)` | :arrow_down: | | [...ever/client/preferences/ui/SettingsController.java](https://codecov.io/gh/FAForever/downlords-faf-client/pull/2945?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FAForever#diff-c3JjL21haW4vamF2YS9jb20vZmFmb3JldmVyL2NsaWVudC9wcmVmZXJlbmNlcy91aS9TZXR0aW5nc0NvbnRyb2xsZXIuamF2YQ==) | `81.65% <ø> (+2.85%)` | :arrow_up: | | [...rever/client/patch/GameBinariesUpdateTaskImpl.java](https://codecov.io/gh/FAForever/downlords-faf-client/pull/2945?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FAForever#diff-c3JjL21haW4vamF2YS9jb20vZmFmb3JldmVyL2NsaWVudC9wYXRjaC9HYW1lQmluYXJpZXNVcGRhdGVUYXNrSW1wbC5qYXZh) | `47.82% <62.50%> (+0.95%)` | :arrow_up: | | [...in/java/com/faforever/client/game/GameService.java](https://codecov.io/gh/FAForever/downlords-faf-client/pull/2945?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FAForever#diff-c3JjL21haW4vamF2YS9jb20vZmFmb3JldmVyL2NsaWVudC9nYW1lL0dhbWVTZXJ2aWNlLmphdmE=) | `70.56% <69.81%> (+6.23%)` | :arrow_up: | | [...va/com/faforever/client/patch/GameUpdaterImpl.java](https://codecov.io/gh/FAForever/downlords-faf-client/pull/2945?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FAForever#diff-c3JjL21haW4vamF2YS9jb20vZmFmb3JldmVyL2NsaWVudC9wYXRjaC9HYW1lVXBkYXRlckltcGwuamF2YQ==) | `87.50% <94.11%> (+5.83%)` | :arrow_up: | | [...orever/client/config/FeaturedModUpdaterConfig.java](https://codecov.io/gh/FAForever/downlords-faf-client/pull/2945?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FAForever#diff-c3JjL21haW4vamF2YS9jb20vZmFmb3JldmVyL2NsaWVudC9jb25maWcvRmVhdHVyZWRNb2RVcGRhdGVyQ29uZmlnLmphdmE=) | `100.00% <100.00%> (ø)` | | | [...com/faforever/client/fa/ForgedAllianceService.java](https://codecov.io/gh/FAForever/downlords-faf-client/pull/2945?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FAForever#diff-c3JjL21haW4vamF2YS9jb20vZmFmb3JldmVyL2NsaWVudC9mYS9Gb3JnZWRBbGxpYW5jZVNlcnZpY2UuamF2YQ==) | `81.42% <100.00%> (+1.74%)` | :arrow_up: | | [...va/com/faforever/client/preferences/DataPrefs.java](https://codecov.io/gh/FAForever/downlords-faf-client/pull/2945?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FAForever#diff-c3JjL21haW4vamF2YS9jb20vZmFmb3JldmVyL2NsaWVudC9wcmVmZXJlbmNlcy9EYXRhUHJlZnMuamF2YQ==) | `100.00% <100.00%> (ø)` | | ... and [2 files with indirect coverage changes](https://codecov.io/gh/FAForever/downlords-faf-client/pull/2945/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FAForever) ------ [Continue to review full report in Codecov by Sentry](https://codecov.io/gh/FAForever/downlords-faf-client/pull/2945?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FAForever). > **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FAForever) > `Δ = absolute (impact)`, `ø = not affected`, `? = missing data` > Powered by [Codecov](https://codecov.io/gh/FAForever/downlords-faf-client/pull/2945?src=pr&el=footer&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FAForever). Last update [5c88d82...2e408b4](https://codecov.io/gh/FAForever/downlords-faf-client/pull/2945?src=pr&el=lastupdated&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FAForever). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=FAForever).
BlackYps commented 1 year ago

Seems to be working now. Still needs tests

Garanas commented 1 year ago

There are more places where you can have issues:

(1) and (3) can be a problem when you were watching a replay from a different featured mod. (2) can be a problem where one game is writing to it (because you're closing it, for example) while the next game is trying to read it (because you're starting it).

Are these taken into account?

BlackYps commented 1 year ago

No, can you elaborate how to take these into account?

Garanas commented 1 year ago

For (1) and (2) the solution would be to delay starting the ladder instance until we're sure that the replay instance has no remaining file handles lingering anywhere. We kill the process, wait a second or two and then launch the game to join ladder. I assume this already happens to some degree.

(3) is more difficult, if I'm not mistaken then the files are updated as you join the queue. This includes the executable. Updating the executable would therefore always fail when it needs to be changed: either when you start the queue while in a replay or when you start the replay while in a queue. To overcome this you'd need to not just separate the game data files, but also separate the executable. This is not limited to watching replays of different featured mods, it can also happen between game versions (the few days after a release)

BlackYps commented 1 year ago

I see there was a misunderstanding. The executable is copied over to a separate directory as well. So 3) shouldn't be an issue. Killing the replay before starting the match seems like a good idea.

Garanas commented 1 year ago

I thought with game files you were referring to just the files in the gamedata directory, miss understanding indeed 😄

Sheikah45 commented 1 year ago

I think the pref file might still be a concern though. Would that be a problem if a replay is open when the game starts?

BlackYps commented 1 year ago

Ideally people don't fiddle with their pref file when they watch a replay anyway, but I understand that this is not always the case. Shouldn't this be addressed by terminating the replay before starting the ladder match?

Sheikah45 commented 1 year ago

I didn't think you wanted to terminate the replay

BlackYps commented 1 year ago

I didn't originally think of that and it's not implemented yet, but it sounds like the best solution. We circumvent these file issues, it frees up system resources and prevents that people miss that the game is starting because they are in the replay

BlackYps commented 1 year ago

I realized that tracking when a replay is started separately from when an online game is started leads to complicated situations when we still want to make e.g. allowing to join a queue while a replay is running dependend on the preference from the settings. I'm starting to wonder if it is even worth it to keep this option at all. Having this options introduces if statements all over the place. The additional files in the replay folder is about 200MB per featured mod. So in the worst case we have about 800MB of additional disk space, assuming people actually watch replays from fafdevelop and fafbeta. The cache folder can easily grow to multiple GBs. Each client version alone is just short of 200MB and there are possibly multiple game versions cached as well. We don't really take steps to keep this folder small either, so it seems inconsistent to warn about a feature that will actually have less impact on disk usage than the cache. We could maybe store our game files for replay watching in the cache folder as well, so they can be easily cleaned and just enable the feature for all people, making the code much nicer.

Sheikah45 commented 1 year ago

Yes I was wondering as well if we should just always have the split folders. Then they could be truly separated in the code.

BlackYps commented 1 year ago

Sounds good. Why is the patch to the game prefs needed? Do we still need to do this then? And one more thing I realized. When people are in a custom game lobby and watch a replay they already have the situation that two instances of the game are running. How would we prevent any game prefs issues? On the other hand people have used this feature for a while and so far I can't remember any complaints about issues with that.

Sheikah45 commented 1 year ago

Yes the patch to the game prefs is to allow multiple instances of the game to run at once.

And with the situation where people are already in a game the first game instance has a lock on the files so no other instance should be able to touch them. And that is the instance with the actual game they will play so has priority. When starting a game with a replay started the replay would have the lock which might not have the settings the player wants for the game itself which is the issue.

BlackYps commented 1 year ago

When we remove the game.prefs edit from the settings we have to check and edit automatically. Where would be a good place for this check?