Skip to content

Commit 0790c99

Browse files
committed
Make boolean game option checks more lenient
1 parent c7410a4 commit 0790c99

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

server/games/coop.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from server.abc.base_game import InitMode
22

3-
from .game import Game, GameType, ValidityState, Victory
3+
from .game import Game
4+
from .typedefs import FA, GameType, ValidityState, Victory
45

56

67
class CoopGame(Game):
@@ -29,9 +30,9 @@ async def validate_game_mode_settings(self):
2930
valid_options = {
3031
"Victory": (Victory.SANDBOX, ValidityState.WRONG_VICTORY_CONDITION),
3132
"TeamSpawn": ("fixed", ValidityState.SPAWN_NOT_FIXED),
32-
"RevealedCivilians": ("No", ValidityState.CIVILIANS_REVEALED),
33+
"RevealedCivilians": (FA.FALSE, ValidityState.CIVILIANS_REVEALED),
3334
"Difficulty": (3, ValidityState.WRONG_DIFFICULTY),
34-
"Expansion": ("true", ValidityState.EXPANSION_DISABLED),
35+
"Expansion": (FA.TRUE, ValidityState.EXPANSION_DISABLED),
3536
}
3637
await self._validate_game_options(valid_options)
3738

server/games/game.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
from ..abc.base_game import GameConnectionState, InitMode
2828
from ..players import Player, PlayerState
2929
from .typedefs import (
30+
FA,
3031
BasicGameInfo,
3132
EndedGameInfo,
3233
FeaturedModType,
@@ -617,11 +618,11 @@ async def validate_game_settings(self):
617618
await self.mark_invalid(ValidityState.FFA_NOT_RANKED)
618619
return
619620
valid_options = {
620-
"AIReplacement": ("Off", ValidityState.HAS_AI_PLAYERS),
621+
"AIReplacement": (FA.FALSE, ValidityState.HAS_AI_PLAYERS),
621622
"FogOfWar": ("explored", ValidityState.NO_FOG_OF_WAR),
622-
"CheatsEnabled": ("false", ValidityState.CHEATS_ENABLED),
623-
"PrebuiltUnits": ("Off", ValidityState.PREBUILT_ENABLED),
624-
"NoRushOption": ("Off", ValidityState.NORUSH_ENABLED),
623+
"CheatsEnabled": (FA.FALSE, ValidityState.CHEATS_ENABLED),
624+
"PrebuiltUnits": (FA.FALSE, ValidityState.PREBUILT_ENABLED),
625+
"NoRushOption": (FA.FALSE, ValidityState.NORUSH_ENABLED),
625626
"RestrictedCategories": (0, ValidityState.BAD_UNIT_RESTRICTIONS),
626627
"TeamLock": ("locked", ValidityState.UNLOCKED_TEAMS)
627628
}

server/games/typedefs.py

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from enum import Enum, unique
2-
from typing import Dict, List, NamedTuple, Optional, Set
2+
from typing import Any, Dict, List, NamedTuple, Optional, Set
33

44
from server.games.game_results import GameOutcome
55
from server.players import Player
@@ -190,3 +190,30 @@ def to_dict(self):
190190
for team_summary in self.team_summaries
191191
],
192192
}
193+
194+
195+
class _FATrue(object):
196+
__slots__ = ()
197+
198+
def __eq__(self, other: Any) -> bool:
199+
if isinstance(other, str):
200+
other = other.lower()
201+
202+
return other in (True, "true", "on", "yes", 1)
203+
204+
205+
class _FAFalse(object):
206+
__slots__ = ()
207+
208+
def __eq__(self, other: Any) -> bool:
209+
if isinstance(other, str):
210+
other = other.lower()
211+
212+
return other in (False, "false", "off", "no", 0)
213+
214+
215+
class FA(object):
216+
__slots__ = ()
217+
218+
TRUE = _FATrue()
219+
FALSE = _FAFalse()

0 commit comments

Comments
 (0)