diff options
author | Philip Paquette <pcpaquette@gmail.com> | 2018-11-13 15:02:07 -0500 |
---|---|---|
committer | Philip Paquette <pcpaquette@gmail.com> | 2019-04-18 11:20:05 -0400 |
commit | f2de602a988a1548cc8c4a5eb855b1db3c247216 (patch) | |
tree | e41acd3c39e8b9e95a1c7d67439334643f4dac9d /diplomacy | |
parent | 3924ed59b6d69a9d79ccd5f9ce4c3f163fa36d47 (diff) |
game_id - Using a random stream of 96 bits encoded as base64
Diffstat (limited to 'diplomacy')
-rw-r--r-- | diplomacy/engine/game.py | 4 | ||||
-rw-r--r-- | diplomacy/server/server.py | 6 |
2 files changed, 5 insertions, 5 deletions
diff --git a/diplomacy/engine/game.py b/diplomacy/engine/game.py index 3f218e4..03a25af 100644 --- a/diplomacy/engine/game.py +++ b/diplomacy/engine/game.py @@ -19,10 +19,10 @@ - Contains the game engine """ # pylint: disable=too-many-lines +import base64 import os import sys import time -import uuid import random from copy import deepcopy @@ -266,7 +266,7 @@ class Game(Jsonable): # Check game ID. if self.game_id is None: - self.game_id = '%s/%s' % (self.timestamp_created, uuid.uuid4()) + self.game_id = base64.b64encode(os.urandom(12), b'-_').decode('utf-8') # Validating status self._validate_status(reinit_powers=(self.timestamp_created is None)) diff --git a/diplomacy/server/server.py b/diplomacy/server/server.py index 5763991..fed4eb6 100644 --- a/diplomacy/server/server.py +++ b/diplomacy/server/server.py @@ -47,10 +47,10 @@ """ import atexit +import base64 import logging import os import signal -import uuid import tornado import tornado.web @@ -739,9 +739,9 @@ class Server(): def create_game_id(self): """ Create and return a game ID not already used by a game in server database. """ - game_id = str(uuid.uuid4()) + game_id = base64.b64encode(os.urandom(12), b'-_').decode('utf-8') while self.has_game_id(game_id): - game_id = str(uuid.uuid4()) + game_id = base64.b64encode(os.urandom(12), b'-_').decode('utf-8') return game_id def remove_token(self, token): |