forked from Hanabi/hanabi-league
37 lines
1 KiB
Python
37 lines
1 KiB
Python
|
from typing import Dict
|
||
|
|
||
|
import unidecode
|
||
|
|
||
|
import constants
|
||
|
from config import config_manager
|
||
|
|
||
|
from log_setup import logger
|
||
|
|
||
|
|
||
|
def normalize_username(username: str) -> str:
|
||
|
decoded = unidecode.unidecode(username)
|
||
|
return decoded.lower()
|
||
|
|
||
|
|
||
|
def are_game_options_allowed(game_id: int, game_options: Dict) -> bool:
|
||
|
"""
|
||
|
Check if the game options are allowed for league.
|
||
|
"""
|
||
|
for forbidden_option in constants.FORBIDDEN_GAME_OPTIONS:
|
||
|
if game_options.get(forbidden_option, False):
|
||
|
logger.debug("Rejected game {} due to option {} set".format(game_id, forbidden_option))
|
||
|
return False
|
||
|
# All options ok
|
||
|
return True
|
||
|
|
||
|
|
||
|
def is_player_count_allowed(game_id: int, num_players: int) -> bool:
|
||
|
"""
|
||
|
Check if the player count is allowed for league.
|
||
|
"""
|
||
|
config = config_manager.get_config()
|
||
|
if not (config.min_player_count <= num_players <= config.max_player_count):
|
||
|
logger.debug("Rejected game {} due to invalid number of players ({})".format(game_id, num_players))
|
||
|
return False
|
||
|
return True
|