Example #1
0
 def post(self, *args, **kwargs):
     '''
     Reset the Game
     '''
     errors = []
     success = None
     try:
         users = User.all()
         for user in users:
             user.money = 0
         teams = Team.all()
         for team in teams:
             if options.banking:
                 team.money = options.starting_team_money
             else:
                 team.money = 0
             team.flags = []
             team.hints = []
             team.boxes = []
             team.items = []
             team.purchased_source_code = []
             level_0 = GameLevel.by_number(0)
             if not level_0:
                 level_0 = GameLevel.all()[0]
             team.game_levels = [level_0]
             self.dbsession.add(team)
         self.dbsession.commit()
         self.dbsession.flush()
         for team in teams:
             for paste in team.pastes:
                 self.dbsession.delete(paste)
             for shared_file in team.files:
                 shared_file.delete_data()
                 self.dbsession.delete(shared_file)
         self.dbsession.commit()
         self.dbsession.flush()
         Penalty.clear()
         Notification.clear()
         snapshot = Snapshot.all()
         for snap in snapshot:
             self.dbsession.delete(snap)
         self.dbsession.commit()
         snapshot_team = SnapshotTeam.all()
         for snap in snapshot_team:
             self.dbsession.delete(snap)
         self.dbsession.commit()
         game_history = GameHistory.instance()
         game_history.take_snapshot()  # Take starting snapshot
         flags = Flag.all()
         for flag in flags:
             flag.value = flag._original_value if flag._original_value else flag.value
             self.dbsession.add(flag)
         self.dbsession.commit()
         self.dbsession.flush()
         success = "Successfully Reset Game"
         self.render('admin/reset.html', success=success, errors=errors)
     except BaseException as e:
         errors.append("Failed to Reset Game")
         logging.error(str(e))
         self.render('admin/reset.html', success=None, errors=errors)
Example #2
0
 def __now__(self):
     ''' Returns snapshot object it as a dict '''
     snapshot = Snapshot()
     bot_manager = BotManager.instance()
     #self.dbsession = DBSession()
     for team in Team.all():
         snapshot_team = SnapshotTeam(team_id=team.id,
                                      money=team.money,
                                      bots=bot_manager.count_by_team(team))
         snapshot_team.game_levels = team.game_levels
         snapshot_team.flags = team.flags
         self.dbsession.add(snapshot_team)
         self.dbsession.flush()
         snapshot.teams.append(snapshot_team)
     self.dbsession.add(snapshot)
     self.dbsession.commit()
     return snapshot
Example #3
0
 def __now__(self):
     ''' Returns snapshot object it as a dict '''
     snapshot = Snapshot()
     bot_manager = BotManager.instance()
     #self.dbsession = DBSession()
     for team in Team.all():
         snapshot_team = SnapshotTeam(
             team_id=team.id,
             money=team.money,
             bots=bot_manager.count_by_team(team)
         )
         snapshot_team.game_levels = team.game_levels
         snapshot_team.flags = team.flags
         self.dbsession.add(snapshot_team)
         self.dbsession.flush()
         snapshot.teams.append(snapshot_team)
     self.dbsession.add(snapshot)
     self.dbsession.commit()
     return snapshot
Example #4
0
 def post(self, *args, **kwargs):
     """
     Reset the Game
     """
     errors = []
     success = None
     try:
         users = User.all()
         for user in users:
             user.money = 0
         teams = Team.all()
         for team in teams:
             if options.banking:
                 team.money = options.starting_team_money
             else:
                 team.money = 0
             team.flags = []
             team.hints = []
             team.boxes = []
             team.items = []
             team.purchased_source_code = []
             level_0 = GameLevel.by_number(0)
             if not level_0:
                 level_0 = GameLevel.all()[0]
             team.game_levels = [level_0]
             self.dbsession.add(team)
         self.dbsession.commit()
         self.dbsession.flush()
         for team in teams:
             for paste in team.pastes:
                 self.dbsession.delete(paste)
             for shared_file in team.files:
                 shared_file.delete_data()
                 self.dbsession.delete(shared_file)
         self.dbsession.commit()
         self.dbsession.flush()
         Penalty.clear()
         Notification.clear()
         snapshot = Snapshot.all()
         for snap in snapshot:
             self.dbsession.delete(snap)
         self.dbsession.commit()
         snapshot_team = SnapshotTeam.all()
         for snap in snapshot_team:
             self.dbsession.delete(snap)
         self.dbsession.commit()
         game_history = GameHistory.instance()
         game_history.take_snapshot()  # Take starting snapshot
         flags = Flag.all()
         for flag in flags:
             # flag.value = flag.value allows a fallback to when original_value was used
             # Allows for the flag value to be reset if dynamic scoring was used
             # Can be removed after depreciation timeframe
             flag.value = flag.value
             self.dbsession.add(flag)
         self.dbsession.commit()
         self.dbsession.flush()
         self.event_manager.push_score_update()
         self.flush_memcached()
         success = "Successfully Reset Game"
         self.render("admin/reset.html", success=success, errors=errors)
     except BaseException as e:
         errors.append("Failed to Reset Game")
         logging.error(str(e))
         self.render("admin/reset.html", success=None, errors=errors)