コード例 #1
0
 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:
                 price = "$" + str(flag.value)
             else:
                 price = str(flag.value) + " points"
             flaginfo = [
                 {
                     "name": flag.name,
                     "description": flag.description,
                     "token": flag.token,
                     "price": price,
                 }
             ]
             captures = []
             for item in Flag.captures(flag.id):
                 team = Team.by_id(item[0])
                 if team:
                     captures.append({"name": team.name})
             attempts = self.attempts(flag)
             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:
                         price = "$" + str(hint.price)
                     else:
                         price = str(hint.price) + " points"
                     hints.append({"name": team.name, "price": price})
             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()
コード例 #2
0
 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()
コード例 #3
0
 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()
コード例 #4
0
 def create_hint(self):
     ''' Add hint to database '''
     try:
         box = Box.by_uuid(self.get_argument('box_uuid', ''))
         if box is None:
             raise ValidationError("Box does not exist")
         hint = Hint(box_id=box.id)
         hint.price = self.get_argument('price', '')
         hint.description = self.get_argument('description', '')
         self.dbsession.add(hint)
         self.dbsession.commit()
         self.redirect('/admin/view/game_objects')
     except ValidationError as error:
         self.render('admin/create/hint.html', errors=[str(error), ])
コード例 #5
0
 def create_hint(self):
     ''' Add hint to database '''
     box = Box.by_uuid(self.get_argument('box_uuid', ''))
     if box is not None:
         try:
             hint = Hint(box_id=box.id)
             hint.price = self.get_argument('price', '')
             hint.description = self.get_argument('description', '')
             self.dbsession.add(hint)
             self.dbsession.commit()
             self.redirect('/admin/view/game_objects')
         except ValueError as error:
             self.render('admin/create/hint.html', errors=["%s" % error])
     else:
         self.render('admin/create/hint.html', errors=["Box does not exist"])
コード例 #6
0
ファイル: Flag.py プロジェクト: moloch--/RootTheBox
 def to_xml(self, parent):
     ''' Write attributes to XML doc '''
     flag_elem = ET.SubElement(parent, "flag")
     flag_elem.set("type", self._type)
     ET.SubElement(flag_elem, "name").text = self.name
     ET.SubElement(flag_elem, "token").text = self.token
     ET.SubElement(flag_elem, "description").text = self.description
     ET.SubElement(flag_elem, "capture_message").text = self.capture_message
     ET.SubElement(flag_elem, "value").text = str(self.value)
     ET.SubElement(flag_elem, "original_value").text = str(self.original_value)
     if self.lock_id:
         ET.SubElement(flag_elem, "depends_on").text = Flag.by_id(self.lock_id).name
     ET.SubElement(flag_elem, "case_sensitive").text = str(self.case_sensitive)
     attachements_elem = ET.SubElement(flag_elem, "flag_attachments")
     attachements_elem.set("count", str(len(self.flag_attachments)))
     for attachement in self.flag_attachments:
         attachement.to_xml(attachements_elem)
     choice_elem = ET.SubElement(flag_elem, "flag_choices")
     choice_elem.set("count", str(len(self.flag_choice)))
     for choice in self.flag_choice:
         ET.SubElement(choice_elem, "choice").text = choice.choice
     from models.Hint import Hint
     xml_hints = Hint.by_flag_id(self.id)
     hints_elem = ET.SubElement(flag_elem, "hints")
     hints_elem.set("count", str(len(xml_hints)))
     for hint in xml_hints:
         if not hint.flag_id is None:
             hint.to_xml(hints_elem)
コード例 #7
0
ファイル: Flag.py プロジェクト: skyroot/RootTheBox
 def to_xml(self, parent):
     ''' Write attributes to XML doc '''
     flag_elem = ET.SubElement(parent, "flag")
     flag_elem.set("type", self._type)
     ET.SubElement(flag_elem, "name").text = self.name
     ET.SubElement(flag_elem, "token").text = self.token
     ET.SubElement(flag_elem, "description").text = self.description
     ET.SubElement(flag_elem, "capture_message").text = self.capture_message
     ET.SubElement(flag_elem, "value").text = str(self.value)
     ET.SubElement(flag_elem,
                   "original_value").text = str(self.original_value)
     if self.lock_id:
         ET.SubElement(flag_elem,
                       "depends_on").text = Flag.by_id(self.lock_id).name
     ET.SubElement(flag_elem,
                   "case_sensitive").text = str(self.case_sensitive)
     attachements_elem = ET.SubElement(flag_elem, "flag_attachments")
     attachements_elem.set("count", str(len(self.flag_attachments)))
     for attachement in self.flag_attachments:
         attachement.to_xml(attachements_elem)
     choice_elem = ET.SubElement(flag_elem, "flag_choices")
     choice_elem.set("count", str(len(self.flag_choice)))
     for choice in self.flag_choice:
         ET.SubElement(choice_elem, "choice").text = choice.choice
     from models.Hint import Hint
     xml_hints = Hint.by_flag_id(self.id)
     hints_elem = ET.SubElement(flag_elem, "hints")
     hints_elem.set("count", str(len(xml_hints)))
     for hint in xml_hints:
         if not hint.flag_id is None:
             hint.to_xml(hints_elem)
