server
server copied to clipboard
Issue/#858 validity in game info
Adds game validity to the game_info messages. This requires quite a lot of refactoring because the validity needs to be re-evaluated every time any of the attributes that affect validity change. Previously, each of the checks only ran at certain times such as when the game launched or after it was finished. Refactoring this was also made more difficult by the fact that the game handling logic is already such a mess. Hopefully this approach of moving the validation code out of the Game class helps with that, but I'm still not 100% happy with it. There are still some problems with it:
- The
ValidationRules are very tightly coupled to theGameclass, some of them even use 'private' variables fromGame - The validity computation is somewhat expensive as it is likely to be called many times, especially while a game is in the lobby state. It is also extremely difficult to cache because it has so many dependencies that would need to invalidate the cache whenever they change.
Some other issues that came up:
- Whenever the
ScenarioFilegame option is set, we need to query the database in order to get the map id and to check if the map is ranked. This is an async operation, but it doesn't otherwise make sense to makeset_game_optionan async function. So it's a little unclear where exactly theawaitshould happen. - Games are marked as dirty quite liberally, even if nothing that affects the
to_dictmethod would actually change - We might want to rename some of the validity states since the enum names are used in the protocol
Closes #858
Api returns HAS_AI, but server defined only HAS_AI_PLAYERS
https://github.com/FAForever/server/blob/7c96b3b727867d7ea3aa4893d55f33b97acf3c87/server/games/typedefs.py#L68

api: MULTIPLE_TEAMS server : MULTI_TEAM