def attempts(self, flag): attempts = [] teamcount = {} for item in Penalty.by_flag_id(flag.id): team = Team.by_id(item.team_id) if team.id in teamcount: teamcount.update({team.id: teamcount[team.id] + 1}) else: teamcount.update({team.id: 1}) if team: if team.id in teamcount: teamcount.update({team.id: teamcount[team.id] + 1}) else: teamcount.update({team.id: 1}) entries = { "name": team.name, "token": item.token, "flag": flag.uuid, "team": team.uuid, "type": flag.type, } if options.penalize_flag_value: penalty = "-" if options.banking: penalty += "$" if (teamcount[team.id] < options.flag_start_penalty or teamcount[team.id] > options.flag_stop_penalty): penalty += "0" else: penalty += str( int(flag.value * (options.flag_penalty_cost * 0.01))) entries.update({"penalty": penalty}) attempts.append(entries) return attempts
def post(self, *args, **kwargs): game_objects = { 'game_level': GameLevel, 'corporation': Corporation, 'flag': Flag, 'box': Box, 'hint': Hint, } obj_name = self.get_argument('obj', '') uuid = self.get_argument('uuid', '') if obj_name in game_objects.keys(): obj = game_objects[obj_name].by_uuid(uuid) if obj is not None: self.write(obj.to_dict()) else: self.write({'Error': 'Invalid uuid.'}) elif obj_name == "stats": flag = Flag.by_uuid(uuid) if flag is not None: if options.banking: flaginfo = [{"name": flag.name, "token": flag.token, "price": "$" + str(flag.value)}] else: flaginfo = [{"name": flag.name, "token": flag.token, "price": str(flag.value) + " points"}] captures = [] for item in Flag.captures(flag.id): team = Team.by_id(item[0]) if team: captures.append({"name": team.name}) attempts = [] for item in Penalty.by_flag_id(flag.id): team = Team.by_id(item.team_id) if team: attempts.append({"name": team.name, "token": item.token}) hints = [] for item in Hint.taken_by_flag(flag.id): team = Team.by_id(item.team_id) hint = Hint.by_id(item.hint_id) if team: if options.banking: hints.append({"name": team.name, "price": "$" + str(hint.price)}) else: hints.append({"name": team.name, "price": str(hint.price) + " points"}) obj = { "flag": flaginfo, "captures": captures, "attempts": attempts, "hints": hints, } self.write(obj) else: self.write({'Error': 'Invalid uuid.'}) else: self.write({'Error': 'Invalid object type.'}) self.finish()