コード例 #8
0
 def post(self, *args, **kwargs):
     ''' Purchase a hint '''
     uuid = self.get_argument('uuid', '')
     hint = Hint.by_uuid(uuid)
     if hint is not None:
         user = self.get_current_user()
         if self.application.settings['game_started'] or user.is_admin():
             flag = hint.flag
             if flag and flag.box.flag_submission_type != FlagsSubmissionType.SINGLE_SUBMISSION_BOX and Penalty.by_count(
                     flag, user.team) >= self.config.max_flag_attempts:
                 self.render_page(
                     hint.box,
                     info=["You can no longer purchase this hint."])
             elif hint.price <= user.team.money:
                 logging.info("%s (%s) purchased a hint for $%d on %s" %
                              (user.handle, user.team.name, hint.price,
                               hint.box.name))
                 self._purchase_hint(hint, user.team)
                 self.render_page(hint.box)
             else:
                 self.render_page(
                     hint.box,
                     info=["You cannot afford to purchase this hint."])
         else:
             self.render('missions/status.html',
                         errors=None,
                         info=["The game has not started yet"])
     else:
         self.render('public/404.html')
コード例 #9
0
 def create_hint(self):
     ''' Add hint to database '''
     try:
         box = Box.by_uuid(self.get_argument('box_uuid', ''))
         if box is None:
             raise ValidationError("Box does not exist")
         hint = Hint(box_id=box.id)
         hint.price = self.get_argument('price', '')
         hint.description = self.get_argument('description', '')
         self.dbsession.add(hint)
         self.dbsession.commit()
         self.redirect('/admin/view/game_objects')
     except ValidationError as error:
         self.render('admin/create/hint.html', errors=[
             str(error),
         ])
コード例 #10
0
 def post(self, *args, **kwargs):
     """ Purchase a hint """
     uuid = self.get_argument("uuid", "")
     hint = Hint.by_uuid(uuid)
     if hint is not None:
         user = self.get_current_user()
         flag = hint.flag
         if (flag and flag.box.flag_submission_type !=
                 FlagsSubmissionType.SINGLE_SUBMISSION_BOX
                 and Penalty.by_count(
                     flag, user.team) >= self.config.max_flag_attempts):
             self.render_page(
                 hint.box, info=["You can no longer purchase this hint."])
         elif hint.price <= user.team.money:
             logging.info(
                 "%s (%s) purchased a hint for $%d on %s" %
                 (user.handle, user.team.name, hint.price, hint.box.name))
             self._purchase_hint(hint, user.team)
             self.render_page(hint.box)
         else:
             self.render_page(
                 hint.box,
                 info=["You cannot afford to purchase this hint."])
     else:
         self.render("public/404.html")
コード例 #11
0
 def edit_hint(self):
     """ Edit a hint object """
     try:
         hint = Hint.by_uuid(self.get_argument("uuid", ""))
         if hint is None:
             raise ValidationError("Hint does not exist")
         logging.debug("Edit hint object with uuid of %s" % hint.uuid)
         price = self.get_argument("price", "")
         if hint.price != price:
             hint.price = price
         description = self.get_argument("description", "")
         hint.description = description
         flag = Flag.by_uuid(self.get_argument("hint-flag_uuid", ""))
         if flag:
             flag_id = flag.id
         else:
             flag_id = None
         hint.flag_id = flag_id
         box = Box.by_id(flag.box_id)
         self.dbsession.add(hint)
         self.dbsession.commit()
         self.redirect("/admin/view/game_objects#%s" % box.uuid)
     except ValidationError as error:
         self.render("admin/view/game_objects.html",
                     success=None,
                     errors=[str(error)])
