Ejemplo n.º 1
0
	def register_team(self, team, sock):
		if not team in self.team_whitelist:
			sock.close(code=messaging.DO_NOT_RECONNECT, reason="This team is not registered for the competition.")
			return

		if team in self.sock_to_team.values():
			sock.close(code=messaging.DO_NOT_RECONNECT, reason="This team already has a connection to the game server.")
			return
		self.sock_to_team[sock] = team

		# All games in a given competition will use the same seed.
		if not self.common_seed:
			self.common_seed = random.randint(1, 1 << 30)

		if not team in self.team_to_game:
			game = Board(seed=self.common_seed)
			game.game_id = util.generate_game_id()
			self.team_to_game[team] = game
		elif self.started:
			# We must be resuming a broken connection.
			Competition.request_next_move(self.team_to_game[team], sock)
			return

		# Game IDs are visible to the client only in testing.
		if self.is_test_run:
			Competition.notify_game_created(sock, game.game_id)
		else:
			Competition.notify_game_created(sock)