Skip to content

Commit

Permalink
Bypass the ascii check when setting matchmaker game names
Browse files Browse the repository at this point in the history
Since the name was generated internally, we can trust it to be ok. The 
ascii
check is really meant to prevent encoding errors accross different 
system
configurations and to encourage the use of English titles. Clan names 
will
be guaranteed to be valid utf8, and the rest of the game title will be 
in
English since we created it that way.
  • Loading branch information
Askaholic committed Feb 20, 2021
1 parent 57034f6 commit 00ba8be
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
11 changes: 9 additions & 2 deletions server/games/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,19 @@ def name(self):
@name.setter
def name(self, value: str):
"""
Avoids the game name to crash the mysql INSERT query by being longer
than the column's max size.
Verifies that names only contain ascii characters.
"""
if not value.isascii():
raise ValueError("Name must be ascii!")

self.set_name_unchecked(value)

def set_name_unchecked(self, value: str):
"""
Sets the game name without doing any validity checks.
Truncates the game name to avoid crashing mysql INSERT statements.
"""
max_len = game_stats.c.gameName.type.length
self._name = value[:max_len]

Expand Down
3 changes: 2 additions & 1 deletion server/ladder_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,14 @@ async def start_game(
game_class=LadderGame,
game_mode=queue.featured_mod,
host=host,
name=game_name(team1, team2),
name="Matchmaker Game",
matchmaker_queue_id=queue.id,
rating_type=queue.rating_type,
max_players=len(all_players)
)
game.init_mode = InitMode.AUTO_LOBBY
game.map_file_path = map_path
game.set_name_unchecked(game_name(team1, team2))

def get_player_mean(player):
return player.ratings[queue.rating_type][0]
Expand Down

0 comments on commit 00ba8be

Please sign in to comment.