コード例 #12
0
 def del_hint(self):
     ''' Delete a hint from the database '''
     hint = Hint.by_uuid(self.get_argument('uuid', ''))
     if hint is not None:
         logging.info("Delete hint: %s" % hint.uuid)
         self.dbsession.delete(hint)
         self.dbsession.commit()
         self.redirect('/admin/view/game_objects')
     else:
         self.render('admin/view/game_objects.html',
                     errors=["Hint does not exist in database."])
コード例 #13
0
 def del_hint(self):
     ''' Delete a hint from the database '''
     hint = Hint.by_uuid(self.get_argument('uuid', ''))
     if hint is not None:
         logging.info("Delete hint: %s" % hint.uuid)
         self.dbsession.delete(hint)
         self.dbsession.commit()
         self.redirect('/admin/view/game_objects')
     else:
         self.render('admin/view/game_objects.html',
             errors=["Hint does not exist in database."]
         )
コード例 #14
0
 def del_hint(self):
     """ Delete a hint from the database """
     hint = Hint.by_uuid(self.get_argument("uuid", ""))
     if hint is not None:
         logging.info("Delete hint: %s" % hint.uuid)
         self.dbsession.delete(hint)
         self.dbsession.commit()
         self.redirect("/admin/view/game_objects")
     else:
         self.render(
             "admin/view/game_objects.html",
             errors=["Hint does not exist in database."],
         )
コード例 #15
0
 def post(self, *args, **kwargs):
     ''' Purchase a hint '''
     uuid = self.get_argument('uuid', '')
     hint = Hint.by_uuid(uuid)
     if hint is not None:
         user = self.get_current_user()
         if hint.price <= user.team.money:
             logging.info("%s (%s) purchased a hint for $%d on %s" % (
                 user.handle, user.team.name, hint.price, hint.box.name
             ))
             self._purchase_hint(hint, user.team)
             self.render_page(hint.box)
         else:
             self.render_page(hint.box, ["You cannot afford to purchase this hint."])
     else:
         self.render('public/404.html')
コード例 #16
0
 def edit_hint(self):
     ''' Edit a hint object '''
     try:
         hint = Hint.by_uuid(self.get_argument('uuid', ''))
         if hint is None:
             raise ValidationError("Hint does not exist")
         logging.debug("Edit hint object with uuid of %s" % hint.uuid)
         price = self.get_argument('price', '')
         if hint.price != price:
             hint.price = price
         description = self.get_argument('description', '')
         hint.description = description
         self.dbsession.add(hint)
         self.dbsession.commit()
         self.redirect('/admin/view/game_objects')
     except ValidationError as error:
         self.render("admin/view/game_objects.html", errors=[str(error), ])
コード例 #17
0
 def edit_hint(self):
     ''' Edit a hint object '''
     try:
         hint = Hint.by_uuid(self.get_argument('uuid', ''))
         if hint is None:
             raise ValidationError("Hint does not exist")
         logging.debug("Edit hint object with uuid of %s" % hint.uuid)
         price = self.get_argument('price', '')
         if hint.price != price:
             hint.price = price
         description = self.get_argument('description', '')
         hint.description = description
         self.dbsession.add(hint)
         self.dbsession.commit()
         self.redirect('/admin/view/game_objects')
     except ValidationError as error:
         self.render("admin/view/game_objects.html", errors=[
             str(error),
         ])
コード例 #18
0
 def edit_hint(self):
     ''' Edit a hint object '''
     hint = Hint.by_uuid(self.get_argument('uuid', ''))
     if hint is not None:
         try:
             logging.debug("Edit hint object with uuid of %s" % hint.uuid)
             price = self.get_argument('price', hint.price)
             if hint.price != price:
                 hint.price = price
             description = self.get_argument('description', hint.description)
             if hint.description != description:
                 hint.description = description
             self.dbsession.add(hint)
             self.dbsession.commit()
             self.redirect('/admin/view/game_objects')
         except ValueError as error:
             self.render("admin/view/game_objects.html", errors=["%s" % error])
     else:
         self.render("admin/view/game_objects.html", errors=["User does not exist"])
