def _create_match(player_uid1, join_token): match = Match(player_uid1, join_token) success = MatchDB.set(_USER_2_MATCH_ID, player_uid1, match.match_id, xx=True) if not success: raise ValueError( 'player {} should register before creating a match'.format( player_uid1)) if join_token: success = MatchDB.set(_PRIVATE_PENDING_MATCH_IDS, join_token, match.match_id, nx=True) if not success: raise exceptions.InvalidMatchState( 'join_token {} is already in use by at least 2 players.'. format(join_token)) else: MatchDB.enqueue(_PUBLIC_PENDING_MATCH_IDS, None, match.match_id) success = MatchDB.set(_ALL_MATCHES, match.match_id, match.to_dict(), nx=True) if not success: raise exceptions.InvalidMatchState( 'Match {} is already created'.format(match.match_id)) chessboard = Chessboard() MatchDB.set(_CHESSBOARD, match.chessboard_id, chessboard.to_dict()) return match
def send_message_from(self, my_uid, msg_type, msg_data): for other_uid in self.player_uids: if other_uid != my_uid: channel_name = self._channel_to(other_uid) message = {'msg_type': msg_type, 'msg_data': msg_data} MatchDB.enqueue('match_channel', channel_name, message)