def get(self): if self.is_admin: challenge_list = monitor.challenges else: challenge_list = monitor.visible_challenges metadata = {name: monitor.metadata(name) for name in challenge_list} challenge_list = sorted(challenge_list, key=lambda n: (metadata[n]['points'], n)) challenges = [{ 'name': name, 'points': metadata[name]['points'], 'captures': len(scoreboard.get_captures_by_challenge(name)), 'status': make_status_widget(self, monitor.status(name), metadata[name]) } for name in challenge_list] self.render('templates/challenge_index.html', user=self.user, selected='challenges', challenges=challenges)
def _update(self): self.dirty = False challenge_points = { challenge : monitor.metadata(challenge)['points'] for challenge in monitor.challenges } entries = [] for user in auth.users: if not auth.is_playing(user): continue user_points = 0 user_captures = 0 user_last_capture_timestamp = float('-inf') for challenge, timestamp in scoreboard.get_captures_by_user(user): user_captures += 1 user_points += challenge_points[challenge] if user_last_capture_timestamp < float(timestamp): user_last_capture_timestamp = float(timestamp) entries.append((user, user_points, user_captures, user_last_capture_timestamp)) self.scoreboard_list = sorted(entries, key=lambda e: (e[1], -e[3]), reverse=True)
def _update(self): self.dirty = False challenge_points = { challenge: monitor.metadata(challenge)['points'] for challenge in monitor.challenges } entries = [] for user in auth.users: if not auth.is_playing(user): continue user_points = 0 user_captures = 0 user_last_capture_timestamp = float('-inf') for challenge, timestamp in scoreboard.get_captures_by_user(user): user_captures += 1 user_points += challenge_points[challenge] if user_last_capture_timestamp < float(timestamp): user_last_capture_timestamp = float(timestamp) entries.append((user, user_points, user_captures, user_last_capture_timestamp)) self.scoreboard_list = sorted(entries, key=lambda e: (e[1], -e[3]), reverse=True)
def get(self, challenge): status = monitor.status(challenge) metadata = monitor.metadata(challenge) if status == None or metadata == None: raise tornado.web.HTTPError(404) if not self.is_admin and not status['visible']: raise tornado.web.HTTPError(404) status_widget = make_status_widget(self, status, metadata, self.is_admin) self.render( 'templates/challenge.html', user=self.user, selected='challenges', challenge_files=metadata.get('public_files', []), challenge_name=metadata.get('name', challenge), challenge_author=metadata.get('author', 'Anonymous'), challenge_points=metadata.get('points', 0), challenge_solves=len( scoreboard.get_captures_by_challenge(challenge)), challenge_description=metadata.get('description', ''), show_capture=auth.is_playing(self.user or ''), status=status_widget, )
def action_capture(self, challenge, flag): if not self.is_playing: raise tornado.web.HTTPError(403) status = monitor.status(challenge) metadata = monitor.metadata(challenge) if status == None or metadata == None or not status['visible']: raise tornado.web.HTTPError(403) if metadata['flag'].strip() == flag.strip(): scoreboard.capture(self.user, challenge) scoreboard_cache.dirty = True
def get(self, challenge): status = monitor.status(challenge) metadata = monitor.metadata(challenge) if status == None or metadata == None: raise tornado.web.HTTPError(404) if not self.is_admin and not status['visible']: raise tornado.web.HTTPError(404) status_widget = make_status_widget(self, status, metadata, self.is_admin) self.render('templates/challenge.html', user=self.user, selected='challenges', challenge_files=metadata.get('public_files', []), challenge_name=metadata.get('name', challenge), challenge_author=metadata.get('author', 'Anonymous'), challenge_points=metadata.get('points', 0), challenge_solves=len(scoreboard.get_captures_by_challenge(challenge)), challenge_description=metadata.get('description', ''), show_capture=auth.is_playing(self.user or ''), status=status_widget, )
def get(self): if self.is_admin: challenge_list = monitor.challenges else: challenge_list = monitor.visible_challenges metadata = { name : monitor.metadata(name) for name in challenge_list } challenge_list = sorted(challenge_list, key=lambda n: (metadata[n]['points'], n)) challenges = [ { 'name' : name, 'points' : metadata[name]['points'], 'captures' : len(scoreboard.get_captures_by_challenge(name)), 'status' : make_status_widget(self, monitor.status(name), metadata[name]) } for name in challenge_list ] self.render('templates/challenge_index.html', user=self.user, selected='challenges', challenges=challenges )