コード例 #19
0
 def post(self, *args, **kwargs):
     ''' Purchase a hint '''
     uuid = self.get_argument('uuid', '')
     hint = Hint.by_uuid(uuid)
     if hint is not None:
         user = self.get_current_user()
         if self.application.settings['game_started'] or user.is_admin():
             flag = hint.flag
             if flag and flag.box.flag_submission_type != FlagsSubmissionType.SINGLE_SUBMISSION_BOX and Penalty.by_count(flag, user.team) >= self.config.max_flag_attempts:
                 self.render_page(
                     hint.box, info=["You can no longer purchase this hint."])
             elif hint.price <= user.team.money:
                 logging.info("%s (%s) purchased a hint for $%d on %s" % (
                     user.handle, user.team.name, hint.price, hint.box.name
                 ))
                 self._purchase_hint(hint, user.team)
                 self.render_page(hint.box)
             else:
                 self.render_page(
                     hint.box, info=["You cannot afford to purchase this hint."])
         else:
             self.render('missions/status.html', errors=None, info=["The game has not started yet"])
     else:
         self.render('public/404.html')
コード例 #20
0
 def create_hint(self):
     """ Add hint to database """
     try:
         box = Box.by_uuid(self.get_argument("box_uuid", ""))
         if box is None:
             raise ValidationError("Box does not exist")
         hint = Hint(box_id=box.id)
         hint.price = self.get_argument("price", "")
         hint.description = self.get_argument("description", "")
         flag = Flag.by_uuid(self.get_argument("flag_uuid", ""))
         if flag:
             hint.flag_id = flag.id
         else:
             hint.flag_id = None
         self.dbsession.add(hint)
         self.dbsession.commit()
         self.redirect("/admin/view/game_objects#%s" % box.uuid)
     except ValidationError as error:
         self.render("admin/create/hint.html", errors=[str(error)])
コード例 #21
0
ファイル: Scoreboard.py プロジェクト: optionalg/RootTheBox
    def update_gamestate(self, app):
        game_state = {
            "teams": {},
            "levels": {},
            "boxes": {},
            "hint_count": len(Hint.all()),
            "flag_count": len(Flag.all()),
            "box_count": len(Box.all()),
            "level_count": len(GameLevel.all()),
        }
        teams = Team.ranks()
        for team in teams:
            if len(team.members) > 0:
                millis = int(round(time.time() * 1000))
                game_state["teams"][team.name] = {
                    "uuid": team.uuid,
                    "flags": [str(flag) for flag in team.flags],
                    "game_levels": [str(lvl) for lvl in team.game_levels],
                    "members_count": len(team.members),
                    "hints_count": len(team.hints),
                    "bot_count":
                    BotManager.instance().count_by_team(team.name),
                    "money": team.money,
                }

                highlights = {"money": 0, "flag": 0, "bot": 0, "hint": 0}
                for item in highlights:
                    value = team.get_score(item)
                    game_state["teams"][team.name][item] = value
                    game_history = app.settings["scoreboard_history"]
                    if team.name in game_history:
                        prev = game_history[team.name][item]
                        if prev < value:
                            highlights[item] = millis
                        else:
                            highlights[item] = game_history[
                                team.name]["highlights"][item]
                highlights["now"] = millis
                game_state["teams"][team.name]["highlights"] = highlights
                app.settings["scoreboard_history"][
                    team.name] = game_state["teams"].get(team.name)
        for level in GameLevel.all():
            game_state["levels"][level.name] = {
                "type": level.type,
                "number": level.number,
                "teams": {},
                "boxes": {},
                "box_count": len(level.boxes),
                "flag_count": len(level.flags),
            }
            for team in teams:
                game_state["levels"][level.name]["teams"][team.name] = {
                    "lvl_count": len(team.level_flags(level.number)),
                    "lvl_unlock": level in team.game_levels,
                }
            for box in level.boxes:
                game_state["levels"][level.name]["boxes"][box.uuid] = {
                    "name": box.name,
                    "teams": {},
                    "flag_count": len(box.flags),
                }
                for team in teams:
                    game_state["levels"][level.name]["boxes"][
                        box.uuid]["teams"][team.name] = {
                            "box_count": len(team.box_flags(box))
                        }
        app.settings["scoreboard_state"] = game_state
コード例 #22
0
ファイル: Box.py プロジェクト: CRYPTOlab/RootTheBox
 def hints(self):
     ''' Returns all hints on this box '''
     return Hint.by_box_id(self.id)
コード例 #23
0
 def hints(self):
     ''' Returns all hints on this box '''
     return Hint.by_box_id(self.id)