Exemplo n.º 1
0
	async def set_map_times(self, map, game_mode, records, v_replay=None, v_replay_checks=None, ghost_replay=None):
		mode = self.mode_to_dedi_mode(game_mode)
		if not mode:
			raise DedimaniaNotSupportedException('Mode is not supported!')

		if not self.session_id:
			raise DedimaniaTransportException('Dedimania not authenticated!')

		times = [{
			'Login': r.login, 'Best': r.score, 'Checks': ','.join([str(c) for c in r.cps]),
		} for r in records if r.updated]
		replays = {
			'VReplay': v_replay or None,
			'VReplayChecks': v_replay_checks or '',
			'Top1GReplay': ghost_replay or ''
		}
		if not replays['VReplay']:
			# Nothing to update!
			logger.debug('Dedimania end map, nothing new to update! Skipping set times call!')
			return

		result = await self.multicall(
			('dedimania.SetChallengeTimes', self.session_id, {
				'UId': map.uid, 'Name': map.name, 'Environment': map.environment, 'Author': map.author_login,
				'NbCheckpoints': map.num_checkpoints, 'NbLaps': map.num_laps,
			}, mode, times, replays)
		)

		try:
			return bool(isinstance(result[0][0]['Records'], list))
		except Exception as e:
			logger.error('Sending times to dedimania failed. Info: {}'.format(result))
			return False
Exemplo n.º 2
0
	async def get_map_details(
		self, map, game_mode, server_name, server_comment, is_private, max_players, max_specs, players, server_login
	):
		"""
		Get records for specific map instance.

		:param map: Map instance.
		:param game_mode: Game mode, either 'Rounds' or 'TA'.
		:param server_name: Name of server
		:param server_comment: Comment
		:param is_private: Is server hidden from lists?
		:param max_players: Maximum number of players.
		:param max_specs: Maximum of spectators.
		:param players: List with players, raw from gbx command!!!!!
		:type map: pyplanet.apps.core.maniaplanet.models.map.Map
		:return: Record list.
		"""
		if not self.session_id:
			await self.authenticate()
		if not self.session_id:
			raise DedimaniaTransportException('Dedimania not authenticated!')

		def is_spectator(player):
			return bool(player['SpectatorStatus'] % 10)

		player_list = [
			{'Login': p['Login'], 'IsSpec': is_spectator(p)} for p in players if p['Login'] != server_login
		]
		num_specs = sum(p['IsSpec'] for p in player_list)
		num_players = len(player_list) - num_specs

		mode = self.mode_to_dedi_mode(game_mode)
		if not mode:
			raise DedimaniaNotSupportedException('Mode is not supported!')

		result = await self.multicall(
			('dedimania.GetChallengeRecords', self.session_id, {
				'UId': map.uid, 'Name': map.name, 'Environment': map.environment, 'Author': map.author_login,
				'NbCheckpoints': map.num_checkpoints, 'NbLaps': map.num_laps,
			}, mode, {
				 'SrvName': server_name, 'Comment': server_comment, 'Private': is_private, 'NumPlayers': num_players,
				 'MaxPlayers': max_players, 'NumSpecs': num_specs, 'MaxSpecs': max_specs
			 }, player_list)
		)
		if not result or not isinstance(result, list):
			raise DedimaniaTransportException('Result seems to be empty!')

		result = result[0][0]
		if not result:
			raise DedimaniaTransportException('Result seems to be empty!')

		allowed_modes = result['AllowedGameModes']
		server_max_rank = result['ServerMaxRank']
		response_players = result['Players']
		raw_records = result['Records']
		records = [
			DedimaniaRecord(r['Login'], r['NickName'], r['Best'], r['Rank'], r['MaxRank'], r['Checks'], r['Vote'])
			for r in raw_records
		]
		return server_max_rank, allowed_modes, response_players, records or []